Sunday 15 December 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();
}


Note: PersistableValueMap is deprecated. So use ModifiableValueMap instead.
Example:

if(resource !=null)
{
ModifiableValueMap valueMap= resource.adaptTo(ModifiableValueMap.class);
valueMap.put("propname","value");

}
resource.commit();   //Once ResourceResolver.commit() is called, the changes are finally persisted.

How to get a JackRabbit session in the Workflow:
final JackrabbitSession jackrabbitSession = (JackrabbitSession) wfsession.getSession();
UserManager userManager = jackrabbitSession.getUserManager();



How to get Page object using resolver?
@Reference 
private PageManagerFactory pageManagerFactory;

@Reference 

private ResourceResolverFactory resourceResolverFactory;

ResourceResolver resolver = null;

//get Resource resolver using resource resolver factory.
resolver = resourceResolverFactory
.getAdministrativeResourceResolver(null);

//Get page manager object using page manager Factory
PageManager pmanager = pageManagerFactory.getPageManager(resolver);

//Get page object using PageManager
Page page = pmanager.getContainingPage(path);

6 comments:

  1. It's interesting that many of the bloggers to helped clarify a few things for me as well as giving.Most of ideas can be nice content.The people to give them a good shake to get your point and across the command

    rpa training in bangalore
    best rpa training in bangalore
    RPA training in bangalore
    rpa courses in bangalore

    ReplyDelete
  2. Whoa! I’m enjoying the template/theme of this website. It’s simple, yet effective. A lot of times it’s very hard to get that “perfect balance” between superb usability and visual appeal. I must say you’ve done a very good job with this.

    AWS Training in Bangalore with Placements | AWS Training in Bangalore Cost
    AWS Training in Pune With Placement | AWS Devops Training in Pune
    AWS Online Training | AWS Online Training Cost
    AWS Training in Bangalore cost| Aws training in Bangalore Besant Technologies

    ReplyDelete
  3. I like the helpful info you supply in your articles. I’ll bookmark your weblog and take a look at once more here regularly. I am relatively certain I will learn a lot of new stuff right here! Good luck for the following!

    hardware and networking training in chennai

    hardware and networking training in velachery

    xamarin training in chennai

    xamarin training in velachery

    ios training in chennai

    ios training in velachery

    iot training in chennai

    iot training in velachery

    ReplyDelete
  4. Providing details can offer more insight to those who might be interested in joining the institute. Remember, personal experiences and anecdotes can make your comment even more impactful.
    python training in marathahalli

    ReplyDelete