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  /**
31   * This class contains some statistics and general information about
32   * an extraction.
33   *
34   * @see Any23
35   * @author Michele Mostarda (mostarda@fbk.eu)
36   * @author Davide Palmisano (palmisano@fbk.eu)
37   */
38  public class ExtractionReport {
39  
40      private final List<Extractor> matchingExtractors;
41  
42      private final String encoding;
43  
44      private final String detectedMimeType;
45  
46      private final ValidationReport validationReport;
47  
48      private final Map<String,Collection<IssueReport.Issue>> extractorIssues;
49  
50      public ExtractionReport(
51              final List<Extractor> matchingExtractors,
52              String encoding,
53              String detectedMimeType,
54              ValidationReport validationReport,
55              Map<String,Collection<IssueReport.Issue>> extractorIssues
56      ) {
57          if(matchingExtractors == null) throw new NullPointerException("list of matching extractors cannot be null.");
58          if(encoding == null) throw new NullPointerException("encoding cannot be null.");
59          // if(detectedMimeType == null) throw new NullPointerException("detected mime type cannot be null.");
60          if(validationReport == null) throw new NullPointerException("validation report cannot be null.");
61  
62          this.matchingExtractors    = Collections.unmodifiableList(matchingExtractors);
63          this.encoding              = encoding;
64          this.detectedMimeType      = detectedMimeType;
65          this.validationReport      = validationReport;
66          this.extractorIssues       = Collections.unmodifiableMap(extractorIssues);
67      }
68  
69      /**
70       * @return <code>true</code> if the extraction has activated
71       *         at least an extractor, <code>false</code> otherwise.
72       */
73      public boolean hasMatchingExtractors() {
74          return matchingExtractors.size() > 0;
75      }
76  
77      /**
78       * @return the (unmodifiable) list of matching extractors.
79       */
80      public List<Extractor> getMatchingExtractors() {
81          return matchingExtractors;
82      }
83  
84      /**
85       * @return the detected encoding for the source stream.
86       */
87      public String getEncoding() {
88          return encoding;
89      }
90  
91      /**
92       * @return the tetected mimetype for the input stream.      
93       */
94      public String getDetectedMimeType() {
95          return detectedMimeType;
96      }
97  
98      /**
99       * @return the validation report applied to the processed document.
100      */
101     public ValidationReport getValidationReport() {
102         return validationReport;
103     }
104 
105     /**
106      * @param extractorName name of the extractor.
107      * @return the (unmodifiable) map of issues per extractor.
108      */
109     public Collection<IssueReport.Issue> getExtractorIssues(String extractorName) {
110         final Collection<IssueReport.Issue> errors = extractorIssues.get(extractorName);
111         return  errors == null
112                 ?
113                 Collections.<IssueReport.Issue>emptyList()
114                 :
115                 Collections.unmodifiableCollection(errors);
116     }
117 
118 }