public ParseResult parse(Content content) throws ParseException {
Parser[] parsers = null;
try {
parsers = this.parserFactory.getParsers(content.getContentType(),
content.getUrl() != null ? content.getUrl():"");
} catch (ParserNotFound e) {
if (LOG.isWarnEnabled()) {
LOG.warn("No suitable parser found when trying to parse content " + content.getUrl() +
" of type " + content.getContentType());
}
throw new ParseException(e.getMessage());
}
ParseResult parseResult = null;
for (int i=0; i< parsers.length; i++) {
if (LOG.isDebugEnabled()) {
LOG.debug("Parsing [" + content.getUrl() + "] with [" + parsers[i] + "]");
}
parseResult = parsers[i].getParse(content);
if (parseResult != null && !parseResult.isEmpty())
return parseResult;
}
if (LOG.isWarnEnabled()) {
LOG.warn("Unable to successfully parse content " + content.getUrl() +
" of type " + content.getContentType());
}
return null;
}
Performs a parse by iterating through a List of preferred Parser s
until a successful parse is performed and a Parse object is
returned. If the parse is unsuccessful, a message is logged to the
WARNING level, and an empty parse is returned. |
public ParseResult parseByExtensionId(String extId,
Content content) throws ParseException {
Parser p = null;
try {
p = this.parserFactory.getParserById(extId);
} catch (ParserNotFound e) {
if (LOG.isWarnEnabled()) {
LOG.warn("No suitable parser found when trying to parse content " + content.getUrl() +
" of type " + content.getContentType());
}
throw new ParseException(e.getMessage());
}
ParseResult parseResult = p.getParse(content);
if (parseResult != null && !parseResult.isEmpty()) {
return parseResult;
} else {
if (LOG.isWarnEnabled()) {
LOG.warn("Unable to successfully parse content " + content.getUrl() +
" of type " + content.getContentType());
}
return null;
}
}
Method parses a Content object using the Parser specified
by the parameter extId, i.e., the Parser's extension ID.
If a suitable Parser is not found, then a WARNING
level message is logged, and a ParseException is thrown. If the parse is
uncessful for any other reason, then a WARNING level
message is logged, and a ParseStatus.getEmptyParse() is
returned. |