[daisy] Get complete navigation Tree
Bruno Dumon
bruno at outerthought.org
Tue May 6 22:44:55 CEST 2008
Greg,
It seems like the navaggregator is pushing you in the wrong direction.
The only reason to look at the navaggregator is for same API examples of
how to use the NavigationManager component.
What the navaggregator does is:
a. it retrieves the navigation tree
b. it dynamically generates a publisher request to get the content of
each the documents listed in the navigation tree
c. publishes all that on one page
You only need step a. The navaggregator is much more complex than what
you need :-)
The result XML you get from the navigation manager looks like this:
<navigationTree xmlns="http://outerx.org/daisy/1.0#navigation" completeTree="false">
<doc id="index" documentId="2-cd" branchId="1" languageId="2" label="Home" path="/index" hasChildren="true" access="read,fullRead">
<doc id="news" documentId="100-cd" branchId="1" languageId="2" label="News & blogs" path="/index/news" hasChildren="false" access="read,fullRead"/>
<doc id="110-cd" documentId="110-cd" branchId="1" languageId="2" label="Background FAQ" path="/index/110-cd" hasChildren="false" access="read,fullRead"/>
<doc id="53-cd" documentId="53-cd" branchId="1" languageId="2" label="Screenshots" path="/index/53-cd" hasChildren="false" access="read,fullRead"/>
</doc>
<doc id="features" documentId="3-cd" branchId="1" languageId="2" label="Features" path="/features" hasChildren="false" access="read,fullRead"/>
<doc id="44-cd" documentId="44-cd" branchId="1" languageId="2" label="License" path="/44-cd" hasChildren="false" access="read,fullRead"/>
<doc id="45-cd" documentId="45-cd" branchId="1" languageId="2" label="Community" path="/45-cd" hasChildren="false" access="read,fullRead"/>
<link label="Documentation Daisy 2.2" id="l1" path="/l1" url="/daisydocs-2_2"/>
<doc id="342-cd" documentId="342-cd" branchId="1" languageId="2" label="Documentation other releases" path="/342-cd" hasChildren="false" access="read,fullRead"/>
<link label="Knowledgebase" id="l2" path="/l2" url="/kb"/>
<link label="Wiki" id="l3" path="/l3" url="/wiki"/>
<link label="Issue tracker" id="l4" path="/l4" url="http://issues.cocoondev.org/secure/BrowseProject.jspa?id=10030"/>
</navigationTree>
Based on this, it is very simple to generate the paths of the documents,
just concat the id attributes with a slash between them, e.g.
'index/news'. Optionally add ".html" at the end.
BTW, I got this data simply by putting this URL in my browser:
http://cocoondev.org:9263/navigation/tree?navigationDocId=1-cd&navigationDocBranch=main&navigationDocLanguage=en&contextualized=false&handleErrors=false
(won't work for you as port 9263 doesn't seem to be publicly accessible)
I don't have time to put together a complete example (maybe someone else
does), but this is the relevant code you need from the navaggregator:
var daisy = getDaisy();
var pageContext = daisy.getPageContext();
var repository = daisy.getRepository();
var siteConf = daisy.getSiteConf();
// Retrieve a generated navigation tree
var activePath = cocoon.request.getParameter("activePath");
var navigationData = new SaxBuffer();
var navigationManager = repository.getExtension("NavigationManager");
var navigationParams = new NavigationParams(siteConf.getNavigationDoc(), activePath, false);
navigationManager.generateNavigationTree(navigationData, navigationParams, null, true);
After this, pass the navigationData variable via the viewData to a
pipeline:
var viewData = new Object();
viewData["navigationData"] = navigationData;
cocoon.sendPage("MySitemapPipeline", viewData);
The pipeline would look something like this:
<map:match pattern="MySitemapPipeline">
<map:generate type="jx" src="page.xml"/>
<map:serialize type="xml"/>
</map:match>
with the page.xml containing something like
<page>${navigationData}</page>
Once this is done, you should see the raw navigation XML as shown above.
To get it to the format you desire, put an XSLT in between the
map:generate and map:serialize. If you can't write such an XSLT, ask
someone for help :-) (as Karel suggested, looking at the navigation.xsl
might help)
Nowhere in the solution, you should be doing things with
"p:publisherResponse/p:document" or with the DaisyLinks transformer.
On Tue, 2008-05-06 at 14:28 -0400, Sieranski, Greg wrote:
> We are currently running into a problem where the url is not displaying
> the nodeId. Using the navaggregator example I modified the
> navaggr_result.xsl to be:
>
> <xsl:for-each select="p:publisherResponse/p:document">
> <a
> href="daisy:{@documentId}@{@branchId}:{@languageId}"><xsl:value-of
> select="@documentId"/></a>
> </xsl:for-each>
>
> I then changed the sitemap to:
> <map:match pattern="navaggr-result">
> <map:generate type="jx" src="navaggr_result.xml"/>
> <map:transform src="navaggr_result.xsl"/>
> <map:transform type="DaisyLinks"/>
> <map:transform type="serializer"/>
> <map:serialize type="xml"/>
> </map:match>
> </map:pipeline>
>
> this gave us <a href="/foo/2-DSY.html?branch=1&language=1">2-DSY</a> but
> we need the node id not documentID. So we want <a
> href="/foo/foo-home.html?branch=1&language=1">2-DSY</a>
>
> Is there a way to get the nodeId instead of the documentId?
>
> --
> Regards,
> </Greg>
--
Bruno Dumon http://outerthought.org/
Outerthought http://www.daisycms.org/
bruno at outerthought.org http://www.kauriproject.org/
More information about the daisy
mailing list