cocoon-docs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@cocoon.apache.org
Subject [Cocoon Wiki] Updated: FlowBasedXMLEditor
Date Thu, 16 Sep 2004 04:08:45 GMT
   Date: 2004-09-15T21:08:44
   Editor: TonyEdwards <anthonybedwards@optusnet.com.au>
   Wiki: Cocoon Wiki
   Page: FlowBasedXMLEditor
   URL: http://wiki.apache.org/cocoon/FlowBasedXMLEditor

   no comment

Change Log:

------------------------------------------------------------------------------
@@ -1,5 +1,5 @@
-==  Page title (cookbook approach, tutorial , ...) ==
-- TARGET-AUDIENCE: '''*beginner*''' advanced expert[[BR]]
+==  Creating and Editing XML Documents using FLow  ==
+- TARGET-AUDIENCE: beginner '''*advanced*''' expert[[BR]]
 - COCOON-RELEASES: 2.1.4, 2.1.5[[BR]]
 - DOCUMENT-STATUS: '''*draft*''' reviewed released[[BR]]
 ----
@@ -9,7 +9,7 @@
 === Your basic skills ===
 Comfortable with Flowscript
 === Technical prerequisites ===
-
+Cocoon 2.1.5
 === Links to other information sources ===
 
 ----
@@ -17,7 +17,9 @@
 - AUTHOR: Tony Edwards[[BR]]
 - AUTHOR-CONTACT: anthonybedwards AT optusnet DOT com DOT au[[BR]]
 - REVIEWED-BY:[[BR]]
+
 - REVIEWER-CONTACT:[[BR]]
+
 My first cocoon application was a simple xml editor written under version 2.0.4.
 [[BR]]It utilised actions extensively and became a bit of a maintenance nightmare. It basically
allowed the user to create, edit and render into different formats an xml document derived
from a proprietory namespace. One of my greatest reservations about this method was the heavy
emphasis on Java as I'm not much of a java programmer at all.
 [[BR]]When 2.1.4 came along I though I'd port the application and jazz it up at the same
time. I managed to scrape up enough examples and snippets to come up with a fairly usable
solution.
@@ -29,14 +31,26 @@
 [[BR]]importClass(org.w3c.dom.Element);
 [[BR]]importClass(org.w3c.dom.NodeList);
 [[BR]] Thereafter is became an exercise in wrapping the DOM functions in flow script. Attached
is my general purpose jsUtils.js file which contains all the necessary methods to carry out
DOM manipulation. If anyone can see any obvious flaws, please let me know!
-To create a new document, pass the name of the document to the newDocument function. Adding
attributes is as simple as calling addAttribute. If the nodeParent parameter is null, the
attribute gets assigned to the document root.
-The use of the sessionManager is interesting. I couldn't for the life of me get a reference
to the DOM if I used the cocoon.session object. I don't know why. I scoured all manner of
places and found the use of the sessionManager, stuck the document in there, and then I was
able to access the DOM from the pipeline. Maybe I missed something, but it works.
+To create a new document, pass the name of the document to the '''newDocument''' function.
Adding attributes is as simple as calling '''addAttribute'''. If the nodeParent parameter
is null, the attribute gets assigned to the document root.
+[[BR]]The use of the '''sessionManager''' is interesting. 
+[[BR]]I couldn't for the life of me get a reference to the DOM if I used the '''cocoon.session'''
object. I don't know why. I scoured all manner of places and found the use of the sessionManager,
stuck the document in there, and then I was able to access the DOM from the pipeline. Maybe
I missed something, but it works.
+[[BR]]
+[[BR]] var sXmlName = "TestDoc";
+[[BR]]    var xmlDoc = newDocument("hierarchy","description",Trim(sXmlName));
+[[BR]]    //Make its hierarchy number = 0 so we know its a newy
+[[BR]]    addAttribute(xmlDoc,null,"hrcyNumber",0);
+[[BR]] 	var sessionManager = cocoon.getComponent("org.apache.cocoon.webapps.session.SessionManager");
+[[BR]]	var session = sessionManager.getSession(true);
+[[BR]]	session.setAttribute("hrcyDoc", hrcyDoc);
+[[BR]]	cocoon.sendPage("tree-menu");		
+[[BR]]
+[[BR]] The sitemap pipeline that process the evergrowing document looks like this (note the
name of the session attribute):
+[[BR]]            <map:match pattern="internal/tree-menu">            
+[[BR]]				<map:generate type="session-attr">
+[[BR]]					<map:parameter name="attr-name" value="xmlDoc"/>
+[[BR]]				</map:generate>								
+[[BR]]	            <map:serialize type="xml" />
+[[BR]]            </map:match>
+[[BR]]
+[[BR]] I then render this up using some javascript tree widget functions to provide the user
with a fairly snappy tree based XML representaiton of their document.
 
- var sXmlName = "TestDoc";
-    var xmlDoc = newDocument("hierarchy","description",Trim(sXmlName));
-    //Make its hierarchy number = 0 so we know its a newy
-    addAttribute(xmlDoc,null,"hrcyNumber",0);
- 	var sessionManager = cocoon.getComponent("org.apache.cocoon.webapps.session.SessionManager");
-	var session = sessionManager.getSession(true);
-	session.setAttribute("hrcyDoc", hrcyDoc);
-	cocoon.sendPage("tree-menu");		

Mime
View raw message