Return-Path: Delivered-To: apmail-cocoon-cvs-archive@www.apache.org Received: (qmail 70293 invoked from network); 20 Mar 2005 15:41:05 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 20 Mar 2005 15:41:05 -0000 Received: (qmail 52711 invoked by uid 500); 20 Mar 2005 15:41:05 -0000 Delivered-To: apmail-cocoon-cvs-archive@cocoon.apache.org Received: (qmail 52672 invoked by uid 500); 20 Mar 2005 15:41:04 -0000 Mailing-List: contact cvs-help@cocoon.apache.org; run by ezmlm Precedence: bulk Reply-To: dev@cocoon.apache.org list-help: list-unsubscribe: List-Post: Delivered-To: mailing list cvs@cocoon.apache.org Received: (qmail 52658 invoked by uid 99); 20 Mar 2005 15:41:04 -0000 X-ASF-Spam-Status: No, hits=-9.8 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from minotaur.apache.org (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Sun, 20 Mar 2005 07:41:04 -0800 Received: (qmail 70258 invoked by uid 65534); 20 Mar 2005 15:41:03 -0000 Message-ID: <20050320154103.70257.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Mailer: svnmailer-1.0.0-dev Date: Sun, 20 Mar 2005 15:41:02 -0000 Subject: svn commit: r158332 - in cocoon/blocks/core/forms/trunk: WEB-INF/xconf/ java/org/apache/cocoon/forms/datatype/convertor/ java/org/apache/cocoon/forms/datatype/typeimpl/ samples/flow/ To: cvs@cocoon.apache.org From: giacomo@apache.org X-Virus-Checked: Checked X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: giacomo Date: Sun Mar 20 07:41:01 2005 New Revision: 158332 URL: http://svn.apache.org/viewcvs?view=3Drev&rev=3D158332 Log: new Datatypes and its Convertor Added: cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/datatype/co= nvertor/BeanConvertor.java cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/datatype/co= nvertor/BeanConvertorBuilder.java cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/datatype/ty= peimpl/BeanType.java cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/datatype/ty= peimpl/BeanTypeBuilder.java Modified: cocoon/blocks/core/forms/trunk/WEB-INF/xconf/cocoon-forms.xconf cocoon/blocks/core/forms/trunk/samples/flow/binding_example.js Modified: cocoon/blocks/core/forms/trunk/WEB-INF/xconf/cocoon-forms.xconf URL: http://svn.apache.org/viewcvs/cocoon/blocks/core/forms/trunk/WEB-INF/x= conf/cocoon-forms.xconf?view=3Ddiff&r1=3D158331&r2=3D158332 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- cocoon/blocks/core/forms/trunk/WEB-INF/xconf/cocoon-forms.xconf (origin= al) +++ cocoon/blocks/core/forms/trunk/WEB-INF/xconf/cocoon-forms.xconf Sun Mar= 20 07:41:01 2005 @@ -108,6 +108,11 @@ + + + + + Added: cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/datatype= /convertor/BeanConvertor.java URL: http://svn.apache.org/viewcvs/cocoon/blocks/core/forms/trunk/java/org/= apache/cocoon/forms/datatype/convertor/BeanConvertor.java?view=3Dauto&rev= =3D158332 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/datatype/co= nvertor/BeanConvertor.java (added) +++ cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/datatype/co= nvertor/BeanConvertor.java Sun Mar 20 07:41:01 2005 @@ -0,0 +1,145 @@ +/* + * Copyright 1999-2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cocoon.forms.datatype.convertor; + +import org.apache.avalon.framework.CascadingRuntimeException; +import org.apache.commons.jxpath.JXPathContext; + +import org.xml.sax.ContentHandler; +import org.xml.sax.SAXException; + +import java.util.Locale; +import java.util.Map; +import java.util.WeakHashMap; + + +/** + * Converts String representation of beans to bean instances and vice vers= a=2E + *=20 + *

+ * Sometimes the toString() method doesn't give a good representation of a + * Java Bean suited for selection list IDs. For this an optional =20 + * <fd:id-path>jx-path</fd:id-path> attribute can be specified= to=20 + * have this convertor to use a different string representation. + *

+ * + * @author Giacomo Pati + * @version $Id: BeanConvertor.java,v 1.3 2004/12/30 13:37:45 giacomo Exp $ + */ +public class BeanConvertor + implements Convertor +{ + //~ Instance fields --------------------------------------------------= ------ + + private Class m_class; + + private Map m_objects =3D new WeakHashMap( ); + + private String m_idPath; + + //~ Constructors -----------------------------------------------------= ------ + + /** + * Construct a new BeanConvertor for a class + * + * @param className The package-qualified name of the class implementi= ng + * the typesafe enum pattern. + * @param idPath Path to the identity field of the bean + * + * @throws CascadingRuntimeException If the class cannot be found + */ + public BeanConvertor( final String className, + final String idPath ) + { + try + { + m_class =3D Class.forName( className ); + } + catch( ClassNotFoundException e ) + { + throw new CascadingRuntimeException( "Class " + className + + " not found", e ); + } + + m_idPath =3D idPath; + } + + //~ Methods ----------------------------------------------------------= ------ + + /** + * @see org.apache.cocoon.forms.datatype.convertor.Convertor#getTypeCl= ass() + */ + public Class getTypeClass( ) + { + return m_class; + } + + /** + * @see org.apache.cocoon.forms.datatype.convertor.Convertor#convertFr= omString(java.lang.String, + * java.util.Locale, + * org.apache.cocoon.forms.datatype.convertor.Convertor.FormatCac= he) + */ + public ConversionResult convertFromString( final String value, + final Locale locale, + final FormatCache formatCac= he ) + { + return new ConversionResult( m_objects.get( value ) ); + } + + /** + * @see org.apache.cocoon.forms.datatype.convertor.Convertor#convertTo= String(java.lang.Object, + * java.util.Locale, + * org.apache.cocoon.forms.datatype.convertor.Convertor.FormatCac= he) + */ + public String convertToString( final Object value, + final Locale locale, + final FormatCache formatCache ) + { + String idValue =3D ""; + + if( null !=3D value ) + { + if( m_idPath !=3D null ) + { + final JXPathContext ctx =3D JXPathContext.newContext( valu= e ); + idValue =3D ctx.getValue( m_idPath ).toString( ); + } + else + { + idValue =3D value.toString( ); + } + } + + m_objects.put( idValue, value ); + + return idValue; + } + + /** + * We do not enerate any SAX events + * + * @param contentHandler The contentHandler + * @param locale The locale + * + * @throws SAXException Just in case of failure that could never happen + */ + public void generateSaxFragment( final ContentHandler contentHandler, + final Locale locale ) + throws SAXException + { + // intentionally empty + } +} Added: cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/datatype= /convertor/BeanConvertorBuilder.java URL: http://svn.apache.org/viewcvs/cocoon/blocks/core/forms/trunk/java/org/= apache/cocoon/forms/datatype/convertor/BeanConvertorBuilder.java?view=3Daut= o&rev=3D158332 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/datatype/co= nvertor/BeanConvertorBuilder.java (added) +++ cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/datatype/co= nvertor/BeanConvertorBuilder.java Sun Mar 20 07:41:01 2005 @@ -0,0 +1,79 @@ +/* + * Copyright 1999-2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cocoon.forms.datatype.convertor; + +import org.apache.cocoon.forms.Constants; +import org.apache.cocoon.forms.util.DomHelper; + +import org.w3c.dom.Element; + + +/** + * Creates {@link BeanConvertor}s + *=20 + *

+ * The optional <fd:bean>FQCN</fd:bean> attribute is used to g= ive=20 + * this convertor a hint of which concrete bean class we are going to work= with. + * If this attribute is not specified java.lang.Object is used. + *

+ * Sometimes the toString() method doesn't give a good representation of a + * Java Bean suited for selection list IDs. For this an optional =20 + * <fd:id-path>jx-path</fd:id-path> attribute can be specified= to=20 + * have this convertor to use a different string representation. + *

+ * + * @author Giacomo Pati + * @version $Id: BeanConvertorBuilder.java,v 1.2 2004/12/27 13:30:48 giaco= mo Exp $ + */ +public class BeanConvertorBuilder + implements ConvertorBuilder +{ + //~ Methods ----------------------------------------------------------= ------ + + /** + * Build a {@link BeanConvertor} + * + * @param configElement The configuration element + * + * @return An initialized {@link Convertor} + * + * @throws Exception In case of failure + */ + public Convertor build( final Element configElement ) + throws Exception + { + if( configElement =3D=3D null ) + { + return null; + } + + final Element beanEl =3D + DomHelper.getChildElement( configElement, Constants.DEFINITION= _NS, + "bean", false ); + final String clazz =3D + ( ( beanEl =3D=3D null ) ? Object.class.getName( ) + : beanEl.getFirstChild( ).getNodeValue( ) ); + final Element idPathEl =3D + DomHelper.getChildElement( configElement, Constants.DEFINITION= _NS, + "id-path", false ); + final String idPath =3D + ( ( idPathEl !=3D null ) + ? idPathEl.getFirstChild( ).getNodeValue( ) : null ); + final BeanConvertor convertor =3D new BeanConvertor( clazz, idPath= ); + + return convertor; + } +} Added: cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/datatype= /typeimpl/BeanType.java URL: http://svn.apache.org/viewcvs/cocoon/blocks/core/forms/trunk/java/org/= apache/cocoon/forms/datatype/typeimpl/BeanType.java?view=3Dauto&rev=3D158332 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/datatype/ty= peimpl/BeanType.java (added) +++ cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/datatype/ty= peimpl/BeanType.java Sun Mar 20 07:41:01 2005 @@ -0,0 +1,75 @@ +/* + * Copyright 1999-2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cocoon.forms.datatype.typeimpl; + +import org.apache.cocoon.forms.datatype.convertor.Convertor; + + +/** + * The CForm type of a bean + * + * @author Giacomo Pati + * @version $Id: BeanType.java,v 1.1 2004/12/21 14:37:32 giacomo Exp $ + */ +public class BeanType + extends AbstractDatatype +{ + //~ Constructors -----------------------------------------------------= ------ + + /** + * Creates a new BeanType object. + * + * @param arrayType whether it's an array or not + * @param builder The {@link BeanTypeBuilder} + */ + public BeanType( final boolean arrayType, + final BeanTypeBuilder builder ) + { + super( ); + setArrayType( arrayType ); + setBuilder( builder ); + } + + //~ Methods ----------------------------------------------------------= ------ + + /** + * @see org.apache.cocoon.forms.datatype.Datatype#getDescriptiveName() + */ + public String getDescriptiveName( ) + { + final Class c1 =3D this.getConvertor( ).getTypeClass( ); + + return this.getConvertor( ).getTypeClass( ).getName( ); + } + + /** + * We make sure the plain Convertor is the same + * + * @return The convertor + */ + public Convertor getPlainConvertor( ) + { + return getConvertor( ); + } + + /** + * @see org.apache.cocoon.forms.datatype.Datatype#getTypeClass() + */ + public Class getTypeClass( ) + { + return this.getConvertor( ).getTypeClass( ); + } +} Added: cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/datatype= /typeimpl/BeanTypeBuilder.java URL: http://svn.apache.org/viewcvs/cocoon/blocks/core/forms/trunk/java/org/= apache/cocoon/forms/datatype/typeimpl/BeanTypeBuilder.java?view=3Dauto&rev= =3D158332 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/datatype/ty= peimpl/BeanTypeBuilder.java (added) +++ cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/datatype/ty= peimpl/BeanTypeBuilder.java Sun Mar 20 07:41:01 2005 @@ -0,0 +1,49 @@ +/* + * Copyright 1999-2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cocoon.forms.datatype.typeimpl; + +import org.apache.cocoon.forms.datatype.Datatype; +import org.apache.cocoon.forms.datatype.DatatypeManager; + +import org.w3c.dom.Element; + + +/** + * Builder for {@link BeanType} + * + * @author Giacomo Pati + * @version $Id: BeanTypeBuilder.java,v 1.1 2004/12/21 14:37:32 giacomo Ex= p $ + */ +public class BeanTypeBuilder + extends AbstractDatatypeBuilder +{ + //~ Methods ----------------------------------------------------------= ------ + + /** + * @see org.apache.cocoon.forms.datatype.DatatypeBuilder#build(org.w3c= .dom.Element, + * boolean, org.apache.cocoon.forms.datatype.DatatypeManager) + */ + public Datatype build( final Element datatypeElement, + final boolean arrayType, + final DatatypeManager datatypeManager ) + throws Exception + { + final BeanType type =3D new BeanType( arrayType, this ); + buildValidationRules( datatypeElement, type, datatypeManager ); + buildConvertor( datatypeElement, type ); + return type; + } +} Modified: cocoon/blocks/core/forms/trunk/samples/flow/binding_example.js URL: http://svn.apache.org/viewcvs/cocoon/blocks/core/forms/trunk/samples/f= low/binding_example.js?view=3Ddiff&r1=3D158331&r2=3D158332 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- cocoon/blocks/core/forms/trunk/samples/flow/binding_example.js (origina= l) +++ cocoon/blocks/core/forms/trunk/samples/flow/binding_example.js Sun Mar = 20 07:41:01 2005 @@ -80,6 +80,8 @@ contact.setId("1"); contact.setFirstName("Hermann"); bean.addContact(contact); + bean.addDrink("Maer"); + bean.addDrink("Leffe"); =20 form.load(bean); form.showForm("form2-display-pipeline");