Skip to main content
Chandra_gupta
Level 4
Oct 16, 2015 2:28 AM UTC
Solved

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

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

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Chandra_gupta
Chandra_guptaAccepted solution
Level 4
Oct 16, 2015 2:28 AM UTC

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());

        }

}

4 replies

Chandra_gupta
Level 4
Oct 16, 2015 2:28 AM UTC

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

Translate
smacdonald2008
Level 10
Oct 16, 2015 2:28 AM UTC

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

 

Translate
smacdonald2008
Level 10
Oct 16, 2015 2:28 AM UTC

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

Translate
Chandra_gupta
Chandra_guptaAuthorAccepted solution
Level 4
Oct 16, 2015 2:28 AM UTC

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());

        }

}

Translate