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  package org.apache.rat.report.xml;
20  
21  import org.apache.rat.ReportConfiguration;
22  import org.apache.rat.analysis.DefaultAnalyserFactory;
23  import org.apache.rat.document.IDocumentAnalyser;
24  import org.apache.rat.document.impl.util.DocumentAnalyserMultiplexer;
25  import org.apache.rat.policy.DefaultPolicy;
26  import org.apache.rat.report.RatReport;
27  import org.apache.rat.report.claim.ClaimStatistic;
28  import org.apache.rat.report.claim.impl.ClaimAggregator;
29  import org.apache.rat.report.claim.impl.xml.SimpleXmlClaimReporter;
30  import org.apache.rat.report.claim.util.ClaimReporterMultiplexer;
31  import org.apache.rat.report.claim.util.LicenseAddingReport;
32  import org.apache.rat.report.xml.writer.IXmlWriter;
33  
34  import java.util.ArrayList;
35  import java.util.List;
36  
37  /**
38   * Creates reports.
39   *
40   */
41  public class XmlReportFactory {
42      public static final RatReport createStandardReport(IXmlWriter writer,
43              final ClaimStatistic pStatistic, ReportConfiguration pConfiguration) {
44          final List<RatReport> reporters = new ArrayList<RatReport>();
45          if (pStatistic != null) {
46              reporters.add(new ClaimAggregator(pStatistic));
47          }
48          if (pConfiguration.isAddingLicenses()) {
49              reporters.add(new LicenseAddingReport(pConfiguration.getCopyrightMessage(), pConfiguration.isAddingLicensesForced()));
50          }
51          reporters.add(new SimpleXmlClaimReporter(writer));
52  
53          final IDocumentAnalyser analyser =
54              DefaultAnalyserFactory.createDefaultAnalyser(pConfiguration.getHeaderMatcher());
55          final DefaultPolicy policy = new DefaultPolicy(pConfiguration.getApprovedLicenseNames(), pConfiguration.isApproveDefaultLicenses());
56  
57          final IDocumentAnalyser[] analysers = {analyser, policy};
58          DocumentAnalyserMultiplexer analysisMultiplexer = new DocumentAnalyserMultiplexer(analysers);
59          return new ClaimReporterMultiplexer(analysisMultiplexer, reporters);
60      }
61  }