吊索:找出资源是否是图像

时间:2015-09-16 15:24:28

标签: jsp cq5 aem sling

我有一个完全设置的CQ5 / AEM应用程序,我应该生成一个sitemap.xml。到目前为止,非常好。

我有一个所有页面的列表,但其中一些页面实际上是图像。我的问题:我怎样才能知道某个页面是否真的是一个图像?两者都有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);
        }
}

所有这些都在JSP中运行并执行它到目前为止应该执行的操作,除了它将图像视为页面并且我想忽略图像文件。我需要做什么?

3 个答案:

答案 0 :(得分:2)

我知道这个问题有点陈旧,似乎也许AEM中的某些事情发生了变化。

我一直在寻找如何确定DAM中的资产是否也是图像,而不是使用我自己的实用程序来检查mime类型。我最终找到了一种内置方式来做到这一点。有一个实用程序名称DamUtil,上面有各种有用的东西。回答OP问题所需的方法是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())
}

答案 1 :(得分:0)

存储在DAM中的图像应该具有jcr:primaryType = dam:Asset。也就是说,你应该能够检查这些属性:

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

图像不具有jcr:content / cq:template属性,并且它没有jcr:content / jcr:primaryType属性等于cq:PageContent。

这些属性存在于jcr:content节点下。尝试点击两个示例网址 - 一个用于图像,一个用于常规页面 - 但添加&#34; .infinity.json&#34;到URL的末尾。这将显示每个属性,以便您可以找到帮助您过滤图像的内容。

答案 2 :(得分:0)

如果两者都有jcr:primaryType = cq:Page,那么您可能想重新考虑构建应用程序的方式。 图像应该从DAM加载,或者在任何地方,它应该有jcr:primaryType = dam:Asset 这个大坝:资产节点将有一个jcr:type = dam:AssetContent的内容,它将包含元数据节点,这个元数据节点将具有dc:format属性,它将通知你文件类型..

相关问题