Function returns an array of Parsers for a given content type. The function consults the internal list of parse plugins for the ParserFactory to determine the list of pluginIds, then gets the appropriate extension points to instantiate as Parsers. @param contentType The co
(String contentType, String url)
| 100 | * <code>[parse-html, parse-rtf]</code>. |
| 101 | */ |
| 102 | public Parser[] getParsers(String contentType, String url) |
| 103 | throws ParserNotFound { |
| 104 | |
| 105 | List<Parser> parsers = null; |
| 106 | List<Extension> parserExts = null; |
| 107 | |
| 108 | ObjectCache objectCache = ObjectCache.get(conf); |
| 109 | |
| 110 | // TODO once the MimeTypes is available |
| 111 | // parsers = getExtensions(MimeUtils.map(contentType)); |
| 112 | // if (parsers != null) { |
| 113 | // return parsers; |
| 114 | // } |
| 115 | // Last Chance: Guess content-type from file url... |
| 116 | // parsers = getExtensions(MimeUtils.getMimeType(url)); |
| 117 | |
| 118 | parserExts = getExtensions(contentType); |
| 119 | if (parserExts == null) { |
| 120 | throw new ParserNotFound(url, contentType); |
| 121 | } |
| 122 | |
| 123 | parsers = new ArrayList<Parser>(parserExts.size()); |
| 124 | for (Extension ext : parserExts) { |
| 125 | Parser p = null; |
| 126 | try { |
| 127 | // check to see if we've cached this parser instance yet |
| 128 | p = (Parser) objectCache.getObject(ext.getId()); |
| 129 | if (p == null) { |
| 130 | // go ahead and instantiate it and then cache it |
| 131 | p = (Parser) ext.getExtensionInstance(); |
| 132 | objectCache.setObject(ext.getId(), p); |
| 133 | } |
| 134 | parsers.add(p); |
| 135 | } catch (PluginRuntimeException e) { |
| 136 | if (LOG.isWarnEnabled()) { |
| 137 | LOG.warn("ParserFactory:PluginRuntimeException when " |
| 138 | + "initializing parser plugin " |
| 139 | + ext.getDescriptor().getPluginId() + " instance in getParsers " |
| 140 | + "function: attempting to continue instantiating parsers: ", e); |
| 141 | } |
| 142 | } |
| 143 | } |
| 144 | return parsers.toArray(new Parser[] {}); |
| 145 | } |
| 146 | |
| 147 | /** |
| 148 | * Function returns a {@link Parser} instance with the specified |