Return-Path: Delivered-To: apmail-xml-cocoon-dev-archive@xml.apache.org Received: (qmail 54074 invoked by uid 500); 15 Feb 2002 17:18:28 -0000 Mailing-List: contact cocoon-dev-help@xml.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: list-post: Reply-To: cocoon-dev@xml.apache.org Delivered-To: mailing list cocoon-dev@xml.apache.org Received: (qmail 54061 invoked from network); 15 Feb 2002 17:18:27 -0000 From: "Piroumian, Konstantin" To: cocoon-dev@xml.apache.org Message-ID: <010101c1b644$c7a36490$6150000a@flagship.ru> References: <85BCB1287CF1D41197570090279A6A0D03952D57@ES02-AUS.bmc.com> Subject: Re: Cocoon, XForms, ExFormula, Chiba, Struts, etc Date: Fri, 15 Feb 2002 20:18:26 +0300 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_00FE_01C1B65D.ECB05F40" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N ------=_NextPart_000_00FE_01C1B65D.ECB05F40 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit > > Thanks for the response fellows. I'm glad this is still considered a > feasible subject. > > Yes, I've looked at XForms and: > 1) It is what I believe we should be shooting for instead of full XForms > support. > Believe me, Struts is extremely useful when you need HTML Forms/Java > binding. > 2) We could use plenty of Struts architecture to add the extra XML layer: > HTML Forms <-> XML/SAX <-> JavaBeans. Excellent tools are already available > for that: Castor (or JAXB), Xerces2 (XML Schema validation) and again Strut' > source base. > 3) I've customized Struts for our project's needs quite a bit and have grown > to understand that it's a very well written tool, which demonstrates lots of > best practices. I've been using Struts for our project, but after using Cocoon some parts of Struts seemed to me a little limiting. From the other point of view, it's perfect for any JavaBean/JSP project. One problem can be that you have to create special FormBean classes for every form or a group of forms. Another thing is that you can't have dynamic forms. > > XPath is obviously a more standard and powerful tool one could use to achive > similar effect. > Two excelent tools are available to do the reflection job for free: > http://jaxen.org/ and http://saxpath.org/ I've created a simple class to test the get and set possibilities by Xpath. You'll find it in the attached files (it requires Xalan and Xerces). The main problem were the perfomance - it takes about 20ms to select a value and a couple of hunderd of ms to set a value with node creation. > > So, using a similar descriptor concept to struts-config.xml, one could > describe: > > a) a form name that maps to a Java Bean class One-to-one relationship between a form and JavaBean is not enough. Very often, I have to use multiple value objects in my forms. So it will be many-to-many, cause you can have also multiple forms on a page. > b) using JAXB (or Castor) one can map the JavaBeans class to XML > representation Agree. For not default mapping you should create a special mapping file. > c) with Jaxen/SaxPath one can acomplish automated population/serialization > of (name=XpathExpression, value=String) to and from HTML POST <-> JavaBean But notice, that you should have created that JavaBean objects before populating them with values. > d) Xerces2 can validate the resulting JavaBean through JAXB SAX parsing > agains an XML Schema. What if the user entered data in incorrect format, e.g. incorrect date and you have a Date field in your bean? Maybe it's better to perform validation before mapping it to JavaBeans? > > At the end the only hard part would seem to be the xsl sheet which converts > an XML form into a client specific format, that will allow customization > like: This part seems to me the less complicated. It can be a set of standart XSL stylesheets, that can be used as is or be included/imported to user stylesheets that can override some templates to add customization. > onFocus="doSomethingElse"/> > > Without the customization part, translating: > > to > > using a generic cocoonform2html.xsl seems trivial. I think that we will need several transformations until the user will get his page. Best regards, Konstantin Piroumian Leading Software Developer Protek Flagship LLC Phone: + 7 095 795 0520 (add. 1288) Fax: + 7 095 795 0525 E-mail: kpiroumian@flagship.ru http://www.protek.com > > > -- > > Sorry for yet another long message. As Steffano cited Pascal, didn't have > time to make it shorter :) > > > Am I dreaming too much? > > > > -= Ivelin =- > > -----Original Message----- > From: Peter Velichko [mailto:peter@softline.kiev.ua] > Sent: Friday, February 15, 2002 6:38 AM > To: cocoon-dev@xml.apache.org > Subject: RE: Cocoon, XForms, ExFormula, Chiba, Struts, etc > > > Did anyone look at http://xform.nanoworks.org? > It is client-side and server-side form validator. > XForm uses Xerces XML Parser and have LGPL license. > > > -----Original Message----- > From: Torsten Curdt [mailto:tcurdt@dff.st] > Sent: Friday, February 15, 2002 1:49 PM > To: cocoon-dev@xml.apache.org > Subject: Re: Cocoon, XForms, ExFormula, Chiba, Struts, etc > > > > > > > > Can we try to unify and finish the job started, so that Cocoon moves to > the > > > next level. > > Would be cool... > > > There isn't anything on the architecture of chiba available so I have > > no idea how closely related chiba to XForms support in Cocoon would > > be. > > I've also tried to find some information about chiba... didn't yet have > the time to install and try it out. > > Although I guess XForm is about to become a RC sooner or later it doesn't > yet go well with the current technologies available. > > Looking into XUL from mozilla could be an interesting alternative... > (although they do not aim completely into the same direction!!) > > http://www.mozilla.org/xpfe/xulref/ > > I haven't had a look into the XForm spec since the exformula stuff. I hope > they fixed some stuff. That days it still felt somehow immature. They spec > didn't say anything how selected options in a multi select optionbox was > supposed to look like in the instance e.g. :-/ > > I am back again a bit sceptic... > > > For Cocoon, I see two different and in part unrelated areas: > > a) populate the form > > b) Given that the client does support XForms, migrate the existing > > actions to be XForms based i.e. make them aware of the changed > > communication protocol. > > c) For clients that do not support XForms > > c1) have XForms output translated to XHTML > > c2) have the returned results transformed to an XML representation > > like an XForms aware client would generate. > > c3) validate the input > > ok > > > I'm currently working on decoupling sitemap components from the input > > layer, making that plugable. I think it could help with b) > > Sounds interesting... could already post some more information. We've > maybe implemented something similar... > > > I think c2) would be easy. I'm not quite sure if suitable components > > exist already. I believe I came across some that looked quite > > promising but didn't investigate it any further. > > > > For c3 it looked like that could be done by e.g. Xerces like you said > > above. > > > > Probably c1 is the most complicated part. > > As I remember c1) isn't yet possible with the current XSLT > spec/implementation. It's only possible with extension functions :-(ugly) > -- > Torsten > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org > For additional commands, email: cocoon-dev-help@xml.apache.org > > > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org > For additional commands, email: cocoon-dev-help@xml.apache.org > > --------------------------------------------------------------------- > To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org > For additional commands, email: cocoon-dev-help@xml.apache.org > ------=_NextPart_000_00FE_01C1B65D.ECB05F40 Content-Type: application/octet-stream; name="XData.java" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="XData.java" package com.protek.abs.apps.basis.xdata;=0A= =0A= import org.w3c.dom.*;=0A= import org.xml.sax.InputSource;=0A= =0A= import javax.xml.parsers.*;=0A= import javax.xml.transform.TransformerException;=0A= =0A= // this must be moved to a wrapper to be independend of Apache=0A= import org.apache.xpath.*;=0A= import org.apache.xpath.objects.*;=0A= =0A= /**=0A= * Title: ABS - advanced billing system=0A= * Description:=0A= * Copyright: Copyright (c) 2001=0A= * Company: Protek Flagship LLC=0A= * @author Konstantin Piroumian=0A= * @version 1.0=0A= */=0A= =0A= public class XData implements XDataInterface {=0A= =0A= Document doc;=0A= Node root;=0A= Node contextNode;=0A= =0A= public XData() throws XDataException {=0A= initialize();=0A= }=0A= =0A= public XData(InputSource is) throws XDataException {=0A= initialize(is);=0A= }=0A= =0A= protected void initialize() throws XDataException {=0A= doc =3D newDocument();=0A= root =3D doc.createDocumentFragment();=0A= doc.appendChild(root);=0A= contextNode =3D root;=0A= }=0A= =0A= protected void initialize(InputSource is) throws XDataException = {=0A= doc =3D getDocument(is);=0A= root =3D doc.getDocumentElement();=0A= contextNode =3D root;=0A= }=0A= =0A= // XDataInterface implementation=0A= public String getValue(String xpath) throws XDataException{=0A= try {=0A= return XPathAPI.eval(contextNode, xpath).toString();=0A= } catch (TransformerException te) {=0A= throw new XDataException(te);=0A= }=0A= }=0A= =0A= public void setValue(String xpath, String value) throws = XDataException {=0A= try {=0A= Node node =3D XPathAPI.selectSingleNode(contextNode, = xpath);=0A= if (node !=3D null) {=0A= switch (node.getNodeType()) {=0A= case Node.TEXT_NODE:=0A= case Node.ATTRIBUTE_NODE: {=0A= node.setNodeValue(value);=0A= break;=0A= }=0A= case Node.ELEMENT_NODE: {=0A= Node child =3D XPathAPI.selectSingleNode(node, = "text()");=0A= if (child =3D=3D null) {=0A= child =3D doc.createTextNode(value);=0A= node.appendChild(child);=0A= }=0A= else {=0A= child.setNodeValue(value);=0A= }=0A= break;=0A= }=0A= }=0A= }=0A= } catch (TransformerException te) {=0A= throw new XDataException(te);=0A= }=0A= }=0A= =0A= public void addValue(String xpath, String value) throws = XDataException {=0A= // try {=0A= // // FIXME How to implement this?=0A= // } catch (TransformerException te) {=0A= // throw new XDataException(te);=0A= // }=0A= }=0A= =0A= public String removeValue(String xpath) throws XDataException {=0A= try {=0A= Node node =3D XPathAPI.selectSingleNode(contextNode, = xpath);=0A= if (node !=3D null) {=0A= return = node.getParentNode().removeChild(node).toString();=0A= }=0A= else {=0A= throw new XDataException("Cannot remove value by = expression: " + xpath);=0A= }=0A= =0A= } catch (TransformerException te) {=0A= throw new XDataException(te);=0A= }=0A= }=0A= =0A= public Node setContextNode(String xpath) throws XDataException {=0A= try {=0A= Node node =3D XPathAPI.selectSingleNode(doc, xpath);=0A= if (node !=3D null) {=0A= contextNode =3D node;=0A= return contextNode;=0A= }=0A= else {=0A= throw new XDataException("Could not set context node = to: " + xpath);=0A= }=0A= } catch (TransformerException te) {=0A= throw new XDataException(te);=0A= }=0A= }=0A= =0A= public static Document newDocument()=0A= throws XDataException=0A= {=0A= try {=0A= DocumentBuilder db =3D = DocumentBuilderFactory.newInstance().newDocumentBuilder();=0A= return db.newDocument();=0A= } catch (ParserConfigurationException pce) {=0A= throw new XDataException(pce);=0A= }=0A= }=0A= =0A= public static Document getDocument(InputSource is)=0A= throws XDataException=0A= {=0A= try {=0A= DocumentBuilder db =3D = DocumentBuilderFactory.newInstance().newDocumentBuilder();=0A= return db.parse(is);=0A= } catch (ParserConfigurationException pce) {=0A= throw new XDataException(pce);=0A= }=0A= catch (java.io.IOException ioe) {=0A= throw new XDataException(ioe);=0A= }=0A= catch (org.xml.sax.SAXException se) {=0A= throw new XDataException(se);=0A= }=0A= }=0A= =0A= =0A= /**=0A= *=0A= */=0A= public static void main(String[] args) {=0A= try {=0A= java.io.StringReader sr =3D new java.io.StringReader(=0A= ""=0A= + ""=0A= + ""=0A= + ""=0A= + ""=0A= );=0A= InputSource is =3D new InputSource(sr);=0A= XDataInterface xd =3D new XData(is);=0A= =0A= String setPath =3D "/person/first_name[@id=3D'1']";=0A= String getPath =3D "/person/first_name[2]";=0A= =0A= long time =3D System.currentTimeMillis();=0A= xd.setValue(setPath, "Konstantin");=0A= time =3D System.currentTimeMillis() - time;=0A= System.out.println("SET value to '" + setPath + "' = processed in: " + time + " ms");=0A= =0A= time =3D System.currentTimeMillis();=0A= String value =3D xd.getValue(getPath);=0A= time =3D System.currentTimeMillis() - time;=0A= System.out.println("Value of '"+ getPath +"': " + = value);=0A= System.out.println("GET processed in: " + time + " ms");=0A= } catch (Exception e) {=0A= System.out.println("Error!!!");=0A= e.printStackTrace();=0A= }=0A= }=0A= }=0A= =0A= =0A= =0A= =0A= ------=_NextPart_000_00FE_01C1B65D.ECB05F40 Content-Type: application/octet-stream; name="XDataInterface.java" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="XDataInterface.java" package com.protek.abs.apps.basis.xdata;=0A= =0A= /**=0A= * Title: ABS - advanced billing system=0A= * Description:=0A= * Copyright: Copyright (c) 2001=0A= * Company: Protek Flagship LLC=0A= * @author Konstantin Piroumian=0A= * @version 1.0=0A= */=0A= =0A= public interface XDataInterface {=0A= public String getValue(String xpath) throws XDataException;=0A= public void setValue(String xpath, String value) throws = XDataException;=0A= public void addValue(String xpath, String value) throws = XDataException;=0A= public String removeValue(String xpath) throws XDataException;=0A= } ------=_NextPart_000_00FE_01C1B65D.ECB05F40 Content-Type: application/octet-stream; name="XDataException.java" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="XDataException.java" package com.protek.abs.apps.basis.xdata;=0A= =0A= /**=0A= * Title: ABS - advanced billing system=0A= * Description:=0A= * Copyright: Copyright (c) 2001=0A= * Company: Protek Flagship LLC=0A= * @author Konstantin Piroumian=0A= * @version 1.0=0A= */=0A= =0A= public class XDataException extends Exception {=0A= public XDataException(Exception e) {=0A= super(e.getMessage());=0A= }=0A= =0A= public XDataException(String s) {=0A= super(s);=0A= }=0A= } ------=_NextPart_000_00FE_01C1B65D.ECB05F40 Content-Type: text/plain; charset=us-ascii --------------------------------------------------------------------- To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org For additional commands, email: cocoon-dev-help@xml.apache.org ------=_NextPart_000_00FE_01C1B65D.ECB05F40--