Skip to main content
Level 4
Dec 25, 2015 11:13 PM UTC
Solved

gettting path of CSS / JS from clientLib category name programatically

Hi all,

 
Hope everyone is doing fine !
 
In JSP usually if we have to include clientLib then we use below statement
<cq:includeClientLib js="personalization.ui"/>
 
And then these gets translated to actual script tags
<script type="text/javascript" src="/etc/clientlibs/personalization.js"></script>
 
Is there any way to get the path of JS referred by the clientLib category name using code ?
 
ie., I pass "personalization.ui" and it returns me back "/etc/clientlibs/personalization.js"
 
We have to do some further processing on this JS path so we need this.

 

Thanks in advance.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Kunal_Gaba_
Kunal_Gaba_Accepted solution
New Member
Dec 26, 2015 8:02 PM UTC

You can use the HtmlLibraryManager API to get the path of the JS from the client lib name.  

First get the ClientLibrary by passing the category name in the below API method-

https://docs.adobe.com/docs/en/cq/5-6-1/javadoc/com/day/cq/widget/HtmlLibraryManager.html#getLibraries(java.lang.String[], com.day.cq.widget.LibraryType, boolean, boolean)

And then get the include path of the JS by calling the following API method-

https://docs.adobe.com/docs/en/cq/5-6-1/javadoc/com/day/cq/widget/ClientLibrary.html#getIncludePath(com.day.cq.widget.LibraryType)

4 replies

edubey
Level 10
Dec 26, 2015 4:13 PM UTC

Can you share your use case.....I mean what you are trying to achieve using JS Path?

Translate
Level 4
Dec 26, 2015 5:10 PM UTC

Hi edubey,

Thanks for looking into it.

We need to pass the JS path to resource resolver to get final JS path

resourceResolver.map(request,jsPath) 

Translate
edubey
Level 10
Dec 26, 2015 6:47 PM UTC

If these are your client library then you already know where they exist and there position will not change (unless you forcefully do) and if there are OOTB, their location will never be changed.

If would be great, if you can provide more insight of use case...

Translate
Kunal_Gaba_
Kunal_Gaba_Accepted solution
New Member
Dec 26, 2015 8:02 PM UTC

You can use the HtmlLibraryManager API to get the path of the JS from the client lib name.  

First get the ClientLibrary by passing the category name in the below API method-

https://docs.adobe.com/docs/en/cq/5-6-1/javadoc/com/day/cq/widget/HtmlLibraryManager.html#getLibraries(java.lang.String[], com.day.cq.widget.LibraryType, boolean, boolean)

And then get the include path of the JS by calling the following API method-

https://docs.adobe.com/docs/en/cq/5-6-1/javadoc/com/day/cq/widget/ClientLibrary.html#getIncludePath(com.day.cq.widget.LibraryType)

Translate