nl.idgis.giserver
Class DomUtils

java.lang.Object
  extended by nl.idgis.giserver.DomUtils

public class DomUtils
extends java.lang.Object

Singleton to keep Dom utils. These methods will hides low level Dom navigation processing.

Author:
bretelerjj

Constructor Summary
DomUtils()
           
 
Method Summary
static void addErrorReport(org.w3c.dom.Document doc, java.lang.String className, java.lang.String methodName, java.lang.Exception e)
          Add a error report as a collection of nodes to the document.
static void addErrorReport(org.w3c.dom.Document doc, java.lang.String className, java.lang.String methodName, java.lang.String message)
          Add a error report as a collection of nodes to the document.
static org.w3c.dom.Element addNewNodeElement(org.w3c.dom.Document doc, org.deegree.datatypes.QualifiedName name, java.lang.String value, org.w3c.dom.Node home)
          Add a new node at the given point into the Dom tree.
static org.w3c.dom.Element addNewNodeElement(org.w3c.dom.Document doc, java.lang.String name, java.lang.String value, org.w3c.dom.Node home)
          Add a new node at the given point into the Dom tree.
static org.w3c.dom.Element addNewNodeElement(java.lang.String name, org.deegree.datatypes.QualifiedName value, org.w3c.dom.Node home)
          Add a new node at the given point into the Dom tree.
static org.w3c.dom.Node addXmlString(org.w3c.dom.Element node, java.lang.String xmlString)
          Add an xml tagged string to a DomTree.
static void clearNode(org.w3c.dom.Node node)
          Get rid of everything for the Dom tree node.
static void clearNodeChilds(org.w3c.dom.Node node)
          Get rid of the children for a Dom tree node.
static org.w3c.dom.Node copyNode(org.w3c.dom.Element nodeToCopy, org.w3c.dom.Element destinationNodeForHook)
          Copy a node from a document to (another) document
static org.w3c.dom.Document createDocument(java.lang.String xml, boolean validation)
          Create for a given xml representation its corresponding DOM tree representation.
static java.lang.String Dom2String(org.w3c.dom.Document document)
          Convert a DOM tree info into a string in standard Xml format.
static void DomPrintWriter(org.w3c.dom.Document document, java.io.PrintWriter pw)
          Writes a Dom document to the given output stream.
static void DomStringWriter(org.w3c.dom.Document document, java.io.StringWriter sw)
          Writes a Dom document to the given string.
static javax.xml.parsers.DocumentBuilder getDocumentBuilder(boolean validation)
          Create a document builder.
static org.w3c.dom.Document getNewDoucument()
          creates a empty Dom document.
static org.w3c.dom.Element getNodeNamed(org.w3c.dom.Node node, java.lang.String name, java.lang.Boolean grandchildren)
          Search recursive in a dom tree for the first child or grant child (grandchildren=true) of type Element with the given name started at the given (parent) node .
static void getNodesNamed(org.w3c.dom.Node startNode, java.lang.String name, java.util.Vector<org.w3c.dom.Node> findNodes, boolean grandchildren)
          Search recursive in a dom tree for the all children or grant children (grand children=true) with the given name started at the given (parent) node.
static org.deegree.datatypes.QualifiedName readQualifiedName(org.w3c.dom.Element node)
          Read qualified name.
static void validateDocument(org.w3c.dom.Document document, javax.xml.transform.Source schemaFile)
          A given DOM tree will be validate again a xsd schema.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DomUtils

public DomUtils()
Method Detail

getNewDoucument

public static org.w3c.dom.Document getNewDoucument()
creates a empty Dom document. Defaults : namespace aware = true. validating = no.

Returns:
the new empty document.

Dom2String

public static java.lang.String Dom2String(org.w3c.dom.Document document)
Convert a DOM tree info into a string in standard Xml format.

Parameters:
document -
Returns:
document in a xml string

getDocumentBuilder

public static javax.xml.parsers.DocumentBuilder getDocumentBuilder(boolean validation)
Create a document builder. The builder may be shared, so this may be a singleton.

Parameters:
validation - parsing with validation on
Returns:
the created document builder

createDocument

public static org.w3c.dom.Document createDocument(java.lang.String xml,
                                                  boolean validation)
                                           throws org.xml.sax.SAXException,
                                                  java.io.IOException
Create for a given xml representation its corresponding DOM tree representation. Defaults : namespace aware = true.

Parameters:
xml - input for the Dom tree.
validation - indication parsing with validation
Returns:
Dom tree in document package.
Throws:
java.io.IOException
org.xml.sax.SAXException

DomPrintWriter

public static void DomPrintWriter(org.w3c.dom.Document document,
                                  java.io.PrintWriter pw)
                           throws javax.xml.transform.TransformerException,
                                  java.io.IOException
Writes a Dom document to the given output stream. The output format will be in standard xml format and the indent mode will be on.

Parameters:
document - the printing document
sw - printer stream write domain
Throws:
javax.xml.transform.TransformerException
java.io.IOException

DomStringWriter

public static void DomStringWriter(org.w3c.dom.Document document,
                                   java.io.StringWriter sw)
                            throws javax.xml.transform.TransformerException
Writes a Dom document to the given string. The output format will be in standard xml format and the indent mode will be on.

Parameters:
document - the printing document
sw - string stream write domain
Throws:
javax.xml.transform.TransformerException

validateDocument

public static void validateDocument(org.w3c.dom.Document document,
                                    javax.xml.transform.Source schemaFile)
                             throws org.xml.sax.SAXException,
                                    java.io.IOException
A given DOM tree will be validate again a xsd schema.

Parameters:
document - to validate
schemaFile - source of the schema as file
Throws:
org.xml.sax.SAXException
java.io.IOException

addNewNodeElement

public static org.w3c.dom.Element addNewNodeElement(org.w3c.dom.Document doc,
                                                    java.lang.String name,
                                                    java.lang.String value,
                                                    org.w3c.dom.Node home)
Add a new node at the given point into the Dom tree.

Parameters:
doc - - document reference needed to create new doc elements
name - - the name of the new node
value - - the value attached to the new node
home - - node in the Dom tree where to insert the new node
Returns:
the new inserted node element.

addNewNodeElement

public static org.w3c.dom.Element addNewNodeElement(org.w3c.dom.Document doc,
                                                    org.deegree.datatypes.QualifiedName name,
                                                    java.lang.String value,
                                                    org.w3c.dom.Node home)
Add a new node at the given point into the Dom tree.

Parameters:
doc - - document reference needed to create new doc elements
name - - the qualified name of the new node
value - - the value attached to the new node
home - - node in the Dom tree where to insert the new node
Returns:
the new inserted node element.

addNewNodeElement

public static org.w3c.dom.Element addNewNodeElement(java.lang.String name,
                                                    org.deegree.datatypes.QualifiedName value,
                                                    org.w3c.dom.Node home)
Add a new node at the given point into the Dom tree.

Parameters:
name - - the name of the new node
value - - the value (qualified name) attached to the new node
home - - node in the Dom tree where to insert the new node
Returns:
the new inserted node element.

clearNodeChilds

public static void clearNodeChilds(org.w3c.dom.Node node)
Get rid of the children for a Dom tree node.

Parameters:
node - in a Dom tree

clearNode

public static void clearNode(org.w3c.dom.Node node)
Get rid of everything for the Dom tree node. That means all children and all attributes will be deleted.

Parameters:
node - in a Dom tree

addErrorReport

public static void addErrorReport(org.w3c.dom.Document doc,
                                  java.lang.String className,
                                  java.lang.String methodName,
                                  java.lang.String message)
Add a error report as a collection of nodes to the document. Each report part will be represented in a named node with its node value.

Parameters:
doc - document
className - report part class name
methodName - report part method name
message - report part additional message

addErrorReport

public static void addErrorReport(org.w3c.dom.Document doc,
                                  java.lang.String className,
                                  java.lang.String methodName,
                                  java.lang.Exception e)
Add a error report as a collection of nodes to the document. Each report part will be represented in a named node with its node value followed by the stack trace where the error was raised.

Parameters:
doc - document
className - report part class name
methodName - report part method name
message - report part additional message

getNodeNamed

public static org.w3c.dom.Element getNodeNamed(org.w3c.dom.Node node,
                                               java.lang.String name,
                                               java.lang.Boolean grandchildren)
Search recursive in a dom tree for the first child or grant child (grandchildren=true) of type Element with the given name started at the given (parent) node .

Parameters:
startNode - start the searching in the Dom tree
name - the child name acting as search key
grandchildren - search for grand children
Returns:

getNodesNamed

public static void getNodesNamed(org.w3c.dom.Node startNode,
                                 java.lang.String name,
                                 java.util.Vector<org.w3c.dom.Node> findNodes,
                                 boolean grandchildren)
Search recursive in a dom tree for the all children or grant children (grand children=true) with the given name started at the given (parent) node.

Parameters:
startNode - start the searching in the Dom tree
namer - the child name acting as search key
findNodes - the collection children
grandchildren - search for grand children

addXmlString

public static org.w3c.dom.Node addXmlString(org.w3c.dom.Element node,
                                            java.lang.String xmlString)
                                     throws org.xml.sax.SAXException,
                                            java.io.IOException
Add an xml tagged string to a DomTree.

Parameters:
node - insertion place
xmlString - info to add
Throws:
java.io.IOException
org.xml.sax.SAXException
java.lang.Exception

copyNode

public static org.w3c.dom.Node copyNode(org.w3c.dom.Element nodeToCopy,
                                        org.w3c.dom.Element destinationNodeForHook)
Copy a node from a document to (another) document

Parameters:
nodeToCopy - source of the copy
destinationNodeForHook - destination node to insert the new copy
Returns:

readQualifiedName

public static org.deegree.datatypes.QualifiedName readQualifiedName(org.w3c.dom.Element node)
                                                             throws org.w3c.dom.DOMException,
                                                                    java.net.URISyntaxException
Read qualified name.

Parameters:
node - containing the qualified name
Returns:
qualified name or null.
Throws:
java.net.URISyntaxException
org.w3c.dom.DOMException