- Common ways to obtain Parser
private void myMethod () {Parser p =
new AutoDetectParser()
TikaConfig config;config.getParser()
ParseContext context;context.get(Parser.class)
- Smart code suggestions by Codota
}
/** * Delegates the method call to the decorated parser. Subclasses should * override this method (and use <code>super.getSupportedTypes()</code> * to invoke the decorated parser) to implement extra decoration. */ public Set<MediaType> getSupportedTypes(ParseContext context) { return parser.getSupportedTypes(context); }
public Set<MediaType> getSupportedTypes(ParseContext context) { return parser.getSupportedTypes(context); }
public Set<MediaType> getSupportedTypes(ParseContext context) { return parser.getSupportedTypes(context); }
public Set<MediaType> getSupportedTypes(ParseContext parseContext) { return parser.getSupportedTypes(parseContext); }
public Map<MediaType, Parser> getParsers(ParseContext context) { Map<MediaType, Parser> map = new HashMap<MediaType, Parser>(); for (Parser parser : parsers) { for (MediaType type : parser.getSupportedTypes(context)) { map.put(registry.normalize(type), parser); } } return map; }
@Override public Set<MediaType> getSupportedTypes(ParseContext context) { return getWrappedParser().getSupportedTypes(context); }
public AbstractMultipleParser(MediaTypeRegistry registry, MetadataPolicy policy, Collection<? extends Parser> parsers) { this.policy = policy; this.parsers = parsers; this.registry = registry; // TODO Only offer those in common to several/all parser // TODO Some sort of specialisation / subtype support this.offeredTypes = new HashSet<>(); for (Parser parser : parsers) { offeredTypes.addAll( parser.getSupportedTypes(new ParseContext()) ); } }
public Set<MediaType> getSupportedTypes(ParseContext context) { return getDelegateParser(context).getSupportedTypes(context); }
new HashMap<MediaType, List<Parser>>(); for (Parser parser : parsers) { for (MediaType type : parser.getSupportedTypes(context)) { MediaType canonicalType = registry.normalize(type); if (types.containsKey(canonicalType)) {
private ParserDetails(Parser p) { if (p instanceof ParserDecorator) { isDecorated = true; decoratedBy = ((ParserDecorator)p).getDecorationName(); p = ((ParserDecorator)p).getWrappedParser(); } className = p.getClass().getName(); shortName = className.substring(className.lastIndexOf('.') + 1); if (p instanceof CompositeParser) { isComposite = true; supportedTypes = Collections.emptySet(); // Get the unique set of child parsers Set<Parser> children = new HashSet<Parser>( ((CompositeParser) p).getParsers(EMPTY_PC).values()); // Sort it by class name childParsers = new ArrayList<Parser>(children); Collections.sort(childParsers, new Comparator<Parser>() { @Override public int compare(Parser p1, Parser p2) { return p1.getClass().getName().compareTo(p2.getClass().getName()); } }); } else { supportedTypes = p.getSupportedTypes(EMPTY_PC); } } }
public boolean isSupported(TikaInputStream input) throws IOException { MediaType type = detector.detect(input, new Metadata()); return parser.getSupportedTypes(new ParseContext()).contains(type); }
addedTypes.addAll(types); for (MediaType type : parser.getSupportedTypes(context)) { if (! types.contains(type)) { excludedTypes.add(type); addedTypes.addAll(parser.getSupportedTypes(context));
@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); Collections.reverse(parsers); // best parser last for (Parser parser : parsers) { for (MediaType type : parser.getSupportedTypes(context)) { map.put(registry.normalize(type), parser); } } } return map; }
if (apt) System.out.println(); if (includeMimeTypes && !isComposite) { for (MediaType mt : p.getSupportedTypes(context)) { System.out.println(indent(i + 3) + ((apt) ? "* " : "") + mt); if (apt) System.out.println();
types = p.getSupportedTypes(context); assertEquals(1, types.size()); assertEquals(types.toString(), true, types.contains(MediaType.TEXT_PLAIN)); types = p.getSupportedTypes(context); assertEquals(1, types.size()); assertEquals(types.toString(), true, types.contains(MediaType.TEXT_PLAIN)); types = p.getSupportedTypes(context); assertEquals(0, types.size()); types = p.getSupportedTypes(context); assertEquals(1, types.size()); assertEquals(types.toString(), true, types.contains(MediaType.OCTET_STREAM)); types = p.getSupportedTypes(context); assertEquals(1, types.size()); assertEquals(types.toString(), true, types.contains(MediaType.OCTET_STREAM));
/** * Delegates the method call to the decorated parser. Subclasses should * override this method (and use <code>super.getSupportedTypes()</code> * to invoke the decorated parser) to implement extra decoration. */ public Set<MediaType> getSupportedTypes(ParseContext context) { return parser.getSupportedTypes(context); }
assertTrue(p.toString(), p instanceof ParserDecorator); assertEquals(EmptyParser.class, ((ParserDecorator)p).getWrappedParser().getClass()); assertEquals("hello/world", p.getSupportedTypes(null).iterator().next().toString()); assertEquals("fail/world", p.getSupportedTypes(null).iterator().next().toString()); } catch (TikaException e) { fail("Unexpected TikaException: " + e);
assertTrue(p.toString(), p instanceof ParserDecorator); assertEquals(EmptyParser.class, ((ParserDecorator)p).getWrappedParser().getClass()); assertEquals("hello/world", p.getSupportedTypes(null).iterator().next().toString()); } catch (TikaException e) { fail("Unexpected TikaException: " + e);
Set<MediaType> types = p.getSupportedTypes(context); assertEquals(2, types.size()); assertEquals(types.toString(), true, types.contains(MediaType.TEXT_PLAIN));
public Map<MediaType, Parser> getParsers(ParseContext context) { Map<MediaType, Parser> map = new HashMap<MediaType, Parser>(); for (Parser parser : parsers) { for (MediaType type : parser.getSupportedTypes(context)) { map.put(registry.normalize(type), parser); } } return map; }