我们有很多内容需要在 AEM 中导入。导入它的最佳方法是什么?从excel文件导入有没有可能?
导出的一个很好的例子是这里 /etc/importers/bulkeditor.html 我们可以使用单个“属性/列”导出文件,我可以在其中定义根路径和属性。
我试过这个包,但不包含我喜欢的东西。https://helpx.adobe.com/experience-manager/using/creating-custom-excel-service-experience.html
我们有很多内容需要在 AEM 中导入。导入它的最佳方法是什么?从excel文件导入有没有可能?
导出的一个很好的例子是这里 /etc/importers/bulkeditor.html 我们可以使用单个“属性/列”导出文件,我可以在其中定义根路径和属性。
我试过这个包,但不包含我喜欢的东西。https://helpx.adobe.com/experience-manager/using/creating-custom-excel-service-experience.html
http://localhost:4502/etc/importers/bulkeditor.html
我刚刚按照上面链接上的说明进行了测试,并且成功了。
我的测试:
根路径 = /content/myapp-path/rootpage
查询参数 = "jcr:title": 我要在搜索中包含的页面的标题
内容模式 = 未选中
属性 / Columnos = sling:resourceType 和 jcr:title
自定义属性/列 = 登陆标签
单击搜索...并工作。
可以通过多种方式将数据导入 AEM。
什么是适合您的“正确”方式,取决于您的具体要求。
以下是一些或多或少常见的方法(从便宜/快速到广泛/舒适)以及文档或示例的链接:
对于解析 excel 数据,我建议您使用 AEM 中已包含的 apache poi (6)。但是使用 csv、json 或 xml 等格式可能会为您节省大量的解析工作。
(1): http://www.aemcq5tutorials.com/tutorials/adobe-cq5-aem-curl-commands/
(2): https://osgi.org/javadoc/r4v42/index.html?org/osgi/service/event/EventHandler.html
(3):https ://docs.adobe.com/docs/en/aem/6-1/develop/extending/workflows/wf-extending.html
(4):https ://docs.adobe.com/docs/en/aem/6-1/administer/operations/workflows/wf-start.html
(5): https://helpx.adobe.com/experience-manager/using/uploading-files-aem1.html
(6): https://poi.apache.org/spreadsheet/index.html
(7):代码示例
@Service
@Component(immediate = true, policy = ConfigurationPolicy.OPTIONAL, description = "Listen to page modification events and track them.")
@Properties(value = { @Property(name = "event.topics", value = { PageEvent.EVENT_TOPIC, DamEvent.EVENT_TOPIC}, propertyPrivate = true),
@Property(name = JobConsumer.PROPERTY_TOPICS, value = ModificationEventHandler.JOB_TOPICS, propertyPrivate = true) })
public class ModificationEventHandler implements EventHandler, JobConsumer {
@Override public void handleEvent(Event event) {
logger.trace("Checking event.");
PageEvent pageEvent = PageEvent.fromEvent(event);
DamEvent damEvent = DamEvent.fromEvent(event);
Map<String, Object> properties = new HashMap<>();
if (damEvent != null) {
// DamEvent is not serializable, so we cannot add the complete event to the map.
logger.trace("Event on {} is a dam event ({}).", damEvent.getAssetPath(), damEvent.getType().name());
properties.put(DAM_EVENT_ASSET_PATH, damEvent.getAssetPath());
}
if (pageEvent != null) {
logger.trace("Event is a page event.");
properties.put(PAGE_EVENT, pageEvent);
}
logger.trace("Adding new job.");
jobManager.addJob(JOB_TOPICS, properties);
}
内容可以通过 SlingPostServlet 导入:operation=import
:https ://sling.apache.org/documentation/bundles/manipulating-content-the-slingpostservlet-servlets-post.html#importing-content-structures 。这是一个改编自页面的示例:
curl -u admin:admin http://localhost:4502/content/mysite/mypage \
-F":operation=import" \
-F":contentType=json"
-F":name=sample" \
-F":content={ 'jcr:primaryType': 'nt:unstructured', 'propOne' : 'propOneValue', 'childOne' : { 'childPropOne' : true } }"
另一个对作者友好的选项是ACS AEM 工具包中包含的CSV 资产导入器。您可以将 Excel 文件保存为 CSV,因此这应该是一个简单的选择。