Class ContextObjectSerializerVisitor
- java.lang.Object
-
- org.smooks.engine.delivery.dom.serialize.ContextObjectSerializerVisitor
-
- All Implemented Interfaces:
ContentHandler
,AfterVisitor
,BeforeVisitor
,ChildrenVisitor
,ElementVisitor
,SaxNgVisitor
,SerializerVisitor
,Visitor
,DOMSerializerVisitor
public class ContextObjectSerializerVisitor extends Object implements DOMSerializerVisitor, ElementVisitor
ExecutionContext
object serializer. Outputs an object bound to theExecutionContext
. The location of the object (context key) must be specified on the "key" attribute.- Author:
- tom.fennelly@gmail.com
-
-
Constructor Summary
Constructors Constructor Description ContextObjectSerializerVisitor()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Element
createElement(Document ownerDocument, String key)
Utility method for creating a <context-object/> element.static String
getContextKey(Element element)
static boolean
isContextObjectElement(Element element)
void
visitAfter(Element element, ExecutionContext executionContext)
Visits the end of anElement
.void
visitBefore(Element element, ExecutionContext executionContext)
Visits the beginning of anElement
.void
visitChildElement(Element childElement, ExecutionContext executionContext)
Visits a childElement
.void
visitChildText(CharacterData characterData, ExecutionContext executionContext)
Visits the character data of anElement
.void
writeCharacterData(Node node, Writer writer, ExecutionContext executionContext)
Write element text.boolean
writeChildElements()
Write the child elements of the element this SerializationUnit is being applied to.void
writeElementCDATA(CDATASection cdata, Writer writer, ExecutionContext executionContext)
Write element CDATA section.void
writeElementComment(Comment comment, Writer writer, ExecutionContext executionContext)
Write element comment.void
writeElementEntityRef(EntityReference entityRef, Writer writer, ExecutionContext executionContext)
Write element entity reference object.void
writeElementNode(Node node, Writer writer, ExecutionContext executionContext)
Write element Node object.void
writeEndElement(Element element, Writer writer, ExecutionContext executionContext)
Write the element end portion; close the element.void
writeStartElement(Element element, Writer writer, ExecutionContext executionContext)
Write the element start portion; the element name and it's attributes.
-
-
-
Method Detail
-
writeStartElement
public void writeStartElement(Element element, Writer writer, ExecutionContext executionContext) throws IOException
Description copied from interface:SerializerVisitor
Write the element start portion; the element name and it's attributes. EG: <a href="http://www.x.com">- Specified by:
writeStartElement
in interfaceSerializerVisitor
- Parameters:
element
- The element start to write.writer
- The writer to be written to.executionContext
- ExecutionContext instance for the delivery context.- Throws:
IOException
- Exception writing output.
-
writeEndElement
public void writeEndElement(Element element, Writer writer, ExecutionContext executionContext) throws IOException
Description copied from interface:SerializerVisitor
Write the element end portion; close the element. EG: </a>- Specified by:
writeEndElement
in interfaceSerializerVisitor
- Parameters:
element
- The element end to write.writer
- The writer to be written to.executionContext
- ExecutionContext instance for the delivery context.- Throws:
IOException
- Exception writing output.
-
writeCharacterData
public void writeCharacterData(Node node, Writer writer, ExecutionContext executionContext) throws IOException
Description copied from interface:SerializerVisitor
Write element text.- Specified by:
writeCharacterData
in interfaceSerializerVisitor
- Parameters:
node
- The Text object to write.writer
- The writer to be written to.executionContext
- ExecutionContext instance for the delivery context.- Throws:
IOException
- Exception writing output.
-
writeElementComment
public void writeElementComment(Comment comment, Writer writer, ExecutionContext executionContext) throws IOException
Description copied from interface:SerializerVisitor
Write element comment.- Specified by:
writeElementComment
in interfaceSerializerVisitor
- Parameters:
comment
- The comment o write.writer
- The writer to be written to.executionContext
- ExecutionContext instance for the delivery context.- Throws:
IOException
- Exception writing output.
-
writeElementEntityRef
public void writeElementEntityRef(EntityReference entityRef, Writer writer, ExecutionContext executionContext) throws IOException
Description copied from interface:SerializerVisitor
Write element entity reference object.- Specified by:
writeElementEntityRef
in interfaceSerializerVisitor
- Parameters:
entityRef
- The entity reference to write.writer
- The writer to be written to.executionContext
- ExecutionContext instance for the delivery context.- Throws:
IOException
- Exception writing output.
-
writeElementCDATA
public void writeElementCDATA(CDATASection cdata, Writer writer, ExecutionContext executionContext) throws IOException
Description copied from interface:SerializerVisitor
Write element CDATA section.- Specified by:
writeElementCDATA
in interfaceSerializerVisitor
- Parameters:
cdata
- The CDATA section to write.writer
- The writer to be written to.executionContext
- ExecutionContext instance for the delivery context.- Throws:
IOException
- Exception writing output.
-
writeElementNode
public void writeElementNode(Node node, Writer writer, ExecutionContext executionContext) throws IOException
Description copied from interface:SerializerVisitor
Write element Node object. Called to write DOM types not covered by the other methods on this interface.- Specified by:
writeElementNode
in interfaceSerializerVisitor
- Parameters:
node
- The node to write.writer
- The writer to be written to.executionContext
- ExecutionContext instance for the delivery context.- Throws:
IOException
- Exception writing output.
-
writeChildElements
public boolean writeChildElements()
Description copied from interface:SerializerVisitor
Write the child elements of the element this SerializationUnit is being applied to.- Specified by:
writeChildElements
in interfaceSerializerVisitor
- Returns:
- True if the child elements are to be writen, otherwise false.
-
createElement
public static Element createElement(Document ownerDocument, String key)
Utility method for creating a <context-object/> element.- Parameters:
ownerDocument
- The owner document.key
- The context key.- Returns:
- The <context-object/> element.
-
isContextObjectElement
public static boolean isContextObjectElement(Element element)
-
visitAfter
public void visitAfter(Element element, ExecutionContext executionContext) throws SmooksException
Description copied from interface:AfterVisitor
Visits the end of anElement
.- Specified by:
visitAfter
in interfaceAfterVisitor
- Parameters:
element
- theElement
representing the end of the fragment. TheElement
's ancestors are traversable unless the global configuration parametermaintain.element.stack
is set to false. TheElement
's child nodes are traversable if one of the following conditions are met:max.node.depth
global config parameter is set to 0 or greater than 1, or- this
AfterVisitor
implementsParameterizedVisitor.getMaxNodeDepth()
which returns an integer greater than 1
executionContext
- the currentExecutionContext
- Throws:
SmooksException
-
visitBefore
public void visitBefore(Element element, ExecutionContext executionContext) throws SmooksException
Description copied from interface:BeforeVisitor
Visits the beginning of anElement
.- Specified by:
visitBefore
in interfaceBeforeVisitor
- Parameters:
element
- theElement
representing the beginning of the fragment. TheElement
's ancestors are traversable unless the global configuration parametermaintain.element.stack
is set to false. TheElement
's child nodes are not traversable.executionContext
- the currentExecutionContext
- Throws:
SmooksException
-
visitChildText
public void visitChildText(CharacterData characterData, ExecutionContext executionContext)
Description copied from interface:ChildrenVisitor
Visits the character data of anElement
. This method is invoked once for each chunk of character data. A shortcut for collecting character data is to annotate theSaxNgVisitor
implementation withorg.smooks.engine.delivery.sax.annotation.StreamResultWriter
, or stash the character data in aTextAccumulatorMemento
and restore theTextAccumulatorMemento
inAfterVisitor.visitAfter(Element, ExecutionContext)
.- Specified by:
visitChildText
in interfaceChildrenVisitor
- Parameters:
characterData
- thenode
which includes character data but not any childElement
s. TheElement
's ancestors are traversable unless the global configuration parametermaintain.element.stack
is set to false.executionContext
- the currentExecutionContext
-
visitChildElement
public void visitChildElement(Element childElement, ExecutionContext executionContext) throws SmooksException
Description copied from interface:ChildrenVisitor
Visits a childElement
. This method is invoked once for each childElement
.- Specified by:
visitChildElement
in interfaceChildrenVisitor
- Parameters:
childElement
- the childElementElement
's ancestors are traversable unless the global configuration parametermaintain.element.stack
is set to false. TheElement
's child nodes are not traversable.executionContext
- the currentExecutionContext
- Throws:
SmooksException
-
-