问题
Yesterday I had to export all AEM tags into Excel file. While surfing for the best solution to do this, I've found out that almost everyone advices writing custom code that takes all of tags and enters it into Excel file.
I consider that solution good, but since there are a lot of people that do things like this for the first time and it will probably take some time for them to figure out how to do this.
For them, let's share some workarounds for this problem.
回答1:
To get a comma separated list of tags I would recommend using the command line, the build-in AEM query builder, curl
and jq
(https://stedolan.github.io/jq/).
The general approach:
- Use query builder to build a JSON representation of
/etc/tags
- Use
curl
to "download" the JSON - Use
jq
to "parse" the JSON and create a CSV
Example:
Exporting all tags below /etc/tags
with their path, title and description would look like this:
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
This would send a GET
request to your local AEM instance (http://localhost:4502
), authenticate as user admin
with password admin
(default settings for AEM), use the query builder API (/bin/querybuilder.json
) to get all resources with type cq:Tag
below /etc/tags
and of those resources it would "select" the properties jcr:path
, jcr:title
and jcr:description
.
The resulting JSON looks like this:
{
"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"
},
]
}
Next, the command above will pipe the resulting JSON from the query builder to jq
, which will use the "query" .hits[] | [."jcr:path", ."jcr:title", ."jcr:description"]
to read only the hits
array and of every item in that array only jcr:path
, jcr:title
and jcr:description
. The resulting arrays are then used as input for @csv
"string formatter" of jq
, which will create proper comma-separated output.
The JSON from above would be formatted to:
"/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"
The last part of the command > tags.csv
will just redirect the output to a file called tags.csv
instead of the command line.
AEM has a query builder debugger which you can use to create queries that you then can use in your command line command:
http://localhost:4502/libs/cq/search/content/querydebug.html
The query parameters I used above would look like this in the tool:
path=/etc/tags
type=cq:Tag
p.hits=selective
p.limit=-1
p.properties=jcr:title jcr:path jcr:description
You can add properties as you like, but for them to show up in the CSV you also have to update the query used by jq
.
If you add translations to your tags they will be stored in a property called jcr:title.<language-code>
. If you translate your tags to German for example, you would have two properties: jcr:title
and jcr:title.de
. If you want the translation you have to extend the p.properties
and add jcr:title.de
etc.
回答2:
If you need to export tags, here is simple solution on how to easy export them and then there are several ways how to import it in the Excel, without need to write custom code for this.
To export AEM tags do the following 5 steps:
- Open package manager
- Create package (give it some meaningful name)
- Edit created package
- Select "filters" tab
- Enter path to tags you wish to export (for example: http://localhost:4502/libs/cq/tagging/gui/content/tags.html/etc/tags/geometrixx-outdoors)
- you can find it under Adobe Experience Manager -> Tools -> General -> Tags
- Done, Save
- Build package
- Download Package
Then you have all tags inside {download_package_name}/jcr_root/etc/tags.
Now there are several ways of getting downloaded tags to Excel file. This is how to do this on Windows -
Source: Is there a way to export a folder structure into excel?
Find the folder in Windows Explorer, then Shift Right click on that folder and select "Open Command Window Here". Type the following prompt:
dir /a /s /b > filelist.txt
That gives you a text file saved in your top folder, which you can open in notebook, then copy and paste into an Excel document.
回答3:
There's a GUI in AEM to export content as excel [well almost]. To get a tsv file of tags in the system AEM's bulk editor can be used. Navigate to '/etc/importers/bulkeditor.html' on the server. Set path as '/etc/tags' or a subtree. In query field type 'type:Tag'. Select the properties that need to be exported and hit search. The results can then be exported to a tsv file via the export button.
References
- https://helpx.adobe.com/in/experience-manager/6-4/sites/administering/using/bulk-editor.html
- https://helpx.adobe.com/experience-manager/6-4/sites/developing/using/reference-materials/javadoc/com/day/cq/wcm/commons/search/GQL.html
来源:https://stackoverflow.com/questions/55529458/how-to-export-aem-tags-into-excel