org.inria.ns.reflex.xml.dom
Class DOMHelper

java.lang.Object
  extended by org.inria.ns.reflex.xml.dom.DOMHelper

public class DOMHelper
extends Object

DOM-helper static methods.

Author:
Philippe Poulard

Method Summary
static Node asNode(Object o)
          Cast an XOperable object to a DOM node.
static DOMSource getDOMSource(Source source)
          Transform a source to a DOM source.
static DOMSource getDOMSource(Source source, ParserConfiguration parserConfiguration)
          Transform a source to a DOM source.
static Node getFirstChild(Node node)
          Return the first child node.
static Node getNextNode(Node node)
          Return the next node.
static Node getNextXPathNode(Node node)
          Return the next node in the XPath data model : container structures are flattenned, and adjacent text nodes are returned as a single node ; in fact, the first non-empty text node of the sequence is returned, but the text value returned by #stringValueOf(Object) is the concatenation of the individual value of the text nodes of the sequence.
static Node getPreviousNode(Node node)
          Return the previous node.
static boolean isTextNode(Node node)
          Indicates whether a node is a text node or not.
static boolean isTextType(int type)
          Indicates whether a type of node is a text node or not.
static int removeNamespaceDeclaration(Element element, String namespaceURI)
          Remove the namespace URI declarations defined by an element, if any.
static Attr renameAttr(Attr attr, QName newName)
          Rename an attribute.
static Element renameElement(Element element, QName newName)
          Rename an element.
static Node renameNode(Node node, QName newName)
          Rename a node by calling one of the relevant methods.
static ProcessingInstruction renameProcessingInstruction(ProcessingInstruction pi, String newName)
          Rename a processing instruction.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getNextXPathNode

public static Node getNextXPathNode(Node node)
Return the next node in the XPath data model : container structures are flattenned, and adjacent text nodes are returned as a single node ; in fact, the first non-empty text node of the sequence is returned, but the text value returned by #stringValueOf(Object) is the concatenation of the individual value of the text nodes of the sequence.

Parameters:
node - A non-null node.
Returns:
The next node, according to the XPath data model. Maybe null if there is no more siblings.
See Also:
getNextNode(Node)

getNextNode

public static Node getNextNode(Node node)
Return the next node. When flatennable container nodes (like entities or document fragments) are found, they are browsed. A Document is not a flatennable node.

Parameters:
node - A non-null node.
Returns:
The next node, considering that the flatennable container nodes of the tree are flatenned.

getPreviousNode

public static Node getPreviousNode(Node node)
Return the previous node. When flatennable container nodes (like entities or document fragments) are found, they are browsed. A Document is not a flatennable node.

Parameters:
node - A non-null node.
Returns:
The previous node, considering that the flatennable container nodes of the tree are flatenned.

getFirstChild

public static Node getFirstChild(Node node)
Return the first child node. When flatennable container nodes (like entities or document fragments) are found, they are browsed.

Parameters:
node - A non-null node.
Returns:
The child node, considering that the flatennable container nodes of the tree are flatenned.

isTextNode

public static boolean isTextNode(Node node)
Indicates whether a node is a text node or not.

Parameters:
node - The node to test.
Returns:
true if the node is a text node (CData section or not), false otherwise.

isTextType

public static boolean isTextType(int type)
Indicates whether a type of node is a text node or not.

Parameters:
type - The type to test.
Returns:
true if the type of node is a text node (CData section or not), false otherwise.
See Also:
Node

renameNode

public static Node renameNode(Node node,
                              QName newName)
Rename a node by calling one of the relevant methods.

Parameters:
node - The node to rename : element, attribute or processing instruction. Other type of nodes are ignored.
newName - The new name of the node (should be an NCName for PIs).
Returns:
A new node, which is a copy of the given one but that has a different name, or the same node it it was not an element, attribute, or processing instruction.
See Also:
renameElement(Element, QName), renameAttr(Attr, QName), renameProcessingInstruction(ProcessingInstruction, String)

renameElement

public static Element renameElement(Element element,
                                    QName newName)
Rename an element.

Parameters:
element - The element to rename.
newName - Its new name.
Returns:
A new element, which is a copy of the given one but that has a different name.

renameAttr

public static Attr renameAttr(Attr attr,
                              QName newName)
Rename an attribute.

Parameters:
attr - The attribute to rename.
newName - Its new name.
Returns:
A new attribute, which is a copy of the given one but that has a different name.

renameProcessingInstruction

public static ProcessingInstruction renameProcessingInstruction(ProcessingInstruction pi,
                                                                String newName)
Rename a processing instruction.

Parameters:
pi - The processing instruction to rename.
newName - Its new name.
Returns:
A new processing instruction, which is a copy of the given one but that has a different name.

getDOMSource

public static DOMSource getDOMSource(Source source)
Transform a source to a DOM source.

Parameters:
source - The input source to convert. If it must be parsed, a namespace aware parser will be used.
Returns:
The DOM source.
See Also:
ParserConfiguration.NAMESPACEAWARE_PARSER_CONFIGURATION, SAXUtil.getSAXSource(Source)

getDOMSource

public static DOMSource getDOMSource(Source source,
                                     ParserConfiguration parserConfiguration)
Transform a source to a DOM source.

Parameters:
source - The input source to convert.
parserConfiguration - If the source must be parsed, this configuration will be used. Can be null if the source hasn't to be parsed.
Returns:
The DOM source.
See Also:
SAXUtil.getSAXSource(Source, ParserConfiguration)

removeNamespaceDeclaration

public static int removeNamespaceDeclaration(Element element,
                                             String namespaceURI)
Remove the namespace URI declarations defined by an element, if any.

Parameters:
element - The element to look inside.
namespaceURI - The namespace URI to remove.
Returns:
The number of namespace declarations removed.

asNode

public static Node asNode(Object o)
                   throws IllegalArgumentException
Cast an XOperable object to a DOM node.

Best effort : errors such as bad XML names are ignored.

Parameters:
o - The object to cast.
Returns:
A node.
Throws:
IllegalArgumentException - When the object is not X-operable.
See Also:
XMaster.getXOperator(Object)