Java: how to best update the jcr:contents of a page? | Community
Skip to main content
jayv25585659
Level 8
January 5, 2018
Solved

Java: how to best update the jcr:contents of a page?

  • January 5, 2018
  • 2 replies
  • 1939 views

So I have an Excel spreadsheet processor/importer where all existing pages are deleted and then it recreates the pages based on the spreadsheet info.

I'm creating new pages via

Page page = pageManager.create(getCorrectPath(main, fish), getValidName(fish), templatePath, fish.getName(), true);

and this creates new pages under /content/data/fishes.

There is a new need where I cannot delete the pages anymore. I need to update it in possibility it's an existing one.

example:

/content/data/fishes/greatwhale

jcr:contents

  species:arachnid

on the spreadsheet, the species has been updated to fish.

I've looked at com.day.cq.wcm.api.PageManager  and com.day.cq.wcm.api.Page

Reading these 2 pages, it seems to me there is no update/edit facility available. So I'm thinking the next option is to delete the page and then recreate it?

Or perhaps you have a better suggestion?

Thank you so much!

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by edubey

You should use ModifiableValueMap

https://sling.apache.org/apidocs/sling7/org/apache/sling/api/resource/ModifiableValueMap.html

Sample code

ModifiableValueMap properties = resource.adaptTo(ModifiableValueMap.class);

properties.put("key", "value");

resourceResolver.commit();

2 replies

edubey
edubeyAccepted solution
Level 10
January 5, 2018

You should use ModifiableValueMap

https://sling.apache.org/apidocs/sling7/org/apache/sling/api/resource/ModifiableValueMap.html

Sample code

ModifiableValueMap properties = resource.adaptTo(ModifiableValueMap.class);

properties.put("key", "value");

resourceResolver.commit();

smacdonald2008
Level 10
January 5, 2018

With PageManager API - you can create new pages - we have a new article that shows this -- Scott's Digital Community: Creating an Experience Manager 6.3 Page using the Page Manager API (be released week of Jan 8)