org.apache.axis2.util
Class XMLUtils

java.lang.Object
  extended byorg.apache.axis2.util.XMLUtils

public class XMLUtils
extends Object


Nested Class Summary
static class XMLUtils.ParserErrorHandler
           
 
Field Summary
static String charEncoding
           
 
Constructor Summary
XMLUtils()
           
 
Method Summary
static String base64encode(byte[] bytes)
           
static Node findNode(Node node, QName name)
          Finds a Node with a given QNameb.
static String getChildCharacterData(Element parentEl)
          Concatinates all the text and cdata node children of this elem and returns the resulting text.
static InputSource getEmptyInputSource()
           
static InputSource getInputSourceFromURI(String uri)
          Utility to get the bytes uri.
static String getNamespace(String prefix, Node e)
           
static String getPrefix(String uri, Node e)
           
static QName getQNameFromString(String str, Node e)
          Returns a QName when passed a string like "foo:bar" by mapping the "foo" prefix to a namespace in the context of the given Node.
static String getStringForQName(QName qname, Element e)
          Returns a string for a particular QName, mapping a new prefix if necessary.
static void initSAXFactory(String factoryClassName, boolean namespaceAware, boolean validating)
          Initializes the SAX parser factory.
static Document newDocument()
          Gets an empty new Document.
static Document newDocument(InputSource inp)
          Gets a new Document read from the input source.
static Document newDocument(InputStream inp)
          Gets a new Document read from the input stream
static Document newDocument(String uri)
          Gets a new Document read from the indicated uri
static Document newDocument(String uri, String username, String password)
          Creates a new document from the given URI.
static void releaseSAXParser(SAXParser parser)
          Returns a SAX parser for reuse.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

charEncoding

public static final String charEncoding
See Also:
Constant Field Values
Constructor Detail

XMLUtils

public XMLUtils()
Method Detail

initSAXFactory

public static void initSAXFactory(String factoryClassName,
                                  boolean namespaceAware,
                                  boolean validating)
Initializes the SAX parser factory.

Parameters:
factoryClassName - The (optional) class name of the desired SAXParserFactory implementation. Will be assigned to the system property javax.xml.parsers.SAXParserFactory unless this property is already set. If null, leaves current setting alone.
namespaceAware - true if we want a namespace-aware parser
validating - true if we want a validating parser

releaseSAXParser

public static void releaseSAXParser(SAXParser parser)
Returns a SAX parser for reuse.

Parameters:
parser - A SAX parser that is available for reuse

newDocument

public static Document newDocument()
                            throws ParserConfigurationException
Gets an empty new Document.

Returns:
Returns Document.
Throws:
ParserConfigurationException - if construction problems occur

newDocument

public static Document newDocument(InputSource inp)
                            throws ParserConfigurationException,
                                   SAXException,
                                   IOException
Gets a new Document read from the input source.

Returns:
Returns Document.
Throws:
ParserConfigurationException - if construction problems occur
SAXException - if the document has xml sax problems
IOException - if i/o exceptions occur

newDocument

public static Document newDocument(InputStream inp)
                            throws ParserConfigurationException,
                                   SAXException,
                                   IOException
Gets a new Document read from the input stream

Returns:
Returns Document.
Throws:
ParserConfigurationException - if construction problems occur
SAXException - if the document has xml sax problems
IOException - if i/o exceptions occur

newDocument

public static Document newDocument(String uri)
                            throws ParserConfigurationException,
                                   SAXException,
                                   IOException
Gets a new Document read from the indicated uri

Returns:
Returns Document.
Throws:
ParserConfigurationException - if construction problems occur
SAXException - if the document has xml sax problems
IOException - if i/o exceptions occur

newDocument

public static Document newDocument(String uri,
                                   String username,
                                   String password)
                            throws ParserConfigurationException,
                                   SAXException,
                                   IOException
Creates a new document from the given URI. Uses the username and password if the URI requires authentication.

Parameters:
uri - the resource to get
username - basic auth username
password - basic auth password
Throws:
ParserConfigurationException - if construction problems occur
SAXException - if the document has xml sax problems
IOException - if i/o exceptions occur

getPrefix

public static String getPrefix(String uri,
                               Node e)

getNamespace

public static String getNamespace(String prefix,
                                  Node e)

getQNameFromString

public static QName getQNameFromString(String str,
                                       Node e)
Returns a QName when passed a string like "foo:bar" by mapping the "foo" prefix to a namespace in the context of the given Node.

Returns:
Returns a QName generated from the given string representation.

getStringForQName

public static String getStringForQName(QName qname,
                                       Element e)
Returns a string for a particular QName, mapping a new prefix if necessary.


getChildCharacterData

public static String getChildCharacterData(Element parentEl)
Concatinates all the text and cdata node children of this elem and returns the resulting text. (by Matt Duftler)

Parameters:
parentEl - the element whose cdata/text node values are to be combined.
Returns:
Returns the concatinated string.

getInputSourceFromURI

public static InputSource getInputSourceFromURI(String uri)
Utility to get the bytes uri. Does NOT handle authenticated URLs, use getInputSourceFromURI(uri, username, password)

Parameters:
uri - the resource to get

base64encode

public static String base64encode(byte[] bytes)

getEmptyInputSource

public static InputSource getEmptyInputSource()

findNode

public static Node findNode(Node node,
                            QName name)
Finds a Node with a given QNameb.

Parameters:
node - parent node
name - QName of the child we need to find
Returns:
Returns child node.