MCPcopy Create free account
hub / github.com/apache/nutch / getParsers

Method getParsers

src/java/org/apache/nutch/parse/ParserFactory.java:102–145  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers 5

setupMethod · 0.80
getParseMethod · 0.80
addToMapMethod · 0.80
testGetParsersMethod · 0.80
parseMethod · 0.80

Calls 10

getMethod · 0.95
getExtensionsMethod · 0.95
getObjectMethod · 0.95
setObjectMethod · 0.95
sizeMethod · 0.80
getExtensionInstanceMethod · 0.80
getPluginIdMethod · 0.80
getIdMethod · 0.45
addMethod · 0.45
getDescriptorMethod · 0.45

Tested by 2

setupMethod · 0.64
testGetParsersMethod · 0.64