Expand my Community achievements bar.

SOLVED

How to get current Page URL or Resource Object when rewriting page output using org.apache.sling.rewriter.

Avatar

Level 4

Can we get current page URL since slingRequestObject is not available in the class? for example i can get SlingRepository, ResourceResolverFactory and SlingSettingsService object by referencing and maven build generates serviceComponent.xml as complete OSGI bundle.

Thanks Chandra

1 Accepted Solution

Avatar

Correct answer by
Level 4

http://dev.day.com/docs/en/cq/current/javadoc/org/apache/sling/rewriter/DefaultTransformer.html

DefaultTransformer init method provides Slign Request.

 

private class StringTransformer extends DefaultTransformer {

        public void init(ProcessingContext context,
                ProcessingComponentConfiguration config) throws java.io.IOException {
            
            StringReWriterImpl.this.request = context.getRequest();        
            LOG.info("INIT is called -------------- ************** -------"+context.getRequest().getResource().getPath());

        }

}

View solution in original post

4 Replies

Avatar

Correct answer by
Level 4

http://dev.day.com/docs/en/cq/current/javadoc/org/apache/sling/rewriter/DefaultTransformer.html

DefaultTransformer init method provides Slign Request.

 

private class StringTransformer extends DefaultTransformer {

        public void init(ProcessingContext context,
                ProcessingComponentConfiguration config) throws java.io.IOException {
            
            StringReWriterImpl.this.request = context.getRequest();        
            LOG.info("INIT is called -------------- ************** -------"+context.getRequest().getResource().getPath());

        }

}

Avatar

Level 10

I am glad that you got this working - we are going to get this subject matter into a community developer article. 

Avatar

Level 10

The following stack overflow thread looks like it will help you to get information on a page such as an URL:

http://stackoverflow.com/questions/10502284/get-url-minus-current-filename-in-jsp-or-cq5

How to use org.apache.sling.rewriter within an OSGi bundle is on our list of articles. 

I also recommend looking at this topic:
http://sling.apache.org/site/output-rewriting-pipelines-orgapacheslingrewriter.html

 

Avatar

Level 4

I have updated ... might be useful for others.Thanks for reply by the way