View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *  http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.apache.any23;
19  
20  import org.apache.any23.extractor.IssueReport;
21  import org.apache.any23.extractor.Extractor;
22  import org.apache.any23.validator.ValidationReport;
23  
24  import java.util.Collection;
25  import java.util.Collections;
26  import java.util.List;
27  import java.util.Map;
28  
29  /**
30   * This class contains some statistics and general information about an extraction.
31   *
32   * @see Any23
33   * 
34   * @author Michele Mostarda (mostarda@fbk.eu)
35   * @author Davide Palmisano (palmisano@fbk.eu)
36   */
37  public class ExtractionReport {
38  
39      private final List<Extractor> matchingExtractors;
40  
41      private final String encoding;
42  
43      private final String detectedMimeType;
44  
45      private final ValidationReport validationReport;
46  
47      private final Map<String, Collection<IssueReport.Issue>> extractorIssues;
48  
49      public ExtractionReport(final List<Extractor> matchingExtractors, String encoding, String detectedMimeType,
50              ValidationReport validationReport, Map<String, Collection<IssueReport.Issue>> extractorIssues) {
51          if (matchingExtractors == null)
52              throw new NullPointerException("list of matching extractors cannot be null.");
53          if (encoding == null)
54              throw new NullPointerException("encoding cannot be null.");
55          // if(detectedMimeType == null) throw new NullPointerException("detected mime type cannot be null.");
56          if (validationReport == null)
57              throw new NullPointerException("validation report cannot be null.");
58  
59          this.matchingExtractors = Collections.unmodifiableList(matchingExtractors);
60          this.encoding = encoding;
61          this.detectedMimeType = detectedMimeType;
62          this.validationReport = validationReport;
63          this.extractorIssues = Collections.unmodifiableMap(extractorIssues);
64      }
65  
66      /**
67       * @return <code>true</code> if the extraction has activated at least an extractor, <code>false</code> otherwise.
68       */
69      public boolean hasMatchingExtractors() {
70          return matchingExtractors.size() > 0;
71      }
72  
73      /**
74       * @return the (unmodifiable) list of matching extractors.
75       */
76      public List<Extractor> getMatchingExtractors() {
77          return matchingExtractors;
78      }
79  
80      /**
81       * @return the detected encoding for the source stream.
82       */
83      public String getEncoding() {
84          return encoding;
85      }
86  
87      /**
88       * @return the tetected mimetype for the input stream.
89       */
90      public String getDetectedMimeType() {
91          return detectedMimeType;
92      }
93  
94      /**
95       * @return the validation report applied to the processed document.
96       */
97      public ValidationReport getValidationReport() {
98          return validationReport;
99      }
100 
101     /**
102      * @param extractorName
103      *            name of the extractor.
104      * 
105      * @return the (unmodifiable) map of issues per extractor.
106      */
107     public Collection<IssueReport.Issue> getExtractorIssues(String extractorName) {
108         final Collection<IssueReport.Issue> errors = extractorIssues.get(extractorName);
109         return errors == null ? Collections.<IssueReport.Issue> emptyList()
110                 : Collections.unmodifiableCollection(errors);
111     }
112 
113 }