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; }
/** * Utility method that goes through all the component parsers and finds all media types for which * more than one parser declares support. This is useful in tracking down conflicting parser * definitions. * * @since Apache Tika 0.10 * @see <a href="https://issues.apache.org/jira/browse/TIKA-660">TIKA-660</a> * @param context parsing context * @return media types that are supported by at least two component parsers */ public Map<MediaType, List<Parser>> findDuplicateParsers(ParseContext context) { Map<MediaType, Parser> types = new HashMap<MediaType, Parser>(); Map<MediaType, List<Parser>> duplicates = new HashMap<MediaType, List<Parser>>(); for (Parser parser : parsers) { for (MediaType type : parser.getSupportedTypes(context)) { MediaType canonicalType = registry.normalize(type); if (types.containsKey(canonicalType)) { List<Parser> list = duplicates.get(canonicalType); if (list == null) { list = new ArrayList<Parser>(); list.add(types.get(canonicalType)); duplicates.put(canonicalType, list); } list.add(parser); } else { types.put(canonicalType, parser); } } } return duplicates; }