try {
Class<? extends Parser> parserClass =
loader.getServiceClass(Parser.class, name);
// https://issues.apache.org/jira/browse/TIKA-866
if (AutoDetectParser.class.isAssignableFrom(parserClass)) {
throw new TikaException(
"AutoDetectParser not supported in a <parser>"
+ " configuration element: " + name);
}
Parser parser = parserClass.newInstance();
NodeList mimes = node.getElementsByTagName("mime");
if (mimes.getLength() > 0) {
Set<MediaType> types = new HashSet<MediaType>();
for (int j = 0; j < mimes.getLength(); j++) {
String mime = getText(mimes.item(j));
MediaType type = MediaType.parse(mime);
if (type != null) {
types.add(type);
} else {
throw new TikaException(
"Invalid media type name: " + mime);
}
}
parser = ParserDecorator.withTypes(parser, types);
}
parsers.add(parser);
} catch (ClassNotFoundException e) {
throw new TikaException(
"Unable to find a parser class: " + name, e);
} catch (IllegalAccessException e) {
throw new TikaException(
"Unable to access a parser class: " + name, e);
} catch (InstantiationException e) {
throw new TikaException(
"Unable to instantiate a parser class: " + name, e);
}
}
if (parsers.isEmpty()) {
return getDefaultParser(mimeTypes, loader);