/** * 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()); } } }
private static ArrayList<String> buildMimeTypes(TikaConfig tikaConfig) { config = tikaConfig; parser = new AutoDetectParser(config); SUPPORTED_MIMETYPES = new ArrayList<String>(); for(MediaType mt : parser.getParsers().keySet()) { // Add the canonical mime type SUPPORTED_MIMETYPES.add( mt.toString() ); // And add any aliases of the mime type too - Alfresco uses some // non canonical forms of various mimetypes, so we need all of them for(MediaType alias : config.getMediaTypeRegistry().getAliases(mt)) { SUPPORTED_MIMETYPES.add( alias.toString() ); } } return SUPPORTED_MIMETYPES; }
private static ArrayList<String> buildMimeTypes(TikaConfig tikaConfig) { config = tikaConfig; parser = new AutoDetectParser(config); SUPPORTED_MIMETYPES = new ArrayList<String>(); for(MediaType mt : parser.getParsers().keySet()) { // Add the canonical mime type SUPPORTED_MIMETYPES.add( mt.toString() ); // And add any aliases of the mime type too - Alfresco uses some // non canonical forms of various mimetypes, so we need all of them for(MediaType alias : config.getMediaTypeRegistry().getAliases(mt)) { SUPPORTED_MIMETYPES.add( alias.toString() ); } } return SUPPORTED_MIMETYPES; }
for(MediaType baseType : parser.getParsers().keySet())
for(MediaType baseType : parser.getParsers().keySet())
@Override protected void render(RenderingContext context) { ContentReader contentReader = context.makeContentReader(); String sourceMimeType = contentReader.getMimetype(); // Check that Tika supports the supplied file AutoDetectParser p = new AutoDetectParser(tikaConfig); MediaType sourceMediaType = MediaType.parse(sourceMimeType); if(! p.getParsers().containsKey(sourceMediaType)) { throw new RenditionServiceException( "Source mime type of " + sourceMimeType + " is not supported by Tika for HTML conversions" ); } // Make the HTML Version using Tika // This will also extract out any images as found generateHTML(p, context); }
@Override protected void render(RenderingContext context) { ContentReader contentReader = context.makeContentReader(); String sourceMimeType = contentReader.getMimetype(); // Check that Tika supports the supplied file AutoDetectParser p = new AutoDetectParser(tikaConfig); MediaType sourceMediaType = MediaType.parse(sourceMimeType); if(! p.getParsers().containsKey(sourceMediaType)) { throw new RenditionServiceException( "Source mime type of " + sourceMimeType + " is not supported by Tika for HTML conversions" ); } // Make the HTML Version using Tika // This will also extract out any images as found generateHTML(p, context); }