この会話は、活動がないためロックされています。新しい投稿を作成してください。
この会話は、活動がないためロックされています。新しい投稿を作成してください。
Hi all,
I have a requirement where I need to read xml file and convert it to aem page. Is there a way to do it?
Regards,
解決済! 解決策の投稿を見る。
表示
返信
いいね!の合計
Hi,
Please check below link
Hi @rk39193348 ,
First we need to write OSGI service to read data and persist key value properties in CRX repo using JCR API's and once the XML data is available in JCR node properties, we can access and display it on any page.
Regards,
Santosh
表示
返信
いいね!の合計
表示
返信
いいね!の合計
There are two options available.
1. Import XML data by scheduler, store it in UGC & use that data on the page based on your requirement.
2. Say storing it in UGC not required, then you can skip saving it in UGC & create page whenever scheduler runs using the xml data.
refer this blog to import & store xml data in UGC.
https://aem.redquark.org/2019/05/import-xml-data-into-aem.html
表示
返信
いいね!の合計
Hi @rk39193348
Can you add screenshot/code snippet where you are getting service resource resolver null, it will be helpful to find out the issue.
表示
返信
いいね!の合計
@reference
private ResourceResolverFactory resourceResolverFactory;
private static final String SERVICE_USER = "service-user"; //create new service user with required permission
private static final Map<String, Object> SERVICE_USER_DETAILS = ImmutableMap
.of(ResourceResolverFactory.SUBSERVICE, (Object) SERVICE_USER);
public String createPage(String pageName) {
log.info("inside createpage****");
try {
ResourceResolver resourceResolver =resourceResolverFactory.getServiceResourceResolver(SERVICE_USER_DETAILS);
//ResourceResolver resourceResolver = slingrequest.getResourceResolver();
log.info("resourceResolver****"+resourceResolver.toString());
}
catch (Exception ex) {
log.info("AEMWatchFolderImpl error$$" + ex.getMessage());
}
return pageName;
}
using resourceResolver I am trying to create a page, but I am getting null. Can you please help?
pageManager = resourceResolver.adaptTo(PageManager.class);
newPage = pageManager.create(pagePath, pageName, templatePath, pageTitle);
表示
返信
いいね!の合計
Can you please highlight the line in above code where you are getting null.
表示
返信
いいね!の合計
I did this - newPage = getPageManager().create(pagePath, "ABC", templatePath, pageTitle); without using resourceResolver it worked.
Now how do I add HTML into it, programmatically?
表示
返信
いいね!の合計
Assuming as per you comment you are getting null here getPageManager().create(). once we get service resource resolver possibility of getting null return value from this method is less because this method returns page if provide parameters are valid & in some cases throws below error. so please cross check after this method execution whether page is created below this pagePath/rootPath.
Path not found exception : when provide pagePath not exist. (/content/site/root-page)
Access denied : when service user does not have create permission at this pagePath/rootPath.
newPage = getPageManager().create(pagePath, "ABC", templatePath, pageTitle);
表示
返信
いいね!の合計
表示
返信
いいね!の合計
Here's how I would do it.
Hi,
Please check below link
表示
返信
いいね!の合計
表示
返信
いいね!の合計
You can read the values stored in the jcr and using pageManager API, we can create page and add values in as required.
First it will be helpful if you come up with the mapping of fields and where/how it should stored under the page. Some of them will go to jcr:content and some go to a component.
Once the mapping is done and you have required template and components created, programmatically we can add components under jcr:content and the values from xml file.
Refer : https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/how-can-i-create-new-cq-pa... for creating pagesprogrammatically
表示
返信
いいね!の合計
表示
返信
いいね!の合計
Hi @rk39193348
Check below code snippet to get service resource resolver & create service user with required permission for the same.
@Reference
private ResourceResolverFactory resourceResolverFactory;
private static final String SERVICE_USER = "service-user"; //create new service user with required permission
private static final Map<String, Object> SERVICE_USER_DETAILS = ImmutableMap
.of(ResourceResolverFactory.SUBSERVICE, (Object) SERVICE_USER);
private static final Logger LOGGER = LoggerFactory.getLogger(ReplicationServlet.class);
@Override
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws IOException {
if(resourceResolverFactory!= null) {
try (ResourceResolver resourceResolver = resourceResolverFactory.getServiceResourceResolver(SERVICE_USER_DETAILS)) {
if (resourceResolver != null) {
}
} catch (LoginException e) {
LOGGER.error("LoginException occurred", e);
}
}
}
表示
返信
いいね!の合計
表示
返信
いいね!の合計