Package org.smooks.engine.delivery.dom
Class SmooksDOMFilter
- java.lang.Object
-
- org.smooks.engine.delivery.AbstractFilter
-
- org.smooks.engine.delivery.dom.SmooksDOMFilter
-
- All Implemented Interfaces:
Closeable,AutoCloseable,org.smooks.api.delivery.Filter
public class SmooksDOMFilter extends AbstractFilter
Smooks DOM based content filtering class. This class is responsible for Filtering XML DOM streams (XML/XHTML/HTML etc) through a process of iterating over the source XML DOM tree and applying theconfiguredContent Delivery Units (DOMElementVisitorsandSerializationUnits). This class doesn't get used directly. See theSmooksclass.XML/XHTML/HTML Filtering Process
SmooksDOMFilter markup processing (XML/XHTML/HTML) is a 2 phase filter, depending on what needs to be done. The first phase is called the "Visit Phase", and the second phase is called the "Serialisation Phase". SmooksDOMFilter can be used to execute either or both of these phases (depending on what needs to be done!). Through this filter, Smooks can be used to analyse and/or transform markup, and then serialise it. So, in a little more detail, the 2 phases are:-
Visit: This phase is executed via either of the
filter(Document)orfilter(Source)methods. This phase is really 2 "sub" phases.-
Assembly: This is effectively a pre-processing phase.
This sub-phase involves iterating over the source XML DOM,
visiting all DOM elements that have
ASSEMBLYphaseDOMElementVisitorstargetedat them for the profile associated with theExecutionContext. This phase can result in DOM elements being added to, or trimmed from, the DOM. This phase is also very usefull for gathering data from the message in the DOM (and storing it in theExecutionContext), which can be used during the processing phase (see below). This phase is only executed if there areDOMElementVisitorstargeted at this phase. -
Processing: Processing takes the assembled DOM and
iterates over it again, so as to perform transformation/analysis.
This sub-phase involves iterating over the source XML DOM again,
visiting all DOM elements that have
PROCESSINGphaseDOMElementVisitorstargetedat them for the profile associated with theExecutionContext. This phase will only operate on DOM elements that were present in the assembled document;DOMElementVisitorswill not be applied to elements that are introduced to the DOM during this phase.
-
Assembly: This is effectively a pre-processing phase.
This sub-phase involves iterating over the source XML DOM,
visiting all DOM elements that have
-
Serialisation: This phase is executed by the
serialize(Node, Writer)method (which uses theSerializerclass). The serialisation phase takes the processed DOM and iterates over it to apply allSerializationUnits, which write the document to the target output stream. Instead of using this serialisation mechanism, you may wish to perform DOM Serialisation via some other mechanism e.g. XSL-FO via something like Apache FOP.
Other Documents
SmooksResourceConfigResourceConfigSortComparator
- Author:
- tom.fennelly@gmail.com
-
-
Constructor Summary
Constructors Constructor Description SmooksDOMFilter(org.smooks.api.ExecutionContext executionContext)Public constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()voiddoFilter()protected voiddoFilter(org.smooks.api.io.Source source, org.smooks.api.io.Sink sink)Nodefilter(org.smooks.api.io.Source source)Phase the supplied input reader.Nodefilter(Document doc)Filter the supplied W3C Document.Nodefilter(Element element)Filter the supplied W3C Element.voidserialize(Node node, Writer writer)Serialise the node to the supplied output writer instance.
-
-
-
Constructor Detail
-
SmooksDOMFilter
public SmooksDOMFilter(org.smooks.api.ExecutionContext executionContext)
Public constructor. Constructs a SmooksDOMFilter instance for delivering content for the supplied execution context.- Parameters:
executionContext- Execution context. This instance is bound to the current Thread of execution. See Threading Issues.
-
-
Method Detail
-
doFilter
public void doFilter() throws org.smooks.api.SmooksException- Throws:
org.smooks.api.SmooksException
-
doFilter
protected void doFilter(org.smooks.api.io.Source source, org.smooks.api.io.Sink sink)
-
close
public void close()
-
filter
public Node filter(org.smooks.api.io.Source source)
Phase the supplied input reader. Simply parses the input reader into a W3C DOM and callsfilter(Document).- Parameters:
source- The source of markup to be filtered.- Returns:
- Node representing filtered document.
-
filter
public Node filter(Document doc)
Filter the supplied W3C Document. Executes the Assembly & Processing phases.- Parameters:
doc- The W3C Document to be filtered.- Returns:
- Node representing filtered document.
-
filter
public Node filter(Element element)
Filter the supplied W3C Element. Executes the Assembly & Processing phases.- Parameters:
element- The W3C Element to be filtered.- Returns:
- Node representing filtered Element.
-
serialize
public void serialize(Node node, Writer writer) throws IOException, org.smooks.api.SmooksException
Serialise the node to the supplied output writer instance. Executes the Serialisation phase, using theSerializerclass to perform the serialization.- Parameters:
node- Document to be serialised.writer- Output writer.- Throws:
IOException- Unable to write to output writer.org.smooks.api.SmooksException- Unable to serialise due to bad Smooks environment. Check cause.
-
-