Return-Path:
org.apache.cocoon.pipeline.component.Finisher
.
In order to link components with each other, the first has to be a
- org.apache.cocoon.pipeline.component.Producer
, the latter
- org.apache.cocoon.pipeline.component.Consumer
.
+ org.apache.cocoon.pipeline.component.Finisher
, the latter
+ org.apache.cocoon.pipeline.component.Producer
.
When the pipeline links the components, it merely checks whether the above mentioned interfaces are present. So the pipeline does not know about the specific capabilities or the compatibility of the components. It is the @@ -108,7 +108,7 @@ Our implementation of StAX pipelines uses just StAX interfaces for retrieving events - the writing interface is proprietary in order to avoid multihreading or continuations. So it is really a hybrid process - the StAX component is called to generate the next events, but it is also allowed to read as much data from the previous pipeline component as it wants. But as the produced events are kept in-memory until a later component pulls for them, the components should not emit large amounts of events during one invocation.
StAXGenerator
is a Starter and normally parses a XML from an InputStream.
StAXSerializer
is a Finisher and writes the StAX Events to an OutputStream.
AbstractStAXTransformer
is the abstract base class for new transformers. It simplifies the task by providing a template method for generating the new events.
StAXCleaningTransformer
is an transformer, which cleans the document from whitespaces and comments.
IncludeTransformer
includes the contents of another document.
For further information refer to the javadoc
The StAXGenerator
is a Starter
component and produces XMLEvents.
-
import java.io.InputStream; +import java.io.InputStream; import java.net.URL; import javax.xml.stream.FactoryConfigurationError; @@ -148,20 +148,20 @@ public XMLEvent peek() throws XMLStreamException { return this.reader.peek(); } - -}
- In order to implement an own
StAXGenerator
the easiest approach is to inherit fromAbstractStAXProducer
. + +}
+ In order to implement an own
StAXGenerator
the easiest approach is to inherit fromAbstractStAXProducer
.- The constructor creates a new XMLEventReader for reading from the inputstream. + The constructor creates a new XMLEventReader for reading from the inputstream.
- The pipeline is started using the
execute
method. As StAX is a pull based approach the last component has to start pulling. + The pipeline is started using theexecute
method. As StAX is a pull based approach the last component has to start pulling.This method should return true if the generator has a next Event.
Returns the next event from the generator.
Returns the next event from the generator, without moving actually to the next event.
-
Implementing a StAX Transformer should be the most common use case. The
AbstractStAXTransformer
provides a foundation for new transformers. But in order to write new transformers even simpler, let's describe another feature first:Navigators allow an easier navigation in the XML document. They also simplify transformers, as usually transformers need only process some parts of the input document and the navigator helps to identify the interesting parts. There are several implementations already included: -
FindStartElementNavigator
finds the start tag with certain properties(name,attribute)
FindEndElementNavigator
finds the end tag with certain properties(name,attribute)
FindCorrespondingStartEndElementPairNavigator
finds both the start and the corresponding end tag.
InSubtreeNavigator
finds whole subtrees, by specifying the properties of the "root" element.- For further information refer to the navigator javadoc -
- Using a navigator is a rather simple task. The transformer peeks or gets the next event and calls
Navigator.fulfillsCriteria
- if true is returned the transformer should be process that event somehow. -Creating a new navigator is a rather simple task and just means implementing two methods:
import javax.xml.stream.events.XMLEvent; +
Implementing a StAX Transformer should be the most common use case. The
AbstractStAXTransformer
provides a foundation for new transformers. But in order to write new transformers even simpler, let's describe another feature first:Navigators allow an easier navigation in the XML document. They also simplify transformers, as usually transformers need only process some parts of the input document and the navigator helps to identify the interesting parts. There are several implementations already included: +
FindStartElementNavigator
finds the start tag with certain properties(name,attribute)
FindEndElementNavigator
finds the end tag with certain properties(name,attribute)
FindCorrespondingStartEndElementPairNavigator
finds both the start and the corresponding end tag.
InSubtreeNavigator
finds whole subtrees, by specifying the properties of the "root" element.+ For further information refer to the navigator javadoc +
+ Using a navigator is a rather simple task. The transformer peeks or gets the next event and calls
Navigator.fulfillsCriteria
- if true is returned the transformer should be process that event somehow. +Creating a new navigator is a rather simple task and just means implementing two methods:
import javax.xml.stream.events.XMLEvent; public class MyNavigator implements Navigator { public boolean fulfillsCriteria(XMLEvent event) { @@ -172,11 +172,11 @@ return false; } } -
- This method returns true if the event matches the criteria of the navigator. +
+ This method returns true if the event matches the criteria of the navigator.
- Returns the result of the last invocation of fulfillsCriteria. -
The next example should show you an transformer featuring navigators and implicit state handling through function calls.
public class DaisyLinkRewriteTransformer extends AbstractStAXTransformer { @Override protected void produceEvents() throws XMLStreamException { while (this.getParent().hasNext()) { @@ -270,4 +270,4 @@ </dependency>Using woodstox is simpler, as the reference implementation depends on JAXP 1.4, which is not part of Java 1.5. -