Search in sources :

Example 1 with DefaultEncodingDetector

use of org.apache.tika.detect.DefaultEncodingDetector in project tika by apache.

the class TikaConfigSerializer method addEncodingDetectors.

private static void addEncodingDetectors(Mode mode, Element rootElement, Document doc, TikaConfig config) throws Exception {
    EncodingDetector encDetector = config.getEncodingDetector();
    if (mode == Mode.MINIMAL && encDetector instanceof DefaultEncodingDetector) {
        // Don't output anything, all using defaults
        Node detComment = doc.createComment("for example: <encodingDetectors><encodingDetector class=\"" + "org.apache.tika.detect.DefaultEncodingDetector\"></encodingDetectors>");
        rootElement.appendChild(detComment);
        return;
    }
    Element encDetectorsElement = doc.createElement("encodingDetectors");
    if (mode == Mode.CURRENT && encDetector instanceof DefaultEncodingDetector || !(encDetector instanceof CompositeEncodingDetector)) {
        Element encDetectorElement = doc.createElement("encodingDetector");
        encDetectorElement.setAttribute("class", encDetector.getClass().getCanonicalName());
        encDetectorsElement.appendChild(encDetectorElement);
    } else {
        List<EncodingDetector> children = ((CompositeEncodingDetector) encDetector).getDetectors();
        for (EncodingDetector d : children) {
            Element encDetectorElement = doc.createElement("encodingDetector");
            encDetectorElement.setAttribute("class", d.getClass().getCanonicalName());
            encDetectorsElement.appendChild(encDetectorElement);
        }
    }
    rootElement.appendChild(encDetectorsElement);
}
Also used : DefaultEncodingDetector(org.apache.tika.detect.DefaultEncodingDetector) CompositeEncodingDetector(org.apache.tika.detect.CompositeEncodingDetector) EncodingDetector(org.apache.tika.detect.EncodingDetector) CompositeEncodingDetector(org.apache.tika.detect.CompositeEncodingDetector) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) DefaultEncodingDetector(org.apache.tika.detect.DefaultEncodingDetector)

Aggregations

CompositeEncodingDetector (org.apache.tika.detect.CompositeEncodingDetector)1 DefaultEncodingDetector (org.apache.tika.detect.DefaultEncodingDetector)1 EncodingDetector (org.apache.tika.detect.EncodingDetector)1 Element (org.w3c.dom.Element)1 Node (org.w3c.dom.Node)1