Sunday, September 15, 2013

How to get Service in JSP?

Below are the two easiest ways to get Service:

1. Using the slingScriptHelper     

<sling:defineObjects />

<%

      ServiceType service = sling.getService(ServiceType.class);

%>

2. Using adaptTo()

adaptTo() method that will translate the object to the class type being passed as the argument.

Example:

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

More Info on Adaptors: http://dev.day.com/docs/en/cq/current/developing/sling-adapters.html

Handy URLs–AEM 5.6

URLs

/crx/explorer/index.jsp  - CRX explorer

/crx/de/index.jsp – CRXDE Lite url

/damadmin     - DAM

/libs/cq/search/content/querydebug.html – Query debug tool

/libs/granite/security/content/admin.html – New user manager standalone ui  [5.6 only?]

/libs/cq/contentsync/content/console.html – Content sync console

/system/console/bundles – Felix web admin console

/system/console/jmx/com.adobe.granite.workflow%3Atype%3DMaintenance - Felix web admin console JMX / Workflow maintenance tasks

/system/console/jmx/com.adobe.granite%3Atype%3DRepository - Felix web admin console JMX / Repository maintenance tasks

/system/console/depfinder – This new 5.6 tool will help you figure out what package exports a class and also prints a Maven Dependency for the class.

/libs/granite/ui/content/dumplibs.rebuild.html?rebuild=true – Helpful link for debugging caching problems. Wipes the clientlibs and designs and forces it to rebuild it. Thanks to Mark Ellis for this link.

/system/console/adapters – This link shows you the Adapters are registered in the system. This helps you figure out what you can adaptTo() from resource to resource.

Params

wcmmode=DISABLED - This handy publisher parameter turns off CQ authoring features so you can preview a page cleanly

Thursday, September 5, 2013

How to get Administrative Resource Resolver in jsp?

 

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);  

%>