5.11.7 Samples
5.11.7.1 Daisy Wiki extension sample: publish document
This sample shows how to publish just one document.
To use, just surf to an URL like:
http://localhost:8888/daisy/<sitename>/ext/publishdoc/<documentId>
in which you need to replace <sitename> with the name of your site and <documentId> with the ID of a document.
This simple example can be useful if you want to integrate a "published document" into an external system. Compared to retrieving a document from the default Daisy URLs, this example will not do any redirecting based on the navigation tree, and doesn't translate links in the document based on the navigation tree, which is the behaviour you'll usually prefer for this kind of applications. It's also easy to modify the XSL to create an XML envelope around the document containing any additional information you may need.
Building on this example, you could also do things like composing a page consisting of multiple published documents, adding one or more navigation trees, etc. All this just by extending the publisher request and doing some appropriate XSLing on the result.
5.11.7.2 Daisy Wiki extension sample: RSS include
This sample shows you how to include a live import of an Atom/RSS feed into a document.
Quite often, such feeds include escaped HTML (i.e. with < and > encoded as < and >), so we need some way to reparse that HTML into proper XML which can be passed through the Daisy publishing pipelines. Luckily, a Cocoon component exists for this exact purpose: the HTMLTransformer which is embedded in the Cocoon HTML Block. The HTML Block isn't included by default in the Daisy distribution, but the compiled jar can be found at the iBiblio Maven repository. Copy cocoon-html-2.1.7.jar into $DAISY_HOME/daisywiki/webapp/WEB-INF/lib/ and you should be set.
Then, you need to define an extension pipeline which transforms Atom markup into HTML for inclusion into a Daisy document.
Create a directory myrss inside <wikidata directory>/sites/cocoon and add this sitemap.xmap to it:
<?xml version="1.0"?>
<map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0">
<map:components>
<map:transformers>
<map:transformer name="htmltransformer"
src="org.apache.cocoon.transformation.HTMLTransformer"/>
</map:transformers>
</map:components>
<map:views>
</map:views>
<map:resources>
</map:resources>
<map:pipelines>
<map:pipeline internal-only="true" type="noncaching">
<map:match pattern="myrss">
<map:generate src="/some/path/leading/upto/myatomfeed.xml"/>
<!-- Thanks to Cocoon, this path could also be a URL.
Keep in mind this URL will be accessed every time
the including document is retrieved! -->
<map:transform type="htmltransformer">
<map:parameter name="tags" value="content"/>
</map:transform>
<map:transform type="xalan" src="atom2html.xsl"/>
<map:serialize type="xml"/>
</map:match>
</map:pipeline>
</map:pipelines>
</map:sitemap>
Next, add this XSL stylesheet (atom2html.xsl) to the myrss directory:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:atom="http://purl.org/atom/ns#">
<xsl:template match="/">
<div>
<xsl:for-each select="/atom:feed/atom:entry">
<h2><xsl:value-of select="atom:title"/></h2>
<xsl:copy-of select="atom:content/html/body/*"/>
<p style="text-align: right; color: #999; font-size: 80%;">
Originally blogged by <xsl:value-of select="atom:author/atom:name"/> on
<a href="{atom:link/@href}"><xsl:value-of select="atom:issued"/></a>.
</p>
</xsl:for-each>
</div>
</xsl:template>
</xsl:stylesheet>
The last work is to include the snippet of generated HTML into a Daisy document. Add an "include"-style paragraph to the document content with this content:
cocoon:/ext/myrss/myrss
That's it! When you save the document, you'll see that the Atom feed is dynamically pulled into the webpage as a partial HTML document.
5.11.7.3 Daisy Wiki extension sample: guestbook
This sample illustrates using a form to collect data (based on Cocoon's form framework, CForms) and creating a document in the repository using the collected data. The theme of the sample is a "guestbook", though we don't want to publicise this as the correct way of building a guestbook.
This sample is not included in the by default deployed cross-site extensions, but must be manually 'installed' (copied) into a certain site, and requires some small customisation. See the directory <webapp>/daisy/ext-samples and the README.txt file over there.
5.11.7.4 Daisy Wiki extension sample: navigation aggregation
This example creates a page composed of all documents occurring in a navigation tree, in the order in which they occur in the navigation tree. It is also possible to limit the result to a certain subsection of the navigation tree.
To use, call an URL like:
http://localhost:8888/daisy/<sitename>/ext/navaggregator/navaggregator
in which you replace <sitename> by the name of your site.
To limit to a certain section of the navigation tree, add an activePath request parameter:
http://localhost:8888/daisy/<sitename>/ext/navaggregator/navaggregator?activePath=/abc/def
You can see the active path in the browser location bar when you move over nodes in a navigation tree, it is the part after the sitename.
The basic example is very simple, it could be extended do to things like:
- adding a table of contents with links to the documents
- supporting getting other navigation trees then the site default one
- support xslfo rendering.
All this isn't that particular difficult to realize either.
5.11.7.5 RSS
RSS feeds are provided in the Daisy Wiki as a cross-site
The URLs for the default feeds provided by this extension are (replace <sitename> with the name of a site):
http://localhost:8888/daisy/<sitename>/ext/rss/minimal-rss.xml http://localhost:8888/daisy/<sitename>/ext/rss/normal-rss.xml http://localhost:8888/daisy/<sitename>/ext/rss/editors-rss.xml
The differences between these feeds are:
- the minimal feed includes only the name of the documents with a recently published live version
- the normal feed includes only the whole rendered content of the documents with a recently published live version
- the editors feed includes both the rendered content and a diff with the previous version (if any) of the documents with a recently created version (regardless of whether the version is published)
The following notes apply to all the feeds.
- The feeds include the documents modified in the last 14 days, with a maximum of 20 items.
- The feeds are cached for 20 minutes, so changes can take up to 20 minutes to show up in the feed (see below for non-cached feeds)
- By default, the feeds are generated for the "guest" user. To specify another user, append ?login=...&password=... to the URL.
- By default, the feeds are generated for the locale "en-US". To specify another locale, append ?locale=... to the URL, e.g. ?locale=fr or ?locale=nl.
- For the minimal and normal feeds, documents of type Navigation, Image and Attachment are excluded.
Non-cached feeds can be accessed with the following URLs:
http://localhost:8888/daisy/<sitename>/ext/rss/minimal-rss-direct.xml http://localhost:8888/daisy/<sitename>/ext/rss/normal-rss-direct.xml http://localhost:8888/daisy/<sitename>/ext/rss/editors-rss-direct.xml
To have RSS-links appear on the recent changes page, the RSS feeds need to be configured in the skinconf.xml. The default skinconf.xml contains the config for the above RSS feeds, so you can have a look there to see how its done.
Previous