取得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服務相關聯:

  • 預設頁面狀態提供者: ​頁面狀態的相關資訊,例如頁面是否已鎖定、頁面是否為使用中工作流程的裝載,以及頁面可用的工作流程。
  • 即時關係資訊提供者: ​有關多網站管理(MSM)的資訊,例如頁面是否為Blue Print的一部分,以及是否為即時副本。
  • 內容語言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服務,使其僅傳回您感興趣之工作流程套件的資訊。 依預設,Workflow Package Info Provider服務會傳回存放庫中每個Workflow套件的資訊。 反複處理工作流程套件的子集會使用較少的伺服器資源。

NOTE
Sidekick的「工作流程」標籤會使用PageInfo servlet來取得工作流程封裝清單。 從清單中,您可以選取要新增目前頁面的封裝。 您建立的篩選器會影響此清單。

服務的識別碼為com.day.cq.wcm.workflow.impl.WorkflowPackageInfoProvider。 若要建立篩選器,請為workflowpackageinfoprovider.filter屬性指定值。

屬性值會加上前置詞+或 — 字元,後面接著套件路徑:

  • 路徑是Workflow套件的根節點的路徑。 路徑使用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應用程式的設定資料夾。

    例如,如果您使用Content Package 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