View Javadoc
1   /*
2   * Licensed to the Apache Software Foundation (ASF) under one   *
3   * or more contributor license agreements.  See the NOTICE file *
4   * distributed with this work for additional information        *
5   * regarding copyright ownership.  The ASF licenses this file   *
6   * to you under the Apache License, Version 2.0 (the            *
7   * "License"); you may not use this file except in compliance   *
8   * with the License.  You may obtain a copy of the License at   *
9   *                                                              *
10  *   http://www.apache.org/licenses/LICENSE-2.0                 *
11  *                                                              *
12  * Unless required by applicable law or agreed to in writing,   *
13  * software distributed under the License is distributed on an  *
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
15  * KIND, either express or implied.  See the License for the    *
16  * specific language governing permissions and limitations      *
17  * under the License.                                           *
18  */
19  
20  package org.apache.rat.report.claim.impl;
21  
22  import org.apache.rat.api.Document;
23  import org.apache.rat.api.MetaData;
24  import org.apache.rat.api.RatException;
25  import org.apache.rat.report.AbstractReport;
26  
27  
28  /**
29   * Abstract base implementation of {@link AbstractReport}.
30   * It is strongly suggested, that implementations derive from
31   * this class.
32   */
33  public abstract class AbstractClaimReporter extends AbstractReport {
34      /**
35       * Empty default implementation.
36       * @param documentCategoryName name of the category
37       */
38      protected void handleDocumentCategoryClaim(String documentCategoryName) {
39          // Does nothing
40      }
41  
42      /**
43       * Empty default implementation.
44       * @param licenseApproved name of the approved license
45       */
46      protected void handleApprovedLicenseClaim(String licenseApproved) {
47          // Does nothing
48      }
49  
50      /**
51       * Empty default implementation.
52       * @param licenseFamilyName name of the license family
53       */
54      protected void handleLicenseFamilyNameClaim(String licenseFamilyName) {
55          // Does Nothing
56      }
57  
58      /**
59       * Empty default implementation.
60       * @param headerCategory name of the header category
61       */
62      protected void handleHeaderCategoryClaim(String headerCategory) {
63          // Does nothing
64      }
65  
66      private void writeDocumentClaim(Document subject)  {
67          final MetaData metaData = subject.getMetaData();
68          writeHeaderCategory(metaData);
69          writeLicenseFamilyName(metaData);
70          writeDocumentCategory(metaData);
71          writeApprovedLicenseClaim(metaData);
72      }
73  
74      private void writeApprovedLicenseClaim(final MetaData metaData) {
75          final MetaData.Datum approvedLicenseDatum = metaData.get(MetaData.RAT_URL_APPROVED_LICENSE);
76          if (approvedLicenseDatum != null) {
77              final String approvedLicense = approvedLicenseDatum.getValue();
78              if (approvedLicense != null) {
79                  handleApprovedLicenseClaim(approvedLicense);
80              }
81          }
82      }
83  
84      private void writeHeaderCategory(final MetaData metaData) {
85          final MetaData.Datum headerCategoryDatum = metaData.get(MetaData.RAT_URL_HEADER_CATEGORY);
86          if (headerCategoryDatum != null) {
87              final String headerCategory = headerCategoryDatum.getValue();
88              if (headerCategory != null) {
89                  handleHeaderCategoryClaim(headerCategory);
90              }
91          }
92      }
93  
94      private void writeLicenseFamilyName(final MetaData metaData) {
95          final MetaData.Datum licenseFamilyNameDatum = metaData.get(MetaData.RAT_URL_LICENSE_FAMILY_NAME);
96          if (licenseFamilyNameDatum != null) {
97              final String licenseFamilyName = licenseFamilyNameDatum.getValue();
98              if (licenseFamilyName != null) {
99                  handleLicenseFamilyNameClaim(licenseFamilyName);
100             }
101         }
102     }
103     
104     private void writeDocumentCategory(final MetaData metaData) {
105         final MetaData.Datum documentCategoryDatum = metaData.get(MetaData.RAT_URL_DOCUMENT_CATEGORY);
106         if (documentCategoryDatum != null) {
107             final String documentCategory = documentCategoryDatum.getValue();
108             if (documentCategory != null) {
109                 handleDocumentCategoryClaim(documentCategory);
110             }
111         }
112     }
113     
114     @Override
115     public void report(Document subject) throws RatException {
116         writeDocumentClaim(subject);
117     }
118 }