Saturday, 27 April 2013

Quick Notes


How to get a Resource when we have node path:

In Java:

@Reference 
private ResourceResolverFactory resourceResolverFactory;

ResourceResolver resolver=null;

resolver = resourceResolverFactory.getAdministrativeResourceResolver(null);

Resource res=null;
res= resolver.getResource("PATH");

In JSP:

Resource res= resourceResolver.getResource("PATH");


How to get a Node, Get node property, Add/Update node property:


Node node = res.adaptTo(Node.class);

Get propoerty:

String prop= node.getProperty("Prop_name").getValue().getString();

String prop = node.setProperty("Prop_name","Value");

Note: Don't forget to save the session when the node is updated.

Update Node using PersistableValueMap:


Resource resource = resolver.getResource("Node Path");
if(resource !=null)
{
PersistableValueMap valueMap= resource.adaptTo(PersistableValueMap.class);
valueMap.put("propname","value");
valueMap.save();

}



How to get a JackRabbit session in the Workflow:

final JackrabbitSession jackrabbitSession = (JackrabbitSession) wfsession.getSession();
UserManager userManager = jackrabbitSession.getUserManager();

No comments:

Post a Comment