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. The menu XML is located at
$MODULE_HOME/config/menu.xml
. Note that we're using the i18n
message for the resource type label which we added in the previous section:
<?xml version="1.0"?> <menu 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"> <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>
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.