String name = e.getName();
if (name.equals("package"))
{
if (!ns.equals("http://www.idpf.org/2007/opf"))
{
report.message(MessageId.OPF_047, new MessageLocation(path, parser.getLineNumber(), parser.getColumnNumber()));
opf12PackageFile = true;
}
/*
* This section checks to see the value of the unique-identifier
* attribute and stores it in the String uniqueIdent or reports
* an error if the unique-identifier attribute is missing or
* does not have a value
*/
String uniqueIdentAttr = e.getAttribute("unique-identifier");
if (uniqueIdentAttr != null && !uniqueIdentAttr.equals(""))
{
uniqueIdent = uniqueIdentAttr;
}
else
{
report.message(MessageId.OPF_048, new MessageLocation(path, parser.getLineNumber(), parser.getColumnNumber()));
}
}
else if (name.equals("item"))
{
String id = e.getAttribute("id");
String href = e.getAttribute("href");
if (href != null
&& !(version == EPUBVersion.VERSION_3 && href
.matches("^[^:/?#]+://.*"))) {
try
{
href = PathUtil.resolveRelativeReference(path, href,
null);
}
catch (IllegalArgumentException ex)
{
report.message(MessageId.OPF_010,
new MessageLocation(path, parser.getLineNumber(), parser.getColumnNumber(), href),
ex.getMessage());
href = null;
}
}
if (href != null && href.matches("^[^:/?#]+://.*")) {
report.info(path, FeatureEnum.REFERENCE, href);
}
String mimeType = e.getAttribute("media-type");
String fallback = e.getAttribute("fallback");
// dirty fix for issue 271: treat @fallback attribute in EPUB3 like fallback-style in EPUB2
// then all the epubcheck mechanisms on checking stylesheet fallbacks will work as in EPUB 2
String fallbackStyle = (version == EPUBVersion.VERSION_3) ? e.getAttribute("fallback") : e.getAttribute("fallback-style");
String namespace = e.getAttribute("island-type");
String properties = e.getAttribute("properties");
if (properties != null)
{
properties = properties.replaceAll("[\\s]+", " ");
}
if (version == EPUBVersion.VERSION_3
&& href.matches("^[^:/?#]+://.*")
&& !OPFChecker30.isBlessedAudioType(mimeType)
&& !OPFChecker30.isBlessedVideoType(mimeType))
{
if (OPFChecker30.isCoreMediaType(mimeType))
{
report.message(MessageId.OPF_010,
new MessageLocation(path, parser.getLineNumber(), parser.getColumnNumber()), href);
}
else
{
// mgy 20120414: this shouldn't even be a warning
// report.warning(
// path,
// parser.getLineNumber(),
// parser.getColumnNumber(),
// "Remote resource not validated");
}
}
OPFItem item = new OPFItem(id, href, mimeType, fallback,
fallbackStyle, namespace, properties,
parser.getLineNumber(), parser.getColumnNumber());
if (id != null)
{
itemMapById.put(id, item);
report.info(href, FeatureEnum.UNIQUE_IDENT, id);
}
else
{
System.err.printf("Item is missing id : %s\n", href);
}
if (properties != null)
{
String propertyArray[] = properties.split(" ");
for (String aPropertyArray : propertyArray)
{
if (aPropertyArray.equals("nav"))
{
item.setNav(true);
}
if (aPropertyArray.equals("scripted"))
{
item.setScripted(true);
}
}
}
if (href != null && registerEntry)
{
itemMapByPath.put(href, item);
items.add(item);
}
}
else if (name.equals("reference"))
{
String type = e.getAttribute("type");
String title = e.getAttribute("title");
String href = e.getAttribute("href");
if (href != null && xrefChecker != null)
{
try
{
href = PathUtil.resolveRelativeReference(path, href,
null);
xrefChecker.registerReference(path,
parser.getLineNumber(),
parser.getColumnNumber(), href,
XRefChecker.RT_GENERIC);
}
catch (IllegalArgumentException ex)
{
report.message(MessageId.OPF_010,
new MessageLocation(path, parser.getLineNumber(), parser.getColumnNumber(), href), ex.getMessage());
href = null;
}
}
if (href != null && href.startsWith("http"))
{
report.info(path, FeatureEnum.REFERENCE, href);
}
OPFReference ref = new OPFReference(type, title, href,
parser.getLineNumber(), parser.getColumnNumber());
refs.add(ref);
}
else if (name.equals("spine"))
{
String pageMap = e.getAttribute("page-map");
if (pageMap != null)
{
pageMapId = pageMap;
pageMapReferenceLocation = new MessageLocation(path, parser.getLineNumber(), parser.getColumnNumber(), String.format("page-map=\"%1$s\"", pageMapId));
report.message(MessageId.OPF_062, pageMapReferenceLocation);
}
String idref = e.getAttribute("toc");
if (idref != null)
{
OPFItem toc = itemMapById.get(idref);
if (toc == null)
{
report.message(MessageId.OPF_049,
new MessageLocation(path, parser.getLineNumber(), parser.getColumnNumber()),
idref);
report.info(null, FeatureEnum.HAS_NCX, "false");
}
else
{
toc.setNcx(true);
report.info(toc.getPath(), FeatureEnum.HAS_NCX, "true");
if (toc.getMimeType() != null
&& !toc.getMimeType().equals(
"application/x-dtbncx+xml"))
{
report.message(MessageId.OPF_050,
new MessageLocation(path, parser.getLineNumber(), parser.getColumnNumber()));
}
}
}
else
{
report.info(null, FeatureEnum.HAS_NCX, "false");
}
}
else if (name.equals("itemref"))
{
String idref = e.getAttribute("idref");
if (idref != null)
{
OPFItem item = getItemById(idref);
if (item != null)
{
spine.add(item);
item.setInSpine(true);
report.info(item.getPath(), FeatureEnum.IS_SPINEITEM, "true");
String linear = e.getAttribute("linear");
if (linear != null && "no".equals(linear.trim()))
{
item.setSpineLinear(false);
}
else
{
item.setSpineLinear(true);
}
report.info(item.getPath(), FeatureEnum.IS_LINEAR, String.valueOf(item.getSpineLinear()));
boolean isFixed = globalPrePaginated;
String properties = e.getAttribute("properties");
if (properties != null && !properties.equals(""))
{
properties = properties.replaceAll("[\\s]+", " ");
String propertyArray[] = properties.split(" ");
for (String prop : propertyArray)
{
if (prop.equals("rendition:layout-pre-paginated"))
{
isFixed = true;
}
else if (prop.equals("rendition:layout-reflowable"))
{
isFixed = false;
}
}
}
if (isFixed)
{
report.info(item.getPath(), FeatureEnum.HAS_FIXED_LAYOUT, String.valueOf(true));
}
}
else
{
report.message(MessageId.OPF_049,
new MessageLocation(path, parser.getLineNumber(), parser.getColumnNumber()),
idref);
}
}
}
else if (name.equals("dc-metadata") || name.equals("x-metadata"))
{
if (!opf12PackageFile)
{
report.message(MessageId.OPF_049,
new MessageLocation(path, parser.getLineNumber(), parser.getColumnNumber()),
name);
}
}
}
else if (ns.equals("http://purl.org/dc/elements/1.1/"))
{
// in the DC metadata, when the <identifier> element is parsed, if
// it has a non-null and non-empty id attribute value that is the
// same as the value of the unique-identifier attribute of the
// package element, set uniqueIdentExists = true (to make sure that
// the unique-identifier attribute references an existing
// <identifier> id attribute
String name = e.getName();
if (name.equals("identifier"))
{
String idAttr = e.getAttribute("id");
if (idAttr != null && !idAttr.equals("")
&& idAttr.equals(uniqueIdent))
{
uniqueIdentExists = true;
}
}
else if (name.equals("creator"))
{
String role = e.getAttributeNS("http://www.idpf.org/2007/opf", "role");
if (role != null && !role.equals("") && !isValidRole(role))
{
report.message(MessageId.OPF_052,
new MessageLocation(path, parser.getLineNumber(), parser.getColumnNumber()), role);
}
}
}
}