6 Replies Latest reply on Mar 15, 2013 6:42 AM by Veena_07

    How to get the nodes from session through java program?

    Dinu_Arya Level 2



           I would like to get the nodes from session objects through java program. I wrote the program like this,


      package com.mycomp.node;


      import javax.jcr.Node;

      import javax.jcr.NodeIterator;

      import javax.jcr.Property;

      import javax.jcr.RepositoryException;

      import javax.jcr.Session;

      import javax.jcr.observation.Event;

      import javax.jcr.observation.EventIterator;

      import javax.jcr.observation.EventListener;

      import javax.jcr.observation.ObservationManager;


      import org.apache.felix.scr.annotations.Reference;

      import org.apache.sling.jcr.api.SlingRepository;

      import org.osgi.service.component.ComponentContext;

      import org.slf4j.Logger;

      import org.slf4j.LoggerFactory;

      import org.apache.felix.scr.annotations.Component;

      import org.apache.sling.api.SlingHttpServletRequest;

      import org.apache.sling.api.resource.Resource;

      import javax.jcr.Session;


      public class GetNode {


          public String getNodeName() throws Exception


              Node node=null;

              SlingHttpServletRequest slingRequest=null;

              Session session=slingRequest.getResourceResolver().adaptTo(Session.class);



              return node.getName();





      And the jsp is,


      <%@include file="/libs/foundation/global.jsp"%><%

      %><%@page session="false" %>

      <%@page import="com.mycomp.node.GetNode"%>


          GetNode gn = new GetNode();





      I successfully build the bundle and it is also in active state. But I'm getting the error like "only a type can be imported, com.mycomp.node resolve to a package".


      Is this the way to get the objects from session. There is another method we have for getting the nodes i.e using session.getWorkspace().getObservationManager(). But I need the solution in this way. Please give the suggestuons.



      Best Regards,