apache > lenya
 

Creating a Resource Type, Part 2: Creating Documents

Adding the Menu

Now we'll add the menu for our module. The first item we need will trigger the usecase to create new person documents. We have to add a sitemap which serves as an entry point for the menu ($MODULE_HOME/menus.xmap):

<?xml version="1.0"?>
<map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0">
  <map:pipelines>
    <map:pipeline>
      <map:match pattern="**">
        <map:generate type="serverpages"
          src="fallback://lenya/modules/person/config/menu.xsp"/>
        <map:serialize type="xml"/>
      </map:match>
    </map:pipeline>
  </map:pipelines>
</map:sitemap>

According to this sitemap, the menu XSP is located at $MODULE_HOME/config/menu.xsp. Note that we're using the i18n message for the resource type label which we added in the previous section:

<?xml version="1.0"?>
<xsp:page 
    language="java" 
    xmlns:xsp="http://apache.org/xsp"
    xmlns:i18n="http://apache.org/cocoon/i18n/2.1"    
    xmlns:uc="http://apache.org/cocoon/lenya/usecase/1.0"
    xmlns="http://apache.org/cocoon/lenya/menubar/1.0">
  <menu>
    <menus>
      <menu i18n:attr="name" name="File">
        <block areas="site authoring">
          <item uc:usecase="sitemanagement.create" href="?doctype=person">
            <i18n:translate>
              <i18n:text>New ... Document</i18n:text>
              <i18n:param><i18n:text>resourceType-person</i18n:text></i18n:param>
            </i18n:translate>
          </item>
        </block>
      </menu>
    </menus>
  </menu>
</xsp:page>

The menu contains an item which triggers the sitemanagement.create usecase with the doctype=person parameter.

Providing the Sample

To create a document, the sitemanagement.create usecase needs a sample XML. We've already specified the sample location in our resource type declaration (see above). Now we have to add the corresponding FoaF person file ($MODULE_HOME/samples/foaf.xml):

<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF
  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  xmlns:foaf="http://xmlns.com/foaf/0.1/">
  <foaf:Person rdf:ID="me">
    <foaf:title>Mr</foaf:title>
    <foaf:givenname>Homer</foaf:givenname>
    <foaf:family_name>Simpson</foaf:family_name>
    <foaf:mbox rdf:resource="mailto:chunkylover53@aol.com"/>
    <foaf:phone rdf:resource="tel:555-555-555"/>
    <foaf:workplaceHomepage rdf:resource="http://powerplantspringfield.com"/>
  </foaf:Person>
</rdf:RDF>

In the next section we'll render our newly created document as an XHTML web page.