use of org.apache.tika.mime.MediaTypeRegistry in project tika by apache.
the class DefaultParser method getParsers.
@Override
public Map<MediaType, Parser> getParsers(ParseContext context) {
Map<MediaType, Parser> map = super.getParsers(context);
if (loader != null) {
// Add dynamic parser service (they always override static ones)
MediaTypeRegistry registry = getMediaTypeRegistry();
List<Parser> parsers = loader.loadDynamicServiceProviders(Parser.class);
// best parser last
Collections.reverse(parsers);
for (Parser parser : parsers) {
for (MediaType type : parser.getSupportedTypes(context)) {
map.put(registry.normalize(type), parser);
}
}
}
return map;
}
use of org.apache.tika.mime.MediaTypeRegistry 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.mime.MediaTypeRegistry 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