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.license.ILicense;
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       * Increment the document type counter.
36       * The default implementations does nothing.
37       * @param type The document type counter to increment.
38       */
39      protected void handleDocumentCategoryClaim(Document.Type type) {
40          // Does nothing
41      }
42  
43      /**
44       * Increment the approved license claim.
45       * The default implementation does nothing.
46       * @param metadata The metadata for the document
47       */
48      protected void handleApprovedLicenseClaim(MetaData metadata) {
49          // Does nothing
50      }
51  
52      /**
53       * Increment the counts associated with the license
54       * The default implementation does nothing.
55       * @param license the license to record the category for.
56       */
57      protected void handleLicenseClaim(ILicense license) {
58          // Does nothing
59      }
60  
61      @Override
62      public void report(Document subject) {
63          final MetaData metaData = subject.getMetaData();
64          metaData.licenses().forEach(this::handleLicenseClaim);
65          handleDocumentCategoryClaim(metaData.getDocumentType());
66          handleApprovedLicenseClaim(metaData);
67      }
68  }