You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by jh...@apache.org on 2005/11/03 15:00:48 UTC
svn commit: r330548 [91/132] - in
/cocoon/whiteboard/maven2/cocoon-flat-layout: ./ cocoon-ajax-block/
cocoon-ajax-block/api/ cocoon-ajax-block/api/src/
cocoon-ajax-block/api/src/main/ cocoon-ajax-block/api/src/main/java/
cocoon-ajax-block/api/src/main/...
Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/AbstractDatatypeBuilder.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/AbstractDatatypeBuilder.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/AbstractDatatypeBuilder.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/AbstractDatatypeBuilder.java Thu Nov 3 05:41:06 2005
@@ -0,0 +1,121 @@
+/*
+ * 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.avalon.framework.configuration.Configurable;
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.avalon.framework.service.Serviceable;
+import org.apache.avalon.framework.context.Contextualizable;
+import org.apache.avalon.framework.context.Context;
+import org.apache.avalon.framework.context.ContextException;
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.cocoon.forms.FormsConstants;
+import org.apache.cocoon.forms.datatype.DatatypeBuilder;
+import org.apache.cocoon.forms.datatype.DatatypeManager;
+import org.apache.cocoon.forms.datatype.ValidationRule;
+import org.apache.cocoon.forms.datatype.convertor.Convertor;
+import org.apache.cocoon.forms.datatype.convertor.ConvertorBuilder;
+import org.apache.cocoon.forms.util.DomHelper;
+import org.apache.cocoon.forms.util.SimpleServiceSelector;
+import org.w3c.dom.Element;
+
+/**
+ * Abstract base class for datatype builders, most concrete datatype builders
+ * will derive from this class.
+ * @version $Id: AbstractDatatypeBuilder.java 326838 2005-10-20 06:26:53Z sylvain $
+ */
+public abstract class AbstractDatatypeBuilder extends AbstractLogEnabled implements DatatypeBuilder, Serviceable, Configurable, Contextualizable {
+ protected ServiceManager serviceManager;
+ private SimpleServiceSelector convertorBuilders;
+ private String defaultConvertorHint;
+ private Convertor plainConvertor;
+ private Context context;
+
+ public void service(ServiceManager serviceManager) throws ServiceException {
+ this.serviceManager = serviceManager;
+ }
+
+ public void contextualize(Context context) throws ContextException {
+ this.context = context;
+ }
+
+ public void configure(Configuration configuration) throws ConfigurationException {
+ convertorBuilders = new SimpleServiceSelector("convertor", ConvertorBuilder.class);
+ try {
+ convertorBuilders.enableLogging(getLogger());
+ convertorBuilders.contextualize(context);
+ convertorBuilders.service(serviceManager);
+ } catch (Exception e) {
+ throw new ConfigurationException("Error setting up convertor builder selector.", e);
+ }
+ Configuration convertorsConf = configuration.getChild("convertors");
+ convertorBuilders.configure(convertorsConf);
+ defaultConvertorHint = convertorsConf.getAttribute("default");
+
+ String plainConvertorHint = convertorsConf.getAttribute("plain");
+ ConvertorBuilder plainConvertorBuilder;
+ try {
+ plainConvertorBuilder = (ConvertorBuilder)convertorBuilders.select(plainConvertorHint);
+ } catch (ServiceException e) {
+ throw new ConfigurationException("Convertor defined in plain attribute unavailable.", e);
+ }
+
+ try {
+ plainConvertor = plainConvertorBuilder.build(null);
+ } catch (Exception e) {
+ throw new ConfigurationException("Error create plain convertor.", e);
+ }
+ }
+
+ public void buildConvertor(Element datatypeEl, AbstractDatatype datatype) throws Exception {
+ Element convertorEl = DomHelper.getChildElement(datatypeEl, FormsConstants.DEFINITION_NS, "convertor", false);
+ Convertor convertor = buildConvertor(convertorEl);
+ datatype.setConvertor(convertor);
+ }
+
+ public Convertor buildConvertor(Element convertorEl) throws Exception {
+ String type = null;
+ // convertor configuration is allowed to be null, so check that it is not null
+ if (convertorEl != null)
+ type = convertorEl.getAttribute("type");
+ if (type == null || type.equals(""))
+ type = defaultConvertorHint;
+ ConvertorBuilder convertorBuilder = (ConvertorBuilder)convertorBuilders.select(type);
+ return convertorBuilder.build(convertorEl);
+ }
+
+ public Convertor getPlainConvertor() {
+ return plainConvertor;
+ }
+
+ protected void buildValidationRules(Element datatypeElement, AbstractDatatype datatype, DatatypeManager datatypeManager) throws Exception {
+ Element validationElement = DomHelper.getChildElement(datatypeElement, FormsConstants.DEFINITION_NS, "validation");
+ if (validationElement != null) {
+ Element[] validationElements = DomHelper.getChildElements(validationElement, FormsConstants.DEFINITION_NS);
+ for (int i = 0; i < validationElements.length; i++) {
+ ValidationRule rule = datatypeManager.createValidationRule(validationElements[i]);
+ if (rule.supportsType(datatype.getTypeClass(), datatype.isArrayType())) {
+ datatype.addValidationRule(rule);
+ } else {
+ throw new Exception("Validation rule \"" + validationElements[i].getLocalName() + "\" cannot be used with strings, error at " + DomHelper.getLocation(validationElements[i]));
+ }
+ }
+ }
+ }
+}
Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/AbstractDatatypeBuilder.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/BeanType.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/BeanType.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/BeanType.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/BeanType.java Thu Nov 3 05:41:06 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 <a href="mailto:giacomo@apache.org">Giacomo Pati</a>
+ * @version $Id$
+ */
+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 = 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( );
+ }
+}
Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/BeanType.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/BeanTypeBuilder.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/BeanTypeBuilder.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/BeanTypeBuilder.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/BeanTypeBuilder.java Thu Nov 3 05:41:06 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 <a href="mailto:giacomo@apache.org">Giacomo Pati</a>
+ * @version $Id$
+ */
+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 = new BeanType( arrayType, this );
+ buildValidationRules( datatypeElement, type, datatypeManager );
+ buildConvertor( datatypeElement, type );
+ return type;
+ }
+}
Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/BeanTypeBuilder.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/BooleanType.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/BooleanType.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/BooleanType.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/BooleanType.java Thu Nov 3 05:41:06 2005
@@ -0,0 +1,31 @@
+/*
+ * 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;
+
+/**
+ * A {@link org.apache.cocoon.forms.datatype.Datatype Datatype} implementation for
+ * java.lang.Boolean's.
+ * @version $Id: BooleanType.java 56582 2004-11-04 10:16:22Z sylvain $
+ */
+public class BooleanType extends AbstractDatatype {
+ public Class getTypeClass() {
+ return Boolean.class;
+ }
+
+ public String getDescriptiveName() {
+ return "boolean";
+ }
+}
Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/BooleanType.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/BooleanTypeBuilder.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/BooleanTypeBuilder.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/BooleanTypeBuilder.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/BooleanTypeBuilder.java Thu Nov 3 05:41:06 2005
@@ -0,0 +1,37 @@
+/*
+ * 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;
+
+/**
+ * Builds {@link BooleanType}s.
+ * @version $Id: BooleanTypeBuilder.java 56582 2004-11-04 10:16:22Z sylvain $
+ */
+public class BooleanTypeBuilder extends AbstractDatatypeBuilder {
+ public Datatype build(Element datatypeElement, boolean arrayType, DatatypeManager datatypeManager) throws Exception {
+ BooleanType type = new BooleanType();
+ type.setArrayType(arrayType);
+ type.setBuilder(this);
+
+ buildValidationRules(datatypeElement, type, datatypeManager);
+ buildConvertor(datatypeElement, type);
+
+ return type;
+ }
+}
Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/BooleanTypeBuilder.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/DateType.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/DateType.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/DateType.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/DateType.java Thu Nov 3 05:41:06 2005
@@ -0,0 +1,34 @@
+/*
+ * 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 java.util.Date;
+
+/**
+ * A {@link org.apache.cocoon.forms.datatype.Datatype Datatype} implementation for
+ * java.util.Date's (so includes a time-component).
+ * @version $Id: DateType.java 56582 2004-11-04 10:16:22Z sylvain $
+ */
+public class DateType extends AbstractDatatype {
+
+ public Class getTypeClass() {
+ return Date.class;
+ }
+
+ public String getDescriptiveName() {
+ return "date";
+ }
+}
Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/DateType.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/DateTypeBuilder.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/DateTypeBuilder.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/DateTypeBuilder.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/DateTypeBuilder.java Thu Nov 3 05:41:06 2005
@@ -0,0 +1,37 @@
+/*
+ * 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;
+
+/**
+ * Builds {@link DateType}s.
+ * @version $Id: DateTypeBuilder.java 56582 2004-11-04 10:16:22Z sylvain $
+ */
+public class DateTypeBuilder extends AbstractDatatypeBuilder {
+ public Datatype build(Element datatypeElement, boolean arrayType, DatatypeManager datatypeManager) throws Exception {
+ DateType type = new DateType();
+ type.setArrayType(arrayType);
+ type.setBuilder(this);
+
+ buildValidationRules(datatypeElement, type, datatypeManager);
+ buildConvertor(datatypeElement, type);
+
+ return type;
+ }
+}
Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/DateTypeBuilder.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/DecimalType.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/DecimalType.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/DecimalType.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/DecimalType.java Thu Nov 3 05:41:06 2005
@@ -0,0 +1,31 @@
+/*
+ * 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;
+
+/**
+ * A {@link org.apache.cocoon.forms.datatype.Datatype Datatype} implementation
+ * for decimal numbers (backed by the java.math.BigDecimal class).
+ * @version $Id: DecimalType.java 56582 2004-11-04 10:16:22Z sylvain $
+ */
+public class DecimalType extends AbstractDatatype {
+ public Class getTypeClass() {
+ return java.math.BigDecimal.class;
+ }
+
+ public String getDescriptiveName() {
+ return "decimal";
+ }
+}
Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/DecimalType.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/DecimalTypeBuilder.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/DecimalTypeBuilder.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/DecimalTypeBuilder.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/DecimalTypeBuilder.java Thu Nov 3 05:41:06 2005
@@ -0,0 +1,37 @@
+/*
+ * 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;
+
+/**
+ * Builds {@link DecimalType}s.
+ * @version $Id: DecimalTypeBuilder.java 56582 2004-11-04 10:16:22Z sylvain $
+ */
+public class DecimalTypeBuilder extends AbstractDatatypeBuilder {
+ public Datatype build(Element datatypeElement, boolean arrayType, DatatypeManager datatypeManager) throws Exception {
+ DecimalType type = new DecimalType();
+ type.setArrayType(arrayType);
+ type.setBuilder(this);
+
+ buildValidationRules(datatypeElement, type, datatypeManager);
+ buildConvertor(datatypeElement, type);
+
+ return type;
+ }
+}
Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/DecimalTypeBuilder.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/DoubleType.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/DoubleType.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/DoubleType.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/DoubleType.java Thu Nov 3 05:41:06 2005
@@ -0,0 +1,32 @@
+/*
+ * 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;
+
+/**
+ * A {@link org.apache.cocoon.forms.datatype.Datatype Datatype} implementation
+ * for double numbers (backed by the java.lang.Double class).
+ *
+ * @version $Id: DoubleType.java 56582 2004-11-04 10:16:22Z sylvain $
+ */
+public class DoubleType extends AbstractDatatype {
+ public Class getTypeClass() {
+ return Double.class;
+ }
+
+ public String getDescriptiveName() {
+ return "double";
+ }
+}
Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/DoubleType.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/DoubleTypeBuilder.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/DoubleTypeBuilder.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/DoubleTypeBuilder.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/DoubleTypeBuilder.java Thu Nov 3 05:41:06 2005
@@ -0,0 +1,38 @@
+/*
+ * 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;
+
+/**
+ * Builds {@link DoubleType}s.
+ *
+ * @version $Id: DoubleTypeBuilder.java 56582 2004-11-04 10:16:22Z sylvain $
+ */
+public class DoubleTypeBuilder extends AbstractDatatypeBuilder {
+ public Datatype build(Element datatypeElement, boolean arrayType, DatatypeManager datatypeManager) throws Exception {
+ DoubleType type = new DoubleType();
+ type.setArrayType(arrayType);
+ type.setBuilder(this);
+
+ buildValidationRules(datatypeElement, type, datatypeManager);
+ buildConvertor(datatypeElement, type);
+
+ return type;
+ }
+}
Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/DoubleTypeBuilder.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/EnumType.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/EnumType.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/EnumType.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/EnumType.java Thu Nov 3 05:41:06 2005
@@ -0,0 +1,64 @@
+/*
+ * 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;
+
+/**
+ * A {@link org.apache.cocoon.forms.datatype.Datatype Datatype} implementation for
+ * types implementing Joshua Bloch's <a href="http://developer.java.sun.com/developer/Books/shiftintojava/page1.html#replaceenums">
+ * typesafe enum</a> pattern.
+ * <p>See the following code for an example:</p>
+ * <pre>
+ * package com.example;
+ *
+ * public class Sex {
+ *
+ * public static final Sex MALE = new Sex("M");
+ * public static final Sex FEMALE = new Sex("F");
+ * private String code;
+ *
+ * private Sex(String code) { this.code = code; }
+ * }
+ * </pre>
+ * <p>If your enumerated type does not provide a {@link java.lang.Object#toString()}
+ * method, the enum convertor will use the fully qualified class name,
+ * followed by the name of the public static final field referring to
+ * each instance, i.e. "com.example.Sex.MALE", "com.example.Sex.FEMALE"
+ * and so on.</p>
+ * <p>If you provide a toString() method which returns something
+ * different, you should also provide a fromString(String, Locale)
+ * method to convert those strings back to instances.
+ *
+ * @version $Id: EnumType.java 151179 2005-02-03 16:55:16Z tim $
+ */
+public class EnumType extends AbstractDatatype {
+
+ public EnumType() {
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.cocoon.forms.datatype.Datatype#getTypeClass()
+ */
+ public Class getTypeClass() {
+ return this.getConvertor().getTypeClass();
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.cocoon.forms.datatype.Datatype#getDescriptiveName()
+ */
+ public String getDescriptiveName() {
+ return this.getConvertor().getTypeClass().getName();
+ }
+}
Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/EnumType.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/EnumTypeBuilder.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/EnumTypeBuilder.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/EnumTypeBuilder.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/EnumTypeBuilder.java Thu Nov 3 05:41:06 2005
@@ -0,0 +1,44 @@
+/*
+ * 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;
+
+/**
+ * Builds {@link EnumType}s.
+ *
+ * @version $Id: EnumTypeBuilder.java 151179 2005-02-03 16:55:16Z tim $
+ */
+public class EnumTypeBuilder extends AbstractDatatypeBuilder {
+
+ /* (non-Javadoc)
+ * @see org.apache.cocoon.forms.datatype.DatatypeBuilder#build(org.w3c.dom.Element, boolean, org.apache.cocoon.forms.datatype.DatatypeManager)
+ */
+ public Datatype build(Element datatypeElement,
+ boolean arrayType,
+ DatatypeManager datatypeManager) throws Exception {
+ EnumType type = new EnumType();
+ type.setArrayType(arrayType);
+ type.setBuilder(this);
+
+ buildValidationRules(datatypeElement, type, datatypeManager);
+ buildConvertor(datatypeElement, type);
+
+ return type;
+ }
+}
Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/EnumTypeBuilder.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/FloatType.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/FloatType.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/FloatType.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/FloatType.java Thu Nov 3 05:41:06 2005
@@ -0,0 +1,31 @@
+/*
+ * 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;
+
+/**
+ * A {@link org.apache.cocoon.forms.datatype.Datatype Datatype} implementation
+ * for float numbers (backed by the java.lang.Float class).
+ * @version $Id: FloatType.java 56582 2004-11-04 10:16:22Z sylvain $
+ */
+public class FloatType extends AbstractDatatype {
+ public Class getTypeClass() {
+ return Float.class;
+ }
+
+ public String getDescriptiveName() {
+ return "float";
+ }
+}
Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/FloatType.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/FloatTypeBuilder.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/FloatTypeBuilder.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/FloatTypeBuilder.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/FloatTypeBuilder.java Thu Nov 3 05:41:06 2005
@@ -0,0 +1,37 @@
+/*
+ * 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;
+
+/**
+ * Builds {@link FloatType}s.
+ * @version $Id: FloatTypeBuilder.java 56582 2004-11-04 10:16:22Z sylvain $
+ */
+public class FloatTypeBuilder extends AbstractDatatypeBuilder {
+ public Datatype build(Element datatypeElement, boolean arrayType, DatatypeManager datatypeManager) throws Exception {
+ FloatType type = new FloatType();
+ type.setArrayType(arrayType);
+ type.setBuilder(this);
+
+ buildValidationRules(datatypeElement, type, datatypeManager);
+ buildConvertor(datatypeElement, type);
+
+ return type;
+ }
+}
Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/FloatTypeBuilder.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/IntegerType.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/IntegerType.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/IntegerType.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/IntegerType.java Thu Nov 3 05:41:06 2005
@@ -0,0 +1,33 @@
+/*
+ * 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;
+
+/**
+ * A {@link org.apache.cocoon.forms.datatype.Datatype Datatype} implementation
+ * for whole numbers.
+ *
+ * @author <a href="mailto:antonio@apache.org">Antonio Gallardo</a>
+ * @version $Id: IntegerType.java 151179 2005-02-03 16:55:16Z tim $
+ */
+public class IntegerType extends AbstractDatatype {
+ public Class getTypeClass() {
+ return Integer.class;
+ }
+
+ public String getDescriptiveName() {
+ return "integer";
+ }
+}
Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/IntegerType.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/IntegerTypeBuilder.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/IntegerTypeBuilder.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/IntegerTypeBuilder.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/IntegerTypeBuilder.java Thu Nov 3 05:41:06 2005
@@ -0,0 +1,39 @@
+/*
+ * 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;
+
+/**
+ * Builds {@link IntegerType}s.
+ *
+ * @author <a href="mailto:antonio@apache.org">Antonio Gallardo</a>
+ * @version $Id: IntegerTypeBuilder.java 151179 2005-02-03 16:55:16Z tim $
+ */
+public class IntegerTypeBuilder extends AbstractDatatypeBuilder {
+ public Datatype build(Element datatypeElement, boolean arrayType, DatatypeManager datatypeManager) throws Exception {
+ IntegerType type = new IntegerType();
+ type.setArrayType(arrayType);
+ type.setBuilder(this);
+
+ buildValidationRules(datatypeElement, type, datatypeManager);
+ buildConvertor(datatypeElement, type);
+
+ return type;
+ }
+}
Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/IntegerTypeBuilder.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/LongType.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/LongType.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/LongType.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/LongType.java Thu Nov 3 05:41:06 2005
@@ -0,0 +1,31 @@
+/*
+ * 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;
+
+/**
+ * A {@link org.apache.cocoon.forms.datatype.Datatype Datatype} implementation
+ * for whole numbers.
+ * @version $Id: LongType.java 56582 2004-11-04 10:16:22Z sylvain $
+ */
+public class LongType extends AbstractDatatype {
+ public Class getTypeClass() {
+ return Long.class;
+ }
+
+ public String getDescriptiveName() {
+ return "long";
+ }
+}
Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/LongType.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/LongTypeBuilder.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/LongTypeBuilder.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/LongTypeBuilder.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/LongTypeBuilder.java Thu Nov 3 05:41:06 2005
@@ -0,0 +1,37 @@
+/*
+ * 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;
+
+/**
+ * Builds {@link LongType}s.
+ * @version $Id: LongTypeBuilder.java 56582 2004-11-04 10:16:22Z sylvain $
+ */
+public class LongTypeBuilder extends AbstractDatatypeBuilder {
+ public Datatype build(Element datatypeElement, boolean arrayType, DatatypeManager datatypeManager) throws Exception {
+ LongType type = new LongType();
+ type.setArrayType(arrayType);
+ type.setBuilder(this);
+
+ buildValidationRules(datatypeElement, type, datatypeManager);
+ buildConvertor(datatypeElement, type);
+
+ return type;
+ }
+}
Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/LongTypeBuilder.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/StringType.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/StringType.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/StringType.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/StringType.java Thu Nov 3 05:41:06 2005
@@ -0,0 +1,32 @@
+/*
+ * 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;
+
+/**
+ * A {@link org.apache.cocoon.forms.datatype.Datatype Datatype} implementation
+ * for strings.
+ * @version $Id: StringType.java 56582 2004-11-04 10:16:22Z sylvain $
+ */
+public class StringType extends AbstractDatatype {
+
+ public Class getTypeClass() {
+ return String.class;
+ }
+
+ public String getDescriptiveName() {
+ return "string";
+ }
+}
Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/StringType.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/StringTypeBuilder.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/StringTypeBuilder.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/StringTypeBuilder.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/StringTypeBuilder.java Thu Nov 3 05:41:06 2005
@@ -0,0 +1,38 @@
+/*
+ * 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;
+
+/**
+ * Builds {@link StringType}s.
+ * @version $Id: StringTypeBuilder.java 56582 2004-11-04 10:16:22Z sylvain $
+ */
+public class StringTypeBuilder extends AbstractDatatypeBuilder {
+
+ public Datatype build(Element datatypeElement, boolean arrayType, DatatypeManager datatypeManager) throws Exception {
+ StringType type = new StringType();
+ type.setArrayType(arrayType);
+ type.setBuilder(this);
+
+ buildValidationRules(datatypeElement, type, datatypeManager);
+ buildConvertor(datatypeElement, type);
+
+ return type;
+ }
+}
Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/StringTypeBuilder.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/validationruleimpl/AbstractValidationRule.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/validationruleimpl/AbstractValidationRule.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/validationruleimpl/AbstractValidationRule.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/validationruleimpl/AbstractValidationRule.java Thu Nov 3 05:41:06 2005
@@ -0,0 +1,115 @@
+/*
+ * 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.validationruleimpl;
+
+import org.apache.cocoon.forms.datatype.ValidationRule;
+import org.apache.cocoon.forms.formmodel.CannotYetResolveWarning;
+import org.apache.cocoon.forms.validation.ValidationError;
+import org.apache.excalibur.xml.sax.XMLizable;
+import org.outerj.expression.Expression;
+import org.outerj.expression.ExpressionContext;
+import org.outerj.expression.ExpressionException;
+
+import java.math.BigDecimal;
+
+/**
+ * Abstract base class providing common functionality for many {@link ValidationRule}
+ * implementations.
+ *
+ * @version $Id: AbstractValidationRule.java 56582 2004-11-04 10:16:22Z sylvain $
+ */
+public abstract class AbstractValidationRule implements ValidationRule {
+ private XMLizable failMessage;
+
+ /**
+ * Sets the failmessage to use for this validation rule, this will be used
+ * instead of the validation rules' built-in message. The message itself should
+ * be an object impementing XMLizable, such as a SaxBuffer instance. This
+ * allows fail messages to contain mixed content (instead of just
+ * being a string).
+ */
+ public void setFailMessage(XMLizable object) {
+ this.failMessage = object;
+ }
+
+ /**
+ * Returns the failMessage wrapped in a ValidationError object.
+ */
+ public ValidationError getFailMessage() {
+ return new ValidationError(failMessage);
+ }
+
+ /**
+ * Returns true if this validation rule has a user-defined fail message.
+ */
+ public boolean hasFailMessage() {
+ return failMessage != null;
+ }
+
+ /**
+ * Helper method for evaluating expressions whose result is numeric.
+ *
+ * @param exprName a name for the expression that's descriptive for the user, e.g. the name of the attribute in which it was defined
+ * @param ruleName a descriptive name for the validation rule, usually the rule's element name
+ * @return either a ValidationError (because expression evaluation failed) or a CannotYetResolveWarning
+ * (because another, required field referenced in the expression has not yet a value), or a BigDecimal.
+ */
+ protected Object evaluateNumeric(Expression expression, ExpressionContext expressionContext, String exprName, String ruleName) {
+ Object expressionResult;
+ try {
+ expressionResult = expression.evaluate(expressionContext);
+ } catch (CannotYetResolveWarning w) {
+ return w;
+ } catch (ExpressionException e) {
+ return new ValidationError("Error evaluating \"" + exprName + "\" expression on \"" +
+ ruleName + "\" validation rule", false);
+ }
+
+ if (!(expressionResult instanceof BigDecimal)) {
+ return new ValidationError("Got non-numeric result from \"" + exprName + "\" expression on \"" +
+ ruleName + "\" validation rule", false);
+ }
+
+ return expressionResult;
+ }
+
+ /**
+ * Helper method for evaluating expressions whose result is comparable.
+ *
+ * @param exprName a name for the expression that's descriptive for the user, e.g. the name of the attribute in which it was defined
+ * @param ruleName a descriptive name for the validation rule, usually the rule's element name
+ * @return either a ValidationError (because expression evaluation failed) or a CannotYetResolveWarning
+ * (because another, required field referenced in the expression has not yet a value), or a BigDecimal.
+ */
+ protected Object evaluateComparable(Expression expression, ExpressionContext expressionContext, String exprName, String ruleName) {
+ Object expressionResult;
+ try {
+ expressionResult = expression.evaluate(expressionContext);
+ } catch (CannotYetResolveWarning w) {
+ return w;
+ } catch (ExpressionException e) {
+ return new ValidationError("Error evaluating \"" + exprName + "\" expression on \"" +
+ ruleName + "\" validation rule", false);
+ }
+
+ if (!(expressionResult instanceof Comparable)) {
+ return new ValidationError("Got non-comparable result from \"" + exprName + "\" expression on \"" +
+ ruleName + "\" validation rule", false);
+ }
+
+ return expressionResult;
+ }
+}
Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/validationruleimpl/AbstractValidationRule.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/validationruleimpl/AbstractValidationRuleBuilder.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/validationruleimpl/AbstractValidationRuleBuilder.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/validationruleimpl/AbstractValidationRuleBuilder.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/validationruleimpl/AbstractValidationRuleBuilder.java Thu Nov 3 05:41:06 2005
@@ -0,0 +1,81 @@
+/*
+ * 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.validationruleimpl;
+
+import org.apache.cocoon.forms.FormsConstants;
+import org.apache.cocoon.forms.datatype.ValidationRuleBuilder;
+import org.apache.cocoon.forms.expression.ExpressionManager;
+import org.apache.cocoon.forms.util.DomHelper;
+import org.apache.avalon.framework.CascadingException;
+import org.apache.avalon.framework.activity.Disposable;
+import org.apache.avalon.framework.service.Serviceable;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.excalibur.xml.sax.XMLizable;
+import org.w3c.dom.Element;
+import org.outerj.expression.Expression;
+import org.outerj.expression.TokenMgrError;
+
+/**
+ * Abstract base class for ValidationRuleBuilder implementations.
+ *
+ * @version $Id: AbstractValidationRuleBuilder.java 326838 2005-10-20 06:26:53Z sylvain $
+ */
+public abstract class AbstractValidationRuleBuilder
+ implements ValidationRuleBuilder, Serviceable, Disposable {
+
+ protected ExpressionManager expressionManager;
+ protected ServiceManager serviceManager;
+
+ /**
+ * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
+ */
+ public void service(ServiceManager serviceManager) throws ServiceException {
+ this.serviceManager = serviceManager;
+ this.expressionManager = (ExpressionManager)serviceManager.lookup(ExpressionManager.ROLE);
+ }
+
+ /**
+ * Checks if the validation rule configuration contains a custom failmessage, and if so,
+ * sets it one the ValidationRule.
+ */
+ protected void buildFailMessage(Element validationRuleElement, AbstractValidationRule rule) {
+ Element failMessageElement = DomHelper.getChildElement(validationRuleElement, FormsConstants.DEFINITION_NS, "failmessage");
+ if (failMessageElement != null) {
+ XMLizable failMessage = DomHelper.compileElementContent(failMessageElement);
+ rule.setFailMessage(failMessage);
+ }
+ }
+
+ /**
+ * Parses an expression and throws a nice error message if this fails.
+ */
+ protected Expression parseExpression(String exprString, Element element, String attrName) throws Exception {
+ try {
+ return expressionManager.parse(exprString);
+ } catch (TokenMgrError e) {
+ throw new CascadingException("Error in expression \"" + exprString + "\" in attribute \"" + attrName + "\" at " + DomHelper.getLocation(element), e);
+ } catch (Exception e) {
+ throw new CascadingException("Error in expression \"" + exprString + "\" in attribute \"" + attrName + "\" at " + DomHelper.getLocation(element), e);
+ }
+ }
+
+ public void dispose() {
+ this.serviceManager.release(this.expressionManager);
+ this.expressionManager = null;
+ this.serviceManager = null;
+ }
+}
Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/validationruleimpl/AbstractValidationRuleBuilder.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/validationruleimpl/AssertValidationRule.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/validationruleimpl/AssertValidationRule.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/validationruleimpl/AssertValidationRule.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/validationruleimpl/AssertValidationRule.java Thu Nov 3 05:41:06 2005
@@ -0,0 +1,59 @@
+/*
+ * 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.validationruleimpl;
+
+import org.apache.cocoon.forms.formmodel.CannotYetResolveWarning;
+import org.apache.cocoon.forms.validation.ValidationError;
+import org.outerj.expression.ExpressionContext;
+import org.outerj.expression.ExpressionException;
+import org.outerj.expression.Expression;
+
+/**
+ * Generic validation rule that evaluates an expression. If the outcome of the expression is true,
+ * the validation is successful, otherwise not.
+ *
+ * @version $Id: AssertValidationRule.java 56582 2004-11-04 10:16:22Z sylvain $
+ */
+public class AssertValidationRule extends AbstractValidationRule {
+ private Expression testExpression;
+
+ public AssertValidationRule(Expression testExpression) {
+ this.testExpression = testExpression;
+ }
+
+ public ValidationError validate(Object value, ExpressionContext expressionContext) {
+ Object expressionResult;
+ try {
+ expressionResult = testExpression.evaluate(expressionContext);
+ } catch (CannotYetResolveWarning w) {
+ return null;
+ } catch (ExpressionException e) {
+ return new ValidationError("Error evaluating expression on assert validation rule.", false);
+ }
+
+ if (!(expressionResult instanceof Boolean))
+ return new ValidationError("Got non-boolean result from expression on assert validation rule.", false);
+
+ if (((Boolean)expressionResult).booleanValue())
+ return null;
+ else
+ return hasFailMessage() ? getFailMessage() : new ValidationError("Assertion validation rule failed.", false);
+ }
+
+ public boolean supportsType(Class clazz, boolean arrayType) {
+ return true;
+ }
+}
Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/validationruleimpl/AssertValidationRule.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/validationruleimpl/AssertValidationRuleBuilder.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/validationruleimpl/AssertValidationRuleBuilder.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/validationruleimpl/AssertValidationRuleBuilder.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/validationruleimpl/AssertValidationRuleBuilder.java Thu Nov 3 05:41:06 2005
@@ -0,0 +1,40 @@
+/*
+ * 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.validationruleimpl;
+
+import org.apache.cocoon.forms.datatype.ValidationRule;
+import org.apache.cocoon.forms.util.DomHelper;
+import org.w3c.dom.Element;
+import org.outerj.expression.Expression;
+
+/**
+ * Builds {@link AssertValidationRule}s.
+ *
+ * @version $Id: AssertValidationRuleBuilder.java 56582 2004-11-04 10:16:22Z sylvain $
+ */
+public class AssertValidationRuleBuilder extends AbstractValidationRuleBuilder {
+ public ValidationRule build(Element validationRuleElement) throws Exception {
+ String exprStr = validationRuleElement.getAttribute("test");
+ if (exprStr.length() == 0)
+ throw new Exception("assert validation rule requires a \"test\" attribute at " + DomHelper.getLocation(validationRuleElement));
+ Expression testExpression = parseExpression(exprStr, validationRuleElement, "test");
+ if (testExpression.getResultType() != null && !Boolean.class.isAssignableFrom(testExpression.getResultType()))
+ throw new Exception("Expression should evaluate to a boolean on assert validation rule at " + DomHelper.getLocation(validationRuleElement));
+ AssertValidationRule rule = new AssertValidationRule(testExpression);
+ buildFailMessage(validationRuleElement, rule);
+ return rule;
+ }
+}
Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/validationruleimpl/AssertValidationRuleBuilder.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/validationruleimpl/EmailValidationRule.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/validationruleimpl/EmailValidationRule.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/validationruleimpl/EmailValidationRule.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/validationruleimpl/EmailValidationRule.java Thu Nov 3 05:41:06 2005
@@ -0,0 +1,196 @@
+/*
+ * 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.validationruleimpl;
+
+import org.apache.cocoon.forms.FormsConstants;
+import org.apache.cocoon.forms.util.I18nMessage;
+import org.apache.cocoon.forms.validation.ValidationError;
+import org.apache.oro.text.perl.Perl5Util;
+import org.outerj.expression.ExpressionContext;
+
+/**
+ * <p>ValidationRule that checks that a string is an email address.</p>
+ * <p>Based on code copied from org.apache.commons.validator.EmailValidator.</p>
+ *
+ * @version $Id: EmailValidationRule.java 326838 2005-10-20 06:26:53Z sylvain $
+ */
+public class EmailValidationRule extends AbstractValidationRule {
+
+ private static final String SPECIAL_CHARS = "\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
+ private static final String VALID_CHARS = "[^\\s" + SPECIAL_CHARS + "]";
+ private static final String QUOTED_USER = "(\"[^\"]*\")";
+ private static final String ATOM = VALID_CHARS + '+';
+ private static final String WORD = "(" + ATOM + "|" + QUOTED_USER + ")";
+
+ // Each pattern must be surrounded by /
+ private static final String LEGAL_ASCII_PATTERN = "/^[\\000-\\177]+$/";
+ private static final String EMAIL_PATTERN = "/^(.+)@(.+)$/";
+ private static final String IP_DOMAIN_PATTERN =
+ "/^(\\d{1,3})[.](\\d{1,3})[.](\\d{1,3})[.](\\d{1,3})$/";
+
+ private static final String USER_PATTERN = "/^" + WORD + "(\\." + WORD + ")*$/";
+ private static final String DOMAIN_PATTERN = "/^" + ATOM + "(\\." + ATOM + ")*$/";
+ private static final String ATOM_PATTERN = "/(" + ATOM + ")/";
+
+ public ValidationError validate(Object value, ExpressionContext expressionContext) {
+ String email = (String)value;
+
+ if (isEmail(email))
+ return null;
+ else
+ return hasFailMessage() ? getFailMessage() : new ValidationError(new I18nMessage("validation.string.invalidemail", FormsConstants.I18N_CATALOGUE));
+ }
+
+ public boolean supportsType(Class clazz, boolean arrayType) {
+ return clazz.isAssignableFrom(String.class) && !arrayType;
+ }
+
+ boolean isEmail(String email) {
+ if (email == null) {
+ return false;
+ }
+
+ Perl5Util matchAsciiPat = new Perl5Util();
+ if (!matchAsciiPat.match(LEGAL_ASCII_PATTERN, email)) {
+ return false;
+ }
+
+ // Check the whole email address structure
+ Perl5Util emailMatcher = new Perl5Util();
+ if (!emailMatcher.match(EMAIL_PATTERN, email)) {
+ return false;
+ }
+
+ if (email.endsWith(".")) {
+ return false;
+ }
+
+ if (!isValidUser(emailMatcher.group(1))) {
+ return false;
+ }
+
+ if (!isValidDomain(emailMatcher.group(2))) {
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * Returns true if the domain component of an email address is valid.
+ * @param domain being validatied.
+ */
+ protected boolean isValidDomain(String domain) {
+ boolean symbolic = false;
+ Perl5Util ipAddressMatcher = new Perl5Util();
+
+ if (ipAddressMatcher.match(IP_DOMAIN_PATTERN, domain)) {
+ if (!isValidIpAddress(ipAddressMatcher)) {
+ return false;
+ }
+ } else {
+ // Domain is symbolic name
+ Perl5Util domainMatcher = new Perl5Util();
+ symbolic = domainMatcher.match(DOMAIN_PATTERN, domain);
+ }
+
+ if (symbolic) {
+ if (!isValidSymbolicDomain(domain)) {
+ return false;
+ }
+ } else {
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * Returns true if the user component of an email address is valid.
+ * @param user being validated
+ */
+ protected boolean isValidUser(String user) {
+ Perl5Util userMatcher = new Perl5Util();
+ return userMatcher.match(USER_PATTERN, user);
+ }
+
+ /**
+ * Validates an IP address. Returns true if valid.
+ * @param ipAddressMatcher Pattren matcher
+ */
+ protected boolean isValidIpAddress(Perl5Util ipAddressMatcher) {
+ for (int i = 1; i <= 4; i++) {
+ String ipSegment = ipAddressMatcher.group(i);
+ if (ipSegment == null || ipSegment.length() <= 0) {
+ return false;
+ }
+
+ int iIpSegment = 0;
+
+ try {
+ iIpSegment = Integer.parseInt(ipSegment);
+ } catch(NumberFormatException e) {
+ return false;
+ }
+
+ if (iIpSegment > 255) {
+ return false;
+ }
+
+ }
+ return true;
+ }
+
+ /**
+ * Validates a symbolic domain name. Returns true if it's valid.
+ * @param domain symbolic domain name
+ */
+ protected boolean isValidSymbolicDomain(String domain) {
+ String[] domainSegment = new String[10];
+ boolean match = true;
+ int i = 0;
+ Perl5Util atomMatcher = new Perl5Util();
+
+ while (match) {
+ match = atomMatcher.match(ATOM_PATTERN, domain);
+ if (match) {
+ domainSegment[i] = atomMatcher.group(1);
+ int l = domainSegment[i].length() + 1;
+ domain =
+ (l >= domain.length())
+ ? ""
+ : domain.substring(l);
+
+ i++;
+ }
+ }
+
+ int len = i;
+ if (domainSegment[len - 1].length() < 2
+ || domainSegment[len - 1].length() > 4) {
+
+ return false;
+ }
+
+ // Make sure there's a host name preceding the domain.
+ if (len < 2) {
+ return false;
+ }
+
+ return true;
+ }
+
+}
Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/validationruleimpl/EmailValidationRule.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/validationruleimpl/EmailValidationRuleBuilder.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/validationruleimpl/EmailValidationRuleBuilder.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/validationruleimpl/EmailValidationRuleBuilder.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/validationruleimpl/EmailValidationRuleBuilder.java Thu Nov 3 05:41:06 2005
@@ -0,0 +1,32 @@
+/*
+ * 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.validationruleimpl;
+
+import org.apache.cocoon.forms.datatype.ValidationRule;
+import org.w3c.dom.Element;
+
+/**
+ * Builds {@link EmailValidationRule}s.
+ *
+ * @version $Id: EmailValidationRuleBuilder.java 56582 2004-11-04 10:16:22Z sylvain $
+ */
+public class EmailValidationRuleBuilder extends AbstractValidationRuleBuilder {
+ public ValidationRule build(Element validationRuleElement) throws Exception {
+ EmailValidationRule rule = new EmailValidationRule();
+ buildFailMessage(validationRuleElement, rule);
+ return rule;
+ }
+}
Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/validationruleimpl/EmailValidationRuleBuilder.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/validationruleimpl/LengthValidationRule.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/validationruleimpl/LengthValidationRule.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/validationruleimpl/LengthValidationRule.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/validationruleimpl/LengthValidationRule.java Thu Nov 3 05:41:06 2005
@@ -0,0 +1,124 @@
+/*
+ * 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.validationruleimpl;
+
+import org.apache.cocoon.forms.FormsConstants;
+import org.apache.cocoon.forms.formmodel.CannotYetResolveWarning;
+import org.apache.cocoon.forms.util.I18nMessage;
+import org.apache.cocoon.forms.validation.ValidationError;
+import org.outerj.expression.ExpressionContext;
+import org.outerj.expression.Expression;
+
+import java.math.BigDecimal;
+
+/**
+ * Checks the length of a String.
+ *
+ * <p>This validation rule can perform 4 different checks:
+ * <ul>
+ * <li>check exact string length
+ * <li>check minimum string length
+ * <li>check maximum string length
+ * <li>check min and max string length
+ * </ul>
+ *
+ * @version $Id: LengthValidationRule.java 326838 2005-10-20 06:26:53Z sylvain $
+ */
+public class LengthValidationRule extends AbstractValidationRule {
+ private Expression exactExpr;
+ private Expression minExpr;
+ private Expression maxExpr;
+
+ public void setExactExpr(Expression exactExpr) {
+ this.exactExpr = exactExpr;
+ }
+
+ public void setMinExpr(Expression minExpr) {
+ this.minExpr = minExpr;
+ }
+
+ public void setMaxExpr(Expression maxExpr) {
+ this.maxExpr = maxExpr;
+ }
+
+ public ValidationError validate(Object value, ExpressionContext expressionContext) {
+ String string = (String)value;
+
+ if (exactExpr != null) {
+ Object result = evaluateNumeric(exactExpr, expressionContext, "exact", "length");
+ if (result instanceof ValidationError) {
+ return (ValidationError)result;
+ } else if (result instanceof CannotYetResolveWarning) {
+ return null;
+ }
+ int length = ((BigDecimal)result).intValue();
+ if (string.length() != length) {
+ return hasFailMessage() ? getFailMessage() : new ValidationError(new I18nMessage("validation.string.exact-length", new String[] {String.valueOf(length)}, FormsConstants.I18N_CATALOGUE));
+ }
+ return null;
+ } else if (minExpr != null && maxExpr != null) {
+ Object result = evaluateNumeric(minExpr, expressionContext, "min", "length");
+ if (result instanceof ValidationError) {
+ return (ValidationError)result;
+ } else if (result instanceof CannotYetResolveWarning) {
+ return null;
+ }
+ int minLength = ((BigDecimal)result).intValue();
+
+ result = evaluateNumeric(maxExpr, expressionContext, "max", "length");
+ if (result instanceof ValidationError) {
+ return (ValidationError)result;
+ } else if (result instanceof CannotYetResolveWarning) {
+ return null;
+ }
+ int maxLength = ((BigDecimal)result).intValue();
+
+ if (string.length() < minLength || string.length() > maxLength) {
+ return hasFailMessage() ? getFailMessage() : new ValidationError(new I18nMessage("validation.string.range-length", new String[] {String.valueOf(minLength), String.valueOf(maxLength)}, FormsConstants.I18N_CATALOGUE));
+ }
+ return null;
+ } else if (minExpr != null) {
+ Object result = evaluateNumeric(minExpr, expressionContext, "min", "length");
+ if (result instanceof ValidationError) {
+ return (ValidationError)result;
+ } else if (result instanceof CannotYetResolveWarning) {
+ return null;
+ }
+ int length = ((BigDecimal)result).intValue();
+ if (string.length() < length) {
+ return hasFailMessage() ? getFailMessage() : new ValidationError(new I18nMessage("validation.string.min-length", new String[] {String.valueOf(length)}, FormsConstants.I18N_CATALOGUE));
+ }
+ return null;
+ } else if (maxExpr != null) {
+ Object result = evaluateNumeric(maxExpr, expressionContext, "max", "length");
+ if (result instanceof ValidationError) {
+ return (ValidationError)result;
+ } else if (result instanceof CannotYetResolveWarning) {
+ return null;
+ }
+ int length = ((BigDecimal)result).intValue();
+ if (string.length() > length) {
+ return hasFailMessage() ? getFailMessage() : new ValidationError(new I18nMessage("validation.string.max-length", new String[] {String.valueOf(length)}, FormsConstants.I18N_CATALOGUE));
+ }
+ return null;
+ }
+ return null;
+ }
+
+ public boolean supportsType(Class clazz, boolean arrayType) {
+ return clazz.isAssignableFrom(String.class) && !arrayType;
+ }
+}