More Related Content
What's hot
Hands-On Java web passando por Servlets, JSP, JSTL, JDBC, Hibernate, DAO, MV...Hands-On Java web passando por Servlets, JSP, JSTL, JDBC, Hibernate, DAO, MV...Mario Jorge Pereira
Creating a Resource Type with Apache Lenya 2.0
- 4. Directory
Layout
$HOME/
apache/
lenya-1.4/ $LENYA_HOME
src/
lenya/ Lenya-related sources
modules/ Modules
person/ quot;personquot; resource type module
4
- 7. Declaring
the
Resource
Type
modules/person/config/cocoon-xconf/resourcetype-person.xconf
<xconf xpath=quot;/cocoon/resource-typesquot;
unless=quot;/cocoon/resource-types/component-instance[@name = 'person']quot;>
<component-instance name=quot;personquot; logger=quot;lenya.resourcetypesquot;
class=quot;org.apache.lenya.cms.publication.ResourceTypeImplquot;>
<schema language=quot;http://relaxng.org/ns/structure/0.9quot;
src=quot;fallback://lenya/modules/person/resources/schemas/foaf.rngquot;/>
<expires seconds=quot;3600quot; />
<sample-name>fallback://lenya/modules/person/samples/foaf.xml</sample-name>
<format name=quot;xhtmlquot; uri=quot;cocoon://modules/person/xhtml.xmlquot;/>
<format name=quot;xhtml-includequot; uri=quot;cocoon://modules/person/xhtml-include.xmlquot;/>
<format name=quot;iconquot; uri=quot;cocoon://modules/person/iconquot;/>
</component-instance>
</xconf>
7
- 10. Menu
XSP
modules/person/config/menu.xsp
<xsp:page language=quot;javaquot; xmlns:xsp=... >
<menu>
<menus>
<menu i18n:attr=quot;namequot; name=quot;Filequot;>
<block areas=quot;site authoringquot;>
<item uc:usecase=quot;sitemanagement.createquot; href=quot;?doctype=personquot;>
<i18n:translate>
<i18n:text>New ... Document</i18n:text>
<i18n:param>Person</i18n:param>
</i18n:translate>
</item>
</block>
</menu>
</menus>
</menu>
</xsp:page>
10
- 12. Presentation
Pipeline
modules/person/sitemap.xmap
<!-- {format}.xml -->
<map:match pattern=quot;*.xmlquot;>
<map:generate src=quot;cocoon:/{1}.xml/{page-envelope:publication-id}/
{page-envelope:area}/{page-envelope:document-uuid}/
{page-envelope:document-language}quot;/>
<map:serialize type=quot;xmlquot;/>
</map:match>
<!-- {format}.xml/{pubId}/{area}/{uuid}/{language} -->
<map:match pattern=quot;*.xml/*/*/*/*quot;>
<map:generate src=quot;lenya-document:{4},lang={5}{link:rev}quot;/>
<map:transform src=quot;fallback://lenya/modules/person/xslt/foaf2xhtml.xslquot;/>
<map:serialize type=quot;xmlquot;/>
</map:match>
12
- 17. Relax
NG
Schema
<grammar xmlns=quot;http://relaxng.org/ns/structure/1.0quot; ...>
<start>
<element name=quot;rdf:RDFquot;>
<element name=quot;foaf:Personquot;>
<attribute name=quot;rdf:IDquot;><data type=quot;NCNamequot;/></attribute>
<element name=quot;foaf:titlequot;><text/></element>
<element name=quot;foaf:givennamequot;><text/></element>
<element name=quot;foaf:family_namequot;><text/></element>
<element name=quot;foaf:mboxquot;>
<attribute name=quot;rdf:resourcequot;><data type=quot;anyURIquot;/></attribute>
</element>
<element name=quot;foaf:phonequot;>
<attribute name=quot;rdf:resourcequot;><data type=quot;NMTOKENquot;/></attribute>
</element>
<element name=quot;foaf:workplaceHomepagequot;>
<attribute name=quot;rdf:resourcequot;><data type=quot;anyURIquot;/></attribute>
</element>
</element>
</element>
</start>
</grammar>
17
- 18. One-Form
Editor
Menu
Item
<menu i18n:attr=quot;namequot; name=quot;Editquot;>
<xsp:logic>
try {
Object doc = <input:get-attribute module=quot;page-envelopequot;
as=quot;objectquot; name=quot;documentquot;/>;
if (doc instanceof Document && ((Document) doc).exists()) {
String doctype = <input:get-attribute module=quot;page-envelopequot;
as=quot;stringquot; name=quot;document-typequot;/>;
if (quot;personquot;.equals(doctype)) {
<block areas=quot;authoringquot;>
<item uc:usecase=quot;editors.oneformquot; href=quot;?quot;>
<i18n:text>With one Form</i18n:text>
</item>
</block>
}
}
}
catch (Exception e) {
throw new ProcessingException(quot;Error during menu generation: quot;, e);
}
</xsp:logic>
</menu>
18
- 19. BXE
Menu
Item
<block areas=quot;authoringquot;>
<item uc:usecase=quot;bxe.editquot; href=quot;?quot;>
<i18n:text>With BXE</i18n:text>
</item>
<item uc:usecase=quot;editors.oneformquot; href=quot;?quot;>
<i18n:text>With one Form</i18n:text>
</item>
</block>
19
- 20. webdavGET
Format
modules/person/config/cocoon-xconf/resourcetype-person.xconf
<format name=quot;webdavGETquot;
uri=quot;cocoon://modules/person/davget.xmlquot;/>
modules/person/sitemap.xmap
<map:match pattern=quot;davget.xmlquot;>
<map:act type=quot;set-headerquot;>
<map:parameter name=quot;Last-Modifiedquot;
value=quot;{date-iso8601-rfc822:
{page-envelope:document-lastmodified}}quot; />
<map:generate src=quot;lenya-document:{page-envelope:document-uuid}quot;/>
<map:transform type=quot;uuid2urlquot;>
<map:parameter name=quot;urlsquot; value=quot;absolutequot;/>
</map:transform>
<map:serialize type=quot;xmlquot;/>
</map:act>
</map:match>
20
- 21. BXE
Attributes
in
XSLT
modules/person/xslt/foaf2xhtml.xsl
<xsl:template name=quot;bxeAttributequot;>
<xsl:param name=quot;elementquot;/>
<xsl:if test=quot;$rendertype = 'edit'quot;>
<xsl:attribute name=quot;bxe_xpathquot;>
/rdf:RDF/foaf:Person/foaf:<xsl:value-of select=quot;$elementquot;/>
</xsl:attribute>
</xsl:if>
</xsl:template>
<tr>
<th>Title:</th>
<td>
<xsl:call-template name=quot;bxeAttributequot;>
<xsl:with-param name=quot;elementquot;>title</xsl:with-param>
</xsl:call-template>
<xsl:value-of select=quot;foaf:titlequot;/>
</td>
</tr>
21
- 23. Next
Steps
• Extend
schema
• Form-based
editing
• Add
content
fields
to
„Create“
screen
• Image
upload
(portrait
photo
/
avatar)
• Additional
presentation
pipelines
• FOAF
XML
file
• XSL-FO
for
PDF
business
card
generation
• vCard
format
(.vcf)
• ...
23