org.enhydra.xml.dom
Class DOMOps

java.lang.Object
  |
  +--org.enhydra.xml.dom.DOMOps

public final class DOMOps
extends Object

Various static methods the do simple operations on the DOM.


Method Summary
static Node adoptNode(Document doc, Node node)
          Call Document#adoptNode(node) on doc if supported.
static int countChildren(Node node)
          Count the number of children in a node has.
static Node getActualNode(Node node)
          Get the real DOM node, bypassing an XMLC-generated container.
static Document getContentDocument(HTMLElement elem)
          Call HTMLElement#getContentDocument(node) on elem if supported.
static Document getDocument(Node node)
          Get the owner document object for a node.
static String getEncoding(Document doc)
          Call Document#getEncoding() on doc if supported.
static String getEncoding(Entity entity)
          Call Entity#getEncoding on entity if supported.
static boolean getStandalone(Document doc)
          Call Document#getStandalone() on doc if supported.
static boolean getStrictErrorChecking(Document doc)
          Call Document#getStrictErrorChecking() on doc if supported.
static String getVersion(Document doc)
          Call Document#getVersion() on doc if supported.
static boolean isLazyDOMInstance(Document doc)
          Determine if a document is a LazyDOM instance document.
static Node replaceNode(Node srcNode, Node destNode)
          Replace a node with one imported from another document.
static void setEncoding(Document doc, String enc)
          Call Document#setEncoding(enc) on doc if supported.
static void setEncoding(Entity entity, String enc)
          Call Entity#setEncoding(enc) on entity if supported.
static void setStandalone(Document doc, boolean val)
          Call Document#setStandalone(val) on doc if supported.
static void setStrictErrorChecking(Document doc, boolean val)
          Call Document#setStrictErrorChecking(val) on doc if supported.
static void setVersion(Document doc, String version)
          Call Document#setVersion(version) on doc if supported.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getDocument

public static Document getDocument(Node node)
Get the owner document object for a node. This gets the actual document. If a XMLC document class instance the contained document is returned.

getActualNode

public static Node getActualNode(Node node)
Get the real DOM node, bypassing an XMLC-generated container. If a XMLC document class instance the contained document is returned. Otherwise the node is returned.

replaceNode

public static Node replaceNode(Node srcNode,
                               Node destNode)
Replace a node with one imported from another document.
Parameters:
srcNode - The node to clone and insert
destNode - The node to be replaced
Returns:
The new node that replaces the destination node.

countChildren

public static int countChildren(Node node)
Count the number of children in a node has.

isLazyDOMInstance

public static boolean isLazyDOMInstance(Document doc)
Determine if a document is a LazyDOM instance document.
Returns:
true if its a LazyDOM instance, false if its a LazyDOM template or not a LazyDOM at all.

getStandalone

public static boolean getStandalone(Document doc)
Call Document#getStandalone() on doc if supported. By using reflection, this method avoids problems when Document.getStandalone() is not supported by the given implementation of org.w3c.dom.Document (e.g. the one provided by JDK 1.4).
Parameters:
doc - the document
Returns:
true if the document is standalone, false else
Throws:
UnsupportedOperationException - if doc does not support the method

setStandalone

public static void setStandalone(Document doc,
                                 boolean val)
Call Document#setStandalone(val) on doc if supported. By using reflection, this method avoids problems when Document.setStandalone() is not supported by the given implementation of org.w3c.dom.Document (e.g. the one provided by JDK 1.4).
Parameters:
doc - the document
val - the new value
Throws:
UnsupportedOperationException - if doc does not support the method

getEncoding

public static String getEncoding(Document doc)
Call Document#getEncoding() on doc if supported. By using reflection, this method avoids problems when Document.getEncoding() is not supported by the given implementation of org.w3c.dom.Document (e.g. the one provided by JDK 1.4).
Parameters:
doc - the document
Returns:
the encoding
Throws:
UnsupportedOperationException - if doc does not support the method

setEncoding

public static void setEncoding(Document doc,
                               String enc)
Call Document#setEncoding(enc) on doc if supported. By using reflection, this method avoids problems when Document.setEncoding() is not supported by the given implementation of org.w3c.dom.Document (e.g. the one provided by JDK 1.4).
Parameters:
doc - the document
enc - the encoding
Returns:
the encoding
Throws:
UnsupportedOperationException - if doc does not support the method

getStrictErrorChecking

public static boolean getStrictErrorChecking(Document doc)
Call Document#getStrictErrorChecking() on doc if supported. By using reflection, this method avoids problems when Document.getStrictErrorChecking() is not supported by the given implementation of org.w3c.dom.Document (e.g. the one provided by JDK 1.4).
Parameters:
doc - the document
Returns:
true if the document has strict error checking, false else
Throws:
UnsupportedOperationException - if doc does not support the method

setStrictErrorChecking

public static void setStrictErrorChecking(Document doc,
                                          boolean val)
Call Document#setStrictErrorChecking(val) on doc if supported. By using reflection, this method avoids problems when Document.setStrictErrorChecking() is not supported by the given implementation of org.w3c.dom.Document (e.g. the one provided by JDK 1.4).
Parameters:
doc - the document
val - the new value
Throws:
UnsupportedOperationException - if doc does not support the method

getVersion

public static String getVersion(Document doc)
Call Document#getVersion() on doc if supported. By using reflection, this method avoids problems when Document.getVersion() is not supported by the given implementation of org.w3c.dom.Document (e.g. the one provided by JDK 1.4).
Parameters:
doc - the document
Returns:
the version
Throws:
UnsupportedOperationException - if doc does not support the method

setVersion

public static void setVersion(Document doc,
                              String version)
Call Document#setVersion(version) on doc if supported. By using reflection, this method avoids problems when Document.setVersion() is not supported by the given implementation of org.w3c.dom.Document (e.g. the one provided by JDK 1.4).
Parameters:
doc - the document
version - the version
Returns:
the version
Throws:
UnsupportedOperationException - if doc does not support the method

adoptNode

public static Node adoptNode(Document doc,
                             Node node)
                      throws DOMException
Call Document#adoptNode(node) on doc if supported. By using reflection, this method avoids problems when Document.adoptNode() is not supported by the given implementation of org.w3c.dom.Document (e.g. the one provided by JDK 1.4).
Parameters:
doc - the document
node - the node
Returns:
the adopted node, or null if this operation fails, such as when the source node comes from a different implementation.
Throws:
UnsupportedOperationException - if doc does not support the method
DOMException - NOT_SUPPORTED_ERR: Raised if the source node is of type DOCUMENT, DOCUMENT_TYPE. NO_MODIFICATION_ALLOWED_ERR: Raised when the source node is readonly.

getEncoding

public static String getEncoding(Entity entity)
Call Entity#getEncoding on entity if supported. By using reflection, this method avoids problems when Entity.getEncoding() is not supported by the given implementation of org.w3c.dom.Entity (e.g. the one provided by JDK 1.4).
Parameters:
entity - the entity
Returns:
the encoding
Throws:
UnsupportedOperationException - if entity does not support the method

setEncoding

public static void setEncoding(Entity entity,
                               String enc)
Call Entity#setEncoding(enc) on entity if supported. By using reflection, this method avoids problems when Entity.setEncoding() is not supported by the given implementation of org.w3c.dom.Entity (e.g. the one provided by JDK 1.4).
Parameters:
entity - the entity
enc - the encoding
Returns:
the encoding
Throws:
UnsupportedOperationException - if entity does not support the method

getContentDocument

public static Document getContentDocument(HTMLElement elem)
Call HTMLElement#getContentDocument(node) on elem if supported. By using reflection, this method avoids problems when HTMLElement.getContentDocument() is not supported by the given implementation of org.w3c.dom.HTMLElement (e.g. the one provided by JDK 1.4).
Parameters:
elem - the element
Returns:
the adopted node, or null if this operation fails, such as when the source node comes from a different implementation.
Throws:
UnsupportedOperationException - if elem does not support the method


Copyright © 1999-2002 enhydra.org (Mark Diekhans, David Li, Richard Kunze). All Rights reserved.