Content Template Service

Table of Contents

26.1. Introduction
26.2. Contributing a content factory
26.2.1. Factory Binding
26.2.2. Template
26.2.3. ACL
26.3. How to Register your own Factory

26.1. Introduction

The content template service helps you to automatically create documents. For instance, you might want to create an english and a french folder each time you create a workspace.

Here is how you can do it easily with a simple contribution.

26.2. Contributing a content factory

26.2.1. Factory Binding

First you have to contribute a factoryBinding to ContentTemplateService facotryBinding extension point. The factories are used whenever a document is created using an EventListener.

<extension target="org.nuxeo.ecm.platform.content.template.service.ContentTemplateService"
  point="factoryBinding">

  <factoryBinding name="LangFactory" factoryName="SimpleTemplateFactory" targetType="Workspace">
     ......
  </factoryBinding>

</extension>

Example 26.1. Example of a factoryBinding registration


Options available are

  • name: name of the factory, defining a factory with the same name will override the first to be registred.

  • factoryName: the name of the factory defined in the factory extensionPoint.

  • targetType: The document Type for wich the factory will be executed.

  • targetFacet: The document Facet for wich the factory will be executed. You should target a facet if you want the factory to be used for different document types.

26.2.2. Template

Once you have a factoryBinding, it is time to think about what kind of Document you want to create automatically.

<factoryBinding name="LangFactory" factoryName="SimpleTemplateFactory" targetType="Workspace">
  <template>
    <templateItem typeName="Folder" id="en_folder" title="EN"
      description="English Folder"/>
    <templateItem typeName="Folder" id="fr_folder" title="FR"
      description="French Folder"/>
  </template>
</factoryBinding>

Example 26.2. Example of a template registration


Options available are

  • typeName: The Type of the Document you want to create

  • id: The id of the Document you want to create.

  • title: The title of the Document you want to create.

  • description: The description of the Document you want to create.

  • path: additionary path, added to factoryBinding's targetType DocPath

26.2.3. ACL

Maybe you don't want every user to have Write right in both folder? If so, you can use ACL to manage rights on your newly created templates.

<factoryBinding name="LangFactory" factoryName="SimpleTemplateFactory" targetType="Workspace">
  <acl>
    <ace principal="Administrator" permission="Everything" granted="true"/>
    <ace principal="administrators" permission="Everything" granted="true"/>
    <ace principal="members" permission="Read" granted="true"/>
    <ace principal="members" permission="Version" granted="true"/>
  </acl>
  <template>
       .....
  </template>
</factoryBinding>

Example 26.3. Example of an ACL registration for all templates of the factory


<templateItem typeName="Folder" id="en_folder" title="EN">
   <acl>
      <ace principal="FRGroup" permission="Read" granted="true" />
      <ace principal="ENGroup" permission="Write" granted="true" />
   </acl>
</templateItem>

Example 26.4. Example of an ACL registration for a single templateItem


Options available are

  • principal: Name of the group/user

  • permission: the permission you want to set.

  • granted: grant or denied the permission.

26.3. How to Register your own Factory

If you need a better control on the factory, you can contribute your own using the following extension point:

<extension target="org.nuxeo.ecm.platform.content.template.service.ContentTemplateService"
  point="factory">

  <contentFactory
    name="SimpleTemplateFactory"
    class="org.nuxeo.ecm.platform.content.template.factories.SimpleTemplateBasedFactory"/>
</extension>        

Example 26.5. Example of a Factory registration


Options available are

  • name: The name of the new factory, used in factoryBinding definition.

  • class: The class implementing ContentFactory.

  • enabled: Boolean to enable/disable the factory.

The newly defined Factory has to implement ContentFactory interface. A better way to do this would be to extend the abstract class BaseContentFactory.