获取JSON格式的页面信息 obtaining-page-information-in-json-format

要获取页面信息,请向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
NOTE
如果您需要使用JSON格式的页面信息,以将内容交付到非传统AEM网页的渠道,例如:
  • 单页面应用程序
  • 本机移动设备应用程序
  • AEM外部的其他渠道和接触点
请参阅Content Services🔗的文档JSON导出程序。

页面信息提供程序 page-information-providers

页面组件可以与一个或多个生成页面元数据的com.day.cq.wcm.api.PageInfoProvider服务关联。 PageInfo servlet调用每个PageInfoProvider服务并聚合元数据:

  1. HTTP客户端向PageInfo servlet发送请求,其中包括页面的URL。
  2. PageInfo servlet将发现哪个组件渲染页面。
  3. PageInfo servlet调用与组件关联的每个PageInfoProvider。
  4. servlet聚合每个PageInfoProvider返回的元数据,并将元数据添加到JSON对象的HTTP响应中。

chlimage_1-2

NOTE
与PageInfoProviders类似,使用ListInfoProviders更新JSON格式的信息列表。 (请参阅自定义网站管理控制台。)

默认页面信息提供程序 default-page-information-providers

/libs/foundation/components/page组件与以下PageInfoProvider服务关联:

  • 默认页面状态提供程序: ​有关页面状态的信息,例如它是否已锁定、该页面是否为活动工作流的负载以及哪些工作流可用于该页面。
  • Live关系信息提供程序: ​有关多站点管理(MSM)的信息,例如页面是否为Blue Print的一部分,以及它是否为Live Copy。
  • 内容语言Servlet: ​当前页面的语言以及有关页面可用的每种语言的信息。
  • 工作流状态提供程序: ​有关将页面作为有效负荷的运行中工作流的状态信息。
  • 工作流包信息提供程序: ​有关存储库中存储的每个工作流包的信息,以及每个包是否包含当前资源。
  • 模拟器信息提供程序: ​有关此资源可用的移动设备模拟器的信息。 如果页面组件不呈现移动设备页面,则没有可用的模拟器。
  • 批注信息提供程序: ​有关页面上的批注的信息。

例如,PageInfo servlet为/content/we-retail/us/en节点返回以下JSON响应:

{
   "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"
         }
      }
   }
}

筛选工作流包信息 filtering-workflow-package-information

配置Day CQ WCM Workflow Package Info Provider服务,以便该服务仅返回有关您感兴趣的工作流包的信息。 默认情况下,工作流包信息提供程序服务会返回有关存储库中每个工作流包的信息。 对工作流包的子集进行迭代使用的服务器资源较少。

NOTE
Sidekick的“工作流”选项卡使用PageInfo servlet获取工作流包的列表。 从列表中,可以选择要向其中添加当前页面的包。 您创建的过滤器会影响此列表。

服务的ID为com.day.cq.wcm.workflow.impl.WorkflowPackageInfoProvider。 要创建筛选器,请为workflowpackageinfoprovider.filter属性指定一个值。

属性值的前缀为+或 — 字符,后跟包路径:

  • 路径是工作流包的根节点的路径。 路径使用FileVault语法。
  • 要包含包,请使用+前缀。
  • 要排除包,请使用 — 前缀。

此服务应用所有过滤器的累积结果。 例如,以下筛选器值排除所有工作流包,但Editions文件夹中的工作流包除外:

-/etc/workflow/packages(/.*)?
+/etc/workflow/packages/Editions(/.&ast;)?
NOTE
使用AEM时,可通过多种方法管理此类服务的配置设置。 有关完整详细信息,请参阅配置OSGi

例如,要使用CRXDE Lite配置服务,请执行以下操作:

  1. 打开CRXDE Lite(http://localhost:4502/crx/de)。

  2. 在应用程序的配置文件夹中,创建一个节点:

    • 名称:com.day.cq.wcm.workflow.impl.WorkflowPackageInfoProvider
    • 类型:sling:OsgiConfig
  3. 选择节点并添加属性:

    • 名称:workflowpackageinfoprovider.filter
    • 类型:String[]
    • 值:使用正确格式的工作流包的路径。
  4. 单击“全部保存”。

要在项目源中配置服务,请执行以下操作:

  1. 在项目源中找到或创建AEM应用程序的配置文件夹。

    例如,如果您使用内容包Maven插件的multimodule原型创建项目,则文件夹路径为<projectroot>/content/src/ for example, content/src/main/content/jcr_root/apps/<appname>/config

  2. 在配置文件夹中,创建一个名为com.day.cq.wcm.workflow.impl.WorkflowPackageInfoProvider.xml的文本文件

  3. 将以下文本复制到文件中:

    code language-none
    <?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. 保存文件。

创建页面信息提供程序 creating-a-page-information-provider

创建自定义页面信息提供程序服务,以添加应用程序可轻松获取的页面元数据。

  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的资源,除了默认的PageInfoProvider元数据外,PageInfo servlet还返回自定义PageInfoProvider元数据。

示例PageInfoProvider实现 example-pageinfoprovider-implementation

以下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服务:

chlimage_1-3

PageUrlInfoProvider服务为/content/we-retail/us/en节点返回以下数据:

"URLs": {
    "publishURL": "http://localhost:4503/content/we-retail/us/en"
}
recommendation-more-help
19ffd973-7af2-44d0-84b5-d547b0dffee2