Package org.apache.axis.utils
Class XMLUtils
java.lang.Object
org.apache.axis.utils.XMLUtils
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static boolean
static final String
protected static org.apache.commons.logging.Log
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Element[]
asElementArray
(List list) Converts a List with org.w3c.dom.Element objects to an Array with org.w3c.dom.Element objects.static final String
base64encode
(byte[] bytes) static void
DocumentToStream
(Document doc, OutputStream out) static String
DocumentToString
(Document doc) turn a whole DOM document into XMLstatic void
DocumentToWriter
(Document doc, Writer writer) static void
ElementToStream
(Element element, OutputStream out) static String
ElementToString
(Element element) turn an element into an XML fragmentstatic void
ElementToWriter
(Element element, Writer writer) static Node
Find a Node with a given QNamestatic String
getChildCharacterData
(Element parentEl) Concat all the text and cdata node children of this elem and return the resulting text.static DocumentBuilder
Gets a DocumentBuilderstatic InputSource
static String
Get the current encoding in effectstatic String
getEncoding
(MessageContext msgContext) Get the current encoding in effectstatic String
getEncoding
(Message message, MessageContext msgContext) static String
getEncoding
(Message message, MessageContext msgContext, XMLEncoder defaultEncoder) static QName
getFullQNameFromString
(String str, 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 String
getInnerXMLString
(Element element) get the inner XML inside an element as a string.static InputSource
Utility to get the bytes uri.static String
getNamespace
(String prefix, Node e) static String
getNamespace
(String prefix, Node e, Node stopNode) Searches for the namespace URI of the given prefix in the given DOM range.static String
static QName
getQNameFromString
(String str, 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 SAXParser
Get a SAX parser instance from the JAXP factory.static String
getStringForQName
(QName qname, Element e) Return a string for a particular QName, mapping a new prefix if necessary.static XMLEncoder
getXMLEncoder
(String encoding) Get the XMLEncoder for specific encodingstatic XMLEncoder
getXMLEncoder
(MessageContext msgContext) Get the current XMLEncoderstatic void
initSAXFactory
(String factoryClassName, boolean namespaceAware, boolean validating) Initialize the SAX parser factory.static Document
Get an empty new Documentstatic Document
newDocument
(InputStream inp) Get a new Document read from the input streamstatic Document
newDocument
(String uri) Get a new Document read from the indicated uristatic Document
newDocument
(String uri, String username, String password) Create a new document from the given URI, use the username and password if the URI requires authentication.static Document
newDocument
(InputSource inp) Get a new Document read from the input sourcestatic void
Trim all new lines from text nodes.static void
PrettyDocumentToStream
(Document doc, OutputStream out) static String
static void
PrettyDocumentToWriter
(Document doc, Writer writer) static void
PrettyElementToStream
(Element element, OutputStream out) static void
PrettyElementToWriter
(Element element, Writer writer) static void
privateElementToWriter
(Element element, Writer writer, boolean omitXMLDecl, boolean pretty) static void
Releases a DocumentBuilderstatic void
releaseSAXParser
(SAXParser parser) Return a SAX parser for reuse.static InputSource
sourceToInputSource
(Source source) Utility to get the bytes uristatic Element
StringToElement
(String namespace, String name, String string) Convert a simple string to an element with a text nodestatic String
static String
xmlEncodeString
(String orig) Encode a string appropriately for XML.
-
Field Details
-
log
protected static org.apache.commons.logging.Log log -
httpAuthCharEncoding
- See Also:
-
enableParserReuse
protected static boolean enableParserReuse
-
-
Constructor Details
-
XMLUtils
public XMLUtils()
-
-
Method Details
-
xmlEncodeString
Encode a string appropriately for XML.- Parameters:
orig
- the String to encode- Returns:
- a String in which XML special chars are repalced by entities
-
getXMLEncoder
Get the current XMLEncoder- Returns:
- XMLEncoder
-
getXMLEncoder
Get the XMLEncoder for specific encoding- Returns:
- XMLEncoder
-
getEncoding
Get the current encoding in effect- Returns:
- string
-
getEncoding
Get the current encoding in effect- Returns:
- string
-
initSAXFactory
public static void initSAXFactory(String factoryClassName, boolean namespaceAware, boolean validating) Initialize 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. Ifnull
, leaves current setting alone.namespaceAware
- true if we want a namespace-aware parservalidating
- true if we want a validating parser
-
getDocumentBuilder
Gets a DocumentBuilder- Returns:
- DocumentBuilder
- Throws:
ParserConfigurationException
-
releaseDocumentBuilder
Releases a DocumentBuilder- Parameters:
db
-
-
getSAXParser
Get a SAX parser instance from the JAXP factory.- Returns:
- a SAXParser instance.
-
releaseSAXParser
Return a SAX parser for reuse.- Parameters:
parser
- A SAX parser that is available for reuse
-
newDocument
Get an empty new Document- Returns:
- Document
- Throws:
ParserConfigurationException
- if construction problems occur
-
newDocument
public static Document newDocument(InputSource inp) throws ParserConfigurationException, SAXException, IOException Get a new Document read from the input source- Returns:
- Document
- Throws:
ParserConfigurationException
- if construction problems occurSAXException
- if the document has xml sax problemsIOException
- if i/o exceptions occur
-
newDocument
public static Document newDocument(InputStream inp) throws ParserConfigurationException, SAXException, IOException Get a new Document read from the input stream- Returns:
- Document
- Throws:
ParserConfigurationException
- if construction problems occurSAXException
- if the document has xml sax problemsIOException
- if i/o exceptions occur
-
newDocument
public static Document newDocument(String uri) throws ParserConfigurationException, SAXException, IOException Get a new Document read from the indicated uri- Returns:
- Document
- Throws:
ParserConfigurationException
- if construction problems occurSAXException
- if the document has xml sax problemsIOException
- if i/o exceptions occur
-
newDocument
public static Document newDocument(String uri, String username, String password) throws ParserConfigurationException, SAXException, IOException Create a new document from the given URI, use the username and password if the URI requires authentication.- Parameters:
uri
- the resource to getusername
- basic auth usernamepassword
- basic auth password- Throws:
ParserConfigurationException
- if construction problems occurSAXException
- if the document has xml sax problemsIOException
- if i/o exceptions occur
-
ElementToString
turn an element into an XML fragment- Parameters:
element
-- Returns:
- stringified element
-
DocumentToString
turn a whole DOM document into XML- Parameters:
doc
- DOM document- Returns:
- string representation of the document, including XML declaration
-
PrettyDocumentToString
-
privateElementToWriter
-
ElementToStream
-
PrettyElementToStream
-
ElementToWriter
-
PrettyElementToWriter
-
DocumentToStream
-
PrettyDocumentToStream
-
DocumentToWriter
-
PrettyDocumentToWriter
-
StringToElement
Convert a simple string to an element with a text node- Parameters:
namespace
- - element namespacename
- - element namestring
- - value of the text node- Returns:
- element - an XML Element, null if no element was created
-
getInnerXMLString
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.- Parameters:
element
-- Returns:
- textual body of the element, or null for no inner body
-
getPrefix
-
getNamespace
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.- Parameters:
prefix
- the prefix to finde
- the starting nodestopNode
- null to search in all the document or a parent node where the search must stop.- Returns:
- null if no namespace is found, or the namespace URI.
-
getNamespace
-
getQNameFromString
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.- Returns:
- a QName generated from the given string representation
-
getFullQNameFromString
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.- Returns:
- a QName generated from the given string representation
-
getStringForQName
Return a string for a particular QName, mapping a new prefix if necessary. -
getChildCharacterData
Concat all the text and cdata node children of this elem and return the resulting text. (by Matt Duftler)- Parameters:
parentEl
- the element whose cdata/text node values are to be combined.- Returns:
- the concatanated string.
-
getInputSourceFromURI
Utility to get the bytes uri. Does NOT handle authenticated URLs, use getInputSourceFromURI(uri, username, password)- Parameters:
uri
- the resource to get- See Also:
-
sourceToInputSource
Utility to get the bytes uri- Parameters:
source
- the resource to get
-
base64encode
-
getEmptyInputSource
-
findNode
Find a Node with a given QName- Parameters:
node
- parent nodename
- QName of the child we need to find- Returns:
- child node
-
normalize
Trim all new lines from text nodes.- Parameters:
node
-
-
trim
-
asElementArray
Converts a List with org.w3c.dom.Element objects to an Array with org.w3c.dom.Element objects.- Parameters:
list
- List containing org.w3c.dom.Element objects- Returns:
- Element[] Array with org.w3c.dom.Element objects
-
getEncoding
-
getEncoding
public static String getEncoding(Message message, MessageContext msgContext, XMLEncoder defaultEncoder)
-