org.apache.xml.security.utils
Class XMLUtils

java.lang.Object
  extended byorg.apache.xml.security.utils.XMLUtils

public class XMLUtils
extends java.lang.Object

DOM and XML accessibility and comfort functions.

Author:
Christian Geuer-Pollmann

Method Summary
static void addReturnToElement(org.w3c.dom.Element e)
          Method addReturnToElement
static void circumventBug2650(org.w3c.dom.Document doc)
          This method spreads all namespace attributes in a DOM document to their children.
static java.lang.Class classForName(java.lang.String className)
          Worker method to load a class.
static java.util.Set convertNodelistToSet(org.w3c.dom.NodeList xpathNodeSet)
          Method convertNodelistToSet
static org.w3c.dom.Element createDSctx(org.w3c.dom.Document doc, java.lang.String prefix, java.lang.String namespace)
          Method createDSctx
static org.w3c.dom.Element createElementInSignatureSpace(org.w3c.dom.Document doc, java.lang.String elementName)
          Creates an Element in the XML Signature specification namespace.
static boolean elementIsInEncryptionSpace(org.w3c.dom.Element element, java.lang.String localName)
          Returns true if the element is in XML Encryption namespace and the local name equals the supplied one.
static boolean elementIsInSignatureSpace(org.w3c.dom.Element element, java.lang.String localName)
          Returns true if the element is in XML Signature namespace and the local name equals the supplied one.
static java.util.Set excludeNodeFromSet(org.w3c.dom.Node signatureElement, java.util.Set inputSet)
           
protected static java.lang.ClassLoader findClassLoader()
          Worker method to figure out which ClassLoader to use.
static java.lang.String getFullTextChildrenFromElement(org.w3c.dom.Element element)
          Method getFullTextChildrenFromElement
static java.lang.String getNodeTypeString(short nodeType)
          Transforms org.w3c.dom.Node.XXX_NODE NodeType values into Strings.
static org.w3c.dom.Document getOwnerDocument(org.w3c.dom.Node node)
          This method returns the owner document of a particular node.
static org.w3c.dom.Document getOwnerDocument(java.util.Set xpathNodeSet)
          This method returns the first non-null owner document of the Node's in this Set.
static void getSet(org.w3c.dom.Node rootNode, java.util.Set result, org.w3c.dom.Node exclude, boolean com)
           
static java.lang.String getXalanVersion()
          Method getXalanVersion
static java.lang.String getXercesVersion()
          Method getXercesVersion
static void outputDOM(org.w3c.dom.Node contextNode, java.io.OutputStream os)
          Outputs a DOM tree to an OutputStream.
static void outputDOM(org.w3c.dom.Node contextNode, java.io.OutputStream os, boolean addPreamble)
          Outputs a DOM tree to an OutputStream.
static void outputDOMc14nWithComments(org.w3c.dom.Node contextNode, java.io.OutputStream os)
          Serializes the contextNode into the OutputStream, but supresses all Exceptions.
static org.w3c.dom.Element selectDsNode(org.w3c.dom.Node sibling, java.lang.String nodeName, int number)
           
static org.w3c.dom.Element[] selectDsNodes(org.w3c.dom.Node sibling, java.lang.String nodeName)
           
static org.w3c.dom.Text selectDsNodeText(org.w3c.dom.Node sibling, java.lang.String nodeName, int number)
           
static org.w3c.dom.Element selectNode(org.w3c.dom.Node sibling, java.lang.String uri, java.lang.String nodeName, int number)
           
static org.w3c.dom.Element[] selectNodes(org.w3c.dom.Node sibling, java.lang.String uri, java.lang.String nodeName)
           
static org.w3c.dom.Text selectNodeText(org.w3c.dom.Node sibling, java.lang.String uri, java.lang.String nodeName, int number)
           
static org.w3c.dom.Element selectXencNode(org.w3c.dom.Node sibling, java.lang.String nodeName, int number)
           
static void spitOutVersions(org.apache.commons.logging.Log log)
          Method spitOutVersions
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getSet

public static void getSet(org.w3c.dom.Node rootNode,
                          java.util.Set result,
                          org.w3c.dom.Node exclude,
                          boolean com)
Parameters:
rootNode -
result -
exclude -
com - wheather comments or not

getXalanVersion

public static java.lang.String getXalanVersion()
Method getXalanVersion

Returns:

getXercesVersion

public static java.lang.String getXercesVersion()
Method getXercesVersion

Returns:

classForName

public static java.lang.Class classForName(java.lang.String className)
                                    throws java.lang.ClassNotFoundException
Worker method to load a class. Factor out loading classes for future use and JDK differences. Copied from javax.xml.*.FactoryFinder

Parameters:
className - name of class to load from an appropriate classLoader
Returns:
the class asked for
Throws:
java.lang.ClassNotFoundException

findClassLoader

protected static java.lang.ClassLoader findClassLoader()
Worker method to figure out which ClassLoader to use. For JDK 1.2 and later use the context ClassLoader. Copied from javax.xml.*.FactoryFinder

Returns:
the appropriate ClassLoader

spitOutVersions

public static void spitOutVersions(org.apache.commons.logging.Log log)
Method spitOutVersions

Parameters:
log -

getNodeTypeString

public static java.lang.String getNodeTypeString(short nodeType)
Transforms org.w3c.dom.Node.XXX_NODE NodeType values into Strings.

Parameters:
nodeType - as taken from the Node.getNodeType() function
Returns:
the String value.
See Also:
Node.getNodeType()

outputDOM

public static void outputDOM(org.w3c.dom.Node contextNode,
                             java.io.OutputStream os)
Outputs a DOM tree to an OutputStream.

Parameters:
contextNode - root node of the DOM tree
os - the OutputStream

outputDOM

public static void outputDOM(org.w3c.dom.Node contextNode,
                             java.io.OutputStream os,
                             boolean addPreamble)
Outputs a DOM tree to an OutputStream. If an Exception is thrown during execution, it's StackTrace is output to System.out, but the Exception is not re-thrown.

Parameters:
contextNode - root node of the DOM tree
os - the OutputStream
addPreamble -

outputDOMc14nWithComments

public static void outputDOMc14nWithComments(org.w3c.dom.Node contextNode,
                                             java.io.OutputStream os)
Serializes the contextNode into the OutputStream, but supresses all Exceptions.
NOTE: This should only be used for debugging purposes, NOT in a production environment; this method ignores all exceptions, so you won't notice if something goes wrong. If you're asking what is to be used in a production environment, simply use the code inside the try{} statement, but handle the Exceptions appropriately.

Parameters:
contextNode -
os -

getFullTextChildrenFromElement

public static java.lang.String getFullTextChildrenFromElement(org.w3c.dom.Element element)
Method getFullTextChildrenFromElement

Parameters:
element -
Returns:

createElementInSignatureSpace

public static org.w3c.dom.Element createElementInSignatureSpace(org.w3c.dom.Document doc,
                                                                java.lang.String elementName)
Creates an Element in the XML Signature specification namespace.

Parameters:
doc - the factory Document
elementName - the local name of the Element
Returns:
the Element

elementIsInSignatureSpace

public static boolean elementIsInSignatureSpace(org.w3c.dom.Element element,
                                                java.lang.String localName)
Returns true if the element is in XML Signature namespace and the local name equals the supplied one.

Parameters:
element -
localName -
Returns:
true if the element is in XML Signature namespace and the local name equals the supplied one

elementIsInEncryptionSpace

public static boolean elementIsInEncryptionSpace(org.w3c.dom.Element element,
                                                 java.lang.String localName)
Returns true if the element is in XML Encryption namespace and the local name equals the supplied one.

Parameters:
element -
localName -
Returns:
true if the element is in XML Encryption namespace and the local name equals the supplied one

getOwnerDocument

public static org.w3c.dom.Document getOwnerDocument(org.w3c.dom.Node node)
This method returns the owner document of a particular node. This method is necessary because it always returns a Document. Node.getOwnerDocument() returns null if the Node is a Document.

Parameters:
node -
Returns:
the owner document of the node

getOwnerDocument

public static org.w3c.dom.Document getOwnerDocument(java.util.Set xpathNodeSet)
This method returns the first non-null owner document of the Node's in this Set. This method is necessary because it always returns a Document. Node.getOwnerDocument() returns null if the Node is a Document.

Parameters:
xpathNodeSet -
Returns:
the owner document

createDSctx

public static org.w3c.dom.Element createDSctx(org.w3c.dom.Document doc,
                                              java.lang.String prefix,
                                              java.lang.String namespace)
Method createDSctx

Parameters:
doc -
prefix -
namespace -
Returns:

addReturnToElement

public static void addReturnToElement(org.w3c.dom.Element e)
Method addReturnToElement

Parameters:
e -

convertNodelistToSet

public static java.util.Set convertNodelistToSet(org.w3c.dom.NodeList xpathNodeSet)
Method convertNodelistToSet

Parameters:
xpathNodeSet -
Returns:

circumventBug2650

public static void circumventBug2650(org.w3c.dom.Document doc)
This method spreads all namespace attributes in a DOM document to their children. This is needed because the XML Signature XPath transform must evaluate the XPath against all nodes in the input, even against XPath namespace nodes. Through a bug in XalanJ2, the namespace nodes are not fully visible in the Xalan XPath model, so we have to do this by hand in DOM spaces so that the nodes become visible in XPath space.

Parameters:
doc -
See Also:
Namespace axis resolution is not XPath compliant

selectDsNode

public static org.w3c.dom.Element selectDsNode(org.w3c.dom.Node sibling,
                                               java.lang.String nodeName,
                                               int number)
Parameters:
sibling -
nodeName -
number -
Returns:

selectXencNode

public static org.w3c.dom.Element selectXencNode(org.w3c.dom.Node sibling,
                                                 java.lang.String nodeName,
                                                 int number)
Parameters:
sibling -
nodeName -
number -
Returns:

selectDsNodeText

public static org.w3c.dom.Text selectDsNodeText(org.w3c.dom.Node sibling,
                                                java.lang.String nodeName,
                                                int number)
Parameters:
sibling -
nodeName -
number -
Returns:

selectNodeText

public static org.w3c.dom.Text selectNodeText(org.w3c.dom.Node sibling,
                                              java.lang.String uri,
                                              java.lang.String nodeName,
                                              int number)
Parameters:
sibling -
uri -
nodeName -
number -
Returns:

selectNode

public static org.w3c.dom.Element selectNode(org.w3c.dom.Node sibling,
                                             java.lang.String uri,
                                             java.lang.String nodeName,
                                             int number)
Parameters:
sibling -
uri -
nodeName -
number -
Returns:

selectDsNodes

public static org.w3c.dom.Element[] selectDsNodes(org.w3c.dom.Node sibling,
                                                  java.lang.String nodeName)
Parameters:
sibling -
nodeName -
Returns:

selectNodes

public static org.w3c.dom.Element[] selectNodes(org.w3c.dom.Node sibling,
                                                java.lang.String uri,
                                                java.lang.String nodeName)
Parameters:
sibling -
uri -
nodeName -
Returns:

excludeNodeFromSet

public static java.util.Set excludeNodeFromSet(org.w3c.dom.Node signatureElement,
                                               java.util.Set inputSet)
Parameters:
signatureElement -
inputSet -
Returns: