Adobe CQ5.5-如何使用API​​显示页面缩略图 [英] Adobe CQ5.5-How to display Page Thumbnail using API

查看:80
本文介绍了Adobe CQ5.5-如何使用API​​显示页面缩略图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用sidekick>页面属性>图像标签为页面配置了图像。现在,我想在我的一个jsp中获取此页面图像(缩略图)。有人可以给我指向我可以用来实现这一目标的api类和方法的指针或代码段。



谢谢,
Rajeev

解决方案

我建议使用默认的图像组件作为示例-/ libs / foundation / components / image。



但是,如果要将代码放入特定页面类型的组件中,则代码应如下所示:

  if(currentNode.hasNode( image)){
字符串imagePath = currentNode.getNode( image)。getPath();
资源imageRes = resourceResolver.getResource(imagePath);
image = new Image(imageRes);

image.loadStyleData(currentStyle);
image.setSelector(。img);

if(!currentDesign.equals(resourceDesign)){
image.setSuffix(currentDesign.getId());
}
image.draw(out);
}

请记住,即使您设置了图像,也并不意味着它将显示-如果您使用默认的页面对话框作为页面属性,它将仅显示损坏的图像。这是因为CQ中存在一个错误,该错误未设置图片的sling:resourceType属性,因此不会显示。这是因为放在图像上的.img选择器不知道要做什么,除非它指向具有.img选择器定义的资源类型,以便它可以正确呈现图像。



我已经使用默认的/ libs / foundation / components / page组件对话框上传了一个软件包,您可以将其用作该问题的修补程序,以便它实际上可以设置资源类型当您上传图片时。您可以从我的 Google云端硬盘中找到/下载该软件包



希望能有所帮助。让我知道您是否需要更多帮助。



编辑



如果要尝试从另一个页面的一个页面获取页面属性图像,您只需要使用资源解析器即可。您应该在CQ中有一个可用的代码,因此从本质上来说应该是以下代码:

  Resource imageRes = resourceResolver.getResource(pathFromYourDialog ); 
Image image = new Image(imageRes);

其余的将是相同的-您只是在给它一条不同的起点。 / p>

I have configured image for my page using sidekick >Page properties>Images tab. Now I want to fetch my this page image(thumbnail) in one of my jsp. Can someone give me pointers or code snippet for api class and method that I can use to achieve this.

Thanks, Rajeev

解决方案

I would suggest using the default image component as an example - /libs/foundation/components/image.

If you're putting your code into a component for your specific page type though, your code should be something like this:

if (currentNode.hasNode("image")) {
    String imagePath = currentNode.getNode("image").getPath();
    Resource imageRes = resourceResolver.getResource(imagePath);
    image = new Image(imageRes);

    image.loadStyleData(currentStyle);
    image.setSelector(".img");

    if (!currentDesign.equals(resourceDesign)) {
        image.setSuffix(currentDesign.getId());
    }
    image.draw(out);
}

Keep in mind though, even though you set an image, it does NOT mean it will show up - if you're using the default page dialog for page properties, it will only show a broken image. That's because there is a bug in CQ where the sling:resourceType property of the image doesn't get set, and thus it won't show up. This is because the .img selector that gets put on the image doesn't know what to do, unless it get's pointed to a resource type with a definition for the .img selector, so it can properly render the image.

I've uploaded a package that you can use as a hotfix for the issue with the default /libs/foundation/components/page component dialog, so that it will actually set the resource type when you upload an image. You can find/download the package from my Google Drive

Hopefully that helps. Let me know if you need more help.

EDIT

If you're trying to get the page properties image from one page on another page, you just need to use a resource resolver. You should have one available to you in CQ, so this would essentially be the code:

Resource imageRes = resourceResolver.getResource(pathFromYourDialog);
Image image = new Image(imageRes);

The rest would be the same - you're just giving it a different path to start from.

这篇关于Adobe CQ5.5-如何使用API​​显示页面缩略图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆