Mark, Thanks for the pointer regarding the session object. I'll check it out. To get my document into the pipeline, I do the following:
Once I've stored the xml document in session I user the session generator in my pipeline to grab it and transform it:
<map:match pattern="internal/tree-menu"> <map:generate type="session-attr">
<map:parameter name="attr-name" value="hrcyDoc"/>
</map:generate>
<map:tansform src="xml2tree.xsl"/> <map:serialize type="html" />
</map:match>
The session-attr generator refers to the SessionAttributeGenerator, declared thus:
<map:generator name="session-attr" logger="sitemap.generator.session-attr" src="org.apache.cocoon.generation.SessionAttributeGenerator"/>
It just grabs a session attribute object which in this case is the xml document we've cobbled together from the flowscript.
Hope this helps!
Tony
Mark Lundquist wrote:
On Aug 4, 2004, at 6:18 PM, Tony Edwards wrote:
Hi Mark,
I'm using flow to create and modify an xml document which I then send
through a pipeline for display.
I've forgotten where I pinched the code from but here's an example:
Thanks for the reply! See below...
importClass(org.apache.xpath.XPathAPI); importClass(javax.xml.parsers.DocumentBuilderFactory); importClass(org.w3c.dom.Node);DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument()
importClass(org.w3c.dom.Element);
importClass(org.w3c.dom.NodeList);
function newDocument(root, attributeName, attributeVal) {
var result =
;
// Create a processing instruction targeted for xml.
var node = result.createProcessingInstruction("xml", "version='1.0'");
result.appendChild(node);
node = null;
// Create a comment for the document.
node = result.createComment(
"sample xml file created using XML DOM object.");
result.appendChild(node);
node=null;
result.appendChild(result.createElement(root));
print("Add attributes to root..." + attributeName);
if (attributeVal != null){
try {
print("creating attribute for root: " + attributeName);
var root = result.getFirstChild();
root.setAttribute(attributeName, attributeVal);
} catch (error) {
cocoon.log.error("Could not add attribute node to root: " +
error); } }
return result;
}
To load an existing document I use this:
// Load a document from an URI, absolute or relative to the current sitemap
function loadDocument(uri) {
var resolver = cocoon.getComponent("org.apache.excalibur.source.SourceResolver");
var source = resolver.resolveURI(uri);
try {
document = Packages.org.apache.cocoon.components.source.SourceUtil.toDOM(source);
} finally {
resolver.release(source);
cocoon.releaseComponent(resolver);
}
return document;
}
OK, that's all routine XML and Cocoon stuff...
I then add the document to the session:cocoon.getComponent("org.apache.cocoon.webapps.session.SessionManager")
var sessionManager =
;
var session = sessionManager.getSession(true);
FYI, you already have a global "session" object in flowscript, so you don't need that bit... see
http://cocoon.apache.org/2.1/userdocs/flow/api.html#Session+Object
session.setAttribute("hrcyDoc", hrcyDoc);
cocoon.sendPage("tree-menu");
the last step (sendPage("tree-menu")) renders the document as a tree using xslt.
OK, so what I need to know is, how does your "tree-menu" pipeline gets the DOM tree out of the session? You've stored it there, but how do you access it?
I was kinda surprised to find nothing in Cocoon to do this, and even Google came up empty-handed. I've been thinking of writing a generator
that would take the DOM tree (and/or an InputStream and/or String) in the context object, just like the "bizData" to JXTemplateGenerator, and
then just plumb that in to its xmlConsumer. So then I could call that pipeline from flowscript using sendPage()... WDYT?
~ml
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
