com.ibm.xcap.xml
Class XMLUtils

java.lang.Object
  extended by com.ibm.xcap.xml.XMLUtils
All Implemented Interfaces:
XcapConstants

public class XMLUtils
extends java.lang.Object
implements XcapConstants


Field Summary
static java.lang.String COPYRIGHT
           
 
Fields inherited from interface com.ibm.xcap.XcapConstants
ANONYMOUS_USER, APPEND_CONTENT_TYPE_CHARSET_UTF8, AUID_OMA_SEARCH, AUID_PRES_RULES, AUID_PRES_RULES_ACLS, AUID_RESOURCE_LISTS, AUID_RESOURCE_LISTS_ACLS, AUID_RLS_SERVICES, AUID_RLS_SERVICES_ACLS, AUID_XCAP_CAPS, AUID_XCAP_DIRECTORY, CHARSET_UTF8, CLIENT_RESOURCE_BUNDLE, CLOSE_BRACKET, CONTENT_TYPE_APPLICATION_ERROR_XML, CONTENT_TYPE_AUTH_POLICY, CONTENT_TYPE_NAMESPACE_BINDING, CONTENT_TYPE_OMA_DIRECTORY, CONTENT_TYPE_OMA_SEARCH, CONTENT_TYPE_PRES_RULES, CONTENT_TYPE_RESOURCE_LISTS, CONTENT_TYPE_RLS_SERVICES, CONTENT_TYPE_XCAP_CAPS, CONTENT_TYPE_XCAP_DIFF, CONTENT_TYPE_XCAP_ERROR, CONTENT_TYPE_XML_ATTRIBUTE, CONTENT_TYPE_XML_ELEMENT, DOC_GLOBAL_DIRECTORY, DOC_GLOBAL_INDEX, DOC_USER_DIRECTORY, DOC_XCAP_CAPS, DOUBLE_FORWARD_SLASH, EMPTY, ENCODED_SINGLE_QUOTE, ENCODED_SLASH_CLOSE_BRACKET, ENCODED_SLASH_OPEN_BRACKET, EXTENSION_LOCAL_CONSTRAINT_FAILURE, FORWARD_SLASH, GLOBAL, GLOBAL_DOC_DIRECTORY_PREFIX, GLOBAL_DOC_DIRECTORY_SUFFIX, HEADER_ACCEPT, HEADER_ALLOW, HEADER_CONTENT_TYPE, HEADER_ETAG, HEADER_IF_MATCH, HEADER_IF_NONE_MATCH, HEADER_LAST_MODIFIED, HEADER_X_3GPP_ASSERTED_IDENTITY, HEADER_X_3GPP_INTENDED_IDENTITY, HEADER_X_XCAP_ASSERTED_IDENTITY, HTTP_METHOD_DELETE, HTTP_METHOD_GET, HTTP_METHOD_POST, HTTP_METHOD_PUT, NS_COMMON_POLICY, NS_OMA_APPUSAGE, NS_OMA_COMMON_POLICY, NS_OMA_URIUSAGE, NS_OMA_XCAP_ERROR, NS_PRES_RULES, NS_RESOURCE_LISTS, NS_RLS_SERVICES, NS_XCAP_CAPS, NS_XCAP_DIRECTORY, NS_XCAP_ERROR, OPEN_BRACKET, PATH_SEARCH, RC_100_CONTINUE, RC_101_SWITCHING_PROTOCOLS, RC_200_OK, RC_201_CREATED, RC_202_ACCEPTED, RC_203_NON_AUTHORITATIVE_INFO, RC_204_NO_CONTENT, RC_205_RESET_CONTENT, RC_206_PARTIAL_CONTENT, RC_300_MULTIPLE_CHOICES, RC_301_MOVED_PERMANANTLY, RC_302_FOUND, RC_303_SEE_OTHER, RC_304_NOT_MODIFIED, RC_305_USE_PROXY, RC_307_TEMPORARY_REDIRECT, RC_400_BAD_REQUEST, RC_401_UNAUTHORIZED, RC_402_PAYMENT_REQUIRED, RC_403_FORBIDDEN, RC_404_NOT_FOUND, RC_405_METHOD_NOT_ALLOWED, RC_406_NOT_ACCEPTABLE, RC_407_PROXY_AUTHENTICATION_REQUIRED, RC_408_REQUEST_TIMEOUT, RC_409_CONFLICT, RC_410_GONE, RC_411_LENGTH_REQUIRED, RC_412_PRECONDITION_FAILED, RC_413_REQUEST_ENTITY_TOO_LARGE, RC_414_REQUEST_URI_TOO_LONG, RC_415_UNSUPPORTED_MEDIA_TYPE, RC_416_REQUESTED_RANGE_NOT_SATISFIABLE, RC_417_EXPECTATION_FAILED, RC_500_INTERNAL_SERVER_ERROR, RC_501_NOT_IMPLEMENTED, RC_502_BAD_GATEWAY, RC_503_SERVICES_UNAVAILABLE, RC_504_GATEWAY_TIMEOUT, RC_505_HTTP_VERSION_NOT_SUPPORTED, SINGLE_QUOTE, SINGLE_SPACE, SLASH_CLOSE_BRACKET, SLASH_OPEN_BRACKET, USERS, UTF_8, UTF8_BYTE_ORDER_MARKER, XML_DECLARATION, XPATH_SEPARATOR
 
Constructor Summary
XMLUtils()
          Constructor for XMLUtils.
 
Method Summary
 void addSchema(java.io.InputStream schema)
          Adds a schema from the InputStream.
 void addSchemas(java.util.ArrayList<java.io.InputStream> schemaInputStreams)
          Adds schemas given an array of InputStreams containing the schemas.
 void addSchemaStrings(java.util.ArrayList<java.lang.String> schemaStrings)
          Adds the schema Strings to the XMLUtils
 java.lang.Object clone()
           
 boolean compareNode(org.w3c.dom.Node node1, org.w3c.dom.Node node2)
          Method compareNode.
 boolean compareXML(java.lang.String xml1, java.lang.String xml2)
          Method compareXML.
static void findNodeElementsByName(org.w3c.dom.Node node, java.lang.String elementName, java.util.ArrayList<org.w3c.dom.Node> resultList)
          Method findNodeElementsByName.
static org.w3c.dom.Attr getAttribute(org.w3c.dom.Element element, java.lang.String attrName, java.lang.String namespace, java.lang.String nsPrefix)
          Returns the attribute associated with the element.
static java.lang.String getDeclaredNamespaces(org.w3c.dom.Element element)
          Returns the declared namespaces for this element.
protected  javax.xml.parsers.DocumentBuilder getDocumentBuilder(boolean isValidating)
          Returns the DocumentBuilder depending on whether validation is needed or not
static java.lang.String getLocalName(org.w3c.dom.Node node)
          Returns the local name without the namespace prefix if any
 org.w3c.dom.Document getNewDocument(boolean isValidating, java.lang.String namespaceURI, java.lang.String qualifiedName, org.w3c.dom.DocumentType doc)
           
static java.lang.String getNodeValue(org.w3c.dom.Node node)
          Returns the element value
static java.lang.String getPrefix(org.w3c.dom.Node node)
          Returns the namespace prefix for the node
 java.util.ArrayList<java.io.InputStream> getSchemaStreams()
          Returns the schemas as an ArrayList of InputStreams
 java.util.ArrayList<java.lang.String> getSchemaStrings()
          Returns the schemas as an ArrayList of Strings
static boolean isNodeMatch(org.w3c.dom.Node node, java.lang.String name, java.lang.String namespace, java.lang.String nsPrefix)
          Returns true if the node matches the given name and matches either the namespace or nsPrefix.
 void loadDefaultSchemas()
          Loads the default xml.xsd, XmlSchema.xsd, and ibm-application-usage.xsd contained within the XcapUtils.jar.
 java.lang.String node2String(org.w3c.dom.Node node)
          Method document2String.
 java.lang.String node2String(org.w3c.dom.Node node, boolean omitXmlDeclaration)
          Method document2String.
 org.w3c.dom.Document stream2Document(java.io.InputStream is, boolean isValidating)
          Converts an InputStream containing XML into a DOM
static java.lang.String stream2String(java.io.InputStream is)
          Converts the InputStream into a String
 org.w3c.dom.Document string2Document(java.lang.String str, boolean isValidating)
          Converts a String containing XML into a DOM
 boolean validateXML(org.w3c.dom.Document doc)
          Method validateXML.
 boolean validateXML(java.lang.String xml)
          Method validateXML.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COPYRIGHT

public static final java.lang.String COPYRIGHT
Constructor Detail

XMLUtils

public XMLUtils()
         throws javax.xml.parsers.ParserConfigurationException,
                javax.xml.transform.TransformerConfigurationException
Constructor for XMLUtils.

Throws:
javax.xml.parsers.ParserConfigurationException
javax.xml.transform.TransformerConfigurationException
Method Detail

getSchemaStrings

public java.util.ArrayList<java.lang.String> getSchemaStrings()
Returns the schemas as an ArrayList of Strings

Returns:
Returns the schemas as an ArrayList of Strings

getSchemaStreams

public java.util.ArrayList<java.io.InputStream> getSchemaStreams()
Returns the schemas as an ArrayList of InputStreams

Returns:
Returns the schemas as an ArrayList of InputStreams

getDocumentBuilder

protected javax.xml.parsers.DocumentBuilder getDocumentBuilder(boolean isValidating)
                                                        throws javax.xml.parsers.ParserConfigurationException,
                                                               java.io.IOException,
                                                               org.xml.sax.SAXException
Returns the DocumentBuilder depending on whether validation is needed or not

Parameters:
isValidating - Is validation needed.
Returns:
Returns the DocumentBuilder depending on whether validation is needed or not
Throws:
javax.xml.parsers.ParserConfigurationException
java.io.IOException
org.xml.sax.SAXException

loadDefaultSchemas

public void loadDefaultSchemas()
                        throws java.io.IOException
Loads the default xml.xsd, XmlSchema.xsd, and ibm-application-usage.xsd contained within the XcapUtils.jar.

Throws:
java.io.IOException

stream2String

public static java.lang.String stream2String(java.io.InputStream is)
                                      throws java.io.IOException
Converts the InputStream into a String

Parameters:
is - An InputStream
Returns:
Returns the String representation of the contents from the InputStream.
Throws:
java.io.IOException

addSchema

public void addSchema(java.io.InputStream schema)
               throws java.io.IOException
Adds a schema from the InputStream.

Parameters:
schema - The InputStream containing the schema.
Throws:
java.io.IOException

addSchemas

public void addSchemas(java.util.ArrayList<java.io.InputStream> schemaInputStreams)
                throws java.io.IOException
Adds schemas given an array of InputStreams containing the schemas.

Parameters:
schemaInputStreams - An array of InputStreams containing the schemas.
Throws:
java.io.IOException

addSchemaStrings

public void addSchemaStrings(java.util.ArrayList<java.lang.String> schemaStrings)
Adds the schema Strings to the XMLUtils

Parameters:
schemaStrings - The ArrayList of String schemas to add.

stream2Document

public org.w3c.dom.Document stream2Document(java.io.InputStream is,
                                            boolean isValidating)
                                     throws javax.xml.parsers.ParserConfigurationException,
                                            java.io.IOException,
                                            org.xml.sax.SAXException
Converts an InputStream containing XML into a DOM

Parameters:
is - An InputStream containing XML
isValidating - Whether the XML should be validated or not.
Returns:
Returns the DOM document
Throws:
javax.xml.parsers.ParserConfigurationException
java.io.IOException
org.xml.sax.SAXException

getNewDocument

public org.w3c.dom.Document getNewDocument(boolean isValidating,
                                           java.lang.String namespaceURI,
                                           java.lang.String qualifiedName,
                                           org.w3c.dom.DocumentType doc)
                                    throws javax.xml.parsers.ParserConfigurationException,
                                           java.io.IOException,
                                           org.xml.sax.SAXException
Throws:
javax.xml.parsers.ParserConfigurationException
java.io.IOException
org.xml.sax.SAXException

string2Document

public org.w3c.dom.Document string2Document(java.lang.String str,
                                            boolean isValidating)
                                     throws javax.xml.parsers.ParserConfigurationException,
                                            java.io.IOException,
                                            org.xml.sax.SAXException
Converts a String containing XML into a DOM

Parameters:
str - A String containing XML
isValidating - Whether the XML should be validated or not.
Returns:
Returns the DOM document
Throws:
javax.xml.parsers.ParserConfigurationException
java.io.IOException
org.xml.sax.SAXException

node2String

public java.lang.String node2String(org.w3c.dom.Node node)
                             throws javax.xml.transform.TransformerConfigurationException,
                                    javax.xml.transform.TransformerException
Method document2String. Prints a textual representation of a DOM object into a text string.

Parameters:
node - The node to convert to a String.
Returns:
String The String representation of the node.
Throws:
javax.xml.transform.TransformerConfigurationException
javax.xml.transform.TransformerException

node2String

public java.lang.String node2String(org.w3c.dom.Node node,
                                    boolean omitXmlDeclaration)
                             throws javax.xml.transform.TransformerConfigurationException,
                                    javax.xml.transform.TransformerException
Method document2String. Prints a textual representation of a DOM object into a text string. Optionally, it can omit the XML declaration.

Parameters:
node - The node to convert to a String.
omitXmlDeclaration - true if the XML Declaration should be omitted, false otherwise
Returns:
String The String representation of the node.
Throws:
javax.xml.transform.TransformerConfigurationException
javax.xml.transform.TransformerException

validateXML

public boolean validateXML(java.lang.String xml)
Method validateXML.

Parameters:
xml -
Returns:
boolean

validateXML

public boolean validateXML(org.w3c.dom.Document doc)
Method validateXML.

Parameters:
doc - The document to validate.
Returns:
Returns true if the document is valid otherwise false.

compareXML

public boolean compareXML(java.lang.String xml1,
                          java.lang.String xml2)
Method compareXML.

Parameters:
xml1 - One XML to compare.
xml2 - Another XML to compare against.
Returns:
Returns true if they are the same otherwise false.

compareNode

public boolean compareNode(org.w3c.dom.Node node1,
                           org.w3c.dom.Node node2)
Method compareNode.

Parameters:
node1 - One node to compare.
node2 - Another node to compare against.
Returns:
Returns true if the nodes are equal otherwise false.

getNodeValue

public static java.lang.String getNodeValue(org.w3c.dom.Node node)
Returns the element value

Parameters:
node - The Node to get the value from
Returns:
Returns the String value from the element

getLocalName

public static java.lang.String getLocalName(org.w3c.dom.Node node)
Returns the local name without the namespace prefix if any

Parameters:
node - The node to inspect
Returns:
Returns the local name without the namespace prefix if any

getPrefix

public static java.lang.String getPrefix(org.w3c.dom.Node node)
Returns the namespace prefix for the node

Parameters:
node - The node to inspect
Returns:
Returns the namespace prefix for the node

isNodeMatch

public static boolean isNodeMatch(org.w3c.dom.Node node,
                                  java.lang.String name,
                                  java.lang.String namespace,
                                  java.lang.String nsPrefix)
Returns true if the node matches the given name and matches either the namespace or nsPrefix.

Parameters:
node - Mandatory node to compare with
name - Mandatory name to compare with
namespace - Optional namespace to compare with
nsPrefix - Optional nsPrefix to compare with
Returns:
Returns true if the node matches the given name and matches either the namespace or nsPrefix.

getAttribute

public static org.w3c.dom.Attr getAttribute(org.w3c.dom.Element element,
                                            java.lang.String attrName,
                                            java.lang.String namespace,
                                            java.lang.String nsPrefix)
Returns the attribute associated with the element. If it does not exist, then return null.

Parameters:
element - Mandatory element containing the attribute.
attrName - Mandatory attribute to find.
namespace - Optional namespace of the attribute
nsPrefix - Optional nsPrefix of the attribute.
Returns:
Returns the attribute associated with the element. If it does not exist, then return null.

getDeclaredNamespaces

public static java.lang.String getDeclaredNamespaces(org.w3c.dom.Element element)
Returns the declared namespaces for this element.

Parameters:
element - Mandatory element containing interested namespaces.
Returns:
Returns the declared namespaces for this element.

findNodeElementsByName

public static void findNodeElementsByName(org.w3c.dom.Node node,
                                          java.lang.String elementName,
                                          java.util.ArrayList<org.w3c.dom.Node> resultList)
Method findNodeElementsByName.

Parameters:
node - Root node to start search.
elementName - Name of element to search for.
resultList - List containing nodes which match node parameter.

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Overrides:
clone in class java.lang.Object
Throws:
java.lang.CloneNotSupportedException