Show Menu
主题×

以JSON格式获取页面信息

要获取页面信息,请向PageInfo servlet发送请求,以JSON格式获取页面元数据。
PageInfo servlet返回有关存储库中资源的信息。 servlet绑定到URL并 https://<server>:<port>/libs/wcm/core/content/pageinfo.json 使用参数 path 标识资源。 以下示例URL返回有关该节点的 /content/we-retail/us/en 信息:
http://localhost:4502/libs/wcm/core/content/pageinfo.json?path=/content/we-retail/us/en

如果需要JSON格式的页面信息,以向非传统AEM网页的渠道提供内容交付,例如:
  • 单页应用程序
  • 本机移动应用程序
  • AEM外部的其他渠道和触点

页面信息提供者

页面组件可以与一个或多个生成页面元 com.day.cq.wcm.api.PageInfoProvider 数据的服务相关联。 PageInfo servlet调用每个PageInfoProvider服务并聚合元数据:
  1. HTTP客户端向PageInfo servlet发送请求,该PageInfo servlet包括页面的URL。
  2. PageInfo servlet可发现呈现页面的组件。
  3. PageInfo servlet调用与组件关联的每个PageInfoProvider。
  4. servlet聚合每个PageInfoProvider返回的元数据,并将元数据添加到JSON对象中的HTTP响应。
与PageInfoProviders类似,使用ListInfoProviders以JSON格式更新信息列表。 (请参 阅自定义网站管理控制台 。)

默认页面信息提供者

/libs/foundation/components/page 组件与以下PageInfoProvider服务关联:
  • ​默认页面状态提供者:有关页面状态的信息,如页面是否已锁定、页面是否是活动工作流的有效负荷以及哪些工作流可用于页面。
  • ​实时关系信息提供者:有关多站点管理(MSM)的信息,例如页面是否属于蓝印,以及页面是否为Live Copy。
  • ​内容语言Servlet:当前页面的语言,以及有关页面可用的每种语言的信息。
  • ​工作流状态提供者:有关将页面作为有效负荷的正在运行的工作流的状态信息。
  • ​工作流包信息提供者:有关存储在存储库中的每个工作流包的信息,以及每个包是否包含当前资源。
  • ​模拟器信息提供者:有关可用于此资源的移动设备模拟器的信息。 如果页面组件不呈现移动页面,则不提供模拟器。
  • ​注释信息提供者:有关页面上的注释的信息。
例如,PageInfo servlet为节点返回以下JSON响 /content/we-retail/us/en 应:
{
   "status":{
      "path":"/content/we-retail/us/en",
      "isLocked":false,
      "lockOwner":"",
      "canUnlock":false,
      "lastModified":1467202845038,
      "lastModifiedBy":"admin",
      "timeUntilValid":0,
      "onTime":0,
      "offTime":0,
      "replication":{
         "numQueued":0
      },
      "isDesignable":true,
      "isDeveloper":true
   },
   "isPage":true,
   "pageResourceType":"weretail/components/structure/page",
   "enableFragmentIdentifier":false,
   "workflow":{
      "isRunning":false
   },
   "workflows":{
      "wcm":{
         "models":[
            {
               "wid":"/etc/workflow/models/dam/adddamsize/jcr:content/model",
               "label":"Add Asset Size",
               "label_xss":"Add Asset Size"
            },
            {
               "wid":"/etc/workflow/models/ac-newsletter-workflow-simple/jcr:content/model",
               "label":"Approve for Adobe Campaign",
               "label_xss":"Approve for Adobe Campaign"
            },
            {
               "wid":"/etc/workflow/models/dam/dam-autotag-assets/jcr:content/model",
               "label":"DAM Smart Tag Assets",
               "label_xss":"DAM Smart Tag Assets"
            },
            {
               "wid":"/etc/workflow/models/dam/update_asset/jcr:content/model",
               "label":"DAM Update Asset",
               "label_xss":"DAM Update Asset"
            },
            {
               "wid":"/etc/workflow/models/cloudservices/DTM_bundle_download/jcr:content/model",
               "label":"Default DTM Bundle Download",
               "label_xss":"Default DTM Bundle Download"
            },
            {
               "wid":"/etc/workflow/models/dam/dam_download_asset/jcr:content/model",
               "label":"Download Asset",
               "label_xss":"Download Asset"
            },
            {
               "wid":"/etc/workflow/models/dam/dynamic-media-video-thumbnail-replacement/jcr:content/model",
               "label":"Dynamic Media Video Thumbnail Replacement",
               "label_xss":"Dynamic Media Video Thumbnail Replacement"
            },
            {
               "wid":"/etc/workflow/models/dam/dynamic-media-video-user-uploaded-thumbnail/jcr:content/model",
               "label":"Dynamic Media Video User Uploaded Thumbnail Process",
               "label_xss":"Dynamic Media Video User Uploaded Thumbnail Process"
            },
            {
               "wid":"/etc/workflow/models/projects/approval_workflow/jcr:content/model",
               "label":"Project Approval Workflow",
               "label_xss":"Project Approval Workflow"
            },
            {
               "wid":"/etc/workflow/models/publish_example/jcr:content/model",
               "label":"Publish Example",
               "label_xss":"Publish Example"
            },
            {
               "wid":"/etc/workflow/models/publish_to_campaign/jcr:content/model",
               "label":"Publish to Adobe Campaign",
               "label_xss":"Publish to Adobe Campaign"
            },
            {
               "wid":"/etc/workflow/models/s7dam/request_to_publish_to_youtube/jcr:content/model",
               "label":"Publish to YouTube",
               "label_xss":"Publish to YouTube"
            },
            {
               "wid":"/etc/workflow/models/projects/request_copy/jcr:content/model",
               "label":"Request Copy",
               "label_xss":"Request Copy"
            },
            {
               "wid":"/etc/workflow/models/request_for_activation/jcr:content/model",
               "label":"Request for Activation",
               "label_xss":"Request for Activation"
            },
            {
               "wid":"/etc/workflow/models/request_for_deactivation/jcr:content/model",
               "label":"Request for Deactivation",
               "label_xss":"Request for Deactivation"
            },
            {
               "wid":"/etc/workflow/models/request_for_deletion/jcr:content/model",
               "label":"Request for Deletion",
               "label_xss":"Request for Deletion"
            },
            {
               "wid":"/etc/workflow/models/request_to_complete_move_operation/jcr:content/model",
               "label":"Request to complete Move operation",
               "label_xss":"Request to complete Move operation"
            },
            {
               "wid":"/etc/workflow/models/screens-update-asset/jcr:content/model",
               "label":"Screens Update Asset",
               "label_xss":"Screens Update Asset"
            },
            {
               "wid":"/etc/workflow/models/s7dam/request_to_remove_from_youtube/jcr:content/model",
               "label":"Unpublish from YouTube",
               "label_xss":"Unpublish from YouTube"
            },
            {
               "wid":"/etc/workflow/models/wcm-translation/create_language_copy/jcr:content/model",
               "label":"WCM: Create Language Copy",
               "label_xss":"WCM: Create Language Copy"
            },
            {
               "wid":"/etc/workflow/models/wcm-translation/prepare_translation_project/jcr:content/model",
               "label":"WCM: Prepare Translation Project",
               "label_xss":"WCM: Prepare Translation Project"
            },
            {
               "wid":"/etc/workflow/models/wcm-translation/translate-i18n-dictionary/jcr:content/model",
               "label":"WCM: Prepare and Translate I18n-Dictionary",
               "label_xss":"WCM: Prepare and Translate I18n-Dictionary"
            },
            {
               "wid":"/etc/workflow/models/wcm-translation/sync_translation_job/jcr:content/model",
               "label":"WCM: Sync Translation Job",
               "label_xss":"WCM: Sync Translation Job"
            },
            {
               "wid":"/etc/workflow/models/wcm-translation/update_language_copy/jcr:content/model",
               "label":"WCM: Update Language Copy",
               "label_xss":"WCM: Update Language Copy"
            }
         ]
      },
      "translation":{
         "models":[
            {
               "wid":"/etc/workflow/models/dam/adddamsize/jcr:content/model",
               "label":"Add Asset Size",
               "label_xss":"Add Asset Size"
            },
            {
               "wid":"/etc/workflow/models/ac-newsletter-workflow-simple/jcr:content/model",
               "label":"Approve for Adobe Campaign",
               "label_xss":"Approve for Adobe Campaign"
            },
            {
               "wid":"/etc/workflow/models/dam/dam-autotag-assets/jcr:content/model",
               "label":"DAM Smart Tag Assets",
               "label_xss":"DAM Smart Tag Assets"
            },
            {
               "wid":"/etc/workflow/models/cloudservices/DTM_bundle_download/jcr:content/model",
               "label":"Default DTM Bundle Download",
               "label_xss":"Default DTM Bundle Download"
            },
            {
               "wid":"/etc/workflow/models/dam/dam_download_asset/jcr:content/model",
               "label":"Download Asset",
               "label_xss":"Download Asset"
            },
            {
               "wid":"/etc/workflow/models/dam/dynamic-media-video-thumbnail-replacement/jcr:content/model",
               "label":"Dynamic Media Video Thumbnail Replacement",
               "label_xss":"Dynamic Media Video Thumbnail Replacement"
            },
            {
               "wid":"/etc/workflow/models/dam/dynamic-media-video-user-uploaded-thumbnail/jcr:content/model",
               "label":"Dynamic Media Video User Uploaded Thumbnail Process",
               "label_xss":"Dynamic Media Video User Uploaded Thumbnail Process"
            },
            {
               "wid":"/etc/workflow/models/projects/approval_workflow/jcr:content/model",
               "label":"Project Approval Workflow",
               "label_xss":"Project Approval Workflow"
            },
            {
               "wid":"/etc/workflow/models/publish_to_campaign/jcr:content/model",
               "label":"Publish to Adobe Campaign",
               "label_xss":"Publish to Adobe Campaign"
            },
            {
               "wid":"/etc/workflow/models/s7dam/request_to_publish_to_youtube/jcr:content/model",
               "label":"Publish to YouTube",
               "label_xss":"Publish to YouTube"
            },
            {
               "wid":"/etc/workflow/models/projects/request_copy/jcr:content/model",
               "label":"Request Copy",
               "label_xss":"Request Copy"
            },
            {
               "wid":"/etc/workflow/models/request_for_deletion/jcr:content/model",
               "label":"Request for Deletion",
               "label_xss":"Request for Deletion"
            },
            {
               "wid":"/etc/workflow/models/request_to_complete_move_operation/jcr:content/model",
               "label":"Request to complete Move operation",
               "label_xss":"Request to complete Move operation"
            },
            {
               "wid":"/etc/workflow/models/screens-update-asset/jcr:content/model",
               "label":"Screens Update Asset",
               "label_xss":"Screens Update Asset"
            },
            {
               "wid":"/etc/workflow/models/translation/jcr:content/model",
               "label":"Translation Prepare",
               "label_xss":"Translation Prepare"
            },
            {
               "wid":"/etc/workflow/models/s7dam/request_to_remove_from_youtube/jcr:content/model",
               "label":"Unpublish from YouTube",
               "label_xss":"Unpublish from YouTube"
            }
         ]
      }
   },
   "translation":{

   },
   "design":{
      "path":"/conf/we-retail/settings/wcm/templates/hero-page/policies",
      "lastModified":0
   },
   "componentsRef":"/libs/wcm/core/content/components.1497341312569.json",
   "editableTemplate":"/conf/we-retail/settings/wcm/templates/hero-page",
   "msm":{
      "msm:isLiveCopy":true,
      "msm:isInBlueprint":false,
      "msm:isSource":false
   },
   "launches":{
      "isLaunch":false,
      "isInLaunch":false
   },
   "language":"en",
   "languages":{
      "rows":[
         {
            "path":"/content/we-retail/us/en",
            "exists":true,
            "hasContent":true,
            "lastModified":0,
            "iso":"en",
            "country":"gb",
            "language":"English"
         },
         {
            "path":"/content/we-retail/us/es",
            "exists":true,
            "hasContent":true,
            "lastModified":0,
            "iso":"es",
            "country":"es",
            "language":"Spanish"
         }
      ]
   },
   "workflowInfo":{
      "isRunning":false
   },
   "workflowPackageInfo":{
      "workflowPackages":[

      ],
      "selectedWorkflowPackages":[

      ],
      "runningSelectedWorkflowPackages":[

      ]
   },
   "emulators":{
      "groups":{
         "responsive":{
            "title":"Responsive Devices",
            "description":"The devices in this group are able to display a website built using responsive design patterns.",
            "path":"/etc/mobile/groups/responsive",
            "galaxy5":{
               "text":"Galaxy S5",
               "action":"start",
               "path":"/libs/wcm/mobile/components/emulators/galaxy5",
               "canRotate":true,
               "hasTouchScrolling":true,
               "contentCssPath":"/etc/mobile/groups/responsive/static.css",
               "width":1080,
               "height":1920,
               "device-pixel-ratio":3
            },
            "ipad":{
               "text":"iPad",
               "action":"start",
               "path":"/libs/wcm/mobile/components/emulators/ios/ipad",
               "canRotate":true,
               "hasTouchScrolling":true,
               "contentCssPath":"/etc/mobile/groups/responsive/static.css",
               "width":768,
               "height":1024,
               "device-pixel-ratio":1
            },
            "iphone5":{
               "text":"iPhone 5",
               "action":"start",
               "path":"/libs/wcm/mobile/components/emulators/ios/iphone5",
               "canRotate":true,
               "hasTouchScrolling":true,
               "contentCssPath":"/etc/mobile/groups/responsive/static.css",
               "width":640,
               "height":1136,
               "device-pixel-ratio":2
            },
            "iphone6":{
               "text":"iPhone 6",
               "action":"start",
               "path":"/libs/wcm/mobile/components/emulators/ios/iphone6",
               "canRotate":true,
               "hasTouchScrolling":true,
               "contentCssPath":"/etc/mobile/groups/responsive/static.css",
               "width":750,
               "height":1334,
               "device-pixel-ratio":2
            },
            "iphone4":{
               "text":"iPhone 4",
               "action":"start",
               "path":"/libs/wcm/mobile/components/emulators/ios/iphone4",
               "canRotate":true,
               "hasTouchScrolling":true,
               "contentCssPath":"/etc/mobile/groups/responsive/static.css",
               "width":640,
               "height":960,
               "device-pixel-ratio":2
            },
            "iphone6plus":{
               "text":"iPhone 6 Plus",
               "action":"start",
               "path":"/libs/wcm/mobile/components/emulators/ios/iphone6plus",
               "canRotate":true,
               "hasTouchScrolling":true,
               "contentCssPath":"/etc/mobile/groups/responsive/static.css",
               "width":1080,
               "height":1920,
               "device-pixel-ratio":2.6
            },
            "nexuss":{
               "text":"Nexus S",
               "action":"start",
               "path":"/libs/wcm/mobile/components/emulators/nexuss",
               "canRotate":true,
               "hasTouchScrolling":true,
               "contentCssPath":"/etc/mobile/groups/responsive/static.css",
               "width":320,
               "height":533,
               "device-pixel-ratio":1
            }
         }
      }
   },
   "annotations":[

   ],
   "permissions":{
      "modify":true,
      "replicate":true,
      "read":true,
      "create":true,
      "delete":true,
      "acl_read":true,
      "acl_edit":true
   },
   "isTargetable":"true",
   "responsive":{
      "breakpoints":{
         "phone":{
            "width":650,
            "title":"Smaller Screen"
         },
         "tablet":{
            "width":1200,
            "title":"Tablet"
         }
      }
   }
}

筛选工作流包信息

配置Day CQ WCM工作流包信息提供程序服务,以便它仅返回您感兴趣的工作流包的相关信息。 默认情况下,工作流包信息提供者服务会返回有关存储库中每个工作流包的信息。 对工作流包的子集进行迭代使用的服务器资源较少。
Sidekick的“工作流”选项卡使用PageInfo servlet获取工作流包的列表。 从列表中,您可以选择要向其添加当前页面的包。 您创建的过滤器会影响此列表。
服务的ID是 com.day.cq.wcm.workflow.impl.WorkflowPackageInfoProvider 。 要创建过滤器,请为属性指定 workflowpackageinfoprovider.filter 值。
属性值前缀有+或——字符,后跟包路径:
  • 路径是工作流包的根节点的路径。 该路径使用FileVault语法。
  • 要包含包,请使用+前缀。
  • 要排除包,请使用——前缀。
该服务应用所有过滤器的累积结果。 例如,以下筛选器值不包括除Editions文件夹中的工作流包以外的所有工作流包:
-/etc/workflow/packages(/.*)?
+/etc/workflow/packages/Editions(/.&ast;)?

使用AEM时,可以通过多种方法管理此类服务的配置设置。 有关完 整的详细信息 ,请参阅配置OSGi。
例如,要使用CRXDE Lite配置服务,请执行以下操作:
  1. 打开CRXDE Lite( http://localhost:4502/crx/de )。
  2. 在应用程序的config文件夹中,创建一个节点:
    • 名称: com.day.cq.wcm.workflow.impl.WorkflowPackageInfoProvider
    • 类型: sling:OsgiConfig
  3. 选择节点并添加一个属性:
    • 名称: workflowpackageinfoprovider.filter
    • 类型: String[]
    • 值:使用正确格式的工作流包的路径。
  4. 单击“全部保存”。
要在项目源中配置服务,请执行以下操作:
  1. 在项目源中找到或创建AEM应用程序的配置文件夹。
    例如,如果您使用内容包Maven插件的多模块原型创建项目,则文件夹路径为 <projectroot>/content/src/ for example content/src/main/content/jcr_root/apps/<appname>/config
  2. 在配置文件夹中,创建一个名为com.day.cq.wcm.workflow.impl.WorkflowPackageInfoProvider.xml的文本文件
  3. 将以下文本复制到文件:
    <?xml version="1.0" encoding="UTF-8"?>
     <jcr:root xmlns:sling="https://sling.apache.org/jcr/sling/1.0"
     xmlns:jcr="https://www.jcp.org/jcr/1.0"
     jcr:primaryType="sling:OsgiConfig"
     workflowpackageinfoprovider.filter="[]"/>
    
    
  4. 在属性周围 [] 的括号()中,键 workflowpackageinfoprovider.filter 入以逗号分隔的过滤器值列表,如下例所示:
    workflowpackageinfoprovider.filter="[-/etc/workflow/packages(/.*)?,+/etc/workflow/packages/Editions(/.*)?]"/>
  5. 保存文件。

创建页面信息提供者

创建自定义页面信息提供者服务,以添加应用程序可轻松获取的页面元数据。
  1. 实现接 com.day.cq.wcm.api.PageInfoProvider 口。
  2. 将类捆绑并部署为OSGi服务。
  3. 在应用程序中创建页面组件。 用 foundation/components/page 作属性的 sling:resourceSuperType 值。
  4. 在名为的组件节点下添加一个节点 cq:infoProviders
  5. 在该节 cq:infoProviders 点下,为PageInfoProvider服务添加一个节点。 您可以为节点指定任何名称。
  6. 将以下属性添加到您的PageInfoProvider节点:
    • 名称:className
    • 类型:字符串
    • 值:PageInfoProvider服务的PID。
对于将应用程序页面组件用作资源 sling:resourceType 的PageInfo servlet除了返回默认的PageInfoProvider元数据外,还返回自定义PageInfoProvider元数据。

示例PageInfoProvider实现

以下Java类实现 PageInfoProvider ,并返回当前页面资源的已发布URL。
package com.adobe.example;

import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.Service;
import org.apache.felix.scr.annotations.Reference;

import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;

import org.apache.sling.commons.json.JSONException;
import org.apache.sling.commons.json.JSONObject;

import com.day.cq.wcm.api.Page;
import com.day.cq.wcm.api.PageInfoProvider;

@Component(metatype = false)
@Properties({
 @Property(name="service.description", value="Returns the public URL of a resource.")
})
@Service
public class PageUrlInfoProvider implements PageInfoProvider {

 @Reference(cardinality = ReferenceCardinality.OPTIONAL_UNARY)
 private com.day.cq.commons.Externalizer externalizer;

 private String fetchExternalUrl(ResourceResolver rr, String path) {
  return externalizer.publishLink(rr, path);
 }

 public void updatePageInfo(SlingHttpServletRequest request, JSONObject info, Resource resource)
   throws JSONException {

  Page page = resource.adaptTo(Page.class);
  JSONObject urlinfo = new JSONObject();
  urlinfo.put("publishURL", fetchExternalUrl(null,page.getPath()));
  info.put("URLs",urlinfo);
 }
}

以下示例在CRXDE lite中显示了配置为使用PageUrlInfoProvider服务的页面组件:
PageUrlInfoProvider服务为节点返回以下数 /content/we-retail/us/en 据:
"URLs": {
    "publishURL": "http://localhost:4503/content/we-retail/us/en"
}