我希望Tika只输出归档文件中的文件名(如果输入文件是归档文件),如果输入文件不是归档文件,则像往常一样输出文件内容。我该怎么做呢?
发布于 2012-10-08 19:36:49
我扩展了ParsingEmbeddedDocumentExtractor类
class CustomParsingEmbeddedDocumentExtractor extends ParsingEmbeddedDocumentExtractor {
public CustomParsingEmbeddedDocumentExtractor(ParseContext context) {
super(context);
}
public void parseEmbedded(
InputStream stream, ContentHandler handler, Metadata metadata, boolean outputHtml)
throws SAXException, IOException {
String name = metadata.get(Metadata.RESOURCE_NAME_KEY);
if (name != null && name.length() > 0 ) {
handler.startElement(XHTML, "h1", "h1", new AttributesImpl());
char[] chars = name.toCharArray();
handler.characters(chars, 0, chars.length);
handler.endElement(XHTML, "h1", "h1");
}
//Removed the parsing logic here.. We just want the file names..
}
}并在执行someparser.parse()之前将其设置为ParseContext变量
context.set(EmbeddedDocumentExtractor.class, new CustomParsingEmbeddedDocumentExtractor(this.context));这只适用于zip、tar和jar。这对我来说已经足够了。
https://stackoverflow.com/questions/12619983
复制相似问题