Creating Your Own Link Header Plug-in

If the default link header plug-in does not meet your requirements, then you can create your own by implementing the LinkHeaderPlugin interface. The following example shows a very basic LinkHeaderPlugin implementation that simply adds the URL of an image (a monkey's face) to the header of all returned sections and content items.

package com.escenic.plugins.monkeyface.core;

import com.escenic.webservice.spi.LinkHeaderPlugin;
import com.escenic.webservice.helper.ServiceLocator;
import com.escenic.domain.Link;
import neo.xredsys.api.IOObject;
import java.util.Collections;
import java.util.List;
import java.net.URI;

/**
 * A LinkHeaderPlugin that adds a linkheader referencing a picture of a monkey
 */
public class MonkeyFaceLinkHeaderPlugin implements LinkHeaderPlugin {
  public List<Link> createLinks(IOObject pContent, ServiceLocator pLocator) {
    return Collections.singletonList(new Link(URI.create("http://upload.wikimedia.org/wikipedia/commons/6/64/Cebus_albifrons_edit.jpg"), 
                                              "monkey", 
                                              "image/jpeg", 
                                              "Mr. Monkey"));
  }
}

In order to make your plug-in known to the system you must also implement the corresponding service provider interface (LinkHeaderPluginSpi) and register it. For example:

package com.escenic.plugins.monkeyface.core;
import com.escenic.webservice.spi.LinkHeaderSpi;
import com.escenic.webservice.spi.LinkHeaderPlugin;

/**
 * The service provider interface of our monkey plugin
 */
public class MonkeyFaceLinkHeaderSpi extends LinkHeaderSpi {

  public MonkeyFaceLinkHeaderSpi() {
    super("Escenic", "1.0", "Creates a LinkHeaderPlugin");
  }

  @Override
  public LinkHeaderPlugin createLinkHeaderPlugin() {
    return new MonkeyFaceLinkHeaderPlugin();
  }
}

To register your service you must create or edit META-INF/services/com.escenic.webservice.spi.LinkHeaderSpi and add a line naming the service:

com.escenic.plugins.monkeyface.core.MonkeyFaceLinkHeaderSpi

You then need to:

  1. Compile your classes and package them together with the service declaration in a JAR file.

  2. Add the JAR file to the server classpath

When this has been done, the Content Engine will see the plug in and load it using Java's ServiceProvider API (see http://download.oracle.com/javase/6/docs/api/java/util/ServiceLoader.html for details). The "monkey face" link header will then be included with all sections and content items returned by the Content Engine.