7.3. Content Type Loader and Initializer

Now that we've written the code for the BirdWatch content type, we've got to write the Loader and Initializer classes. The Loader is run when the package containing the content type is first loaded. This needs to include any one-time data loading, such as creating the ContentType object, registering it in the appropriate content sections, creating the authoring kit components, etc. The steps required for loading a content type are very similar from one content type to another. Unless you have specific custom requirements, the only differences are already expressed in the authoring kit XML file we've already written. Thus our loader class, BirdWatchLoader is fairly simple:

model com.arsdigita.package1;

import com.arsdigita.cms.contenttypes.AbstractContentTypeLoader;

public class BirdWatchLoader extends AbstractContentTypeLoader {

    private static final String[] TYPES = {
        "/WEB-INF/content-types/com/arsdigita/package1/BirdWatch.xml"
    };

    public String[] getTypes() {
        return TYPES;
    }

}

The Initializer class will run each time the server is restarted. This class is ultimately responsible for loading and registering any necessary object types, registering stylesheets, and, if required, registering any custom adapters for XML generation. Since we don't need any custom initializer behavior beyond registering our object type and XSL stylesheet, our initializer class, BirdWatchInitializer, is fairly straightforward:

model com.arsdigita.package1;

import com.arsdigita.cms.contenttypes.ContentTypeInitializer;

public class BirdWatchInitializer extends ContentTypeInitializer {

    public ServiceInitializer() {
        super("ccm-cms-types-birdwatch.pdl.mf", Service\
.BASE_DATA_OBJECT_TYPE);
    }

    public String[] getStylesheets() {
        return new String[] { "/static/content-types/com/arsdigita/\
package1/BirdWatch.xsl" };
    }
}

Once we've got the initializer and loader, we specify them (and dependency information, etc.) in ccm-cms-types-birdwatch.load as follows:

<load>
  <requires>
    <table name="inits"/>
    <table name="acs_objects"/>
    <table name="cms_items"/>
    <initializer class="com.arsdigita.cms.Initializer"/>
  </requires>
  <provides>
    <table name="ct_birdwatch"/>
    <initializer class="com.arsdigita.package1.BirdWatchInitializer"/>
  </provides>
  <scripts>
    <schema directory="ccm-cms-types-birdwatch"/>
    <data class="com.arsdigita.package1.BirdWatchLoader"/>
  </scripts>
</load>

If we had any configurable parameters for our content type, we would reference the config class and properties files in ccm-cms-types-birdwatch.config:

<?xml version="1.0" encoding="utf-8"?>
<registry>
  <!-- nothing yet -->
</registry>