Package com.adobe.epubcheck.opf
Class OPFHandler
- java.lang.Object
-
- org.xml.sax.helpers.DefaultHandler
-
- org.xml.sax.ext.DefaultHandler2
-
- com.adobe.epubcheck.xml.handlers.LocationHandler
-
- com.adobe.epubcheck.xml.handlers.BaseURLHandler
-
- com.adobe.epubcheck.xml.handlers.XMLHandler
-
- com.adobe.epubcheck.opf.OPFHandler
-
- All Implemented Interfaces:
org.xml.sax.ContentHandler,org.xml.sax.DTDHandler,org.xml.sax.EntityResolver,org.xml.sax.ErrorHandler,org.xml.sax.ext.DeclHandler,org.xml.sax.ext.EntityResolver2,org.xml.sax.ext.LexicalHandler
- Direct Known Subclasses:
OPFHandler30
public class OPFHandler extends XMLHandler
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Map<java.lang.String,OPFItem.Builder>itemBuildersprotected java.util.Map<io.mola.galimatias.URL,OPFItem.Builder>itemBuildersByURLprivate OPFItemsitemsprivate booleanopf12PackageFileprotected java.lang.StringpageMapIdprotected EPUBLocationpageMapReferenceLocationprivate java.util.Vector<OPFReference>refsprivate java.util.List<java.lang.String>spineIDsprivate intspineItemCounterprotected static java.lang.StringTEXT(package private) java.lang.Stringuidprivate java.lang.StringuniqueIdentprivate booleanuniqueIdentExistsprivate static java.util.HashSet<java.lang.String>validRoles-
Fields inherited from class com.adobe.epubcheck.xml.handlers.XMLHandler
context, path, report
-
-
Constructor Summary
Constructors Constructor Description OPFHandler(ValidationContext context)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidbuildItems()voidcharacters(char[] chars, int start, int len)booleancheckUniqueIdentExists()Checks to see if the unique-identifier attribute of the package element references an existing DC metadata identifier element's id attributevoidendElement()java.lang.StringgetIdentId()com.google.common.base.Optional<OPFItem>getItemById(java.lang.String id)Search the list of item by ID.com.google.common.base.Optional<OPFItem>getItemByURL(io.mola.galimatias.URL url)Search the list of item by URL.java.util.List<OPFItem>getItems()Returns an immutable list of all the items in the OPF, in document order, including those represented bylinkelements pointing to local resources.booleangetOpf12PackageFile()booleangetOpf20PackageFile()java.lang.StringgetPath()OPFReferencegetReference(int index)intgetReferenceCount()java.util.List<OPFItem>getSpineItems()Returns an immutable list of the items in the spine.java.lang.StringgetUid()private static booleanisValidRole(java.lang.String role)protected voidreportItem(OPFItem item)Report features or messages for a given item.voidstartElement()-
Methods inherited from class com.adobe.epubcheck.xml.handlers.XMLHandler
currentElement, endElement, registerReference, registerReference, setDocumentLocator, startElement
-
Methods inherited from class com.adobe.epubcheck.xml.handlers.BaseURLHandler
baseURL, checkURL
-
Methods inherited from class com.adobe.epubcheck.xml.handlers.LocationHandler
location, location
-
Methods inherited from class org.xml.sax.ext.DefaultHandler2
attributeDecl, comment, elementDecl, endCDATA, endDTD, endEntity, externalEntityDecl, getExternalSubset, internalEntityDecl, resolveEntity, resolveEntity, startCDATA, startDTD, startEntity
-
-
-
-
Field Detail
-
TEXT
protected static final java.lang.String TEXT
- See Also:
- Constant Field Values
-
pageMapId
protected java.lang.String pageMapId
-
pageMapReferenceLocation
protected EPUBLocation pageMapReferenceLocation
-
itemBuilders
protected final java.util.Map<java.lang.String,OPFItem.Builder> itemBuilders
-
itemBuildersByURL
protected final java.util.Map<io.mola.galimatias.URL,OPFItem.Builder> itemBuildersByURL
-
spineIDs
private final java.util.List<java.lang.String> spineIDs
-
items
private OPFItems items
-
refs
private final java.util.Vector<OPFReference> refs
-
validRoles
private static final java.util.HashSet<java.lang.String> validRoles
-
uniqueIdent
private java.lang.String uniqueIdent
-
uniqueIdentExists
private boolean uniqueIdentExists
-
uid
java.lang.String uid
-
opf12PackageFile
private boolean opf12PackageFile
-
spineItemCounter
private int spineItemCounter
-
-
Constructor Detail
-
OPFHandler
public OPFHandler(ValidationContext context)
-
-
Method Detail
-
getPath
public java.lang.String getPath()
-
getOpf12PackageFile
public boolean getOpf12PackageFile()
-
getOpf20PackageFile
public boolean getOpf20PackageFile()
-
getItemById
public com.google.common.base.Optional<OPFItem> getItemById(java.lang.String id)
Search the list of item by ID.- Parameters:
id- the ID of the item to search- Returns:
- an
Optionalcontaining the item of the given ID if found, orOptional.absent()
-
getItemByURL
public com.google.common.base.Optional<OPFItem> getItemByURL(io.mola.galimatias.URL url)
Search the list of item by URL.- Parameters:
id- the URL of the item to search- Returns:
- an
Optionalcontaining the item of the given URL if found, orOptional.absent()
-
getSpineItems
public java.util.List<OPFItem> getSpineItems()
Returns an immutable list of the items in the spine. May contain duplicates if severalitemrefelements point to the same item.Returns the empty list if the items have not been parsed yet.
- Returns:
- the list of items in the spine, guaranteed non-null.
-
getItems
public java.util.List<OPFItem> getItems()
Returns an immutable list of all the items in the OPF, in document order, including those represented bylinkelements pointing to local resources.Returns the empty list if the items have not been parsed yet.
- Returns:
- the list of all items, guaranteed non-null.
-
getReferenceCount
public int getReferenceCount()
-
getReference
public OPFReference getReference(int index)
-
checkUniqueIdentExists
public boolean checkUniqueIdentExists()
Checks to see if the unique-identifier attribute of the package element references an existing DC metadata identifier element's id attribute- Returns:
- true if there is an identifier with an id attribute that matches the value of the unique-identifier attribute of the package element. False otherwise.
-
getUid
public java.lang.String getUid()
-
isValidRole
private static boolean isValidRole(java.lang.String role)
-
startElement
public void startElement()
- Overrides:
startElementin classXMLHandler
-
getIdentId
public java.lang.String getIdentId()
-
endElement
public void endElement()
- Overrides:
endElementin classXMLHandler
-
characters
public void characters(char[] chars, int start, int len)- Specified by:
charactersin interfaceorg.xml.sax.ContentHandler- Overrides:
charactersin classorg.xml.sax.helpers.DefaultHandler
-
buildItems
private void buildItems()
-
reportItem
protected void reportItem(OPFItem item)
Report features or messages for a given item.- Parameters:
item- the item to report.
-
-