Creating a Resource Type, Part 4: Editing
In this section we make our person documents editable.
Adding the Relax NG Schema
When we allow to edit documents, we have to make sure that the resulting
XML conforms to the FoaF specification. For this purpose we provide a
Relax NG schema for the FoaF person XML format.
Here's a simple schema, created with Trang,
which - according to the resource type declaration - has to be located at
$MODULE_HOME/resources/schemas/foaf.rng
:
<?xml version="1.0" encoding="UTF-8"?> <grammar xmlns="http://relaxng.org/ns/structure/1.0" xmlns:foaf="http://xmlns.com/foaf/0.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes"> <start> <element name="rdf:RDF"> <element name="foaf:Person"> <attribute name="rdf:ID"><data type="NCName"/></attribute> <element name="foaf:title"><text/></element> <element name="foaf:givenname"><text/></element> <element name="foaf:family_name"><text/></element> <element name="foaf:mbox"> <attribute name="rdf:resource"> <data type="anyURI"/> </attribute> </element> <element name="foaf:phone"> <attribute name="rdf:resource"> <data type="NMTOKEN"/> </attribute> </element> <element name="foaf:workplaceHomepage"> <attribute name="rdf:resource"> <data type="anyURI"/> </attribute> </element> </element> </element> </start> </grammar>
Enabling the Source Editor
In the first step we don't want to invest much time, so we just
enable the source editor. We have to add the corresponding menu item
to our menu.xml
file. But since we want to enable it only
for person documents, we have to test if the currently displayed document
has the person resource type. Here's the extended menu.xml
file. Note the resourceTypes
attribute of the <block>
element:
<?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>resourceType-person</i18n:param> </i18n:translate> </item> </block> </menu> <menu i18n:attr="name" name="Edit"> <block areas="authoring" resourceTypes="person"> <item uc:usecase="editors.oneform"> <i18n:text>editors.sourceEditor</i18n:text> </item> </block> </menu> </menus> </menu>
Now you should be able to edit your person document with the source editor.
In the next section we explain how to make person documents editable with the BXE WYSIWYG editor.