Class DocumentReader

java.lang.Object
  |
  +--DocumentReader
Direct Known Subclasses:
DocumentWriter, HierarchicalDocumentReader

public class DocumentReader
extends java.lang.Object

Accessor Class

Nice wrapper class to access documents with
Contains only static methods that are not specific to the document in question.

Version:
Vanilla-1 Mon Mar 19 14:41:37 2001
Author:
M. Oliver Möller

Field Summary
protected  java.util.Hashtable hashOriginalIDsToElements
          Store once for every translation
protected  org.w3c.dom.Document origDoc
          Document it wraps around
static boolean sanityChecks
          Setting this true, slows down but is good for debugging.
 
Constructor Summary
DocumentReader(org.w3c.dom.Document theDoc)
          Constructor with hand-over of document
 
Method Summary
static org.w3c.dom.NodeList getAllChildrenWithLabel(org.w3c.dom.Element el, java.lang.String label)
          Return all child nodes that have a specific label
static java.lang.String getCdataOfElement(org.w3c.dom.Element el)
          If the Element is a tag containing CDATA, then this data is returned.
 org.w3c.dom.Element getElementByID(java.lang.String id)
          Return the Element-Node in the original document that is augmented with the specific id
Throw excpetion, if it does not exist.

static java.lang.String getElementID(org.w3c.dom.Element el)
          Read the id of a given element
Throw exception, if it does not exist
static java.lang.String getElementName(org.w3c.dom.Element el)
          Read the contens of name child of a given element
Throw exception, if it does not exist
static org.w3c.dom.Element getFirstChildWithLabel(org.w3c.dom.Element el, java.lang.String label)
          Get first child that has the designated label.
Throw exception, if no such child exists
static org.w3c.dom.Element getFirstChildWithLabelIfExists(org.w3c.dom.Element el, java.lang.String label)
          Get first child that has the designated label.
Returns null, if no such child exists
static org.w3c.dom.Element getTheChildWithLabel(org.w3c.dom.Element el, java.lang.String label)
          Get the child that has the designated label.
Throw exception, if none or more than one such child exists.
static org.w3c.dom.Element getTheChildWithLabelIfExists(org.w3c.dom.Element el, java.lang.String label)
          Get the child that has the designated label.
Throw exception, if more than one such child exists.
 long getXCoordinate(org.w3c.dom.Element e)
          Read x coordinate (as long).
Return "0L" if not present
 long getYCoordinate(org.w3c.dom.Element e)
          Read y coordinate (as long).
Return "0L" if not present
static int max(int a, int b)
          the larger of two integers
static long max(long a, long b)
          the larger of two longs
static int max3(int a, int b, int c)
          the larger of three integers
static int max4(int a, int b, int c, int d)
          the larger of four integers
static int max5(int a, int b, int c, int d, int e)
          the larger of five integers
 void memorizeIDsOfOriginalDocument()
          Enter IDs in the hashtable hashOriginalIDsToElements

Throws exception, if document is not set properly
static int min(int a, int b)
          the lesser of two integers
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

origDoc

protected org.w3c.dom.Document origDoc
Document it wraps around

hashOriginalIDsToElements

protected java.util.Hashtable hashOriginalIDsToElements
Store once for every translation

sanityChecks

public static final boolean sanityChecks
Setting this true, slows down but is good for debugging.
Constructor Detail

DocumentReader

public DocumentReader(org.w3c.dom.Document theDoc)
Constructor with hand-over of document
Method Detail

getElementID

public static java.lang.String getElementID(org.w3c.dom.Element el)
                                     throws java.lang.Exception
Read the id of a given element
Throw exception, if it does not exist

getElementName

public static java.lang.String getElementName(org.w3c.dom.Element el)
                                       throws java.lang.Exception
Read the contens of name child of a given element
Throw exception, if it does not exist

getCdataOfElement

public static java.lang.String getCdataOfElement(org.w3c.dom.Element el)
                                          throws java.lang.Exception
If the Element is a tag containing CDATA, then this data is returned. If no children exist or cdata is empty, then the empty string is returned.

Otherwise, an exception is thrown.

getAllChildrenWithLabel

public static org.w3c.dom.NodeList getAllChildrenWithLabel(org.w3c.dom.Element el,
                                                           java.lang.String label)
Return all child nodes that have a specific label

getFirstChildWithLabel

public static org.w3c.dom.Element getFirstChildWithLabel(org.w3c.dom.Element el,
                                                         java.lang.String label)
                                                  throws java.lang.Exception
Get first child that has the designated label.
Throw exception, if no such child exists

getFirstChildWithLabelIfExists

public static org.w3c.dom.Element getFirstChildWithLabelIfExists(org.w3c.dom.Element el,
                                                                 java.lang.String label)
                                                          throws java.lang.Exception
Get first child that has the designated label.
Returns null, if no such child exists

getTheChildWithLabel

public static org.w3c.dom.Element getTheChildWithLabel(org.w3c.dom.Element el,
                                                       java.lang.String label)
                                                throws java.lang.Exception
Get the child that has the designated label.
Throw exception, if none or more than one such child exists.

getTheChildWithLabelIfExists

public static org.w3c.dom.Element getTheChildWithLabelIfExists(org.w3c.dom.Element el,
                                                               java.lang.String label)
                                                        throws java.lang.Exception
Get the child that has the designated label.
Throw exception, if more than one such child exists. Returns null, if none exists

getXCoordinate

public long getXCoordinate(org.w3c.dom.Element e)
Read x coordinate (as long).
Return "0L" if not present

getYCoordinate

public long getYCoordinate(org.w3c.dom.Element e)
Read y coordinate (as long).
Return "0L" if not present

getElementByID

public org.w3c.dom.Element getElementByID(java.lang.String id)
                                   throws java.lang.Exception
Return the Element-Node in the original document that is augmented with the specific id
Throw excpetion, if it does not exist.

Note: There should be a org.w3c.dom.Document method doing this (getElementByID) for us, but it seems to be buggy (see bugreport in ./Bug)

See Also:
Document

memorizeIDsOfOriginalDocument

public void memorizeIDsOfOriginalDocument()
                                   throws java.lang.Exception
Enter IDs in the hashtable hashOriginalIDsToElements

Throws exception, if document is not set properly

min

public static int min(int a,
                      int b)
the lesser of two integers

max

public static long max(long a,
                       long b)
the larger of two longs

max

public static int max(int a,
                      int b)
the larger of two integers

max3

public static int max3(int a,
                       int b,
                       int c)
the larger of three integers

max4

public static int max4(int a,
                       int b,
                       int c,
                       int d)
the larger of four integers

max5

public static int max5(int a,
                       int b,
                       int c,
                       int d,
                       int e)
the larger of five integers