org.pf.pax
Class XmlUtil

java.lang.Object
  extended by org.pf.pax.XmlUtil

public class XmlUtil
extends java.lang.Object

This class provides general helper classes that normally should be part of the Java API.

Version:
1.0
Author:
Manfred Duchrow

Field Summary
static java.lang.String DEFAULT_NS_PREFIX
          The prefix name that is used for the default namespace (i.e.
 
Method Summary
 void addNamespacesFrom(NamespacePrefixMapper namespaces, org.w3c.dom.Element element)
          Adds all namespaces that are declared in the given element with their prefix to the provided namespace prefix mapper.
 void addNamespacesFromElementAndChildren(NamespacePrefixMapper namespaces, org.w3c.dom.Element element)
          Adds all namespaces that are declared in the given element and all child elements together with their prefixes to the provides namespace prefix mapper.
static XmlUtil current()
          Returns the only instance this class supports (design pattern "Singleton")
 javax.xml.namespace.NamespaceContext extractNamespacesFrom(org.w3c.dom.Document document)
          Extracts all namespace definitions from the given document and returns them in a NamespaceContext implementation.
 javax.xml.namespace.NamespaceContext extractNamespacesFrom(org.w3c.dom.Element rootElement)
          Extracts all namespace definitions from the given root element and returns them in a NamespaceContext implementation.
 org.w3c.dom.Document readXmlFile(java.lang.String filename)
          Returns the document object read from the specified XML file.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_NS_PREFIX

public static final java.lang.String DEFAULT_NS_PREFIX
The prefix name that is used for the default namespace (i.e. "dns").

See Also:
Constant Field Values
Method Detail

current

public static XmlUtil current()
Returns the only instance this class supports (design pattern "Singleton")


readXmlFile

public org.w3c.dom.Document readXmlFile(java.lang.String filename)
                                 throws java.lang.Exception
Returns the document object read from the specified XML file. If the file cannot be found directly with the given name it will be looked-up on the classpath.

Throws:
java.lang.Exception

addNamespacesFrom

public void addNamespacesFrom(NamespacePrefixMapper namespaces,
                              org.w3c.dom.Element element)
Adds all namespaces that are declared in the given element with their prefix to the provided namespace prefix mapper.

Parameters:
namespaces - An implementation of a NamespaceContext that can collect prefix to namespace mappings (must not be null)
element - The element from which to extract namespace declarations.

addNamespacesFromElementAndChildren

public void addNamespacesFromElementAndChildren(NamespacePrefixMapper namespaces,
                                                org.w3c.dom.Element element)
Adds all namespaces that are declared in the given element and all child elements together with their prefixes to the provides namespace prefix mapper.

Parameters:
namespaces - An implementation of a NamespaceContext that can collect prefix to namespace mappings (must not be null)
element - The element from which to start recursivly extracting namespace declarations.

extractNamespacesFrom

public javax.xml.namespace.NamespaceContext extractNamespacesFrom(org.w3c.dom.Element rootElement)
Extracts all namespace definitions from the given root element and returns them in a NamespaceContext implementation.


extractNamespacesFrom

public javax.xml.namespace.NamespaceContext extractNamespacesFrom(org.w3c.dom.Document document)
Extracts all namespace definitions from the given document and returns them in a NamespaceContext implementation.