Solprovider Lenya Kongregate Registration for Free Flash Games and Chat with solprovider

Integrating external data into Lenya

This article is about how to pull XML data from another web server and integrate it into a Lenya website. It assumes you have read Displaying Lenya Documents for a desciption of how Lenya turns content into webpages.

Your first decision is where Lenya enters your code. There are two good possibilities for your goals:
1. Interrupt before <map:match pattern="**.html">
2. Interrupt at getting the data.


In the examples, the URL for your website would be:
"people" is from the match. Modify the map:match to change the URL used.
"key" is passed to your external URL.

The XML data will be retrieved from:
Modify the map:generate to change the source of the XML data.

First Solution

1. Interrupt before <map:match pattern="**.html">
Add a match and write everything needed to create your page.
{1} = url before "/people/"
{2} = url between "people/" and ".html"
<map:match pattern="**/people/*.html">
<map:aggregate element="cmsbody">
<map:part src="cocoon://navigation/{page-envelope:publication-id}/{page-envelope:area}/breadcrumb/index.xml"/>
<map:part src="cocoon://navigation/{page-envelope:publication-id}/{page-envelope:area}/tabs/index.xml"/>
<map:part src="cocoon://navigation/{page-envelope:publication-id}/{page-envelope:area}/menu/index.xml"/>
<map:part src="cocoon://navigation/{page-envelope:publication-id}/{page-envelope:area}/search/index.xml"/>
<map:part src="cocoon:/people-{2}"/>
<map:transform src="xslt/page2xhtml-people.xsl"/>
<map:serialize type="xml"/>

(You should copy all the code in <map:match pattern="lenyabody-*/*/*/*/**">.

<map:match pattern="people-**">
<map:generate src="{1}"/>
<map:transform src="xslt/xmlhack.xsl"/>
<map:serialize type="html"/>

Notice I added the filename requested (without an extension) to the querystring of the remote request.

Second Solution

2. Interrupt at getting the data.
2.a Set a new doctype in "parameter-doctype.xmap". This code must be before <map:match pattern="*/**.html">:
<map:match pattern="**/people/*.html">
<map:generate type="serverpages" src="../../config/parameters/default.xsp">
<map:parameter name="value" value="people"/>
<map:serialize type="xml"/>

2.b Get the content from the remote source in "doctypes.xmap". This code must be inside the <map:match pattern="*/*/*/**.xml"> (if it exists) to prevent duplicate matches:
{1} = "view"
{2} = area
{3} = document=path with final ".xml" removed
<map:match pattern="*/*/people/**.xml">
<map:generate src="{3}"/>
<map:transform src="xslt/people2xhtml.xsl">
<map:parameter name="rendertype" value="{1}"/>
<map:parameter name="nodeid" value="{page-envelope:document-node-id}"/>
<map:parameter name="language" value="{page-envelope:document-language}"/>
<map:serialize type="xml"/>

Notice I added the filename requested (without an extension) to the querystring of the remote request.

2.c Use these filenames for your transformation:
xslt/people2xhtml.xsl (Use whatever is specified in 2.b, but this is the standard naming convention.)

I recommend the second option. It is much less code (less chance of bugs), and takes advantage of Lenya's standards.

If the results are weird

Check your <map:serialize type="xml"/> and <map:serialize type="html"/>. If the XML is sent to a browser, it displays "only the cmsbody parts with a weird presentation, as if the XSL are not being found or correctly used."  The XSL is being used (Lenya would error if the file was missing or bad), but the results are not being converted to HTML. The latter statement displays HTML. Each entry pipeline must return HTML.  Pipelines used internally (such as the src of <map:part> or <map:generate>) should serialize XML.

<< Aggregate DirectoriesDeepestSourceFactory >>

Contact Solprovider
Paul Ercolino