chore(epub): avoid EpubContainer in EpubMetadataExtractor (#2128)
This commit is contained in:
+21
-3
@@ -180,11 +180,29 @@ public class EpubMetadataExtractor implements FileMetadataExtractor {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Document getOPFDocumentFromEpub(File epubFile) throws IOException, ParserConfigurationException, SAXException {
|
||||||
|
Book book = new EpubReader().readEpubLazy(epubFile.toPath(), "UTF-8");
|
||||||
|
|
||||||
|
var opfResource = book.getOpfResource();
|
||||||
|
|
||||||
|
if (opfResource == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
try (var inputStream = opfResource.getInputStream()) {
|
||||||
|
return SecureXmlUtils.createSecureDocumentBuilder(true)
|
||||||
|
.parse(inputStream);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BookMetadata extractMetadata(File epubFile) {
|
public BookMetadata extractMetadata(File epubFile) {
|
||||||
try (EpubContainer container = EpubContainers.open(epubFile.toPath())) {
|
try {
|
||||||
String opfPath = findOpfPath(container);
|
Document doc = getOPFDocumentFromEpub(epubFile);
|
||||||
Document doc = parseXmlFromContainer(container, opfPath);
|
|
||||||
|
if (doc == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
Element metadata = (Element) doc.getElementsByTagNameNS("*", "metadata").item(0);
|
Element metadata = (Element) doc.getElementsByTagNameNS("*", "metadata").item(0);
|
||||||
if (metadata == null) return null;
|
if (metadata == null) return null;
|
||||||
|
|||||||
Reference in New Issue
Block a user