java - 如何将 AEM 标签导出到 Excel

标签 java tags aem

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

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

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

最佳答案

要获取逗号分隔的标签列表,我建议使用命令行,内置 AEM query builder , curljq (https://stedolan.github.io/jq/)。

一般方法:

  1. 使用查询生成器构建 /etc/tags 的 JSON 表示形式
  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

这将发送 GET向您的本地 AEM 实例 ( http://localhost:4502 ) 发出请求,以用户 admin 身份进行身份验证有密码admin (AEM 的默认设置),使用查询生成器 API ( /bin/querybuilder.json ) 获取类型为 cq:Tag 的所有资源下面/etc/tags在这些资源中,它将“选择”属性 jcr:path , jcr: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"
    },
  ]
}

接下来,上面的命令会将查询生成器中生成的 JSON 通过管道传输到 jq ,它将使用“查询”.hits[] | [."jcr:path", ."jcr:title", ."jcr:description"]只读取hits数组以及该数组中的每个项目的 jcr:path , jcr:titlejcr: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"

命令的最后一部分> 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

您可以根据需要添加属性,但为了让它们显示在 CSV 中,您还必须更新 jq 使用的查询。 .

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

关于java - 如何将 AEM 标签导出到 Excel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55529458/

相关文章:

java - 如何创建 OkHttp 所需的虚拟 ResponseBody 对象?

java - S3错误线程中的异常 "main"java.lang.UnsatisfiedLinkError : org. apache.hadoop.io.nativeio.NativeIO$Windows.access0

java - 反射器: How to list getters of a class and invoke them in Java?

json - AEM 将 html 信息注释插入 json

java - JSP 中循环遍历 map 失败

AEM-6.4 吊索原始值 :resourceSuperType for/libs/foundation/components/redirect

java - 将 List<javax.persistence.Tuple> 序列化为 JSON

python - django 标记 - 按标记过滤

html - 使用纯 HTML5/CSS3 创建标签云

javascript - 如何禁用 HTML 代码中的脚本并仍然显示它们?