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 java.util.ArrayList;
22  import java.util.List;
23  
24  import org.apache.rat.ReportConfiguration;
25  import org.apache.rat.analysis.DefaultAnalyserFactory;
26  import org.apache.rat.document.IDocumentAnalyser;
27  import org.apache.rat.document.impl.util.DocumentAnalyserMultiplexer;
28  import org.apache.rat.policy.DefaultPolicy;
29  import org.apache.rat.report.RatReport;
30  import org.apache.rat.report.claim.ClaimStatistic;
31  import org.apache.rat.report.claim.impl.ClaimAggregator;
32  import org.apache.rat.report.claim.impl.xml.SimpleXmlClaimReporter;
33  import org.apache.rat.report.claim.util.ClaimReporterMultiplexer;
34  import org.apache.rat.report.claim.util.LicenseAddingReport;
35  import org.apache.rat.report.xml.writer.IXmlWriter;
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          final IDocumentAnalyser analyser = 
53              DefaultAnalyserFactory.createDefaultAnalyser(pConfiguration.getHeaderMatcher());
54          final DefaultPolicy policy = new DefaultPolicy(pConfiguration.getApprovedLicenseNames());
55          final IDocumentAnalyser[] analysers = {analyser, policy};
56          DocumentAnalyserMultiplexer analysisMultiplexer = new DocumentAnalyserMultiplexer(analysers);
57          return new ClaimReporterMultiplexer(analysisMultiplexer, reporters);
58      }
59  }