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);
importClass(org.w3c.dom.Element);
importClass(org.w3c.dom.NodeList);


function newDocument(root, attributeName, attributeVal) {
var result = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument() ;


// 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:
var sessionManager = cocoon.getComponent("org.apache.cocoon.webapps.session.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]



Reply via email to