best way to access JCR data AEM 6.0/ cq5 -
i know, in following 3 ways, 1 should used access jcr data.
resolverfactory.getserviceresourceresolver(map authinfo); resolverfactory.getresourceresolver(map authinfo); session.getservice('servicename', null);
could please share knowledge on these specific methods , how provide authinfo , in scenarios each of these methods used.
it seems, aem 6.0 onwards getadministrativeresourceresolver
method deprecated because of security reasons ??
thank you, sri
from aem 6.1 cannot use "admin" access nodes. have detailed solution here resourceresolverfactory getserviceresourceresolver throws exception in aem 6.1
and here's have done read , write data jcr.
public class interacthelper { @reference private resourceresolverfactory resolverfactory; private resourceresolver resourceresolver; @activate private void activate(componentcontext context) { ... map<string, object> param = new hashmap<string, object>(); // aem_subservice service name need define osgi param.put(resourceresolverfactory.subservice, aem_subservice); try { resourceresolver = resolverfactory.getserviceresourceresolver(param); ... } /** write data node */ public void savetorepository(resourceresolver resourceresolver, string datastring) throws exception { session session = resourceresolver.adaptto(session.class); node usernode; node userjcrcontentnode; string nodepath=""; if (session!=null) { node usersrootnode = session.getnode(users_root_folder); usernode = session.getnode(usersrootnode.getpath() + "/" + "suren"); if (usernode!=null) { nodepath = usernode.getpath(); } if (!session.itemexists(nodepath)) { usernode = usersrootnode.addnode("suren", "cq:page"); userjcrcontentnode = usernode.addnode("jcr:content", "cq:pagecontent"); } if(!session.itemexists(nodepath+"/jcr:content")){ userjcrcontentnode = usernode.addnode("jcr:content", "cq:pagecontent"); } userjcrcontentnode = usernode.getnode("jcr:content"); userjcrcontentnode.setproperty("abc-shoppingcart",datastring); // save session changes , log out session.save(); session.logout(); } } /** read data node */ public void readfromrepository(resourceresolver resourceresolver, string encodedshoppingcartstring) throws exception { session session = resourceresolver.adaptto(session.class); if (session!=null) { node usersrootnode = session.getnode(users_root_folder); node usernode = usersrootnode.addnode("suren", "cq:page"); node userjcrcontentnode = usernode.addnode("jcr:content", "cq:pagecontent"); userjcrcontentnode = usernode.getnode("jcr:content"); userjcrcontentnode.setproperty("abc-shoppingcart",datastring); // save session changes , log out session.save(); session.logout(); } }
Comments
Post a Comment