Hi,
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);
node=session.getNode("/apps/mysite/components/page/samplecomponent");
System.out.println("nnnnnnnnn"+node.getName());
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();
%>
<%=gn.getNodeName()%>
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,
G.Dinakar.