The Content Provider

The Content Provider is responsible to resolve the content for the request, to load the that content and last but not least return it into the view.

You can specifiy which Content Provider you want to use by defininig the attribute type within the element <content/>. Currently only the Content Provider type xml is available:

<content name="..." type="xml" src="..."/>

Depending on the type of the Content Provider, additional attributes are required. The xml Content Provider for example requires the attribute src that defines the path to the content XML document to be loaded.

Creating your own Content Provider

Currently only the xml Content Provider is available, but it's easy to create and integrate your own Content Provider. This can be done in two simple steps:

Step 1: Create the implementation

Create an implementation of your Content Provider by implementing the interface ContentProvider. Here is an example:

import com.logabit.webtools.patchwork.content.ContentProvider;

public class MyContentProvider implements ContentProvider {

  public Object getContent(ContentProviderDescriptor descriptor) 
        throws ContentProviderException {

    // Logic for content resolving and loading  goes here

  }
}

Step 2: Register the implementation

The last step is to register the Content Provider within the component having the role com.logabit.webtools.patchwork.content.ContentProviderSelector in the cocoon.xconf file by adding a new entry within the <component/> as shown in the example below:

<component role="com.logabit.webtools.patchwork.content.ContentProviderSelector" ...>
  ...
 <component-instance class="foo.bar.MyContentProvider" name="my"/>
</component>

After restarting Cocoon you can use your content provider by referencing its name within your patchwork configuration:

<content name="..." type="my" .../>