Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.apache.axis.utils
Class XMLUtils  view XMLUtils download XMLUtils.java

java.lang.Object
  extended byorg.apache.axis.utils.XMLUtils

public class XMLUtils
extends java.lang.Object


Nested Class Summary
static class XMLUtils.ParserErrorHandler
           
private static class XMLUtils.ThreadLocalDocumentBuilder
           
 
Field Summary
private static java.io.ByteArrayInputStream bais
           
private static javax.xml.parsers.DocumentBuilderFactory dbf
           
private static XMLUtils.ThreadLocalDocumentBuilder documentBuilder
           
private static org.xml.sax.helpers.DefaultHandler doNothingContentHandler
           
private static java.lang.String EMPTY
           
protected static boolean enableParserReuse
           
static java.lang.String httpAuthCharEncoding
           
protected static org.apache.commons.logging.Log log
           
private static javax.xml.parsers.SAXParserFactory saxFactory
           
private static java.lang.String saxParserFactoryProperty
           
private static java.util.Stack saxParsers
           
private static boolean tryReset
           
 
Constructor Summary
XMLUtils()
           
 
Method Summary
static org.w3c.dom.Element[] asElementArray(java.util.List list)
          Converts a List with org.w3c.dom.Element objects to an Array with org.w3c.dom.Element objects.
static java.lang.String base64encode(byte[] bytes)
           
static void DocumentToStream(org.w3c.dom.Document doc, java.io.OutputStream out)
           
static java.lang.String DocumentToString(org.w3c.dom.Document doc)
          turn a whole DOM document into XML
static void DocumentToWriter(org.w3c.dom.Document doc, java.io.Writer writer)
           
static void ElementToStream(org.w3c.dom.Element element, java.io.OutputStream out)
           
static java.lang.String ElementToString(org.w3c.dom.Element element)
          turn an element into an XML fragment
static void ElementToWriter(org.w3c.dom.Element element, java.io.Writer writer)
           
static org.w3c.dom.Node findNode(org.w3c.dom.Node node, javax.xml.namespace.QName name)
          Find a Node with a given QName
static java.lang.String getChildCharacterData(org.w3c.dom.Element parentEl)
          Concat all the text and cdata node children of this elem and return the resulting text.
static javax.xml.parsers.DocumentBuilder getDocumentBuilder()
          Gets a DocumentBuilder
private static javax.xml.parsers.DocumentBuilderFactory getDOMFactory()
           
static org.xml.sax.InputSource getEmptyInputSource()
           
static java.lang.String getEncoding()
          Get the current encoding in effect
static java.lang.String getEncoding(org.apache.axis.MessageContext msgContext)
          Get the current encoding in effect
static java.lang.String getEncoding(org.apache.axis.Message message, org.apache.axis.MessageContext msgContext)
           
static java.lang.String getEncoding(org.apache.axis.Message message, org.apache.axis.MessageContext msgContext, org.apache.axis.components.encoding.XMLEncoder defaultEncoder)
           
static javax.xml.namespace.QName getFullQNameFromString(java.lang.String str, org.w3c.dom.Node e)
          Return 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 java.lang.String getInnerXMLString(org.w3c.dom.Element element)
          get the inner XML inside an element as a string.
static org.xml.sax.InputSource getInputSourceFromURI(java.lang.String uri)
          Utility to get the bytes uri.
private static org.xml.sax.InputSource getInputSourceFromURI(java.lang.String uri, java.lang.String username, java.lang.String password)
          Utility to get the bytes at a protected uri This will retrieve the URL if a username and password are provided.
static java.lang.String getNamespace(java.lang.String prefix, org.w3c.dom.Node e)
           
static java.lang.String getNamespace(java.lang.String prefix, org.w3c.dom.Node e, org.w3c.dom.Node stopNode)
          Searches for the namespace URI of the given prefix in the given DOM range.
static java.lang.String getPrefix(java.lang.String uri, org.w3c.dom.Node e)
           
static javax.xml.namespace.QName getQNameFromString(java.lang.String str, org.w3c.dom.Node e)
          Return a QName when passed a string like "foo:bar" by mapping the "foo" prefix to a namespace in the context of the given Node.
private static javax.xml.namespace.QName getQNameFromString(java.lang.String str, org.w3c.dom.Node e, boolean defaultNS)
           
static javax.xml.parsers.SAXParser getSAXParser()
          Get a SAX parser instance from the JAXP factory.
static java.lang.String getStringForQName(javax.xml.namespace.QName qname, org.w3c.dom.Element e)
          Return a string for a particular QName, mapping a new prefix if necessary.
private static java.io.Writer getWriter(java.io.OutputStream os)
           
static org.apache.axis.components.encoding.XMLEncoder getXMLEncoder(org.apache.axis.MessageContext msgContext)
          Get the current XMLEncoder
static org.apache.axis.components.encoding.XMLEncoder getXMLEncoder(java.lang.String encoding)
          Get the XMLEncoder for specific encoding
static void initSAXFactory(java.lang.String factoryClassName, boolean namespaceAware, boolean validating)
          Initialize the SAX parser factory.
static org.w3c.dom.Document newDocument()
          Get an empty new Document
static org.w3c.dom.Document newDocument(org.xml.sax.InputSource inp)
          Get a new Document read from the input source
static org.w3c.dom.Document newDocument(java.io.InputStream inp)
          Get a new Document read from the input stream
static org.w3c.dom.Document newDocument(java.lang.String uri)
          Get a new Document read from the indicated uri
static org.w3c.dom.Document newDocument(java.lang.String uri, java.lang.String username, java.lang.String password)
          Create a new document from the given URI, use the username and password if the URI requires authentication.
static void normalize(org.w3c.dom.Node node)
          Trim all new lines from text nodes.
static void PrettyDocumentToStream(org.w3c.dom.Document doc, java.io.OutputStream out)
           
static java.lang.String PrettyDocumentToString(org.w3c.dom.Document doc)
           
static void PrettyDocumentToWriter(org.w3c.dom.Document doc, java.io.Writer writer)
           
static void PrettyElementToStream(org.w3c.dom.Element element, java.io.OutputStream out)
           
static void PrettyElementToWriter(org.w3c.dom.Element element, java.io.Writer writer)
           
private static java.lang.String privateElementToString(org.w3c.dom.Element element, boolean omitXMLDecl)
           
static void privateElementToWriter(org.w3c.dom.Element element, java.io.Writer writer, boolean omitXMLDecl, boolean pretty)
           
static void releaseDocumentBuilder(javax.xml.parsers.DocumentBuilder db)
          Releases a DocumentBuilder
static void releaseSAXParser(javax.xml.parsers.SAXParser parser)
          Return a SAX parser for reuse.
static org.xml.sax.InputSource sourceToInputSource(javax.xml.transform.Source source)
          Utility to get the bytes uri
static org.w3c.dom.Element StringToElement(java.lang.String namespace, java.lang.String name, java.lang.String string)
          Convert a simple string to an element with a text node
static java.lang.String trim(java.lang.String str)
           
static java.lang.String xmlEncodeString(java.lang.String orig)
          Encode a string appropriately for XML.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static org.apache.commons.logging.Log log

httpAuthCharEncoding

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

saxParserFactoryProperty

private static final java.lang.String saxParserFactoryProperty
See Also:
Constant Field Values

dbf

private static javax.xml.parsers.DocumentBuilderFactory dbf

saxFactory

private static javax.xml.parsers.SAXParserFactory saxFactory

saxParsers

private static java.util.Stack saxParsers

doNothingContentHandler

private static org.xml.sax.helpers.DefaultHandler doNothingContentHandler

EMPTY

private static java.lang.String EMPTY

bais

private static java.io.ByteArrayInputStream bais

tryReset

private static boolean tryReset

enableParserReuse

protected static boolean enableParserReuse

documentBuilder

private static XMLUtils.ThreadLocalDocumentBuilder documentBuilder
Constructor Detail

XMLUtils

public XMLUtils()
Method Detail

xmlEncodeString

public static java.lang.String xmlEncodeString(java.lang.String orig)
Encode a string appropriately for XML.


getXMLEncoder

public static org.apache.axis.components.encoding.XMLEncoder getXMLEncoder(org.apache.axis.MessageContext msgContext)
Get the current XMLEncoder


getXMLEncoder

public static org.apache.axis.components.encoding.XMLEncoder getXMLEncoder(java.lang.String encoding)
Get the XMLEncoder for specific encoding


getEncoding

public static java.lang.String getEncoding(org.apache.axis.MessageContext msgContext)
Get the current encoding in effect


getEncoding

public static java.lang.String getEncoding()
Get the current encoding in effect


initSAXFactory

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


getDOMFactory

private static javax.xml.parsers.DocumentBuilderFactory getDOMFactory()

getDocumentBuilder

public static javax.xml.parsers.DocumentBuilder getDocumentBuilder()
                                                            throws javax.xml.parsers.ParserConfigurationException
Gets a DocumentBuilder


releaseDocumentBuilder

public static void releaseDocumentBuilder(javax.xml.parsers.DocumentBuilder db)
Releases a DocumentBuilder


getSAXParser

public static javax.xml.parsers.SAXParser getSAXParser()
Get a SAX parser instance from the JAXP factory.


releaseSAXParser

public static void releaseSAXParser(javax.xml.parsers.SAXParser parser)
Return a SAX parser for reuse.


newDocument

public static org.w3c.dom.Document newDocument()
                                        throws javax.xml.parsers.ParserConfigurationException
Get an empty new Document


newDocument

public static org.w3c.dom.Document newDocument(org.xml.sax.InputSource inp)
                                        throws javax.xml.parsers.ParserConfigurationException,
                                               org.xml.sax.SAXException,
                                               java.io.IOException
Get a new Document read from the input source


newDocument

public static org.w3c.dom.Document newDocument(java.io.InputStream inp)
                                        throws javax.xml.parsers.ParserConfigurationException,
                                               org.xml.sax.SAXException,
                                               java.io.IOException
Get a new Document read from the input stream


newDocument

public static org.w3c.dom.Document newDocument(java.lang.String uri)
                                        throws javax.xml.parsers.ParserConfigurationException,
                                               org.xml.sax.SAXException,
                                               java.io.IOException
Get a new Document read from the indicated uri


newDocument

public static org.w3c.dom.Document newDocument(java.lang.String uri,
                                               java.lang.String username,
                                               java.lang.String password)
                                        throws javax.xml.parsers.ParserConfigurationException,
                                               org.xml.sax.SAXException,
                                               java.io.IOException
Create a new document from the given URI, use the username and password if the URI requires authentication.


privateElementToString

private static java.lang.String privateElementToString(org.w3c.dom.Element element,
                                                       boolean omitXMLDecl)

ElementToString

public static java.lang.String ElementToString(org.w3c.dom.Element element)
turn an element into an XML fragment


DocumentToString

public static java.lang.String DocumentToString(org.w3c.dom.Document doc)
turn a whole DOM document into XML


PrettyDocumentToString

public static java.lang.String PrettyDocumentToString(org.w3c.dom.Document doc)

privateElementToWriter

public static void privateElementToWriter(org.w3c.dom.Element element,
                                          java.io.Writer writer,
                                          boolean omitXMLDecl,
                                          boolean pretty)

ElementToStream

public static void ElementToStream(org.w3c.dom.Element element,
                                   java.io.OutputStream out)

PrettyElementToStream

public static void PrettyElementToStream(org.w3c.dom.Element element,
                                         java.io.OutputStream out)

ElementToWriter

public static void ElementToWriter(org.w3c.dom.Element element,
                                   java.io.Writer writer)

PrettyElementToWriter

public static void PrettyElementToWriter(org.w3c.dom.Element element,
                                         java.io.Writer writer)

DocumentToStream

public static void DocumentToStream(org.w3c.dom.Document doc,
                                    java.io.OutputStream out)

PrettyDocumentToStream

public static void PrettyDocumentToStream(org.w3c.dom.Document doc,
                                          java.io.OutputStream out)

getWriter

private static java.io.Writer getWriter(java.io.OutputStream os)

DocumentToWriter

public static void DocumentToWriter(org.w3c.dom.Document doc,
                                    java.io.Writer writer)

PrettyDocumentToWriter

public static void PrettyDocumentToWriter(org.w3c.dom.Document doc,
                                          java.io.Writer writer)

StringToElement

public static org.w3c.dom.Element StringToElement(java.lang.String namespace,
                                                  java.lang.String name,
                                                  java.lang.String string)
Convert a simple string to an element with a text node


getInnerXMLString

public static java.lang.String getInnerXMLString(org.w3c.dom.Element element)
get the inner XML inside an element as a string. This is done by converting the XML to its string representation, then extracting the subset between beginning and end tags.


getPrefix

public static java.lang.String getPrefix(java.lang.String uri,
                                         org.w3c.dom.Node e)

getNamespace

public static java.lang.String getNamespace(java.lang.String prefix,
                                            org.w3c.dom.Node e,
                                            org.w3c.dom.Node stopNode)
Searches for the namespace URI of the given prefix in the given DOM range. The namespace is not searched in parent of the "stopNode". This is usefull to get all the needed namespaces when you need to ouput only a subtree of a DOM document.


getNamespace

public static java.lang.String getNamespace(java.lang.String prefix,
                                            org.w3c.dom.Node e)

getQNameFromString

public static javax.xml.namespace.QName getQNameFromString(java.lang.String str,
                                                           org.w3c.dom.Node e)
Return a QName when passed a string like "foo:bar" by mapping the "foo" prefix to a namespace in the context of the given Node.


getFullQNameFromString

public static javax.xml.namespace.QName getFullQNameFromString(java.lang.String str,
                                                               org.w3c.dom.Node e)
Return a QName when passed a string like "foo:bar" by mapping the "foo" prefix to a namespace in the context of the given Node. If default namespace is found it is returned as part of the QName.


getQNameFromString

private static javax.xml.namespace.QName getQNameFromString(java.lang.String str,
                                                            org.w3c.dom.Node e,
                                                            boolean defaultNS)

getStringForQName

public static java.lang.String getStringForQName(javax.xml.namespace.QName qname,
                                                 org.w3c.dom.Element e)
Return a string for a particular QName, mapping a new prefix if necessary.


getChildCharacterData

public static java.lang.String getChildCharacterData(org.w3c.dom.Element parentEl)
Concat all the text and cdata node children of this elem and return the resulting text. (by Matt Duftler)


getInputSourceFromURI

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


sourceToInputSource

public static org.xml.sax.InputSource sourceToInputSource(javax.xml.transform.Source source)
Utility to get the bytes uri


getInputSourceFromURI

private static org.xml.sax.InputSource getInputSourceFromURI(java.lang.String uri,
                                                             java.lang.String username,
                                                             java.lang.String password)
                                                      throws java.io.IOException,
                                                             java.net.ProtocolException,
                                                             java.io.UnsupportedEncodingException
Utility to get the bytes at a protected uri This will retrieve the URL if a username and password are provided. The java.net.URL class does not do Basic Authentication, so we have to do it manually in this routine. If no username is provided, we create an InputSource from the uri and let the InputSource go fetch the contents.


base64encode

public static final java.lang.String base64encode(byte[] bytes)

getEmptyInputSource

public static org.xml.sax.InputSource getEmptyInputSource()

findNode

public static org.w3c.dom.Node findNode(org.w3c.dom.Node node,
                                        javax.xml.namespace.QName name)
Find a Node with a given QName


normalize

public static void normalize(org.w3c.dom.Node node)
Trim all new lines from text nodes.


trim

public static java.lang.String trim(java.lang.String str)

asElementArray

public static org.w3c.dom.Element[] asElementArray(java.util.List list)
Converts a List with org.w3c.dom.Element objects to an Array with org.w3c.dom.Element objects.


getEncoding

public static java.lang.String getEncoding(org.apache.axis.Message message,
                                           org.apache.axis.MessageContext msgContext)

getEncoding

public static java.lang.String getEncoding(org.apache.axis.Message message,
                                           org.apache.axis.MessageContext msgContext,
                                           org.apache.axis.components.encoding.XMLEncoder defaultEncoder)