public class SAXElement extends Object
SAXVisitor
implementations will be passed
an instance of this class for each of the event methods of
SAXVisitor
implementations.
writer
set on it.
SAXVisitor
implementations can take care of
serializing the elements at which they are targeted themselves. Alternatively, they
can use the SAXElementWriterUtil
class.
SAXVisitor
implementations can also control the serialization
of their "child elements" by setting the writer
on the SAXElement instance they receive. This works because Smooks passes the
writer instance that's set on a SAXElement instance to all of the SAXElement
instances created for child elements.
Only one SAXVisitor
can have access to the writer
for any individual SAXElement
. The first visitor to request access to
the writer via the getWriter(SAXVisitor)
method "owns" the writer
for that element. Any other visitors requesting access to get or change the writer
will result in a SAXWriterAccessException
being thrown. In this situation,
you need to restructure the offending Smooks configuration and eliminate one of the
visitors attempting to gain access to the writer. If developing a new Visitor,
you should annotate the new Visitor class with the @StreamResultWriter
annotation.Constructor and Description |
---|
SAXElement(QName name,
Attributes attributes,
SAXElement parent)
Public constructor.
|
SAXElement(String namespaceURI,
String localName)
Public constructor.
|
SAXElement(String namespaceURI,
String localName,
SAXElement parent)
Public constructor.
|
SAXElement(String namespaceURI,
String localName,
String qName,
Attributes attributes,
SAXElement parent)
Public constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
accumulateText()
Turn on
text accumulation for this SAXElement . |
void |
addText(String text)
Add a text object to this instance.
|
void |
addText(String text,
TextType type)
Add a text object to this instance.
|
boolean |
equals(Object obj) |
String |
getAttribute(String attribute)
Get the named attribute from this element.
|
String |
getAttribute(String namespaceURI,
String attribute)
Deprecated.
|
String |
getAttributeNS(String namespaceURI,
String attribute)
Get the named attribute from this element.
|
Attributes |
getAttributes()
Get the element attributes.
|
Object |
getCache()
Deprecated.
Use
getCache(SAXVisitor) . |
Object |
getCache(SAXVisitor visitor)
Get the element cache object.
|
QName |
getName()
Get the element naming details.
|
SAXElement |
getParent()
Get parent element.
|
List<SAXText> |
getText()
Get the child
text list associated with this SAXElement . |
String |
getTextContent()
|
Writer |
getWriter(SAXVisitor visitor)
Get the writer to which this element should be writen to.
|
int |
hashCode() |
boolean |
isWriterOwner(SAXVisitor visitor)
|
void |
removeAttribute(String name)
Remove the named attribute.
|
void |
removeAttributeNS(String namespaceURI,
String name)
Remove the named attribute, having the specified namespace.
|
void |
setAttribute(String attribute,
String value)
Set the named attribute on this element.
|
void |
setAttributeNS(String namespaceURI,
String name,
String value)
Set the named attribute on this element.
|
void |
setAttributes(Attributes attributes)
Set the element attributes.
|
void |
setCache(Object cache)
Deprecated.
|
void |
setCache(SAXVisitor visitor,
Object cache)
Set the element cache object.
|
void |
setName(QName name)
Set the naming details for the Element.
|
void |
setParent(SAXElement parent)
Set parent element.
|
void |
setWriter(Writer writer,
SAXVisitor visitor)
Set the writer to which this element should be writen to.
|
Element |
toDOMElement(Document document)
Create a DOM
Element instance from this SAXElement
instance. |
String |
toString() |
public SAXElement(String namespaceURI, String localName)
namespaceURI
- The Namespace URI, or the empty string if the
element has no Namespace URI or if Namespace
processing is not being performed.localName
- The local name (without prefix), or the
empty string if Namespace processing is not being
performed.public SAXElement(String namespaceURI, String localName, SAXElement parent)
namespaceURI
- The Namespace URI, or the empty string if the
element has no Namespace URI or if Namespace
processing is not being performed.localName
- The local name (without prefix), or the
empty string if Namespace processing is not being
performed.parent
- Parent element, or null if the element is the document root element.public SAXElement(String namespaceURI, String localName, String qName, Attributes attributes, SAXElement parent)
namespaceURI
- The Namespace URI, or the empty string if the
element has no Namespace URI or if Namespace
processing is not being performed.localName
- The local name (without prefix), or the
empty string if Namespace processing is not being
performed.qName
- The qualified name (with prefix), or the
empty string if qualified names are not available.attributes
- The attributes attached to the element. If
there are no attributes, it shall be an empty
Attributes object.parent
- Parent element, or null if the element is the document root element.public SAXElement(QName name, Attributes attributes, SAXElement parent)
name
- The element QName
.attributes
- The attributes attached to the element. If
there are no attributes, it shall be an empty
Attributes object.parent
- Parent element, or null if the element is the document root element.public void accumulateText()
text
accumulation for this SAXElement
.
For performance reasons, Text
accumulation is not on by default.TextConsumer
public List<SAXText> getText()
text
list associated with this SAXElement
.text
list associated with this SAXElement
,
or null if this SAXElement
is not accumulating text
.accumulateText()
,
TextConsumer
public void addText(String text)
text
- The text to be added.accumulateText()
,
TextConsumer
public void addText(String text, TextType type)
text
- The text to be added.type
- The text type.accumulateText()
,
TextConsumer
public String getTextContent() throws SmooksException
SAXText
objects associated with this SAXElement
,
as an accumulated
String.
This method will produce a string containing all TextType
SAXText
objects associated with this SAXElement
. If you need to filter out specific
TextType
SAXText
objects, use the getText()
method and manually
produce a String.SAXText
objects associated with this SAXElement
,
as an accumulated
String.SmooksException
- This SAXElement
instance does not have
text accumulation
turned on.accumulateText()
,
TextConsumer
public Writer getWriter(SAXVisitor visitor) throws SAXWriterAccessException
visitor
- The visitor requesting access to element writer.SAXWriterAccessException
- Invalid access request for the element writer. See element writing.StreamResultWriter
public void setWriter(Writer writer, SAXVisitor visitor) throws SAXWriterAccessException
writer
- The element writer.visitor
- The visitor requesting to set the element writer.SAXWriterAccessException
- Invalid access request for the element writer. See element writing.StreamResultWriter
public boolean isWriterOwner(SAXVisitor visitor)
SAXVisitor
the owner of the Writer
associated
with this SAXElement
instance.
See element writing.visitor
- The visitor being checked.SAXVisitor
owns the Writer
associated
with this SAXElement
instance, otherwise false.StreamResultWriter
public QName getName()
public void setName(QName name)
name
- The element naming details.public Attributes getAttributes()
public void setAttributes(Attributes attributes)
attributes
- The element attributes.public String getAttribute(String attribute)
attribute
- The attribute name.public String getAttributeNS(String namespaceURI, String attribute)
namespaceURI
- The namespace URI of the required attribute.attribute
- The attribute name.public String getAttribute(String namespaceURI, String attribute)
getAttributeNS(String, String)
.namespaceURI
- The namespace URI of the required attribute.attribute
- The attribute name.public void setAttribute(String attribute, String value)
attribute
- The attribute name.value
- The attribute value.public void setAttributeNS(String namespaceURI, String name, String value)
namespaceURI
- The attribute namespace URI.name
- The attribute name.value
- The attribute value.public void removeAttribute(String name)
name
- Attribute name.public void removeAttributeNS(String namespaceURI, String name)
namespaceURI
- The attribute namespace.name
- The attribute name.public Object getCache()
getCache(SAXVisitor)
.public void setCache(Object cache)
setCache(SAXVisitor, Object)
.cache
- The element cache Object.public Object getCache(SAXVisitor visitor)
visitor
- The SAXElement instance associated with the cache object.public void setCache(SAXVisitor visitor, Object cache)
visitor
- The SAXElement instance to which the cache object is to be associated.cache
- The element cache Object.public SAXElement getParent()
public void setParent(SAXElement parent)
parent
- Parent element, or null if it's the documnent root.public Element toDOMElement(Document document)
Element
instance from this SAXElement
instance.document
- The document to use to create the DOM Element.Copyright © 2020. All rights reserved.