Output Rewriting Pipelines (org.apache.sling.rewriter)Page edited by Carsten ZiegelerApache Sling RewriterThe Apache Sling Rewriter is a module for rewriting the output generated by a usual Sling rendering process. Some possible use cases include rewriting or checking all links in an html page, manipulating the html page, or using the generated output as the base for further transformation. An example of futher transformation is to use XSLT to transform rendered XML to some output format like HTML or XSL:FO for generating PDF. For supporting these use cases, the rewriter uses the concept for a processor. The processor is a component that is injected through a servlet filter into the response. By implementing the Processor interface one is able to rewrite the whole response in one go. A more convenient way of processing the output is by using a so called pipeline; the Apache Sling rewriter basically uses the same concept as the famous Apache Cocoon: an XML based pipeline for further post processing of output. The pipeline is based on SAX events. SAX PipelinesThe rewriter allows to configure a pipeline for post processing of the generated response. The pipeline starts with a generator. The generator gets the output from Sling. It's the task of the generator to generate SAX events (XML) and stream these into the pipeline. A transformer is a component in the middle of the pipeline, a pipeline can have zero to n transformers. The transformer receives SAX events from the previous component in the pipeline and sends SAX events to the next component in the pipeline. A transformer can remove events, change events, add events or just pass on the events. The pipeline ends with a serializer collecting all SAX events and writing the output to a provided output stream. Sling contains a default pipeline which is executed for all html responses: it starts with an html generator, parsing the html output and sending events into the pipeline. A html serializer collects all events and serializes the output. The pipelines can be configured in the repository as a child node of /apps/APPNAME/config/rewriter (or /libs/APPNAME/config/rewriter). (In fact the configured search paths of the resource resolver are observed.) Each node can have the following properties:
If a component needs a configuration, the configuration is stored in a child node which name is COMPONENTTYPE-NAME, e.g. to configure the html generator (named html-generator), the node should have the name generator-html-generator. Configuring the HTML GeneratorBy default the used html generator only generates events for some of the html tags. If you want to change this, create a pipeline config like outlined above for the pipeline and configure the html generator by adding the generator-html-generator node with a multi value string property named includeTags. The values define the tags, the parser uses. Default PipelineThe default pipeline is configured for the text/html mime type and consists of the html-generator as generator, and the html-serializer for generating the final response. Implementing Pipeline ComponentsEach pipeline component type has a corresponding Java interface (Generator, Transformer, and Serializer) together with a factory interface (GeneratorFactory, TransformerFactory, and SerializerFactory). When implementing such a component, both interfaces need to be implemented. The factory has only one method which creates a new instance of that type for the current request. The factory has to be registered as a service. For example if you're using the Maven SCR plugin, it looks like this: @scr.component metatype="no" @scr.service interface="TransformerFactory" @scr.property value="pipeline.type" value="validator"
Change Notification Preferences
View Online
|
View Change
|
Add Comment
|
- [CONF] Apache Sling Website > Output Rewriting Pipelines (or... confluence
- [CONF] Apache Sling Website > Output Rewriting Pipeline... confluence
- [CONF] Apache Sling Website > Output Rewriting Pipeline... confluence
- [CONF] Apache Sling Website > Output Rewriting Pipeline... confluence
- [CONF] Apache Sling Website > Output Rewriting Pipeline... confluence
- [CONF] Apache Sling Website > Output Rewriting Pipeline... confluence
