0

I have a completely set-up CQ5/AEM application and am supposed to generate a sitemap.xml. So far, so good.

I have a list of all the pages, but some of those pages are actually images. My question: How can I find out if a page is actually an image? Both have jcr:primaryType=cq:Page

public void getMoreChildren(HttpServletRequest request, JspWriter out, Page incomingChildPage) {
        Iterator<Page> childPageChildren = incomingChildPage.listChildren();
        while (childPageChildren.hasNext()) {
            Page childPage = childPageChildren.next();
            String pagePath = childPage.getPath();
            SlingHttpServletRequest slingRequest = (SlingHttpServletRequest)request;

            ResourceResolver resourceResolver = slingRequest.getResourceResolver();
            Externalizer externalizer = resourceResolver.adaptTo(Externalizer.class);

            String externalUrl = externalizer.publishLink(resourceResolver,pagePath) + ".html";
            //do things with data so far
            getMoreChildren(request, out, childPage);
        }
}

All of this runs within a JSP and does what it's supposed to do so far, except that it treats images as pages and I want to ignore image files. What do I need to do?

Jene
  • 53
  • 5

3 Answers3

4

I know this question is a little old, it also seems that maybe somethings in AEM have changed.

I was looking for how to determine if an asset in the DAM was an image too, without making my own utility to check the mime type. I eventually found a built in way to do this. There is a utility name DamUtil that has all kinds of useful things on it. The method needed to answer the OP's question is isImage().

Resource resource = resourceResolver.resolve("/content/dam/we-retail/en/people/womens/women_2.jpg");
Asset asset = resource.adaptTo(Asset.class);

if(com.day.cq.dam.commons.util.DamUtil.isImage(asset)) {
    Log.debug("Found and image at: {}", asset.getPath())
}
Tim Schruben
  • 1,535
  • 1
  • 12
  • 10
0

Images stored in the DAM should have jcr:primaryType=dam:Asset. That said, you should be able to check these properties:

jcr:content
    jcr:primaryType=cq:PageContent
    cq:template=/apps/yourApp/yourTemplate

An image won't have a jcr:content/cq:template property, and it won't have a jcr:content/jcr:primaryType property that equals cq:PageContent.

Those properties exist under the jcr:content node. Try hitting two sample urls--one for the image, and one for the regular page--but add ".infinity.json" to the end of the URL. That will show you the properties of each so you can find things to help you filter out the images.

Shawn
  • 8,374
  • 5
  • 37
  • 60
  • This got me onto the right path. We're giving different "sling:resourceType" attributes at least for different types of content, and I saw this in the json. – Jene Sep 18 '15 at 08:00
  • com.adobe.granite.asset.core.impl.AssetUtils.isAsset(yourResource) is a handy method for checking that your resource type is the appropriate dam:Asset as explained by Shawn. – CFJ90210 Dec 08 '15 at 21:37
0

If both have jcr:primaryType=cq:Page, then you might want to reconsider the way you are structuring your application. The image should be loaded from DAM, or, anywhere it is, it should have the jcr:primaryType= dam:Asset and this dam:Asset node will have a jcr:content of type= dam:AssetContent , which will contain metadata node and this metadata node will have a property of dc:format, which will inform you about the file type..

anubhs
  • 566
  • 1
  • 8
  • 26
  • I didn't design the application nor am I maintaining the content. I can guarantee that images don't "jcr:primaryType= dam:Asset" because wouldn't that just make my life easy – Jene Sep 17 '15 at 08:11