HOWTO: Implementing and registering a new Content Provider

Implementing and registering a new Content Provider is straight forward. For an example look at the spcp7.imagegallery.cp.impl.alfresco project. The following steps are necessary:

  1. Create a new maven project. Easiest way to do this is to simply copy spcp7.imagegallery.cp.impl.alfresco and delete everything which is not needed. Please follow the spcp7 naming scheme and call your project spcp7.imagegallery.cp.impl. plus the name of your new content provider.
  2. Change the project's pom.xml to fit your needs. The pom.xml of the alfresco content provider is configured to use Hibernate with JPA and annotations, Spring, ICEFaces and Liferay. Add or remove these dependencies as you like. At the bottom of the former Alfresco Content Provider dependency list you can find the spcp7 internal dependencies. Leave them as they are.
  3. For central building and testing reference your pom.xml within the pom.xml of the spcp7.aggregation project and vice versa.
  4. Currently only the ContentRetrievalFace interface within the spcp7.imagegallery.abstraction.api project is ready to use. Implement ContentRetrievalFace and ContentProviderFace . The name of your implementation classes should start with the name of your content provider (e.g. AlfrescoContentProviderImpl.java for the implementation of ContentProviderFace of Alfresco).
  5. Give your content provider a describing dot seperated name which starts with spcp7.imagegallery.contentprovider. to prevent collisions. You can see the Alfresco version below.
    public static final String contentProviderTypeID = "spcp7.imagegallery.contentprovider.alfresco";

    Beware that this name has to be unique within the whole image gallery.

  6. Register your Content Provider within the spring configuration of the Content Provider Registry. You can find the configuration within the spcp7.imagegallery.abstraction.impl project in the file spcp7_image_gallery_applicationContext.xml .

    The appropriate part looks similar to this:
    <!-- spcp7_image_gallery_applicationContext.xml -->
    <bean id="ContentProviderRegistry"
     class="spcp7.imagegallery.abstractionlayer.impl.internal.ContentProviderRegistryImpl">
     <property name="contentProviders">
      <list>
       <!-- This reference can be found in the alfresco spring configuration -->
       <ref bean="AlfrescoContentProvider"/>
      </list>
     </property>
     <property name="generalValidationUtil" ref="GeneralValidation"/>
     <property name="cprValidation" ref="CprValidation"/>
     <property name="entityManagerFactory" ref="entityManagerFactory"/>
    </bean>

    If you want to add a new content provider you have to add a reference to its bean definition below <ref bean="AlfrescoContentProvider"/> . After adding your Content Provider the part of the file might look similar to the extract below.

    <!-- spcp7_image_gallery_applicationContext.xml -->
    <bean id="ContentProviderRegistry"
     class="spcp7.imagegallery.abstractionlayer.impl.internal.ContentProviderRegistryImpl">
     <property name="contentProviders">
      <list>
       <!-- This reference can be found in the alfresco spring configuration -->
       <ref bean="AlfrescoContentProvider"/>
       <!-- THIS CAN BE YOUR CONTENT PROVIDER -->
       <ref bean="FilesystemContentProvider"/>
      </list>
     </property>
     <property name="generalValidationUtil" ref="GeneralValidation"/>
     <property name="cprValidation" ref="CprValidation"/>
     <property name="entityManagerFactory" ref="entityManagerFactory"/>
    </bean>
    <!-- do not forget the bean definition for the new content provider -->
    <bean id="FilesystemContentProvider" 
     class="spcp7.imagegallery.cp.impl.filesystem.FilesystemContentProviderImpl"/>

    After that your new content provider is registered and you can use it within the gui.

  7. If your Content Provider brings his own properties (e.g. standard folders or additional authentication information) you can define them in your Content Provider implementation as a Map which should be returned by getDefaultProperties() within ContentProviderFace . Sometimes it can be necessary to overwrite the default properties of the spcp7-imagegallery which are defined within the project spcp7-imagegallery-abstraction-api within the enum spcp7.imagegallery.abstractionlayer.enums.DefaultProperties . If you want to do this just specify a property with the same key in your Content Provider default properties as the default properties of the image gallery will be overwritten by properties of a content provider. The method responsible for this functionality is called mergeCpAndDefaultPropertiesPersistent() and can be found within ContentProviderRegistryImpl . For a more general explanation of the properties feature look at Architecture .