cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daniel Fagerstrom <>
Subject [cforms] Simple XML binding
Date Tue, 08 Jun 2004 16:11:41 GMT
I have written an adapter: org.apache.cocoon.forms.util.XMLAdapter 
between a form object and a simple XML format that can be used without 
needing to wriite a binding definition.

In the applications where we have used cforms we mostly have connected 
the form objects to XML through the binding framework. While the binding 
framework has a lot of flexibility in how to bind the form to DOM, we 
usually have used a more or less 1-1 coupling between DOM and the form. 
So the flexibilty of the binding framework feels in our applications 
like overkill and writing the bindings unnecessary.

                              --- o0o ---

The XML format is such that there is one XML element for each widget and 
the element get the widget id as name. Exceptions from this is that the 
elements in a repeater gets the name "item" and a attribute "position" 
with the position of the repeater child, instead of just a number (which 
is not allowed as element name). Childs of a MultiValueField are also 
embeded within an "item" element. If the Form widget does not have an id 
it get the name "unknown". I added the possiblity to give an id to the 
Form widget.

An AggregateField can both be interpreted as one value and as several 
widgets. This ambiguity is resolved by chosing to emit the single value 
rather than the fields as XML. For population of the form both forms are 
however allowed.

XMLAdapter implements XMLConsumer and XMLizable, so it can be used both 
as a SAX source and destination. I added a utility function to forms.js: 
getXML(), that returns the widget wrapped in an XMLAdapter. A typical 
flowscript can look like:

function form2simpleXML(form) {
     // get the documentURI parameter from the sitemap which contains the
     // location of the file to be edited
     var documentURI = cocoon.parameters["documentURI"];

     // get the XML adapter
     var xmlAdapter = form.getXML();

     // parse the document to a widget tree
     var pipeUtil =
     pipeUtil.processToSAX(documentURI, null, xmlAdapter);

     // show the form to the user until it is validated successfully

     // show the xml generated from the form
     cocoon.sendPage("form2simpleXML-success-pipeline", xmlAdapter);

I also checked in a sample, (a variant of the binding sample), that show 
  how to use the adapter.



View raw message