eTextReader.OEB
Class OEBPackageFileImpl

java.lang.Object
  extended by eTextReader.OEB.OEBPackageFileImpl
All Implemented Interfaces:
OEBPackageFile

public class OEBPackageFileImpl
extends java.lang.Object
implements OEBPackageFile

An implementation of the methods in the OEBPackageFile interface that works by constructing a DOM model of the package file

Author:
Ryan McFall

Field Summary
private  java.util.List contributorList
          A List of OEBContributor objects corresponding to the dc:Contributor elements in the package file
private  java.util.List creatorList
          A List of String objects corresponding to the dc:Creator elements in the package file
private  java.lang.String description
           
private  java.lang.String documentURI
          the URI of the package file this object is currently representing
private  java.net.URL documentURL
          the URL of the package file this object is current representing
private  java.lang.String format
           
private  java.util.Map identifierMap
          A Map of objects corresponding to the dc:Identifier elements in the package file.
private  java.lang.String language
           
private  java.util.HashMap manifestItemMap
          maps ID's to item #'s
private  java.lang.String packageIdentity
           
private  org.w3c.dom.Document parsedDocument
          a DOM Document object representing the package file
private  javax.xml.parsers.DocumentBuilder parser
          the DOM parser used to parse and store a tree representation of the package file
private  java.lang.String publicationTitle
           
private  java.lang.String publisher
           
private  java.lang.String rightsDescription
           
private  java.lang.String source
           
private  OEBSpine spine
          A OEBSpine reference to the package file's spine object
private  java.util.List subjectList
          A List of String objects corresponding to the dc:Subject elements in the package file
private  java.lang.String tableOfContents
          a string representing the table of contents; generated when the method getTableOfContents() is called.
private  org.w3c.dom.traversal.DocumentTraversal traversableDocument
          a DOM DocumentTraversal object which facilitates the tree traversal
private  java.util.Map urlMap
          a set containing the URL's in the spine element; used to support the {link #contains method}
 
Constructor Summary
OEBPackageFileImpl()
           
OEBPackageFileImpl(java.lang.String uri)
          constructs a package file object from the contents at the specified URI
 
Method Summary
protected  void createManifest()
          reads the information contained in the package's manifest element and stores it so that it is available via the various get methods.
protected  void createMetaData()
          reads the information contained in the package's metadata element and stores it so that it is accessible via the various get methods
protected  void createSpine()
          reads the information stored in the package's manifest element and stores it.
 java.util.List getContributors()
          Retrieves a list of contributors to the publication
 java.util.List getCreators()
          Retrieves a list of creators for this publication
 java.util.Date getDate(java.lang.String event)
          Retrieves the specified date specified for the publication Specific dates events are not currently defined by the OEB publication structure
 java.lang.String getDescription()
          Returns a (perhaps verbose) description of the publication
 OEBItem getFirstItem()
          Retrieve an OEBItem object corresponding to the first item referenced in the spine
 java.lang.String getFormat()
          Retrieves the format of the publication as a whole
 OEBItem getGuideTableOfContents()
          retrieves the OEBItem corresponding to the "toc" element in the guide, which references an element in the manifest.
 OEBIdentifier getIdentifier(java.lang.String scheme)
          Retrieves a particular identifier
 java.util.List getIdentifiers()
          Retrieves a list of identifiers for this publication
 java.lang.String getLanguage()
          The language of the publication
 OEBItem getLastItem()
          Retrieve an OEBItem object corresponding to the last item referenced in the spine
 OEBItem getManifestItem(java.lang.String id)
          Retrieves a specific item from the manifest
 OEBItem getManifestItem(java.lang.String id, java.util.Set allowedTypes)
          Retrieves a specific item from the manifest with a specific media type.
 java.util.List getManifestItems()
          Retrieves a list of the resources making up this publication
 OEBItem getNextItem(java.lang.String id)
          Retrieve an OEBItem object corresponding to the item after the specified item
protected  java.lang.String getNodeContent(org.w3c.dom.Node node)
          returns a string representation of the content stored in a node.
protected  java.lang.String getNodeContent(org.w3c.dom.Node node, boolean trimLeadingWS, boolean trimTrailingWS)
          returns a string representation of the content stored in a node.
 java.lang.String getPackageIdentity()
          Returns the unique identifier for this publication
 OEBItem getPreviousItem(java.lang.String id)
          Retrieve an OEBItem object corresponding to the item before the specified item
 java.lang.String getPublicationTitle()
          Retrieves the human readable title of this publication
 java.lang.String getPublisher()
          Returns a string identifying the publication's publisher
 java.lang.String getRights()
          Retrieves a description of the user's rights for use of this publication.
 java.lang.String getSource()
          Retrieves a source this publication is derived from
 OEBSpine getSpine()
          Retrieves an OEBSpine element for this publication
 java.util.List getSubjects()
          Retrieves the subjects of the publication
 java.lang.String getTableOfContents()
          constructs an HTML document representing the table of contents for the package
 boolean isFirstItem(java.lang.String id)
          Determine whether the OEBItem object identified using the given id is the first item in the spine
 boolean isLastItem(java.lang.String id)
          Determine whether the OEBItem object identified using the given id is the last item in the spine
 java.util.ListIterator listIterator()
          Retrieves an object useful for iterating over the spine elements
 OEBItem lookupURL(java.lang.String url)
          returns the OEB item corresponding to a given URL in the publication
 OEBItem lookupURLByPkgID(java.lang.String url)
          returns the OEB item corresponding to a given URL in the publication based on the PackageIdentity URL
static void main(java.lang.String[] args)
          allows testing of the various methods
protected static java.lang.StringBuffer normalizeWhitespace(java.lang.StringBuffer str, boolean trimLeadingWS, boolean trimTrailingWS)
          removes leading and consecutive whitespace from a string
protected  void parse()
          parses the document indicated by the value of the member documentURI
 void setURI(java.lang.String uri)
          sets the URI this package file object references
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

identifierMap

private java.util.Map identifierMap
A Map of objects corresponding to the dc:Identifier elements in the package file. Keys are the scheme Strings and values are OEBIdentifier objects


contributorList

private java.util.List contributorList
A List of OEBContributor objects corresponding to the dc:Contributor elements in the package file


creatorList

private java.util.List creatorList
A List of String objects corresponding to the dc:Creator elements in the package file


manifestItemMap

private java.util.HashMap manifestItemMap
maps ID's to item #'s


urlMap

private java.util.Map urlMap
a set containing the URL's in the spine element; used to support the {link #contains method}


subjectList

private java.util.List subjectList
A List of String objects corresponding to the dc:Subject elements in the package file


spine

private OEBSpine spine
A OEBSpine reference to the package file's spine object


packageIdentity

private java.lang.String packageIdentity

publicationTitle

private java.lang.String publicationTitle

description

private java.lang.String description

publisher

private java.lang.String publisher

format

private java.lang.String format

language

private java.lang.String language

source

private java.lang.String source

rightsDescription

private java.lang.String rightsDescription

parser

private javax.xml.parsers.DocumentBuilder parser
the DOM parser used to parse and store a tree representation of the package file


documentURI

private java.lang.String documentURI
the URI of the package file this object is currently representing


documentURL

private java.net.URL documentURL
the URL of the package file this object is current representing


parsedDocument

private org.w3c.dom.Document parsedDocument
a DOM Document object representing the package file

See Also:
DOM Java Bindings for more information

traversableDocument

private org.w3c.dom.traversal.DocumentTraversal traversableDocument
a DOM DocumentTraversal object which facilitates the tree traversal

See Also:
DOM Level 2 Traversal and Range for more information

tableOfContents

private java.lang.String tableOfContents
a string representing the table of contents; generated when the method getTableOfContents() is called.

Constructor Detail

OEBPackageFileImpl

public OEBPackageFileImpl()

OEBPackageFileImpl

public OEBPackageFileImpl(java.lang.String uri)
                   throws java.lang.Exception
constructs a package file object from the contents at the specified URI

Parameters:
uri - the Uniform Resource Identifier for the package file
Throws:
java.lang.Exception - if an error occurs parsing the document
Method Detail

getPackageIdentity

public java.lang.String getPackageIdentity()
Returns the unique identifier for this publication

Specified by:
getPackageIdentity in interface OEBPackageFile
Returns:
an OEBIdentifier object corresponding to the dc:Identifier element whose ID is referenced by the unique-identifier attribute of the package element

getPublicationTitle

public java.lang.String getPublicationTitle()
Retrieves the human readable title of this publication

Specified by:
getPublicationTitle in interface OEBPackageFile

getCreators

public java.util.List getCreators()
Retrieves a list of creators for this publication

Specified by:
getCreators in interface OEBPackageFile

getSubjects

public java.util.List getSubjects()
Retrieves the subjects of the publication

Specified by:
getSubjects in interface OEBPackageFile
Returns:
a List item containing the subjects of the publication

getDescription

public java.lang.String getDescription()
Returns a (perhaps verbose) description of the publication

Specified by:
getDescription in interface OEBPackageFile

getPublisher

public java.lang.String getPublisher()
Returns a string identifying the publication's publisher

Specified by:
getPublisher in interface OEBPackageFile

getContributors

public java.util.List getContributors()
Retrieves a list of contributors to the publication

Specified by:
getContributors in interface OEBPackageFile
Returns:
a List item that contains OEB.OEBContributor objects describing the creators for the publication

getDate

public java.util.Date getDate(java.lang.String event)
Retrieves the specified date specified for the publication Specific dates events are not currently defined by the OEB publication structure

Specified by:
getDate in interface OEBPackageFile
Parameters:
event - a string identifying the date being requested, such as the publication date, last modification date, etc.

getFormat

public java.lang.String getFormat()
Retrieves the format of the publication as a whole

Specified by:
getFormat in interface OEBPackageFile
Returns:
The mime-type of the publication file

getSource

public java.lang.String getSource()
Retrieves a source this publication is derived from

Specified by:
getSource in interface OEBPackageFile
Returns:
a String representing the source, or null if there is no prior source

getLanguage

public java.lang.String getLanguage()
The language of the publication

Specified by:
getLanguage in interface OEBPackageFile
Returns:
a string identifying the language of the resource in RFC 3066 format
See Also:
Open eBook description of this element

getRights

public java.lang.String getRights()
Retrieves a description of the user's rights for use of this publication. This is not expressed in a formal rights language

Specified by:
getRights in interface OEBPackageFile

getIdentifiers

public java.util.List getIdentifiers()
Retrieves a list of identifiers for this publication

Specified by:
getIdentifiers in interface OEBPackageFile
Returns:
a List containing OEBIdentifier objects corresponding to the dc:Identifier elements in the publication package

getIdentifier

public OEBIdentifier getIdentifier(java.lang.String scheme)
                            throws java.util.NoSuchElementException
Retrieves a particular identifier

Specified by:
getIdentifier in interface OEBPackageFile
Parameters:
scheme - the particular scheme whose identifier is being requested
Returns:
a OEBIdentifier object corresponding to the requested scheme
Throws:
java.util.NoSuchElementException - if no identifier matching the requested scheme can be found

getManifestItems

public java.util.List getManifestItems()
Retrieves a list of the resources making up this publication

Specified by:
getManifestItems in interface OEBPackageFile
Returns:
a List of OEBItem objects

getManifestItem

public OEBItem getManifestItem(java.lang.String id)
                        throws java.util.NoSuchElementException
Retrieves a specific item from the manifest

Specified by:
getManifestItem in interface OEBPackageFile
Parameters:
id - The unique identifier for the resource
Returns:
an OEBItem that corresponds to the given id; the first item found is returned, regardless of its media type
Throws:
java.util.NoSuchElementException - if no item corresponding to the given id exists in the manifest

getManifestItem

public OEBItem getManifestItem(java.lang.String id,
                               java.util.Set allowedTypes)
                        throws java.util.NoSuchElementException
Retrieves a specific item from the manifest with a specific media type. The fallbackID attribute of the requested item will be used to locate an appropriate item

Specified by:
getManifestItem in interface OEBPackageFile
Parameters:
id - The unique identifier for the resource
allowedTypes - a set of allowed media types for the resource.
Returns:
an OEBItem that corresponds to the given id, AND has a media type contained in the allowedTypes Set.
Throws:
java.util.NoSuchElementException - if the requested id does not exist, or if now item with an allowable media type is found

getSpine

public OEBSpine getSpine()
Description copied from interface: OEBPackageFile
Retrieves an OEBSpine element for this publication

Specified by:
getSpine in interface OEBPackageFile

getGuideTableOfContents

public OEBItem getGuideTableOfContents()
                                throws java.util.NoSuchElementException
Description copied from interface: OEBPackageFile
retrieves the OEBItem corresponding to the "toc" element in the guide, which references an element in the manifest. Provided only for compatibility with OEB package file specification use getTableOfContents instead, as it is dynamically generated

Specified by:
getGuideTableOfContents in interface OEBPackageFile
Throws:
java.util.NoSuchElementException

getTableOfContents

public java.lang.String getTableOfContents()
Description copied from interface: OEBPackageFile
constructs an HTML document representing the table of contents for the package

Specified by:
getTableOfContents in interface OEBPackageFile

getFirstItem

public OEBItem getFirstItem()
Description copied from interface: OEBPackageFile
Retrieve an OEBItem object corresponding to the first item referenced in the spine

Specified by:
getFirstItem in interface OEBPackageFile

getLastItem

public OEBItem getLastItem()
Description copied from interface: OEBPackageFile
Retrieve an OEBItem object corresponding to the last item referenced in the spine

Specified by:
getLastItem in interface OEBPackageFile

getNextItem

public OEBItem getNextItem(java.lang.String id)
Description copied from interface: OEBPackageFile
Retrieve an OEBItem object corresponding to the item after the specified item

Specified by:
getNextItem in interface OEBPackageFile
Parameters:
id - the unique identifier of the item before the requested item

getPreviousItem

public OEBItem getPreviousItem(java.lang.String id)
Description copied from interface: OEBPackageFile
Retrieve an OEBItem object corresponding to the item before the specified item

Specified by:
getPreviousItem in interface OEBPackageFile
Parameters:
id - the unique identifier of the item after the requested item

listIterator

public java.util.ListIterator listIterator()
Description copied from interface: OEBPackageFile
Retrieves an object useful for iterating over the spine elements

Specified by:
listIterator in interface OEBPackageFile
Returns:
a listIterator object that can be used to retrieve the spine elements in order

lookupURL

public OEBItem lookupURL(java.lang.String url)
                  throws java.util.NoSuchElementException
Description copied from interface: OEBPackageFile
returns the OEB item corresponding to a given URL in the publication

Specified by:
lookupURL in interface OEBPackageFile
Parameters:
url - the fully specified URL to check
Returns:
an OEBItem for the URL specified by url
Throws:
java.util.NoSuchElementException - if the URL url is not contained in the manifest for this publication

lookupURLByPkgID

public OEBItem lookupURLByPkgID(java.lang.String url)
                         throws java.util.NoSuchElementException
Description copied from interface: OEBPackageFile
returns the OEB item corresponding to a given URL in the publication based on the PackageIdentity URL

Specified by:
lookupURLByPkgID in interface OEBPackageFile
Parameters:
url - the fully specified URL to check
Returns:
an OEBItem for the URL specified by url
Throws:
java.util.NoSuchElementException - if the URL url is not contained in the manifest for this publication

parse

protected void parse()
              throws java.lang.Exception
parses the document indicated by the value of the member documentURI

Throws:
java.lang.Exception - if no URI has been set

setURI

public void setURI(java.lang.String uri)
            throws java.net.MalformedURLException,
                   java.lang.Exception
sets the URI this package file object references

Parameters:
uri - the URI of the package file
Throws:
java.net.MalformedURLException - if the uri
java.lang.Exception - if an error occurs parsing the document referenced by the uri parameter parameter is not a syntactically correct URI

createMetaData

protected void createMetaData()
reads the information contained in the package's metadata element and stores it so that it is accessible via the various get methods


createManifest

protected void createManifest()
                       throws java.net.MalformedURLException
reads the information contained in the package's manifest element and stores it so that it is available via the various get methods. in particular, creates OEBItem objects and stores them in the manifestItemMap member with their id attribute as the key

Throws:
java.net.MalformedURLException

createSpine

protected void createSpine()
                    throws java.util.NoSuchElementException
reads the information stored in the package's manifest element and stores it. The information is made available via the methods getManifestItems(), getManifestItem(String) and getManifestItem(String,java.util.Set)

Throws:
java.util.NoSuchElementException - if one of the idref attributes in the spine's itemref elements does not have a corresponding entry in the manifest

getNodeContent

protected java.lang.String getNodeContent(org.w3c.dom.Node node)
returns a string representation of the content stored in a node. this implementation trims leading, but not trailing, white space

Parameters:
node - the node whose content is to be returned
Returns:
the normalized content of all text nodes descended from node.
See Also:
OEB.OEBPackageFileImpl#normalizeWhitespace(StringBuffer,boolean,boolean)

getNodeContent

protected java.lang.String getNodeContent(org.w3c.dom.Node node,
                                          boolean trimLeadingWS,
                                          boolean trimTrailingWS)
returns a string representation of the content stored in a node.

Parameters:
node - the node whose content is to be returned
trimLeadingWS - indicates whether leading whitespace should be removed
trimTrailingWS - indicates whether trailing whitespace should be removed
Returns:
the normalized content of all text nodes descended from node.
See Also:
OEB.OEBPackageFileImpl#normalizeWhitespace(StringBuffer,boolean,boolean)

normalizeWhitespace

protected static java.lang.StringBuffer normalizeWhitespace(java.lang.StringBuffer str,
                                                            boolean trimLeadingWS,
                                                            boolean trimTrailingWS)
removes leading and consecutive whitespace from a string

Parameters:
str - the content to be normalized
trimLeadingWS - indicates whether leading whitespace should be removed
trimTrailingWS - indicates whether trailing whitespace should be removed
Returns:
a StringBuffer object whose contents are the same as str, except that consecutive whitespace characters have been removed, and leading and trailing whitespace are gone if specified

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
allows testing of the various methods

Throws:
java.lang.Exception

isFirstItem

public boolean isFirstItem(java.lang.String id)
Description copied from interface: OEBPackageFile
Determine whether the OEBItem object identified using the given id is the first item in the spine

Specified by:
isFirstItem in interface OEBPackageFile
Parameters:
id - an id identifying the item in the book
Returns:
true if the item is the first item in the book, false otherwise

isLastItem

public boolean isLastItem(java.lang.String id)
Description copied from interface: OEBPackageFile
Determine whether the OEBItem object identified using the given id is the last item in the spine

Specified by:
isLastItem in interface OEBPackageFile
Parameters:
id - an id identifying the item in the book
Returns:
true if the item is the last item in the book, false otherwise