/** * 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()); } } }
/** Performs a one time intialization of Tika's Media-Type components and media type collection constants <br/> * Please note that this is a private static method which is called once per CLASS (not per instance / object) */ private static void initMediaTypes() { mediaTypeRegistry = new AutoDetectParser().getMediaTypeRegistry(); // to find media type aliases /* XML media types (and all aliases) */ XML_MEDIA_TYPES.add(APPLICATION_XML); XML_MEDIA_TYPES.addAll(mediaTypeRegistry.getAliases(APPLICATION_XML)); /* TEXT media types (and all aliases) */ TEXT_MEDIA_TYPES.add(TEXT_PLAIN); TEXT_MEDIA_TYPES.addAll(mediaTypeRegistry.getAliases(TEXT_PLAIN)); /* GZIP media types (and all aliases) */ MediaType gzipMediaType = MediaType.parse("application/gzip"); GZ_MEDIA_TYPES.add(gzipMediaType); GZ_MEDIA_TYPES.addAll(mediaTypeRegistry.getAliases(gzipMediaType)); } }