apache > lenya
 

Resource Types (formerly known as Document Types)

Basics

A resource type defines a certain XML source format, together with processing options. It typically consists of

  • an XML structure definition (e.g., Relax NG)
  • a workflow schema,
  • some presentation pipelines,
  • some presentation XSLT stylesheets,
  • a Lenya menubar.

All of these can be shared between several resource types.

Adding a Resource Type to a Publication

Adding a custom resource type to your publication includes the following steps:

Choose a Unique Resource Type Name

You should choose a reasonable name for your resource type. In the examples, we use profile (page with information about a person).

Providing a Sample XML Document

If you want to enable users to create new resources belonging to your resource type, it is useful to provide a sample XML document. If you want to use the DefaultBranchCreator that ships with Lenya, you have to add the sample document because it is used as a template for creating new resources.

The sample document is placed in {publication}/config/doctypes/samples/. You can choose an arbitrary filename, but it is recommended to use the resource type name (e.g., profile.xml).

Providing an XML Structure Definition

This step is only needed if you want to edit resources with Lenya or validate them after they have been imported or manipulated. The type of the structure definition (XML Schema, Relax NG, ...) depends on the editor or validator you want to use. For instance, the BXE WYSIWYG editor requires a Relax NG document.

The structure definition document is placed in the directory {publication}/config/doctypes/schemas/. The name of the file is arbitrary, but it is recommended to use the resource type name (e.g., profile.rng).

Creating a Workflow Schema

If your resources should have a workflow, you have to add a workflow schema for your resource type as described in Workflow Configuration. A workflow schema can be shared between multiple resource types.

The Resource Type Definition

To assign the creator and the workflow schema to your resource type, declare it in {publication}/config/doctypes/doctypes.xconf:

<doc type="profile">
    <creator src="org.apache.lenya.cms.authoring.DefaultBranchCreator">
      <sample-name>profile.xml</sample-name>
    </creator>
    <workflow src="2stage.xml"/>
  </doc>

Define the Mapping From URLs to Resource Types

The resource type of a resource is determined based on the resource URL. This mapping happens in {publication}/parameter-doctype.xmap.

A typical approach to determine the resource type is to apply the SourceTypeAction on the source document:

<map:match pattern="*/**.html">
  <map:act type="sourcetype" src="content/{1}/{page-envelope:document-path}">
    <map:generate type="serverpages" src="../../config/parameters/default.xsp">
      <map:parameter name="value" value="{sourcetype}"/>
    </map:generate>
    <map:serialize type="xml"/>
  </map:act>
</map:match>

Another way is to return the resource type by just matching certain URLs:

<map:match pattern="*/profiles/*.html">
  <map:generate type="serverpages" src="../../config/parameters/default.xsp">
    <map:parameter name="value" value="profile"/>
  </map:generate>
  <map:serialize type="xml"/>
</map:match>

Define a Custom Menubar

If you want to use a custom menubar for your resource type, follow the guidelines on the page The Lenya Menubar. Typically, a menubar is shared between multiple resource types. Small customizations can be achieved with Java code in the menubar XSP.

To let the user create new resources using the DefaultBranchCreator, you have to add the following menu item:

<item uc:usecase="create" uc:step="showscreen" href="?doctype=profile"><i18n:text>New Document</i18n:text></item>

Presentation

To make your resources available as HTTP pages, you have to add the appropriate pipelines and XSLT stylesheets. In general, there are no restrictions.

If you derive your publication from the default publication, the pipelines have to be placed in {publication}/doctypes.xmap. The stylesheets are located in {publication}/xslt/ and are named {resource-type}2xhtml.xsl (e.g., profile2xhtml.xsl). The stylesheet is supposed to generate a valid XHTML fragment (in the XHTML namespace) with <div id="body"> as the document element.