Generic Code to get service from the OSGI service registry:
================================================================
If you are in a JSP Script you can do
<cq:defineObjects />
<%
ServiceType service = sling.getService(ServiceType.class);
%>
==================================================================
Get Administrative Resource Resolver :
<%!
/**
@Parms: ResourceResolverFactory
returns ResourceResolver , Admin resource resolver will be return
*/
public ResourceResolver getRR(ResourceResolverFactory resolverFactory)
{
ResourceResolver rr=null;
try{
rr= resolverFactory.getAdministrativeResourceResolver(null);
}catch(Exception e)
{
System.out.println("RRF Exception:"+e.getMessage());
}
return rr;
}
%>
<%
//Get ResourceResolverFactory service from OSGI service Registry
org.apache.sling.api.resource.ResourceResolverFactory rrFactory = sling.getService(org.apache.sling.api.resource.ResourceResolverFactory.class);
Resource r = getRR(rrFactory);
%>
No comments:
Post a Comment