com.pega.pegarules.pub.util
Class XMLUtils

java.lang.Object
  extended by com.pega.pegarules.pub.util.XMLUtils

public class XMLUtils
extends java.lang.Object

Utilities for dealing with XML NOTE: XMLEncode is available in JDK 1.4 (java.beans.XMLEncoder)

Version:
$Revision: 19894 $ $Date: 2012-01-26 16:36:22 -0500 (Thu, 26 Jan 2012) $
Author:
Tim Miranda

Field Summary
static java.lang.String COPYRIGHT
           
static java.lang.String VERSION
           
 
Constructor Summary
XMLUtils()
           
 
Method Summary
static java.lang.StringBuffer encode(java.lang.String string)
          Deprecated.  
static java.lang.StringBuffer encode(java.lang.StringBuffer in)
          Encode the xml special characters "<",">","'",""","&".
static java.lang.String encodeString(java.lang.String in)
          Encode the xml special characters "<",">","'",""","&".
static java.util.List getAllAttributes(org.w3c.dom.Element aNode)
          Return all attributes of the given element node.
static java.util.List getAllChildElements(org.w3c.dom.Element aNode)
          Return all child elements of the given element node.
static java.lang.String getAttributeValue(org.w3c.dom.Element aNode, java.lang.String aAttrName)
          Return the string value of the named attribute.
static java.lang.String getAttributeValue(org.w3c.dom.Element aNode, java.lang.String aNamespaceURI, java.lang.String aLocalName)
          Return the string value of the fully-qualified attribute.
static org.w3c.dom.Element getChildElement(org.w3c.dom.Element aParent, java.lang.String aName)
          Perform a depth-first traversal of the parent element, and return the first child element with a matching tag name.
static java.lang.String getElementNodeValue(org.w3c.dom.Element aNode)
          Return a concatenated string of the text node children of the given element node.
static org.w3c.dom.Element getFirstChildElement(org.w3c.dom.Element aNode)
          Return the first child element node of the given element node.
static org.w3c.dom.Element getNamedChildElement(org.w3c.dom.Element aNode, java.lang.String aElemName)
          Return the first child element node with a matching unqualified name.
static org.w3c.dom.Element getNamedChildElement(org.w3c.dom.Element aNode, java.lang.String aNamespaceURI, java.lang.String aLocalName)
          Return the first child element node with a matching qualified name.
static java.util.List getNamedChildElements(org.w3c.dom.Element aNode, java.lang.String aElemName)
          Return all child element nodes with a matching unqualified name.
static java.util.List getNamedChildElements(org.w3c.dom.Element aNode, java.lang.String aNamespaceURI, java.lang.String aLocalName)
          Return all child element nodes with a matching qualified name.
static org.w3c.dom.Element getNamedSiblingElement(org.w3c.dom.Element aNode, java.lang.String aElemName)
          Return the first sibling element node with a matching unqualified name.
static org.w3c.dom.Element getNamedSiblingElement(org.w3c.dom.Element aNode, java.lang.String aNamespaceURI, java.lang.String aLocalName)
          Return the first sibling element node with a matching qualified name.
static org.w3c.dom.Element getNextSiblingElement(org.w3c.dom.Element aNode)
          Return the immediate sibling element node of the given element node.
static javax.xml.namespace.QName getTypeQName(org.w3c.dom.Element aNode)
          Return the resolved qualified name of the type referred to by the 'xsi:type' attribute of the given element node.
static boolean isNil(org.w3c.dom.Element aNode)
          Return the boolean value of the named attribute.
static java.lang.String resolveNamespaceURI(org.w3c.dom.Element aNode, java.lang.String aPrefix)
          Return the namespace URI associated with the given prefix.
static java.lang.String resolveNSPrefix(org.w3c.dom.Element aNode, java.lang.String aNamespaceURI)
          Return the prefix associated with the given namespace URI.
static javax.xml.namespace.QName resolveQNameRef(org.w3c.dom.Element aNode, java.lang.String aRefVal)
          Return the resolved qualified name of the specified value, which may contain a prefix that refers to a namespace mapping in one of the node's ancestors.
static void simpleAddElement(java.lang.StringBuffer xml, java.lang.String tag, long data)
          Given a stringbuffer of xml data, append a new tag named tag data of data.
static void simpleAddElement(java.lang.StringBuffer xml, java.lang.String tag, java.lang.String data)
          Given a stringbuffer of xml data, append a new tag named tag data of data.
static void simpleAddElement(java.lang.StringBuffer xml, java.lang.String tag, java.lang.StringBuffer data)
          Given a stringbuffer of xml data, append a new tag named tag data of data.
static void simpleEmbedElements(java.lang.StringBuffer xml, java.lang.String tag, java.lang.String data)
          Given a stringbuffer of xml data, append a new tag named tag data of data.
static void simpleEmbedElements(java.lang.StringBuffer xml, java.lang.String tag, java.lang.StringBuffer data)
          Given a stringbuffer of xml data, append a new tag named tag data of data.
static java.lang.String simpleStripHeader(java.lang.String xml)
          Remove the XML header.
static java.lang.String simpleStripRoot(java.lang.String xml)
          Strips root element from a string of xml.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COPYRIGHT

public static final java.lang.String COPYRIGHT
See Also:
Constant Field Values

VERSION

public static final java.lang.String VERSION
Constructor Detail

XMLUtils

public XMLUtils()
Method Detail

resolveNamespaceURI

public static java.lang.String resolveNamespaceURI(org.w3c.dom.Element aNode,
                                                   java.lang.String aPrefix)
Return the namespace URI associated with the given prefix. Traverse through all ancestors of the given node looking for the 'xmlns:prefix' attribute.

Parameters:
aNode - the element node that the search will start from
aPrefix - the prefix shortcut for the namespace URI
Returns:
the namespace URI, or null if not found

resolveNSPrefix

public static java.lang.String resolveNSPrefix(org.w3c.dom.Element aNode,
                                               java.lang.String aNamespaceURI)
Return the prefix associated with the given namespace URI. Traverse through all ancestors of the given node looking for the 'xmlns:prefix' attribute.

Parameters:
aNode - the element node that the search will start from
aNamespaceURI - the namespace URI for the prefix
Returns:
the prefix, or null if not found

resolveQNameRef

public static javax.xml.namespace.QName resolveQNameRef(org.w3c.dom.Element aNode,
                                                        java.lang.String aRefVal)
Return the resolved qualified name of the specified value, which may contain a prefix that refers to a namespace mapping in one of the node's ancestors.

Parameters:
aNode - the element node that the search will start from
aRefVal - the value to be resolved
Returns:
the qualified name, or null if the namespace URI could not be resolved

getTypeQName

public static javax.xml.namespace.QName getTypeQName(org.w3c.dom.Element aNode)
Return the resolved qualified name of the type referred to by the 'xsi:type' attribute of the given element node. The type reference may contain a prefix that refers to a namespace mapping in one of the node's ancestors.

Parameters:
aNode - the element node that may contain the 'xsi:type' attribute
Returns:
the qualified name, or null if the type attribute isn't present or the namespace URI could not be resolved

getAttributeValue

public static java.lang.String getAttributeValue(org.w3c.dom.Element aNode,
                                                 java.lang.String aAttrName)
Return the string value of the named attribute.

Parameters:
aNode - the element that contains the attribute
aAttrName - the unqualified attribute name
Returns:
the attribute value, or null if not found

isNil

public static boolean isNil(org.w3c.dom.Element aNode)
Return the boolean value of the named attribute.

Parameters:
aNode - the element that contains the attribute
Returns:
the attribute value

getAttributeValue

public static java.lang.String getAttributeValue(org.w3c.dom.Element aNode,
                                                 java.lang.String aNamespaceURI,
                                                 java.lang.String aLocalName)
Return the string value of the fully-qualified attribute.

Parameters:
aNode - the element node that contains the attribute
aNamespaceURI - the namespace qualifier of the attribute name
aLocalName - the local part of the attribute name
Returns:
the attribute value, or null if not found

getElementNodeValue

public static java.lang.String getElementNodeValue(org.w3c.dom.Element aNode)
Return a concatenated string of the text node children of the given element node.

Parameters:
aNode - the element node
Returns:
the concatenated value of the child text nodes

getFirstChildElement

public static org.w3c.dom.Element getFirstChildElement(org.w3c.dom.Element aNode)
Return the first child element node of the given element node.

Parameters:
aNode - the parent element node
Returns:
the child element node, or null if not found

getNextSiblingElement

public static org.w3c.dom.Element getNextSiblingElement(org.w3c.dom.Element aNode)
Return the immediate sibling element node of the given element node.

Parameters:
aNode - the element node
Returns:
the sibling element node, or null if not found

getNamedChildElement

public static org.w3c.dom.Element getNamedChildElement(org.w3c.dom.Element aNode,
                                                       java.lang.String aElemName)
Return the first child element node with a matching unqualified name.

Parameters:
aNode - the parent element node
aElemName - the unqualified child element name
Returns:
the child element node, or null if not found

getNamedChildElement

public static org.w3c.dom.Element getNamedChildElement(org.w3c.dom.Element aNode,
                                                       java.lang.String aNamespaceURI,
                                                       java.lang.String aLocalName)
Return the first child element node with a matching qualified name.

Parameters:
aNode - the parent element node
aNamespaceURI - the namespace qualifier of the child element name
aLocalName - the local part of the child element name
Returns:
the child element node, or null if not found

getNamedSiblingElement

public static org.w3c.dom.Element getNamedSiblingElement(org.w3c.dom.Element aNode,
                                                         java.lang.String aElemName)
Return the first sibling element node with a matching unqualified name.

Parameters:
aNode - the starting element node
aElemName - the unqualified sibling element name
Returns:
the sibling element node, or null if not found

getNamedSiblingElement

public static org.w3c.dom.Element getNamedSiblingElement(org.w3c.dom.Element aNode,
                                                         java.lang.String aNamespaceURI,
                                                         java.lang.String aLocalName)
Return the first sibling element node with a matching qualified name.

Parameters:
aNode - the starting element node
aNamespaceURI - the namespace qualifier of the sibling element name
aLocalName - the local part of the sibling element name
Returns:
the sibling element node, or null if not found

getNamedChildElements

public static java.util.List getNamedChildElements(org.w3c.dom.Element aNode,
                                                   java.lang.String aElemName)
Return all child element nodes with a matching unqualified name.

Parameters:
aNode - the parent element node
aElemName - the unqualified child element name
Returns:
the list of matching child element nodes

getNamedChildElements

public static java.util.List getNamedChildElements(org.w3c.dom.Element aNode,
                                                   java.lang.String aNamespaceURI,
                                                   java.lang.String aLocalName)
Return all child element nodes with a matching qualified name.

Parameters:
aNode - the parent element node
aNamespaceURI - the namespace qualifier of the child element name
aLocalName - the local part of the child element name
Returns:
the list of matching child element nodes

getAllAttributes

public static java.util.List getAllAttributes(org.w3c.dom.Element aNode)
Return all attributes of the given element node.

Parameters:
aNode - the element node
Returns:
the list of attribute nodes

getAllChildElements

public static java.util.List getAllChildElements(org.w3c.dom.Element aNode)
Return all child elements of the given element node.

Parameters:
aNode - the parent element node
Returns:
the list of child element nodes

getChildElement

public static org.w3c.dom.Element getChildElement(org.w3c.dom.Element aParent,
                                                  java.lang.String aName)
Perform a depth-first traversal of the parent element, and return the first child element with a matching tag name.

Parameters:
aParent - the parent element node
aName - the element tag name to search for
Returns:
the matching child element, or null if not found

encodeString

public static java.lang.String encodeString(java.lang.String in)
Encode the xml special characters "<",">","'",""","&". Prefer this method over encode(String), if no encoding is required then there are no extra objects created.

Parameters:
in - string to encode
Returns:
the encoded string or null on null input

encode

public static java.lang.StringBuffer encode(java.lang.String string)
Deprecated. 

Encode the xml special characters "<",">","'",""","&".

Parameters:
string - to encode
Returns:
encoded string as a stringbuffer

encode

public static java.lang.StringBuffer encode(java.lang.StringBuffer in)
Encode the xml special characters "<",">","'",""","&".

Parameters:
in - buffer to encode
Returns:
new encoded buffer

simpleAddElement

public static void simpleAddElement(java.lang.StringBuffer xml,
                                    java.lang.String tag,
                                    java.lang.StringBuffer data)
Given a stringbuffer of xml data, append a new tag named tag data of data.

Data will be encoded.

Parameters:
xml -
tag -
data -

simpleAddElement

public static void simpleAddElement(java.lang.StringBuffer xml,
                                    java.lang.String tag,
                                    java.lang.String data)
Given a stringbuffer of xml data, append a new tag named tag data of data.

Data will be encoded.

Parameters:
xml -
tag -
data -

simpleAddElement

public static void simpleAddElement(java.lang.StringBuffer xml,
                                    java.lang.String tag,
                                    long data)
Given a stringbuffer of xml data, append a new tag named tag data of data.

Parameters:
xml -
tag -
data -

simpleEmbedElements

public static void simpleEmbedElements(java.lang.StringBuffer xml,
                                       java.lang.String tag,
                                       java.lang.StringBuffer data)
Given a stringbuffer of xml data, append a new tag named tag data of data.

Data will *not* be encoded.

Parameters:
xml -
tag -
data -

simpleEmbedElements

public static void simpleEmbedElements(java.lang.StringBuffer xml,
                                       java.lang.String tag,
                                       java.lang.String data)
Given a stringbuffer of xml data, append a new tag named tag data of data.

Data will *not* be encoded.

Parameters:
xml -
tag -
data -

simpleStripHeader

public static java.lang.String simpleStripHeader(java.lang.String xml)
Remove the XML header.

Useful if this XML is to be encapsulated by other tags...

Parameters:
xml -
Returns:
xml without the header

simpleStripRoot

public static java.lang.String simpleStripRoot(java.lang.String xml)
Strips root element from a string of xml.
 ex:   in: 
                out: 
 

Parameters:
xml - XML to strip
Returns:
the stipped xml


Copyright © 2012 Pegasystems Inc. All Rights Reserved.