I tried creating a sitemap.XML file which contains the data of all the active pages as shown in What is the best API to use to create files in the JCR programatically?
Though we can see that the XML file gets created, it's not in the saved state, we have to click "save all" again to save. Any programmatically made changes are not getting reflected as session.save() is not creating the file in saved state
I have used session.save ,session.refresh(true) and also resolver.commit(), which didn't solve my problem.
When I tried applying a smaller value to jcr:data, its getting created in the saved state.
Is there any limit on the size of binary we apply as a value to the property jcr: data to create a file in the saved state.
First i'm creating an xml file using Document api. which is not in prettify format so i'm using Transformer api to prettify it and then converting it to input stream
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
DOMSource source = new DOMSource(doc);//doc contains the xml data
StreamResult streamResult = new StreamResult(outputStream);
TransformerFactory transformerFactory = TransformerFactory
Transformer transformer = transformerFactory.newTransformer();
InputStream is = new ByteArrayInputStream(
after this step, i'm creating the node sitemap.xml as shown below
mySession = resolver.adaptTo(Session.class);
Binary binary = mySession.getValueFactory().createBinary(is);
Node myNewNode = mySession.getNode(page.getPath());// path example: /content/adobe/en
Node xmlNode = myNewNode.addNode(SITEMAP_XML, "nt:file");
Node contentNode = xmlNode.addNode("jcr:content", "nt:resource");
Calendar lastModified = Calendar.getInstance();
you can see in the image that the created document is not in saved state.I have to manually save it after creation.
please help me here!!
Can you try to replace your custom code with this utility function "JcrUtil.putFile()"? It should pretty much the thing you want to do.
Regarding your screenshot: When you run your code, it is using a JCR session, which is different from the session you use in the CRX DE Lite Frontend. So executing the code will not save any session in the CRX DE Lite!
The problem is because of formatting the xml. I tried removing the below code
which formats the xml. Now the file is getting created in saved state.
Still confused that why those 3 lines are causing the issue.