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      protected void handleDocumentCategoryClaim(String documentCategoryName) {
35          // Does nothing
36      }
37  
38      protected void handleApprovedLicenseClaim(String licenseApproved) {
39          // Does nothing
40      }
41  
42      protected void handleLicenseFamilyNameClaim(String licenseFamilyName) {
43          // Does Nothing
44      }
45  
46      protected void handleHeaderCategoryClaim(String headerCategory) {
47          // Does nothing
48      }
49  
50      private void writeDocumentClaim(Document subject)  {
51          final MetaData metaData = subject.getMetaData();
52          writeHeaderCategory(metaData);
53          writeLicenseFamilyName(metaData);
54          writeDocumentCategory(metaData);
55          writeApprovedLicenseClaim(metaData);
56      }
57  
58      private void writeApprovedLicenseClaim(final MetaData metaData) {
59          final MetaData.Datum approvedLicenseDatum = metaData.get(MetaData.RAT_URL_APPROVED_LICENSE);
60          if (approvedLicenseDatum != null) {
61              final String approvedLicense = approvedLicenseDatum.getValue();
62              if (approvedLicense != null) {
63                  handleApprovedLicenseClaim(approvedLicense);
64              }
65          }
66      }
67  
68      private void writeHeaderCategory(final MetaData metaData) {
69          final MetaData.Datum headerCategoryDatum = metaData.get(MetaData.RAT_URL_HEADER_CATEGORY);
70          if (headerCategoryDatum != null) {
71              final String headerCategory = headerCategoryDatum.getValue();
72              if (headerCategory != null) {
73                  handleHeaderCategoryClaim(headerCategory);
74              }
75          }
76      }
77  
78      private void writeLicenseFamilyName(final MetaData metaData) {
79          final MetaData.Datum licenseFamilyNameDatum = metaData.get(MetaData.RAT_URL_LICENSE_FAMILY_NAME);
80          if (licenseFamilyNameDatum != null) {
81              final String licenseFamilyName = licenseFamilyNameDatum.getValue();
82              if (licenseFamilyName != null) {
83                  handleLicenseFamilyNameClaim(licenseFamilyName);
84              }
85          }
86      }
87      
88      private void writeDocumentCategory(final MetaData metaData) {
89          final MetaData.Datum documentCategoryDatum = metaData.get(MetaData.RAT_URL_DOCUMENT_CATEGORY);
90          if (documentCategoryDatum != null) {
91              final String documentCategory = documentCategoryDatum.getValue();
92              if (documentCategory != null) {
93                  handleDocumentCategoryClaim(documentCategory);
94              }
95          }
96      }
97      
98      @Override
99      public void report(Document subject) throws RatException {
100         writeDocumentClaim(subject);
101     }
102 }