Skip to content

Commit

Permalink
优化
Browse files Browse the repository at this point in the history
  • Loading branch information
821938089 committed Dec 8, 2023
1 parent 2f49d09 commit d8cc932
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,6 @@ public byte[] getData() throws IOException {
throw new IOException(
"Could not load the contents of resource: " + this.getHref());
} else {
/*掌上书苑有很多自制书OPF的nameSpace格式不标准,强制修复成正确的格式*/
if (getHref().endsWith("opf")) {
String string = new String(readData)
.replace(" smlns=\"", " xmlns=\"")
.replace(" mlns=\"", " xmlns=\"");
readData = string.getBytes();
}
this.data = readData;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ public static void read(
Resource packageResource, EpubReader epubReader, EpubBook book,
Resources resources)
throws SAXException, IOException {
/*掌上书苑有很多自制书OPF的nameSpace格式不标准,强制修复成正确的格式*/
String string = new String(packageResource.getData())
.replace(" smlns=\"", " xmlns=\"")
.replace(" mlns=\"", " xmlns=\"");
packageResource.setData(string.getBytes());

Document packageDocument = ResourceUtil.getAsDocument(packageResource);
String packageHref = packageResource.getHref();
resources = fixHrefs(packageHref, resources);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,6 @@ public static Resources loadResources(
} else {
resource = ResourceUtil
.createResource(zipEntry.getName(), zipFileWrapper.getInputStream(zipEntry));
/*掌上书苑有很多自制书OPF的nameSpace格式不标准,强制修复成正确的格式*/
if (href.endsWith("opf")) {
String string = new String(resource.getData())
.replace(" smlns=\"", " xmlns=\"")
.replace(" mlns=\"", " xmlns=\"");
resource.setData(string.getBytes());
}

}

if (resource.getMediaType() == MediaTypes.XHTML) {
Expand Down Expand Up @@ -134,17 +126,10 @@ public static Resources loadResources(ZipInputStream zipInputStream,
if ((zipEntry == null) || zipEntry.isDirectory()) {
continue;
}
String href = zipEntry.getName();
//String href = zipEntry.getName();

// store resource
Resource resource = ResourceUtil.createResource(zipEntry.getName(), zipInputStream);
///*掌上书苑有很多自制书OPF的nameSpace格式不标准,强制修复成正确的格式*/
if (href.endsWith("opf")) {
String string = new String(resource.getData())
.replace(" smlns=\"", " xmlns=\"")
.replace(" mlns=\"", " xmlns=\"");
resource.setData(string.getBytes());
}
if (resource.getMediaType() == MediaTypes.XHTML) {
resource.setInputEncoding(defaultHtmlEncoding);
}
Expand Down

0 comments on commit d8cc932

Please sign in to comment.