use of org.apache.tika.parser.CompositeParser in project tika by apache.
the class TikaCLI method displaySupportedTypes.
/**
* Prints all the known media types, aliases and matching parser classes.
*/
private void displaySupportedTypes() {
AutoDetectParser parser = new AutoDetectParser();
MediaTypeRegistry registry = parser.getMediaTypeRegistry();
Map<MediaType, Parser> parsers = parser.getParsers();
for (MediaType type : registry.getTypes()) {
System.out.println(type);
for (MediaType alias : registry.getAliases(type)) {
System.out.println(" alias: " + alias);
}
MediaType supertype = registry.getSupertype(type);
if (supertype != null) {
System.out.println(" supertype: " + supertype);
}
Parser p = parsers.get(type);
if (p != null) {
if (p instanceof CompositeParser) {
p = ((CompositeParser) p).getParsers().get(type);
}
System.out.println(" parser: " + p.getClass().getName());
}
}
}
use of org.apache.tika.parser.CompositeParser in project tika by apache.
the class TikaMimeTypes method getMediaTypes.
protected List<MediaTypeDetails> getMediaTypes() {
MediaTypeRegistry registry = TikaResource.getConfig().getMediaTypeRegistry();
Map<MediaType, Parser> parsers = ((CompositeParser) TikaResource.getConfig().getParser()).getParsers();
List<MediaTypeDetails> types = new ArrayList<TikaMimeTypes.MediaTypeDetails>(registry.getTypes().size());
for (MediaType type : registry.getTypes()) {
MediaTypeDetails details = new MediaTypeDetails();
details.type = type;
details.aliases = registry.getAliases(type).toArray(new MediaType[0]);
MediaType supertype = registry.getSupertype(type);
if (supertype != null && !MediaType.OCTET_STREAM.equals(supertype)) {
details.supertype = supertype;
}
Parser p = parsers.get(type);
if (p != null) {
if (p instanceof CompositeParser) {
p = ((CompositeParser) p).getParsers().get(type);
}
details.parser = p.getClass().getName();
}
types.add(details);
}
return types;
}
Aggregations