Archive for September, 2012

CQ Tips and Tricks #1 – How to define a SlingServlet [CQ5.5-5.6]

There are many ways to define an OSGI service.
This is the preferred coding style for CQ version 5.5-5.6 that we follow on our team.

Registering the servlet by path

import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.sling.SlingServlet;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.servlets.SlingAllMethodsServlet;

import javax.servlet.ServletException;
import java.io.IOException;

@SlingServlet(
    paths={"/services/unicom/v1/"}
)
@Properties({
    @Property(name="service.pid", value="com.adobe.unicom.v1.servlets.OmnnitureLoggingServlet",propertyPrivate=false),
    @Property(name="service.description",value="Omniture service call logging servlet", propertyPrivate=false),
    @Property(name="service.vendor",value="Adobe Systems Incorporated - Adobe@Adobe Team", propertyPrivate=false)
})
public class OmnnitureLoggingServlet extends SlingAllMethodsServlet
{
    @Override
    protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException
    {
        //Do something fun here
    }

    @Override
    protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException
    {
        //Do something fun here
    }
}

OR  registering the servlet by resource type and extension

import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.sling.SlingServlet;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.servlets.SlingAllMethodsServlet;

import javax.servlet.ServletException;
import java.io.IOException;

@SlingServlet(
    resourceTypes = {"rep:User"},
    methods = {"GET", "POST"}
)
@Properties({
    @Property(name="service.pid", value="com.adobe.unicom.v1.servlets.OmnnitureLoggingServlet",propertyPrivate=false),
    @Property(name="service.description",value="Omniture service call logging servlet", propertyPrivate=false),
    @Property(name="service.vendor",value="Adobe Systems Incorporated - Adobe@Adobe Team", propertyPrivate=false)
})
public class OmnnitureLoggingServlet extends SlingAllMethodsServlet
{
    @Override
    protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException
    {
        //Do something fun here
    }

    @Override
    protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException
    {
        //Do something fun here
    }
}

To handle all requests and filter on selector you can change the example above to read something like this.

import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.sling.SlingServlet;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.servlets.SlingAllMethodsServlet;

import javax.servlet.ServletException;
import java.io.IOException;

@SlingServlet(
    resourceTypes = {"sling/servlet/default"},
    methods = {"GET"},
    selectors = {"report"},
    extensions = {"json"}
)
@Properties({
    @Property(name="service.pid", value="com.adobe.unicom.v1.servlets.OmnnitureLoggingServlet",propertyPrivate=false),
    @Property(name="service.description",value="Omniture service call logging servlet", propertyPrivate=false),
    @Property(name="service.vendor",value="Adobe Systems Incorporated - Adobe@Adobe Team", propertyPrivate=false)
})
public class OmnnitureLoggingServlet extends SlingAllMethodsServlet
{
........

For more details on the Felix Annotations see

Introducing the new CQ Typekit integration component

After it was announced that we were acquiring Typekit I had to go see what we were buying. I was pleased to find a great new tool for my web toolbox. Over the years I have had the displeasure of having to reject comp from designers because of their use of beautiful fonts. In some cases I had to cut up comps into a million pieces to try to perserve the intergerty of the design. Over all non standard web fonts have been a real pain to deal with. Yes, there have been other solutions to help me deal with custom fonts overtime but none I really liked. I really like Typekit and the website itself is a work of art.
I am going over the top a bit but its a great platform and I am glad we acquired the company.

Now that I have found a new friend in Typekit, I needed to introduce it to my best friend CQ. After my first integration I thought “Wouldn’t it be cool if an author could do this without any coding or IT help?”. So I went off and created a simple page property extension that allows a author to bind a page and its children to a Typekit kit ID.

The following is a video I shot demoing our new integration component which can be found on the CQ package share. Please forgive my lack of enthusiasm in the video. I was very tired on the day of the shoot.

Our customer package share recently underwent a major upgrade. While I am working on getting this package re-hosted in the package share here is a link to the current version.

Adobe’s social media strategy + Adobe Digital Marketing Suite = Awesome ROI

As a leader in digital marketing and digital media software, Adobe doesn’t have to turn far to find the products and technology that it needs to create, deploy, measure, and optimize digital marketing campaigns. For the launch of Adobe Creative Suite 6 and Adobe Creative Cloud, Adobe took the opportunity to showcase its robust social media initiatives and Adobe Digital Marketing Suite.

“We wanted to engage customers and drive solid business results through social media, so we had to clearly understand the impact of all our strategies,” says Maria Poveromo, director of social media for Adobe. “We not only set out to generate as much buzz as possible, but we also wanted to continually adapt our strategies along the way and see the returns.” Continue reading…