如何将 AEM 标签导出到 Excel

Tad*_*lić 0 java tags aem

昨天我不得不将所有AEM 标签导出到 Excel 文件中。在浏览最佳解决方案时,我发现几乎每个人都建议编写自定义代码,将所有标签输入到Excel文件中。

我认为这个解决方案很好,但是因为有很多人是第一次做这样的事情,他们可能需要一些时间来弄清楚如何做到这一点。

对于他们,让我们分享一些解决此问题的方法。

Jen*_*ens 5

为了得到一个逗号分隔的标签列表我会建议使用命令行,集结在AEM查询生成器curljqhttps://stedolan.github.io/jq/)。

一般方法:

  1. 使用查询构建器构建 JSON 表示 /etc/tags
  2. 使用curl到“下载”的JSON
  3. 使用jq以“解析”的JSON,并创建一个CSV

例子:

导出以下所有标签/etc/tags及其路径、标题和描述将如下所示:

curl \
    --user admin:admin \
    --silent \
    "http://localhost:4502/bin/querybuilder.json?p.hits=selective&p.limit=-1&p.properties=jcr%3atitle%20jcr%3apath%20jcr%3adescription&path=%2fetc%2ftags&type=cq%3aTag" \
    | jq --raw-output '.hits[] | [."jcr:path", ."jcr:title", ."jcr:description"] | @csv' \
    > tags.csv
Run Code Online (Sandbox Code Playgroud)

这将向GET您的本地 AEM 实例 ( http://localhost:4502)发送请求,admin使用密码admin(AEM 的默认设置)以用户身份进行身份验证,使用查询构建器 API ( /bin/querybuilder.json) 获取具有cq:Tag以下类型的所有资源/etc/tags以及它将“选择”这些资源的属性jcr:pathjcr:titlejcr:description

生成的 JSON 如下所示:

{
  "success": true,
  "results": 2,
  "total": 2,
  "more": false,
  "offset": 0,
  "hits": [
    {
      "jcr:path": "/etc/tags/experience-fragments",
      "jcr:description": "Tag structured used by the Experience Fragments feature",
      "jcr:title": "Experience Fragments"
    },
    {
      "jcr:path": "/etc/tags/experience-fragments/variation",
      "jcr:description": "A tag used by the experience fragments variations",
      "jcr:title": "Variation"
    },
  ]
}
Run Code Online (Sandbox Code Playgroud)

接下来,上面的命令将通过管道将生成的 JSON 从查询构建器传送到jq,这将使用“查询”.hits[] | [."jcr:path", ."jcr:title", ."jcr:description"]仅读取hits数组和该数组中的每个项目jcr:pathjcr:title以及jcr:description。然后将生成的数组用作 的@csv“字符串格式化程序”的输入jq,这将创建适当的逗号分隔输出。

上面的 JSON 将被格式化为:

"/etc/tags/experience-fragments","Experience Fragments","Tag structured used by the Experience Fragments feature"
"/etc/tags/experience-fragments/variation","Variation","A tag used by the experience fragments variations"
Run Code Online (Sandbox Code Playgroud)

命令的最后一部分> tags.csv只是将输出重定向到一个名为tags.csv而不是命令行的文件。

AEM 有一个查询构建器调试器,您可以使用它来创建查询,然后您可以在命令行命令中使用这些查询:

http://localhost:4502/libs/cq/search/content/querydebug.html

我上面使用的查询参数在工具中看起来像这样:

path=/etc/tags
type=cq:Tag
p.hits=selective
p.limit=-1
p.properties=jcr:title jcr:path jcr:description
Run Code Online (Sandbox Code Playgroud)

您可以根据需要添加属性,但要使它们显示在 CSV 中,您还必须更新jq.

如果您向标签添加翻译,它们将存储在名为jcr:title.<language-code>. 例如,如果您将标签翻译成德语,您将拥有两个属性:jcr:titlejcr:title.de。如果你想要翻译,你必须扩展p.properties和添加jcr:title.de等。