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,
Solved! Go to Solution.
Views
Replies
Total Likes
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
Views
Replies
Total Likes
Views
Replies
Total Likes
Views
Replies
Total Likes
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
Views
Replies
Total Likes
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.
Views
Replies
Total Likes
@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);
Views
Replies
Total Likes
Can you please highlight the line in above code where you are getting null.
Views
Replies
Total Likes
I did this - newPage = getPageManager().create(pagePath, "ABC", templatePath, pageTitle); without using resourceResolver it worked.
Now how do I add HTML into it, programmatically?
Views
Replies
Total Likes
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);
Views
Replies
Total Likes
Views
Replies
Total Likes
Here's how I would do it.
Hi,
Please check below link
Views
Replies
Total Likes
Views
Replies
Total Likes
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
Views
Replies
Total Likes
Views
Replies
Total Likes
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);
}
}
}
Views
Replies
Total Likes
Views
Replies
Total Likes
Views
Like
Replies