|
@@ -35,6 +35,7 @@ import me.ag2s.epublib.domain.Spine;
|
|
|
import me.ag2s.epublib.domain.SpineReference;
|
|
import me.ag2s.epublib.domain.SpineReference;
|
|
|
import me.ag2s.epublib.util.ResourceUtil;
|
|
import me.ag2s.epublib.util.ResourceUtil;
|
|
|
import me.ag2s.epublib.util.StringUtil;
|
|
import me.ag2s.epublib.util.StringUtil;
|
|
|
|
|
+import me.ag2s.epublib.util.URLEncodeUtil;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* Reads the opf package document as defined by namespace http://www.idpf.org/2007/opf
|
|
* Reads the opf package document as defined by namespace http://www.idpf.org/2007/opf
|
|
@@ -108,6 +109,7 @@ public class PackageDocumentReader extends PackageDocumentBase {
|
|
|
for (int i = 0; i < originItemElements.getLength(); i++) {
|
|
for (int i = 0; i < originItemElements.getLength(); i++) {
|
|
|
Element itemElement = (Element) originItemElements.item(i).cloneNode(false);
|
|
Element itemElement = (Element) originItemElements.item(i).cloneNode(false);
|
|
|
String href = DOMUtil.getAttribute(itemElement, NAMESPACE_OPF, OPFAttributes.href);
|
|
String href = DOMUtil.getAttribute(itemElement, NAMESPACE_OPF, OPFAttributes.href);
|
|
|
|
|
+ href = URLEncodeUtil.encode(href);
|
|
|
String resolvedHref = packagePath.resolve(href).toString();
|
|
String resolvedHref = packagePath.resolve(href).toString();
|
|
|
itemElement.setAttribute("href", resolvedHref);
|
|
itemElement.setAttribute("href", resolvedHref);
|
|
|
fixedElements.add(itemElement);
|
|
fixedElements.add(itemElement);
|
|
@@ -451,9 +453,9 @@ public class PackageDocumentReader extends PackageDocumentBase {
|
|
|
OPFTags.item, OPFAttributes.id, coverResourceId,
|
|
OPFTags.item, OPFAttributes.id, coverResourceId,
|
|
|
OPFAttributes.href);
|
|
OPFAttributes.href);
|
|
|
if (StringUtil.isNotBlank(coverHref)) {
|
|
if (StringUtil.isNotBlank(coverHref)) {
|
|
|
- result.add(packagePath.resolve(coverHref).toString());
|
|
|
|
|
|
|
+ result.add(resolvePath(packagePath, coverHref));
|
|
|
} else {
|
|
} else {
|
|
|
- String resolved = packagePath.resolve(coverResourceId).toString();
|
|
|
|
|
|
|
+ String resolved = resolvePath(packagePath, coverResourceId);
|
|
|
result.add(
|
|
result.add(
|
|
|
resolved); // maybe there was a cover href put in the cover id attribute
|
|
resolved); // maybe there was a cover href put in the cover id attribute
|
|
|
}
|
|
}
|
|
@@ -464,11 +466,21 @@ public class PackageDocumentReader extends PackageDocumentBase {
|
|
|
OPFTags.reference, OPFAttributes.type, OPFValues.reference_cover,
|
|
OPFTags.reference, OPFAttributes.type, OPFValues.reference_cover,
|
|
|
OPFAttributes.href);
|
|
OPFAttributes.href);
|
|
|
if (StringUtil.isNotBlank(coverHref)) {
|
|
if (StringUtil.isNotBlank(coverHref)) {
|
|
|
- result.add(packagePath.resolve(coverHref).toString());
|
|
|
|
|
|
|
+ result.add(resolvePath(packagePath, coverHref));
|
|
|
}
|
|
}
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private static String resolvePath(URI parentPath, String href) {
|
|
|
|
|
+ href = URLEncodeUtil.encode(href);
|
|
|
|
|
+ String resolved = parentPath.resolve(href).toString();
|
|
|
|
|
+ try {
|
|
|
|
|
+ return URLDecoder.decode(resolved, Constants.CHARACTER_ENCODING);
|
|
|
|
|
+ } catch (UnsupportedEncodingException e) {
|
|
|
|
|
+ throw new RuntimeException(e);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* Finds the cover resource in the packageDocument and adds it to the book if found.
|
|
* Finds the cover resource in the packageDocument and adds it to the book if found.
|
|
|
* Keeps the cover resource in the resources map
|
|
* Keeps the cover resource in the resources map
|