我希望 Tika 仅输出存档中文件的名称(如果输入文件是存档)和文件内容,如果输入文件不是存档,则照常输出文件内容。我该怎么做?
我扩展了 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));
这仅适用于拉链、焦油和罐子。这对我来说已经足够了。