How to programmatically find out the Resource given a URL? | Community
Skip to main content
October 16, 2015
Solved

How to programmatically find out the Resource given a URL?

  • October 16, 2015
  • 3 replies
  • 996 views

According to ResourceResolver Interface:

http://dev.day.com/docs/en/cq/current/javadoc/org/apache/sling/api/resource/ResourceResolver.html

There are ways to resolve either path or request to a Resource:

     Resource   resolve(HttpServletRequest request) Deprecated. as of 2.0.4, use resolve(HttpServletRequest, String) instead. Resource   resolve(HttpServletRequest request, String absPath) Resolves the resource from the given absPath optionally taking HttpServletRequest into account, such as the value of the Host request header. Resource   resolve(String absPath) Resolves the resource from the given absolute path.

But, if I have a random given URL string (e.g. 'http://www.mycompany.com/whatever.html'). How do I programmatically find out the corresponding Resource from a given URL string?

In other words, how is 

Adobe Experience Manager Web Console
Sling Resource Resolver

implemented?

 
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 JustinEd3

Hi,

If you look at the code Joerg pointed to, you'll see how to do this - generate a synthetic HttpServletRequest object.

Regards,
Justin

3 replies

October 16, 2015

Not really.

All the codes indicate given a request (e.g. HttpServletRequest) I can call ResourceResolve.resolve(request) to programmatically translate a Request to Resource. However, if I don't have a Request, but only a URL String, how do I figure out the Resource of a random given URL String?

Thanks,

JustinEd3Adobe EmployeeAccepted solution
Adobe Employee
October 16, 2015

Hi,

If you look at the code Joerg pointed to, you'll see how to do this - generate a synthetic HttpServletRequest object.

Regards,
Justin