You can also find references for components and dam images using parameter debug=layout. Click Here to see.
@SlingServlet(paths = "/bin/assetreference", metatype = true, methods = {
"GET"
})
public class AssetReference extends AbstractPredicateServlet {
private static final long serialVersionUID = 1 L;
public void doGet(final SlingHttpServletRequest slingHTTPrequest, final SlingHttpServletResponse response) throws IOException {
try {
String pagePath = slingHTTPrequest.getParameter("path");
ResourceResolver resourceResolver = slingHTTPrequest.getResourceResolver();
Resource resource = resourceResolver.getResource(pagePath + "/" + JcrConstants.JCR_CONTENT);
Node node = resource.adaptTo(Node.class);
AssetReferenceSearch assetReference = new AssetReferenceSearch(node, "/content/dam", resourceResolver);
for (Map.Entry < String, Asset > assetMap: assetReference.search().entrySet()) {
String val = assetMap.getKey();
Asset asset = assetMap.getValue();
LoggerUtil.debugLog(this.getClass(), "Key and Value are {}{}", val, asset.getPath());
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
"GET"
})
public class AssetReference extends AbstractPredicateServlet {
private static final long serialVersionUID = 1 L;
public void doGet(final SlingHttpServletRequest slingHTTPrequest, final SlingHttpServletResponse response) throws IOException {
try {
String pagePath = slingHTTPrequest.getParameter("path");
ResourceResolver resourceResolver = slingHTTPrequest.getResourceResolver();
Resource resource = resourceResolver.getResource(pagePath + "/" + JcrConstants.JCR_CONTENT);
Node node = resource.adaptTo(Node.class);
AssetReferenceSearch assetReference = new AssetReferenceSearch(node, "/content/dam", resourceResolver);
for (Map.Entry < String, Asset > assetMap: assetReference.search().entrySet()) {
String val = assetMap.getKey();
Asset asset = assetMap.getValue();
LoggerUtil.debugLog(this.getClass(), "Key and Value are {}{}", val, asset.getPath());
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
Reference: https://cqwemblog.wordpress.com/2013/12/07/how-to-get-image-dam-reference-from-any-cq5-page/
No comments:
Post a Comment
If you have any doubts or questions, please let us know.