Monday, May 6, 2013

cq development overview

Create a resource

First, create a resource, typically under /content.
You can use curl, http://localhost:4502/crxde, or http://localhost:4502/libs/wcm/core/content/siteadmin.html.
Let's say you created /content/example/page  node of type cq:Page,  and /content/example/page/jcr:content of type cq:PageContent.

Set type of the resource

Add a property called sling:resourceType for this node: /content/example/page/jcr:content
For example, /content/example/page/jcr:content/sling:resourceType = 'my/base/page'

Define the type

Now, you can define the type, my/base/page,  by creating a scriptlet under /apps/my/base/page/page.jsp  (or /apps/my/base/page/html.jsp . Read this:

Or, define a servlet and register it with my/base/page.
For example,
import org.apache.felix.scr.annotations.*;
@Component(immediate = true, metatype = false)
@Properties({@Property(name = "service.description", value = "my example page"),
        @Property(name = "service.vendor", value = "The Apache Software Foundation"),
        @Property(name = "sling.servlet.resourceTypes", value = {"my/base/page"}),
        @Property(name = "sling.servlet.extensions", value = {"html"}),
        @Property(name = "sling.servlet.methods", value = {"GET"})
public class BasePageServlet extends SlingAllMethodsServlet {

 (read:  and  )

Make requests to the resource

Now, you can do GET /content/example/page.html .
The request will be handled by /apps/my/base/page/page.jsp  (if you used scriptlet)  or BasePageServlet (if you used provided an OSGi component).


You create resources. Tag each resource with sling:resourceType, which defines how the resource responds to HTTP requests.

CQ components behave the same way.
Normally, a CQ page is made of many components (resources):

Each resource has type. If you're using scriptlet, you can use <cq:include> or <sling:include> (read: to include those child nodes.

1 comment: