Package org.camunda.spin.impl.xml.dom
Class DomXmlElement
- java.lang.Object
-
- org.camunda.spin.Spin<T>
-
- org.camunda.spin.xml.SpinXmlNode<SpinXmlElement>
-
- org.camunda.spin.xml.SpinXmlElement
-
- org.camunda.spin.impl.xml.dom.DomXmlElement
-
public class DomXmlElement extends SpinXmlElement
Wrapper for an xml dom element.- Author:
- Sebastian Menski
-
-
Field Summary
Fields Modifier and Type Field Description protected static javax.xml.transform.TransformercachedTransformerprotected static javax.xml.xpath.XPathFactorycachedXPathFactoryprotected DomXmlDataFormatdataFormatprotected org.w3c.dom.ElementdomElement
-
Constructor Summary
Constructors Constructor Description DomXmlElement(org.w3c.dom.Element domElement, DomXmlDataFormat dataFormat)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidadoptElement(DomXmlElement elementToAdopt)Adopts an xml dom element to the owner document of this element if necessary.SpinXmlElementappend(java.util.Collection<SpinXmlElement> childElements)Appends child elements to thiselement.SpinXmlElementappend(SpinXmlElement childElement)SpinXmlElementappend(SpinXmlElement... childElements)Appends child elements to thiselement.SpinXmlElementappendAfter(SpinXmlElement childElement, SpinXmlElement existingChildElement)SpinXmlElementappendBefore(SpinXmlElement childElement, SpinXmlElement existingChildElement)Appends a child element to this element before the existing child element.SpinXmlAttributeattr(java.lang.String attributeName)Returns the wrapped attribute for an empty namespace and the given name.SpinXmlElementattr(java.lang.String attributeName, java.lang.String value)Sets the attribute value in the local namespace of this element.java.util.List<java.lang.String>attrNames()Returns all names of the attributes of this element.java.util.List<java.lang.String>attrNames(java.lang.String namespace)Returns all names of the attributes in the given namespace.SpinXmlAttributeattrNs(java.lang.String namespace, java.lang.String attributeName)Returns the wrapped attribute for the given namespace and name.SpinXmlElementattrNs(java.lang.String namespace, java.lang.String attributeName, java.lang.String value)Sets the attribute value in the given namespace.SpinList<SpinXmlAttribute>attrs()Returns all wrapped attributes of this element.SpinList<SpinXmlAttribute>attrs(java.lang.String namespace)Returns all wrapped attributes for the given namespace.SpinXmlElementchildElement(java.lang.String elementName)Returns a single wrapped child element for the given name in the local namespace of this element.SpinXmlElementchildElement(java.lang.String namespace, java.lang.String elementName)Returns a single wrapped childelementfor the given namespace and name.SpinList<SpinXmlElement>childElements()Returns all child elements of thiselements.SpinList<SpinXmlElement>childElements(java.lang.String elementName)Returns all childelementswith a given name in the local namespace of this element.SpinList<SpinXmlElement>childElements(java.lang.String namespace, java.lang.String elementName)Returns all childelementswith a given namespace and name.java.lang.StringgetDataFormatName()Provides the name of the dataformat used by this spin.protected javax.xml.xpath.XPathFactorygetXPathFactory()Returns a XPath FactorybooleanhasAttr(java.lang.String attributeName)Checks whether this element has a attribute with an empty namespace and the given name.booleanhasAttrNs(java.lang.String namespace, java.lang.String attributeName)Checks whether this element has a attribute with the given namespace and name.booleanhasNamespace(java.lang.String namespace)Checks if the node has a given namespace.booleanhasPrefix(java.lang.String prefix)Checks if the node has a given prefix.<C> CmapTo(java.lang.Class<C> javaClass)Maps XML into specific class<C> CmapTo(java.lang.String javaClass)Maps Xml into specific classjava.lang.Stringname()Returns the local name of the node without namespace or prefix.java.lang.Stringnamespace()Returns the namespace uri of the node and not the prefix.java.lang.Stringprefix()Returns the prefix of the node and not the namespace uri.SpinXmlElementremove(java.util.Collection<SpinXmlElement> childElements)Removes all child elements from this element.SpinXmlElementremove(SpinXmlElement childElement)SpinXmlElementremove(SpinXmlElement... childElements)Removes all child elements from this element.SpinXmlElementremoveAttr(java.lang.String attributeName)Removes the attribute with an empty namespace.SpinXmlElementremoveAttrNs(java.lang.String namespace, java.lang.String attributeName)Removes the attribute under the given namespace.SpinXmlElementreplace(SpinXmlElement newElement)Replaces this element by an new one.SpinXmlElementreplaceChild(SpinXmlElement existingChildElement, SpinXmlElement newChildElement)Replaces an existing child element with a new one.java.lang.StringtextContent()Returns the text content of an element.SpinXmlElementtextContent(java.lang.String textContent)Sets the text content of an element.java.lang.StringtoString()Returns the wrapped XML element as string representation.org.w3c.dom.Elementunwrap()Return the wrapped object.voidwriteToWriter(java.io.Writer writer)Writes the wrapped XML element to a existing writer.SpinXPathQueryxPath(java.lang.String expression)Creates a XPath query on this element.
-
-
-
Field Detail
-
cachedTransformer
protected static javax.xml.transform.Transformer cachedTransformer
-
cachedXPathFactory
protected static javax.xml.xpath.XPathFactory cachedXPathFactory
-
domElement
protected final org.w3c.dom.Element domElement
-
dataFormat
protected final DomXmlDataFormat dataFormat
-
-
Constructor Detail
-
DomXmlElement
public DomXmlElement(org.w3c.dom.Element domElement, DomXmlDataFormat dataFormat)
-
-
Method Detail
-
getDataFormatName
public java.lang.String getDataFormatName()
Description copied from class:SpinProvides the name of the dataformat used by this spin.- Specified by:
getDataFormatNamein classSpin<SpinXmlElement>- Returns:
- the name of the dataformat used by this Spin.
-
unwrap
public org.w3c.dom.Element unwrap()
Description copied from class:SpinReturn the wrapped object. The return type of this method depends on the concrete data format.- Specified by:
unwrapin classSpin<SpinXmlElement>- Returns:
- the object wrapped by this wrapper.
-
name
public java.lang.String name()
Description copied from class:SpinXmlNodeReturns the local name of the node without namespace or prefix.- Specified by:
namein classSpinXmlNode<SpinXmlElement>- Returns:
- the name of the node
-
namespace
public java.lang.String namespace()
Description copied from class:SpinXmlNodeReturns the namespace uri of the node and not the prefix.- Specified by:
namespacein classSpinXmlNode<SpinXmlElement>- Returns:
- the namespace of the node
-
prefix
public java.lang.String prefix()
Description copied from class:SpinXmlNodeReturns the prefix of the node and not the namespace uri.- Specified by:
prefixin classSpinXmlNode<SpinXmlElement>- Returns:
- the prefix of the node
-
hasPrefix
public boolean hasPrefix(java.lang.String prefix)
Description copied from class:SpinXmlNodeChecks if the node has a given prefix.- Specified by:
hasPrefixin classSpinXmlNode<SpinXmlElement>- Parameters:
prefix- the prefix to check- Returns:
- true if the name has the same prefix
-
hasNamespace
public boolean hasNamespace(java.lang.String namespace)
Description copied from class:SpinXmlNodeChecks if the node has a given namespace.- Specified by:
hasNamespacein classSpinXmlNode<SpinXmlElement>- Parameters:
namespace- the namespace to check- Returns:
- true if the node has the same namespace
-
attr
public SpinXmlAttribute attr(java.lang.String attributeName)
Description copied from class:SpinXmlElementReturns the wrapped attribute for an empty namespace and the given name.- Specified by:
attrin classSpinXmlElement- Parameters:
attributeName- the name of the attribute- Returns:
- the wrapped
attribute
-
attrNs
public SpinXmlAttribute attrNs(java.lang.String namespace, java.lang.String attributeName)
Description copied from class:SpinXmlElementReturns the wrapped attribute for the given namespace and name.- Specified by:
attrNsin classSpinXmlElement- Parameters:
namespace- the namespace of the attributeattributeName- the name of the attribute- Returns:
- the wrapped
attribute
-
hasAttr
public boolean hasAttr(java.lang.String attributeName)
Description copied from class:SpinXmlElementChecks whether this element has a attribute with an empty namespace and the given name.- Specified by:
hasAttrin classSpinXmlElement- Parameters:
attributeName- the name of the attribute- Returns:
- true if the element has an attribute with this name under the local namespace, false otherwise
-
hasAttrNs
public boolean hasAttrNs(java.lang.String namespace, java.lang.String attributeName)Description copied from class:SpinXmlElementChecks whether this element has a attribute with the given namespace and name.- Specified by:
hasAttrNsin classSpinXmlElement- Parameters:
namespace- the namespace of the attributeattributeName- the name of the attribute- Returns:
- true if the element has an attribute with this name under given namespace, false otherwise
-
attrs
public SpinList<SpinXmlAttribute> attrs()
Description copied from class:SpinXmlElementReturns all wrapped attributes of this element.- Specified by:
attrsin classSpinXmlElement- Returns:
- the wrapped attributes or an empty list of no attributes are found
-
attrs
public SpinList<SpinXmlAttribute> attrs(java.lang.String namespace)
Description copied from class:SpinXmlElementReturns all wrapped attributes for the given namespace.- Specified by:
attrsin classSpinXmlElement- Parameters:
namespace- the namespace of the attributes- Returns:
- the wrapped attributes or an empty list of no attributes are found
-
attrNames
public java.util.List<java.lang.String> attrNames()
Description copied from class:SpinXmlElementReturns all names of the attributes of this element.- Specified by:
attrNamesin classSpinXmlElement- Returns:
- the names of the attributes
-
attrNames
public java.util.List<java.lang.String> attrNames(java.lang.String namespace)
Description copied from class:SpinXmlElementReturns all names of the attributes in the given namespace.- Specified by:
attrNamesin classSpinXmlElement- Returns:
- the names of the attributes
-
textContent
public java.lang.String textContent()
Description copied from class:SpinXmlElementReturns the text content of an element.- Specified by:
textContentin classSpinXmlElement- Returns:
- the text content or an empty string if non exists
-
textContent
public SpinXmlElement textContent(java.lang.String textContent)
Description copied from class:SpinXmlElementSets the text content of an element.- Specified by:
textContentin classSpinXmlElement- Parameters:
textContent- the text content to set- Returns:
- the wrapped
element
-
childElement
public SpinXmlElement childElement(java.lang.String elementName)
Description copied from class:SpinXmlElementReturns a single wrapped child element for the given name in the local namespace of this element.- Specified by:
childElementin classSpinXmlElement- Parameters:
elementName- the element name- Returns:
- the wrapped child
element
-
childElement
public SpinXmlElement childElement(java.lang.String namespace, java.lang.String elementName)
Description copied from class:SpinXmlElementReturns a single wrapped childelementfor the given namespace and name.- Specified by:
childElementin classSpinXmlElement- Parameters:
namespace- the namespace of the elementelementName- the element name- Returns:
- the wrapped child
element
-
childElements
public SpinList<SpinXmlElement> childElements()
Description copied from class:SpinXmlElementReturns all child elements of thiselements.- Specified by:
childElementsin classSpinXmlElement- Returns:
- list of wrapped child
elements
-
childElements
public SpinList<SpinXmlElement> childElements(java.lang.String elementName)
Description copied from class:SpinXmlElementReturns all childelementswith a given name in the local namespace of this element.- Specified by:
childElementsin classSpinXmlElement- Parameters:
elementName- the element name- Returns:
- a collection of wrapped
elements
-
childElements
public SpinList<SpinXmlElement> childElements(java.lang.String namespace, java.lang.String elementName)
Description copied from class:SpinXmlElementReturns all childelementswith a given namespace and name.- Specified by:
childElementsin classSpinXmlElement- Parameters:
namespace- the namespace of the elementelementName- the element name- Returns:
- a collection of wrapped
elements
-
attr
public SpinXmlElement attr(java.lang.String attributeName, java.lang.String value)
Description copied from class:SpinXmlElementSets the attribute value in the local namespace of this element.- Specified by:
attrin classSpinXmlElement- Parameters:
attributeName- the name of the attributevalue- the value to set- Returns:
- the wrapped
element
-
attrNs
public SpinXmlElement attrNs(java.lang.String namespace, java.lang.String attributeName, java.lang.String value)
Description copied from class:SpinXmlElementSets the attribute value in the given namespace.- Specified by:
attrNsin classSpinXmlElement- Parameters:
namespace- the namespace of the attributeattributeName- the name of the attributevalue- the value to set- Returns:
- the wrapped
element
-
removeAttr
public SpinXmlElement removeAttr(java.lang.String attributeName)
Description copied from class:SpinXmlElementRemoves the attribute with an empty namespace.- Specified by:
removeAttrin classSpinXmlElement- Parameters:
attributeName- the name of the attribute- Returns:
- the wrapped
element
-
removeAttrNs
public SpinXmlElement removeAttrNs(java.lang.String namespace, java.lang.String attributeName)
Description copied from class:SpinXmlElementRemoves the attribute under the given namespace.- Specified by:
removeAttrNsin classSpinXmlElement- Parameters:
namespace- the namespace of the attributeattributeName- the name of the attribute- Returns:
- the wrapped
element
-
append
public SpinXmlElement append(SpinXmlElement... childElements)
Description copied from class:SpinXmlElementAppends child elements to thiselement.- Specified by:
appendin classSpinXmlElement- Parameters:
childElements- the child elements to append- Returns:
- the wrapped
element
-
append
public SpinXmlElement append(SpinXmlElement childElement)
-
append
public SpinXmlElement append(java.util.Collection<SpinXmlElement> childElements)
Description copied from class:SpinXmlElementAppends child elements to thiselement.- Specified by:
appendin classSpinXmlElement- Parameters:
childElements- the child elements to append- Returns:
- the wrapped
element
-
appendBefore
public SpinXmlElement appendBefore(SpinXmlElement childElement, SpinXmlElement existingChildElement)
Description copied from class:SpinXmlElementAppends a child element to this element before the existing child element.- Specified by:
appendBeforein classSpinXmlElement- Parameters:
childElement- the child element to appendexistingChildElement- the child element to append before- Returns:
- the wrapped
element
-
appendAfter
public SpinXmlElement appendAfter(SpinXmlElement childElement, SpinXmlElement existingChildElement)
Description copied from class:SpinXmlElement- Specified by:
appendAfterin classSpinXmlElement- Parameters:
childElement- the child element to appendexistingChildElement- the child element to append after- Returns:
- the wrapped
element
-
remove
public SpinXmlElement remove(SpinXmlElement... childElements)
Description copied from class:SpinXmlElementRemoves all child elements from this element.- Specified by:
removein classSpinXmlElement- Parameters:
childElements- the child elements to remove- Returns:
- the wrapped
element
-
remove
public SpinXmlElement remove(SpinXmlElement childElement)
-
remove
public SpinXmlElement remove(java.util.Collection<SpinXmlElement> childElements)
Description copied from class:SpinXmlElementRemoves all child elements from this element.- Specified by:
removein classSpinXmlElement- Parameters:
childElements- the child elements to remove- Returns:
- the wrapped
element
-
replace
public SpinXmlElement replace(SpinXmlElement newElement)
Description copied from class:SpinXmlElementReplaces this element by an new one.- Specified by:
replacein classSpinXmlElement- Parameters:
newElement- the new element- Returns:
- the new wrapped
element
-
replaceChild
public SpinXmlElement replaceChild(SpinXmlElement existingChildElement, SpinXmlElement newChildElement)
Description copied from class:SpinXmlElementReplaces an existing child element with a new one.- Specified by:
replaceChildin classSpinXmlElement- Parameters:
existingChildElement- the existing child element to replacenewChildElement- the new child element- Returns:
- the wrapped
element
-
xPath
public SpinXPathQuery xPath(java.lang.String expression)
Description copied from class:SpinXmlElementCreates a XPath query on this element.- Specified by:
xPathin classSpinXmlElement- Parameters:
expression- the XPath expression- Returns:
- the XPath query
-
adoptElement
protected void adoptElement(DomXmlElement elementToAdopt)
Adopts an xml dom element to the owner document of this element if necessary.- Parameters:
elementToAdopt- the element to adopt
-
toString
public java.lang.String toString()
Description copied from class:SpinXmlElementReturns the wrapped XML element as string representation.- Specified by:
toStringin classSpinXmlElement- Returns:
- the string representation
-
writeToWriter
public void writeToWriter(java.io.Writer writer)
Description copied from class:SpinXmlElementWrites the wrapped XML element to a existing writer.- Specified by:
writeToWriterin classSpinXmlElement- Parameters:
writer- the writer to write to
-
getXPathFactory
protected javax.xml.xpath.XPathFactory getXPathFactory()
Returns a XPath Factory- Returns:
- the XPath factory
-
mapTo
public <C> C mapTo(java.lang.Class<C> javaClass)
Description copied from class:SpinXmlNodeMaps XML into specific class- Specified by:
mapToin classSpinXmlNode<SpinXmlElement>- Parameters:
javaClass- Class to which the Xml should be mapped- Returns:
- mapped Class
-
mapTo
public <C> C mapTo(java.lang.String javaClass)
Description copied from class:SpinXmlNodeMaps Xml into specific class- Specified by:
mapToin classSpinXmlNode<SpinXmlElement>- Parameters:
javaClass- canonical name of the class- Returns:
- mapped class
-
-