Package org.apache.axiom.om.util
Class ElementHelper
- java.lang.Object
-
- org.apache.axiom.om.util.ElementHelper
-
public class ElementHelper extends Object
Helper class to provide extra utility stuff against elements. The code is designed to work with any element implementation.
-
-
Constructor Summary
Constructors Constructor Description ElementHelper(OMElement element)Constructs and binds to an element.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static OMElementgetChildWithName(OMElement parent, String childName)Deprecated.please use OMElement.getFirstChildWithName(qname) instead!static StringgetContentID(XMLStreamReader parser)static StringgetContentID(XMLStreamReader parser, String charsetEncoding)Deprecated.usegetContentID(XMLStreamReader)instead (see WSCOMMONS-429)static StringgetContentIDFromHref(String href)Extract the content ID from a href attribute value, i.e.static ReadergetTextAsStream(OMElement element, boolean cache)Returns a stream representing the concatenation of the text nodes that are children of a given element.static OMElementimportOMElement(OMElement omElement, OMFactory omFactory)Some times two OMElements needs to be added to the same object tree.QNameresolveQName(String qname)Turns a prefix:local qname string into a proper QName, evaluating it in the OMElement context.QNameresolveQName(String qname, boolean defaultToParentNameSpace)Turns a prefix:local qname string into a proper QName, evaluating it in the OMElement context.static voidsetNewElement(OMElement parent, OMElement myElement, OMElement newElement)static SOAPHeaderBlocktoSOAPHeaderBlock(OMElement omElement, SOAPFactory factory)This is a method to convert regular OMElements to SOAPHeaderBlocks.static voidwriteTextTo(OMElement element, Writer out, boolean cache)Write the content of the text nodes that are children of a given element to aWriter.
-
-
-
Constructor Detail
-
ElementHelper
public ElementHelper(OMElement element)
Constructs and binds to an element.- Parameters:
element- element to work with
-
-
Method Detail
-
resolveQName
public QName resolveQName(String qname, boolean defaultToParentNameSpace)
Turns a prefix:local qname string into a proper QName, evaluating it in the OMElement context.- Parameters:
qname- qname to resolvedefaultToParentNameSpace- flag that controls behaviour when there is no namespace.- Returns:
- Returns null for any failure to extract a qname.
-
resolveQName
public QName resolveQName(String qname)
Turns a prefix:local qname string into a proper QName, evaluating it in the OMElement context. Unprefixed qnames resolve to the local namespace.- Parameters:
qname- prefixed qname string to resolve- Returns:
- Returns null for any failure to extract a qname.
-
setNewElement
public static void setNewElement(OMElement parent, OMElement myElement, OMElement newElement)
-
getChildWithName
public static OMElement getChildWithName(OMElement parent, String childName)
Deprecated.please use OMElement.getFirstChildWithName(qname) instead!
-
getContentID
public static String getContentID(XMLStreamReader parser, String charsetEncoding)
Deprecated.usegetContentID(XMLStreamReader)instead (see WSCOMMONS-429)
-
getContentID
public static String getContentID(XMLStreamReader parser)
-
getContentIDFromHref
public static String getContentIDFromHref(String href)
Extract the content ID from a href attribute value, i.e. from a URI following the cid: scheme defined by RFC2392.- Parameters:
href- the value of the href attribute- Returns:
- the corresponding content ID
-
importOMElement
public static OMElement importOMElement(OMElement omElement, OMFactory omFactory)
Some times two OMElements needs to be added to the same object tree. But in Axiom, a single tree should always contain object created from the same type of factory (eg: LinkedListImplFactory, DOMFactory, etc.,). If one OMElement is created from a different factory than that of the factory which was used to create the object in the existing tree, we need to convert the new OMElement to match to the factory of existing object tree. This method will convert omElement to the given omFactory.- See Also:
to convert instances of OMAttribute
-
toSOAPHeaderBlock
public static SOAPHeaderBlock toSOAPHeaderBlock(OMElement omElement, SOAPFactory factory) throws Exception
This is a method to convert regular OMElements to SOAPHeaderBlocks.- Parameters:
omElement-factory-- Returns:
- TODO
- Throws:
Exception
-
getTextAsStream
public static Reader getTextAsStream(OMElement element, boolean cache)
Returns a stream representing the concatenation of the text nodes that are children of a given element. The stream returned by this method produces exactly the same character sequence as the the stream created by the following expression:new StringReader(element.getText())
The difference is that the stream implementation returned by this method is guaranteed to have constant memory usage and is optimized for performance.- Parameters:
element- the element to read the text nodes fromcache- whether to enable caching when accessing the element- Returns:
- a stream representing the concatenation of the text nodes
- See Also:
OMElement.getText()
-
writeTextTo
public static void writeTextTo(OMElement element, Writer out, boolean cache) throws XMLStreamException, IOException
Write the content of the text nodes that are children of a given element to aWriter. Ifcacheis true, this method has the same effect as the following instruction:out.write(element.getText())
The difference is that this method is guaranteed to have constant memory usage and is optimized for performance.- Parameters:
element- the element to read the text nodes fromout- the stream to write the content tocache- whether to enable caching when accessing the element- Throws:
XMLStreamException- if an error occurs when reading from the elementIOException- if an error occurs when writing to the stream- See Also:
OMElement.getText()
-
-