uk.co.demon.ursus.dom
Class PMRDelegate

java.lang.Object
  |
  +--uk.co.demon.ursus.dom.PMRDelegate

public class PMRDelegate
extends java.lang.Object

re-usable routines to support PMR* interfaces


Constructor Summary
PMRDelegate()
           
 
Method Summary
static void addAttributes(org.w3c.dom.Element element, org.xml.sax.AttributeList attributeList)
           
static void copyAttributesFrom(org.w3c.dom.Element toElement, org.w3c.dom.Element fromElement)
           
static org.w3c.dom.Node copyNode(org.w3c.dom.Document toDocument, org.w3c.dom.Node fromNode, boolean deep)
          make a copy of the Node in a different document context.
static void debug(org.w3c.dom.Node node)
           
static void deleteWhitespaceDecsendants(org.w3c.dom.Document document)
          recursively removes all whitespace nodes
static void deleteWhitespaceDescendants(org.w3c.dom.Element element)
          recursively deletes all whitespace descendants
static java.util.Enumeration depthFirstEnumeration(org.w3c.dom.Element element)
           
static java.util.Enumeration depthFirstEnumeration(org.w3c.dom.Node node)
          iterate through whole tree
static org.w3c.dom.Element getAncestor(org.w3c.dom.Element element, java.lang.String tagName)
          gets first ancestor of 'element' with tagName; [element is not its own ancestor]
static java.util.Vector getAncestors(org.w3c.dom.Element element)
          gets all ancestors of 'element' including the document Element but not Document.
static org.w3c.dom.Element getAncestorWithClass(org.w3c.dom.Element element, java.lang.Class theClass)
          gets first ancestor of 'element' of given class (or superclass) [element is not its ancestor]
static java.lang.String getAttributeString(org.w3c.dom.Attr att)
          returns a string representing a single attribute in a start tag, e.g.
static java.lang.String getAttributeString(org.w3c.dom.Element element)
          returns the attributes in concatenated text form (suitable for insertion to start tags).
static java.util.Vector getChild(org.w3c.dom.Element element, java.lang.String tagName, java.lang.String attributeName, java.lang.String attributeValue)
          get children with combination of tagNames, attribute names and values.
static org.w3c.dom.Element getChildElement(org.w3c.dom.Element element, int index)
          get the index'th Element child.
static java.util.Hashtable getChildElementNameTable(org.w3c.dom.Element parentElement)
          make a list of all child element names and the instances of each.
static java.util.Vector getChildElements(org.w3c.dom.Element element)
          get all Element children.
static java.util.Vector getChildrenWithElementName(org.w3c.dom.Element element, java.lang.String name)
          gets vector of XNode children with given element name (ignored if name is null or bad value of sensitivity).
static java.util.Vector getDescendants(org.w3c.dom.Element element, int level, java.lang.String tagName)
          gets all children at given level.
static java.util.Vector getDescendantsWithClass(org.w3c.dom.Node node, java.lang.Class theClass)
          gets descendants of 'element' of given class (or superclass) [element is not its descendant].
static org.w3c.dom.Element getFirstChildWithElementName(org.w3c.dom.Element element, java.lang.String name)
          gets first child with given element name (ignored if name is null).
static org.w3c.dom.Text getPCDATAChildNode(org.w3c.dom.Element element)
          if this has a single PCDATA child, returns it, else null
static java.lang.String getPCDATAContent(org.w3c.dom.Element element)
          if this has a single PCDATA child, returns its string value, else null
static java.lang.String getValue(org.w3c.dom.Element element)
          returns value of first child if this is Text else ""
static boolean isEmptyAttribute(java.lang.String attributeValue)
          UTILITIES
static void outputChildContent(org.w3c.dom.Element element, java.io.Writer w, int type, int level)
          subclassed by specialist classes
static void outputEndElement(org.w3c.dom.Element element, java.io.Writer w, int level)
          for building the tree.
static void outputEndTag(org.w3c.dom.Element element, java.io.Writer w, int type, int level)
          subclassed by specialist classes
static java.lang.String outputEventStream(org.w3c.dom.Node node, java.io.Writer w, int type, int level)
          gets the event stream (as XML or text).
static void outputHTML(org.w3c.dom.Element element, java.io.Writer w)
          output node as HTML - normally subclassed
static void outputHTML(org.w3c.dom.Node node, java.io.Writer w)
          output node as HTML - normally subclassed
static void outputStartElement(org.w3c.dom.Element element, java.io.Writer w, org.w3c.dom.Element parentNode, int level)
          for building the tree.
static void outputStartTag(org.w3c.dom.Element element, java.io.Writer w, int type, int level)
          subclassed by specialist classes
static java.util.Enumeration preorderEnumeration(org.w3c.dom.Element element)
          iterate through whole tree.
static java.util.Enumeration preorderEnumeration(org.w3c.dom.Node node)
          iterate through whole tree.
static void removeChildNodes(org.w3c.dom.Element element)
          remove all child nodes
static void removeNode(org.w3c.dom.Node node)
          remove a node from its parent.
 void replace(org.w3c.dom.Element toElement, org.w3c.dom.Element fromElement)
          transfer children from fromElement to toElement; replace toElement by fromElement and copy attributes and children
static void setPCDATAContent(org.w3c.dom.Element element, java.lang.String s)
          Sets a string to be the content of an existing single PCDATANode.
static void testEdit(org.w3c.dom.Node node)
          create a deep or shallow copy of an element, including correct classes; tag and owner document set to those from element.
static void transfer(org.w3c.dom.Document toDocument, org.w3c.dom.Document fromDocument)
          transfers complete fromDocument, changing ownership and subsclassing
static java.lang.String write(java.io.Writer w, org.w3c.dom.Document document, int type, int level)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PMRDelegate

public PMRDelegate()
Method Detail

deleteWhitespaceDescendants

public static void deleteWhitespaceDescendants(org.w3c.dom.Element element)
recursively deletes all whitespace descendants

removeNode

public static void removeNode(org.w3c.dom.Node node)

remove a node from its parent.

.

removeChildNodes

public static void removeChildNodes(org.w3c.dom.Element element)
remove all child nodes

replace

public void replace(org.w3c.dom.Element toElement,
                    org.w3c.dom.Element fromElement)
transfer children from fromElement to toElement; replace toElement by fromElement and copy attributes and children

transfer

public static void transfer(org.w3c.dom.Document toDocument,
                            org.w3c.dom.Document fromDocument)
transfers complete fromDocument, changing ownership and subsclassing

depthFirstEnumeration

public static java.util.Enumeration depthFirstEnumeration(org.w3c.dom.Element element)

preorderEnumeration

public static java.util.Enumeration preorderEnumeration(org.w3c.dom.Element element)

iterate through whole tree. Kludged to use dethFirst

.

outputHTML

public static void outputHTML(org.w3c.dom.Element element,
                              java.io.Writer w)
                       throws java.io.IOException
output node as HTML - normally subclassed

getChildElements

public static java.util.Vector getChildElements(org.w3c.dom.Element element)
get all Element children. If none, returns empty Vector

getDescendants

public static java.util.Vector getDescendants(org.w3c.dom.Element element,
                                              int level,
                                              java.lang.String tagName)
gets all children at given level. If tagName != null, selects those with tagName, else gets all. use level==-1 to select infinite depth

getChildElement

public static org.w3c.dom.Element getChildElement(org.w3c.dom.Element element,
                                                  int index)
get the index'th Element child. If none returns null. Count ignores non-Element nodes

getChildElementNameTable

public static java.util.Hashtable getChildElementNameTable(org.w3c.dom.Element parentElement)
make a list of all child element names and the instances of each. The Hashtable elements are Vectors of Element instances

getDescendantsWithClass

public static java.util.Vector getDescendantsWithClass(org.w3c.dom.Node node,
                                                       java.lang.Class theClass)
gets descendants of 'element' of given class (or superclass) [element is not its descendant]. If none found, zero element Vector returned
Parameters:
Element - element the element whose descendants are searched
Class - theClass class of element to find (includes subclasses)
Returns:
Vector vector of Elements (none = zero-length vector)

getAncestors

public static java.util.Vector getAncestors(org.w3c.dom.Element element)
gets all ancestors of 'element' including the document Element but not Document. [element is not its own ancestor]
Parameters:
Element - element to analyse
Returns:
Element the ancestor (null = none)

getAncestor

public static org.w3c.dom.Element getAncestor(org.w3c.dom.Element element,
                                              java.lang.String tagName)
gets first ancestor of 'element' with tagName; [element is not its own ancestor]
Parameters:
Element - element to analyse
String - tagName the full element name
Returns:
Element the ancestor (null = none)

getAncestorWithClass

public static org.w3c.dom.Element getAncestorWithClass(org.w3c.dom.Element element,
                                                       java.lang.Class theClass)
gets first ancestor of 'element' of given class (or superclass) [element is not its ancestor]

getAttributeString

public static java.lang.String getAttributeString(org.w3c.dom.Element element)
returns the attributes in concatenated text form (suitable for insertion to start tags). If none, returns "". Example:
xml:link="simple" href="http://www.some/where"
Returns:
String the attribute String

getAttributeString

public static java.lang.String getAttributeString(org.w3c.dom.Attr att)
returns a string representing a single attribute in a start tag, e.g. foo=bar plugh"; String starts with space and delimiters are QUOT, not APOS

addAttributes

public static void addAttributes(org.w3c.dom.Element element,
                                 org.xml.sax.AttributeList attributeList)

copyAttributesFrom

public static void copyAttributesFrom(org.w3c.dom.Element toElement,
                                      org.w3c.dom.Element fromElement)

copyNode

public static org.w3c.dom.Node copyNode(org.w3c.dom.Document toDocument,
                                        org.w3c.dom.Node fromNode,
                                        boolean deep)
make a copy of the Node in a different document context. attributes are always copied, element children depend on deep

getChildrenWithElementName

public static java.util.Vector getChildrenWithElementName(org.w3c.dom.Element element,
                                                          java.lang.String name)
gets vector of XNode children with given element name (ignored if name is null or bad value of sensitivity).
Parameters:
int - nameType LOCAL, QUALIFIED or UNIVERSAL
String - name the elementName (must match exactly other than case)
int - sensitivity can take values CASE or IGNORECASE
Returns:
Vector the vector of children (null if none)

getFirstChildWithElementName

public static org.w3c.dom.Element getFirstChildWithElementName(org.w3c.dom.Element element,
                                                               java.lang.String name)
gets first child with given element name (ignored if name is null).
Parameters:
String - name the elementName
Returns:
Element the first child or null

getPCDATAContent

public static java.lang.String getPCDATAContent(org.w3c.dom.Element element)
if this has a single PCDATA child, returns its string value, else null
Returns:
String String content of single PCDATA child

getPCDATAChildNode

public static org.w3c.dom.Text getPCDATAChildNode(org.w3c.dom.Element element)
if this has a single PCDATA child, returns it, else null
Returns:
PCDATANode single PCDATA child

setPCDATAContent

public static void setPCDATAContent(org.w3c.dom.Element element,
                                    java.lang.String s)
Sets a string to be the content of an existing single PCDATANode. If there are no children, create a new PCDATANode. If there are non-PCDATA children or more than one PCDATANode child, return false without action.
Parameters:
String - s to be added to PCDATA content
Returns:
boolean was able to append String

write

public static java.lang.String write(java.io.Writer w,
                                     org.w3c.dom.Document document,
                                     int type,
                                     int level)
                              throws java.io.IOException

outputEventStream

public static java.lang.String outputEventStream(org.w3c.dom.Node node,
                                                 java.io.Writer w,
                                                 int type,
                                                 int level)
                                          throws java.io.IOException
gets the event stream (as XML or text). Options for type
This is a mess and needs recoding into subclasses **
Parameters:
Writer - w outputs to this stream.
int - type type chosen from list above
int - level of indentation (normally set to 0 when called, and expanded recursively internally);
Returns:
String output event stream if w is StringWriter

outputStartTag

public static void outputStartTag(org.w3c.dom.Element element,
                                  java.io.Writer w,
                                  int type,
                                  int level)
                           throws java.io.IOException
subclassed by specialist classes

outputStartElement

public static void outputStartElement(org.w3c.dom.Element element,
                                      java.io.Writer w,
                                      org.w3c.dom.Element parentNode,
                                      int level)
                               throws java.io.IOException
for building the tree. If writer is null, builds a tree by adding this to parentNode, else outputs a start tag.
Parameters:
Element - parentNode the parentNode if not null
Writer - w if not null, output to writer rather than building tree

outputChildContent

public static void outputChildContent(org.w3c.dom.Element element,
                                      java.io.Writer w,
                                      int type,
                                      int level)
                               throws java.io.IOException
subclassed by specialist classes

outputEndTag

public static void outputEndTag(org.w3c.dom.Element element,
                                java.io.Writer w,
                                int type,
                                int level)
                         throws java.io.IOException
subclassed by specialist classes

outputEndElement

public static void outputEndElement(org.w3c.dom.Element element,
                                    java.io.Writer w,
                                    int level)
                             throws java.io.IOException
for building the tree. If writer is null, noop; else outputs an end tag.
Parameters:
Writer - w if not null, output to writer rather than building tree

depthFirstEnumeration

public static java.util.Enumeration depthFirstEnumeration(org.w3c.dom.Node node)

iterate through whole tree

.

preorderEnumeration

public static java.util.Enumeration preorderEnumeration(org.w3c.dom.Node node)

iterate through whole tree. Kludged to use dethFirst

.

outputHTML

public static void outputHTML(org.w3c.dom.Node node,
                              java.io.Writer w)
                       throws java.io.IOException
output node as HTML - normally subclassed

deleteWhitespaceDecsendants

public static void deleteWhitespaceDecsendants(org.w3c.dom.Document document)
recursively removes all whitespace nodes

debug

public static void debug(org.w3c.dom.Node node)

testEdit

public static void testEdit(org.w3c.dom.Node node)
create a deep or shallow copy of an element, including correct classes; tag and owner document set to those from element. Can't do this unless can set create element of given class with given tagname in document context. Will try to rewrite using subclassed Document.createElement

isEmptyAttribute

public static boolean isEmptyAttribute(java.lang.String attributeValue)
UTILITIES

getValue

public static java.lang.String getValue(org.w3c.dom.Element element)
returns value of first child if this is Text else ""

getChild

public static java.util.Vector getChild(org.w3c.dom.Element element,
                                        java.lang.String tagName,
                                        java.lang.String attributeName,
                                        java.lang.String attributeValue)
get children with combination of tagNames, attribute names and values. null means wildcard