23
Creatinga ResourceType AndreasHartmann BeCompanyGmbH 1

Creating a Resource Type with Apache Lenya 2.0

  • Upload
    nobby

  • View
    3.104

  • Download
    3

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: Creating a Resource Type with Apache Lenya 2.0

CreatingaResourceType

AndreasHartmannBeCompanyGmbH

1

Page 2: Creating a Resource Type with Apache Lenya 2.0

Agenda

DeclaringtheResourceType

CreatingDocuments

Presentation(Pipelines,XSLT)

EditingwiththeOne-FormEditor

EditingwiththeBXEEditor

2

Page 3: Creating a Resource Type with Apache Lenya 2.0

ResourceType„Person“

• FOAF:FriendofaFriend(www.foaf-project.org)

• Machine-readableinformationaboutpeople(SemanticWeb)

• BasedonRDFschema

• Analyzationandvisualizationofsocialnetworks

3

Page 4: Creating a Resource Type with Apache Lenya 2.0

DirectoryLayout

$HOME/ apache/ lenya-1.4/ $LENYA_HOME src/ lenya/ Lenya-related sources modules/ Modules person/ "person" resource type module

4

Page 5: Creating a Resource Type with Apache Lenya 2.0

ModuleDirectoryLayout

person/ config/ menu.xsp module.xml cocoon-xconf/ resourcetype-person.xconf resources/ icons/ person.gif samples/ foaf.xml xslt/ foaf2xhtml.xml menus.xmap

5

Page 6: Creating a Resource Type with Apache Lenya 2.0

ModuleDescriptormodules/person/config/module.xml

<?xml version="1.0" encoding="UTF-8"?><module xmlns="http://apache.org/lenya/module/1.0">

<id>org.yourproject.lenya.modules.person</id> <package>org.yourproject.lenya.modules</package> <version>0.1-dev</version> <name>person</name> <lenya-version>@lenya.version@</lenya-version>

<description> Resource type to store person details </description>

</module>

6

Page 7: Creating a Resource Type with Apache Lenya 2.0

DeclaringtheResourceTypemodules/person/config/cocoon-xconf/resourcetype-person.xconf

<xconf xpath="/cocoon/resource-types" unless="/cocoon/resource-types/component-instance[@name = 'person']"><component-instance name="person" logger="lenya.resourcetypes" class="org.apache.lenya.cms.publication.ResourceTypeImpl"> <schema language="http://relaxng.org/ns/structure/0.9" src="fallback://lenya/modules/person/resources/schemas/foaf.rng"/> <expires seconds="3600" /> <sample-name>fallback://lenya/modules/person/samples/foaf.xml</sample-name> <format name="xhtml" uri="cocoon://modules/person/xhtml.xml"/><format name="xhtml-include" uri="cocoon://modules/person/xhtml-include.xml"/><format name="icon" uri="cocoon://modules/person/icon"/> </component-instance></xconf>

7

Page 8: Creating a Resource Type with Apache Lenya 2.0

RegisterModule+ResourceType

local.build.properties:

modules.root.dirs=...

publication.xml:

<module name="person"/><resource-type name="person" workflow="..."/>

8

Page 9: Creating a Resource Type with Apache Lenya 2.0

MenuSitemap

modules/person/menus.xmap

<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>

9

Page 10: Creating a Resource Type with Apache Lenya 2.0

MenuXSPmodules/person/config/menu.xsp

<xsp:page language="java" xmlns:xsp=... > <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>Person</i18n:param> </i18n:translate> </item> </block> </menu> </menus> </menu></xsp:page>

10

Page 11: Creating a Resource Type with Apache Lenya 2.0

ProvidingtheSample

modules/person/samples/foaf.xml

<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:[email protected]"/> <foaf:phone rdf:resource="tel:555-555-555"/> <foaf:workplaceHomepage rdf:resource="http://powerplantspringfield.com"/> </foaf:Person></rdf:RDF>

11

Page 12: Creating a Resource Type with Apache Lenya 2.0

PresentationPipelinemodules/person/sitemap.xmap

<!-- {format}.xml --><map:match pattern="*.xml"> <map:generate src="cocoon:/{1}.xml/{page-envelope:publication-id}/ \ {page-envelope:area}/{page-envelope:document-uuid}/ \ {page-envelope:document-language}"/> <map:serialize type="xml"/></map:match> <!-- {format}.xml/{pubId}/{area}/{uuid}/{language} --><map:match pattern="*.xml/*/*/*/*"> <map:generate src="lenya-document:{4},lang={5}{link:rev}"/> <map:transform src="fallback://lenya/modules/person/xslt/foaf2xhtml.xsl"/> <map:serialize type="xml"/></map:match>

12

Page 13: Creating a Resource Type with Apache Lenya 2.0

PresentationXSLT(1)

modules/person/xslt/foaf2xhtml.xsl

<xsl:template match="rdf:RDF"> <html> <body> <div id="body"> <xsl:apply-templates select="foaf:Person"/> </div> </body> </html></xsl:template>

13

Page 14: Creating a Resource Type with Apache Lenya 2.0

PresentationXSLT(2)modules/person/xslt/foaf2xhtml.xsl

<xsl:template match="foaf:Person"> <h2>Person Details</h2> <table class="person"> <tr> <th>Title:</th> <td><xsl:value-of select="foaf:title"/></td> </tr> ... <tr> <th>E-Mail:</th> <td> <xsl:variable name="mbox" select="foaf:mbox/@rdf:resource"/> <a href="{$mbox}"> <xsl:value-of select="substring-after($mbox, 'mailto:')"/> </a> </td> </tr> ...

14

Page 15: Creating a Resource Type with Apache Lenya 2.0

CSS

pubs/default/resources/shared/css/person.css

table.person { font-size: small;}

table.person th { font-weight: normal; color: #999999; text-align: left; padding-right: 1em;}

15

Page 16: Creating a Resource Type with Apache Lenya 2.0

Presentation

16

Page 17: Creating a Resource Type with Apache Lenya 2.0

RelaxNGSchema<grammar xmlns="http://relaxng.org/ns/structure/1.0" ...> <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>

17

Page 18: Creating a Resource Type with Apache Lenya 2.0

One-FormEditorMenuItem<menu i18n:attr="name" name="Edit"> <xsp:logic> try { Object doc = <input:get-attribute module="page-envelope" as="object" name="document"/>; if (doc instanceof Document &amp;&amp; ((Document) doc).exists()) { String doctype = <input:get-attribute module="page-envelope" as="string" name="document-type"/>; if ("person".equals(doctype)) { <block areas="authoring"> <item uc:usecase="editors.oneform" href="?"> <i18n:text>With one Form</i18n:text> </item> </block> } } } catch (Exception e) { throw new ProcessingException("Error during menu generation: ", e); } </xsp:logic></menu>

18

Page 19: Creating a Resource Type with Apache Lenya 2.0

BXEMenuItem

<block areas="authoring"> <item uc:usecase="bxe.edit" href="?"> <i18n:text>With BXE</i18n:text> </item> <item uc:usecase="editors.oneform" href="?"> <i18n:text>With one Form</i18n:text> </item></block>

19

Page 20: Creating a Resource Type with Apache Lenya 2.0

webdavGETFormatmodules/person/config/cocoon-xconf/resourcetype-person.xconf

<format name="webdavGET" uri="cocoon://modules/person/davget.xml"/>

modules/person/sitemap.xmap

<map:match pattern="davget.xml"> <map:act type="set-header"> <map:parameter name="Last-Modified" value="{date-iso8601-rfc822: {page-envelope:document-lastmodified}}" /> <map:generate src="lenya-document:{page-envelope:document-uuid}"/> <map:transform type="uuid2url"> <map:parameter name="urls" value="absolute"/> </map:transform> <map:serialize type="xml"/> </map:act></map:match>

20

Page 21: Creating a Resource Type with Apache Lenya 2.0

BXEAttributesinXSLTmodules/person/xslt/foaf2xhtml.xsl

<xsl:template name="bxeAttribute"> <xsl:param name="element"/> <xsl:if test="$rendertype = 'edit'"> <xsl:attribute name="bxe_xpath"> /rdf:RDF/foaf:Person/foaf:<xsl:value-of select="$element"/> </xsl:attribute> </xsl:if></xsl:template>

<tr> <th>Title:</th> <td> <xsl:call-template name="bxeAttribute"> <xsl:with-param name="element">title</xsl:with-param> </xsl:call-template> <xsl:value-of select="foaf:title"/> </td></tr>

21

Page 22: Creating a Resource Type with Apache Lenya 2.0

EditinginBXE

22

Page 23: Creating a Resource Type with Apache Lenya 2.0

NextSteps

• Extendschema

• Form-basedediting

• Addcontentfieldsto„Create“screen

• Imageupload(portraitphoto/avatar)

• Additionalpresentationpipelines• FOAFXMLfile• XSL-FOforPDFbusinesscardgeneration• vCardformat(.vcf)• ...

23