How to get current Page URL or Resource Object when rewriting page output using org.apache.sling.rewriter. | Community
Skip to main content
Chandra_gupta
Level 4
October 16, 2015
Solved

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

  • October 16, 2015
  • 4 replies
  • 11039 views

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.
Best answer by Chandra_gupta

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
Chandra_guptaAuthorAccepted solution
Level 4
October 16, 2015

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

        }

}

smacdonald2008
Level 10
October 16, 2015

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

smacdonald2008
Level 10
October 16, 2015

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

 

Chandra_gupta
Level 4
October 16, 2015

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