All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.any23.ExtractionReport Maven / Gradle / Ivy

/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.any23;

import org.apache.any23.extractor.IssueReport;
import org.apache.any23.extractor.Extractor;
import org.apache.any23.validator.ValidationReport;

import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * This class contains some statistics and general information about an extraction.
 *
 * @see Any23
 * 
 * @author Michele Mostarda ([email protected])
 * @author Davide Palmisano ([email protected])
 */
public class ExtractionReport {

    private final List matchingExtractors;

    private final String encoding;

    private final String detectedMimeType;

    private final ValidationReport validationReport;

    private final Map> extractorIssues;

    public ExtractionReport(final List matchingExtractors, String encoding, String detectedMimeType,
            ValidationReport validationReport, Map> extractorIssues) {
        if (matchingExtractors == null)
            throw new NullPointerException("list of matching extractors cannot be null.");
        if (encoding == null)
            throw new NullPointerException("encoding cannot be null.");
        // if(detectedMimeType == null) throw new NullPointerException("detected mime type cannot be null.");
        if (validationReport == null)
            throw new NullPointerException("validation report cannot be null.");

        this.matchingExtractors = Collections.unmodifiableList(matchingExtractors);
        this.encoding = encoding;
        this.detectedMimeType = detectedMimeType;
        this.validationReport = validationReport;
        this.extractorIssues = Collections.unmodifiableMap(extractorIssues);
    }

    /**
     * @return true if the extraction has activated at least an extractor, false otherwise.
     */
    public boolean hasMatchingExtractors() {
        return matchingExtractors.size() > 0;
    }

    /**
     * @return the (unmodifiable) list of matching extractors.
     */
    public List getMatchingExtractors() {
        return matchingExtractors;
    }

    /**
     * @return the detected encoding for the source stream.
     */
    public String getEncoding() {
        return encoding;
    }

    /**
     * @return the tetected mimetype for the input stream.
     */
    public String getDetectedMimeType() {
        return detectedMimeType;
    }

    /**
     * @return the validation report applied to the processed document.
     */
    public ValidationReport getValidationReport() {
        return validationReport;
    }

    /**
     * @param extractorName
     *            name of the extractor.
     * 
     * @return the (unmodifiable) map of issues per extractor.
     */
    public Collection getExtractorIssues(String extractorName) {
        final Collection errors = extractorIssues.get(extractorName);
        return errors == null ? Collections. emptyList()
                : Collections.unmodifiableCollection(errors);
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy