maiolum.xml
Class XMLBibleFragmentFactory

java.lang.Object
  extended bymaiolum.BibleFragmentFactory
      extended bymaiolum.xml.XMLBibleFragmentFactory

public class XMLBibleFragmentFactory
extends BibleFragmentFactory

This is an implementation of AbstractBibleFactory to work with files containing XML data. XML is then represented via DOM nodes, elements and documents.

Instance of the class must be instantiated with either String or File referencing valid file containing XML data.

All overriden methods return XMLBibleFragment objects.


Field Summary
private  org.w3c.dom.Node entireDocument
          Node containing whole document read from file.
private static org.apache.log4j.Logger logger
           
 
Constructor Summary
XMLBibleFragmentFactory(java.io.File f)
           
XMLBibleFragmentFactory(java.lang.String filename)
           
 
Method Summary
protected  void finalize()
           
private  XMLBibleFragment getFirstMatch(java.lang.String xpath)
          Returns XMLFragment, which XML data match given XPath.
 BibleFragment getNextSibling(BibleFragment fragment)
          Returns next XMLBibleFragment to the given fragment in the document order.
 BibleFragment getNextSibling(java.lang.String id)
          Returns next XMLBibleFragment to the fragment given by ID in the document order.
private  java.lang.String getNodeNameByID(java.lang.String id)
          Returns name of Node, that has given ID.
 BibleFragment getPreviousSibling(BibleFragment fragment)
          Returns first preceding BibleFragment relative to given BibleFragment in document order.
 BibleFragment getPreviousSibling(java.lang.String id)
          Returns first preceding BibleFragment relative to given BibleFragment specified by its ID in document order.
 BibleFragment newBibleFragment()
          Returns new fragment containing whole parsed document.
 XMLBibleFragment newBibleFragment(org.w3c.dom.Document doc, java.lang.String id)
          Returns new BibleFragment (in this case XMLBibleFragment) which has an ID attribute value of id, while reading data from the given Node.
 BibleFragment newBibleFragment(java.lang.String id)
          Finds within the parsed document an element with given ID and returns its contents as new fragment.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

entireDocument

private org.w3c.dom.Node entireDocument
Node containing whole document read from file.


logger

private static org.apache.log4j.Logger logger
Constructor Detail

XMLBibleFragmentFactory

public XMLBibleFragmentFactory(java.io.File f)
                        throws ParseException

XMLBibleFragmentFactory

public XMLBibleFragmentFactory(java.lang.String filename)
                        throws ParseException
Method Detail

newBibleFragment

public BibleFragment newBibleFragment()
                               throws ParseException
Returns new fragment containing whole parsed document.

Throws:
ParseException

newBibleFragment

public BibleFragment newBibleFragment(java.lang.String id)
                               throws java.lang.Exception
Finds within the parsed document an element with given ID and returns its contents as new fragment. In case the document does not contain element with given ID, null is returned.

Returns:
new BibleFragment with given ID or null when the parent document does not contain element with given ID-
Throws:
java.lang.Exception

newBibleFragment

public XMLBibleFragment newBibleFragment(org.w3c.dom.Document doc,
                                         java.lang.String id)
                                  throws java.lang.Exception
Returns new BibleFragment (in this case XMLBibleFragment) which has an ID attribute value of id, while reading data from the given Node.

Returns:
BibleFragment with given ID found in specified Document. null, when no element with required ID exists
Throws:
java.lang.Exception

getNextSibling

public BibleFragment getNextSibling(BibleFragment fragment)
                             throws java.lang.Exception
Returns next XMLBibleFragment to the given fragment in the document order.

Specified by:
getNextSibling in class BibleFragmentFactory
Returns:
XMLBibleFragment which is sibling to the given fragment or null when no such element exists.
Throws:
java.lang.Exception

getNextSibling

public BibleFragment getNextSibling(java.lang.String id)
                             throws java.lang.Exception
Returns next XMLBibleFragment to the fragment given by ID in the document order.

Returns:
XMLBibleFragment which is next sibling to the fragment with specified ID or null when no such element exists.
Throws:
java.lang.Exception

getPreviousSibling

public BibleFragment getPreviousSibling(BibleFragment fragment)
                                 throws java.lang.Exception
Returns first preceding BibleFragment relative to given BibleFragment in document order.

Specified by:
getPreviousSibling in class BibleFragmentFactory
Throws:
java.lang.Exception

getPreviousSibling

public BibleFragment getPreviousSibling(java.lang.String id)
                                 throws java.lang.Exception
Returns first preceding BibleFragment relative to given BibleFragment specified by its ID in document order.

Returns:
first preceding BibleFragment to the fragment with given ID, null when no element with given exists, or there is no valid previous element.
Throws:
java.lang.Exception

getFirstMatch

private XMLBibleFragment getFirstMatch(java.lang.String xpath)
                                throws java.lang.Exception
Returns XMLFragment, which XML data match given XPath.

The document is matched to the given xpath and from the nodes that are matched, is taken only first. This first node is then taken for the root of XMLdata of returned XMLBibleFragment.

Returns:
XMLFragment, which XML data are created from the first element conforming to given XPath. null is returned when no nodes match the given XPath.
Throws:
java.lang.Exception

getNodeNameByID

private java.lang.String getNodeNameByID(java.lang.String id)
                                  throws java.lang.Exception
Returns name of Node, that has given ID. E.g. if XML tag, which has specified id is , then this method returns String "chapter".

Throws:
java.lang.Exception

finalize

protected void finalize()