aem - How to create a directory on the basis of path in cq5? -


i have string path of page example /content/xperia/public/events/eventeditor. gererating xml of page , saving dam, want save in similar tree structure under /content.

i tried following code

string page = "/content/xperia/public/events/eventeditor"; page = page.replace("/content", "/content/dam"); if (adminsession.nodeexists(page+ "/"+ "jcr:content")) {     node node = adminsession.getnode(page+ "/"+ "jcr:content");     node.setproperty("jcr:data", sb.tostring());                 } else {     node feednode = jcrutil.createpath(page,"nt:file", adminsession);                node datanode = jcrutil.createpath(feednode.getpath() + "/"+ "jcr:content", "nt:resource", adminsession);            datanode.setproperty("jcr:data",sb.tostring()); } 

but gives following error

no matching child node definition found {http://www.jcp.org/jcr/1.0}content

because there no such path in repository. there way through can create directory on fly. because save file, need create entire tree xperia/public/events under /content/dam , save eventeditor.xml in directory .

please suggest.

there few issues code. jcrutil.createpath(string absolutepath, string nodetype, session session) creates non-existent intermediate path given nodetype.

this means nodes xperia, public , events created type nt:file instead of sling:orderedfolder.

you can use createpath(string absolutepath, boolean createuniqueleaf, string intermediatenodetype, string nodetype, session session, boolean autosave) method instead, specify type of intermediary nodes created.

string page = "/content/xperia/public/events/eventeditor"; page = page.replace("/content", "/content/dam"); page += ".xml";  if (adminsession.nodeexists(page+ "/"+ "jcr:content")) {     node node = adminsession.getnode(page+ "/"+ "jcr:content");     node.setproperty("jcr:data", sb.tostring());                 } else {     node feednode = jcrutil.createpath(page, true, "sling:orderedfolder", "nt:file", adminsession, false);                node datanode = feednode.addnode("jcr:content", "nt:resource");            datanode.setproperty("jcr:data",sb.tostring()); }  adminsession.save(); 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -