use of org.apache.tika.detect.CompositeEncodingDetector 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);
}
use of org.apache.tika.detect.CompositeEncodingDetector in project tika by apache.
the class TikaEncodingDetectorTest method testEncodingDetectorsAreLoaded.
@Test
public void testEncodingDetectorsAreLoaded() {
EncodingDetector encodingDetector = ((AbstractEncodingDetectorParser) new TXTParser()).getEncodingDetector();
assertTrue(encodingDetector instanceof CompositeEncodingDetector);
}
Aggregations