Custom Rewriter Transformer to rewrite any HTML Output generated by Sling Rendering Process

Problem Context.

 I came across a unique business problem and found such solution is not available on the web so writing this blog might help others.

Sling Link Rewriting based on sling: pipeline is mainly focused on how to rewrite any anchor link inside or any html element i.e. <a> <form> <img> where SAX Transformer API rewrites html data through events.

Please refer to the Adobe Wiki

http://helpx.adobe.com/cq/kb/HowToImplementACustomRewriterTransformerFactory.html

Above wiki is very helpful if rewrite need to be done for any html element where start () method needed to be implement for custom business logic.

But what about if you need to overwrite or replace value of any string in the html not in side any html tag?

public void characters(char[] ac, int i, int j) throws SAXException {} 

By implementing above method of the same class that almost split html line by line and based on that it returns offset and total length of the string.

This helps content author to use String token during content authoring and would be overwritten during rendering of the page from central generic location.

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s