hi,
i have requirement access node inside servlet class.
how can access it?
in jsp, can access noed below.
session session1 = resourceresolver.adaptto(session.class);
node node = session1.getnode(currentpage.getpath() + "/jcr:content");
i want implement simmilar code inside servlet.
any helpful.
thanks
hi,
you can use example following code:
-> in servlet class add following import , public variable:
import org.apache.sling.jcr.api.slingrepository;
/** @scr.reference policy="static" */
public slingrepository repository;
-> in dopost or doget method need pass in request attribute path page , use following code:
session session = repository.loginadministrative(repository.getdefaultworkspace());
node node = session.getrootnode();
int pos = path.lastindexof('/');
if (pos != -1) {
stringtokenizer st = new stringtokenizer(path.substring(0, pos), "/");
while (st.hasmoretokens()) {
string token = st.nexttoken();
if (node.hasnode("jcr:content")) {
try {
node.getnode(token);
} catch (repositoryexception e) {
log.warn("error while creating intermediate node", e);
}
}
}
}
i hope example helps you,
regards,
kasq
More discussions in Archived Spaces
adobe
Comments
Post a Comment