cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jheym...@apache.org
Subject svn commit: r330548 [89/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/...
Date Thu, 03 Nov 2005 14:00:48 GMT
Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/FlowJXPathSelectionListBuilder.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/FlowJXPathSelectionListBuilder.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/FlowJXPathSelectionListBuilder.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/FlowJXPathSelectionListBuilder.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,101 @@
+/*
+ * 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;
+
+import org.apache.avalon.framework.context.Context;
+import org.apache.avalon.framework.context.ContextException;
+import org.apache.avalon.framework.context.Contextualizable;
+import org.apache.cocoon.forms.FormsConstants;
+import org.apache.cocoon.forms.util.DomHelper;
+import org.w3c.dom.Element;
+
+import java.util.Map;
+
+/**
+ * Builds a selection list that will take its values from the flow page data.
+ * The items list and, for each item, its value and label, are fetched using
+ * JXPath expressions.
+ *
+ * <p>If an item has no label, its value is used as the label.
+ *
+ * <p>Example:
+ * <pre>
+ *   &lt;fd:selection-list type="flow-jxpath"
+ *       list-path="selectList" value-path="value" label-path="label"/gt;
+ * </pre>
+ * Flow script:
+ * <pre>
+ *   var data = {
+ *      selectList: [{value:3, label:"three"}, {value:4}]
+ *   };
+ *   form.showForm("form.html", data);
+ * </pre>
+ *
+ * @see org.apache.cocoon.forms.datatype.FlowJXPathSelectionList
+ * @author <a href="http://www.apache.org/~sylvain/">Sylvain Wallez</a>
+ * @version $Id: FlowJXPathSelectionListBuilder.java 326838 2005-10-20 06:26:53Z sylvain $
+ */
+public class FlowJXPathSelectionListBuilder implements SelectionListBuilder, Contextualizable {
+
+    private Context context;
+
+    public void contextualize(Context context) throws ContextException {
+        this.context = context;
+    }
+
+    public SelectionList build(Element selectionListElement, Datatype datatype) throws Exception {
+
+        String listPath = DomHelper.getAttribute(selectionListElement, "list-path");
+        String valuePath = DomHelper.getAttribute(selectionListElement, "value-path");
+        Map nspfx = DomHelper.getInheritedNSDeclarations(selectionListElement);
+        String i18nPfx = FormsConstants.I18N_PREFIX;
+        if (nspfx != null) {
+            i18nPfx = (String)nspfx.get( FormsConstants.I18N_NS );
+            if (i18nPfx == null ) {
+                i18nPfx = FormsConstants.I18N_PREFIX;
+            }
+        }
+        String labelPath = DomHelper.getAttribute(selectionListElement, "label-path", null);
+        boolean labelIsI18nKey = false;
+        if( labelPath == null )
+        {
+            labelPath = DomHelper.getAttribute(selectionListElement, i18nPfx + ":label-path");
+            labelIsI18nKey = true;
+        }
+        String nullText = DomHelper.getAttribute(selectionListElement, "null-text", null);
+        boolean nullTextIsI18nKey = false;
+        if( nullText == null ) {
+            nullText = DomHelper.getAttribute(selectionListElement, i18nPfx + ":null-text", null);
+            if( nullText != null ) {
+                nullTextIsI18nKey = true;
+            }
+        }
+        
+        String i18nCatalog = DomHelper.getAttribute(selectionListElement, "catalogue", null);
+
+
+        return new FlowJXPathSelectionList(context, 
+                                           listPath, 
+                                           valuePath, 
+                                           labelPath, 
+                                           datatype, 
+                                           nullText, 
+                                           nullTextIsI18nKey, 
+                                           i18nCatalog, 
+                                           labelIsI18nKey);
+    }
+
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/FlowJXPathSelectionListBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/JavaSelectionList.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/JavaSelectionList.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/JavaSelectionList.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/JavaSelectionList.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,35 @@
+/*
+ * 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;
+
+/**
+ * A selection list that takes its values from the custom java class itself.
+ * @version $Id$
+ */
+public interface JavaSelectionList extends SelectionList {
+
+	void setDatatype(Datatype datatype);
+
+	boolean isNullable();
+
+	void setNullable(boolean nullable);
+
+	String getAttribute(String name);
+
+	void setAttribute(String name, String value);
+
+	void removeAttribute(String name);
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/JavaSelectionList.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/JavaSelectionListBuilder.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/JavaSelectionListBuilder.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/JavaSelectionListBuilder.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/JavaSelectionListBuilder.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,95 @@
+/*
+ * 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;
+
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+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.thread.ThreadSafe;
+import org.apache.avalon.framework.component.Component;
+
+import org.apache.cocoon.components.LifecycleHelper;
+import org.apache.cocoon.forms.util.DomHelper;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+
+/**
+ * Builds {@link SelectionList}s from a JavaSelectionList class
+ *
+ * @version $Id$
+ */
+public class JavaSelectionListBuilder extends AbstractLogEnabled
+                                      implements SelectionListBuilder,
+                                                 Contextualizable, Serviceable, ThreadSafe, Component {
+
+    /**
+     * The Avalon Context
+     */
+    private Context context;
+
+    /**
+     * The Service Manager
+     */
+	private ServiceManager manager;
+
+    public void contextualize(Context context) throws ContextException {
+        this.context = context;
+    }
+
+    public void service(ServiceManager manager) throws ServiceException {
+        this.manager = manager;
+    }
+
+	public SelectionList build(Element selectionListElement, Datatype datatype)
+    throws Exception {
+		String className = DomHelper.getAttribute(selectionListElement, "class");
+		boolean nullable = DomHelper.getAttributeAsBoolean(selectionListElement, "nullable", true);
+
+		try {
+			Class clasz = Class.forName(className);
+			if (JavaSelectionList.class.isAssignableFrom(clasz)) {
+				JavaSelectionList list = (JavaSelectionList) clasz.newInstance();
+				LifecycleHelper.setupComponent(list, getLogger(), this.context, this.manager, null, true);
+				list.setDatatype(datatype);
+				list.setNullable(nullable);
+
+                // pass the attributes to the SelectionList
+				NamedNodeMap attrs = selectionListElement.getAttributes();
+				final int size = attrs.getLength();
+				for (int i = 0; i < size; i++) {
+					final Node attr = attrs.item(i);
+					final String name = attr.getNodeName();
+					list.setAttribute(name, attr.getNodeValue());
+				}
+
+				return list;
+			} else {
+                getLogger().warn("Class " + className + " does not implement JavaSelectionList, returning empty selection list.");
+				return new StaticSelectionList(datatype);
+			}
+		} catch (Exception e) {
+            if (getLogger().isDebugEnabled()) {
+                getLogger().debug("Got exception in build, re-throwing", e);
+            }
+			throw e;
+		}
+	}
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/JavaSelectionListBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/SelectionList.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/SelectionList.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/SelectionList.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/SelectionList.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,36 @@
+/*
+ * 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;
+
+import java.util.Locale;
+
+import org.xml.sax.ContentHandler;
+import org.xml.sax.SAXException;
+
+/**
+ * Interface to be implemented by selection lists.
+ * @version $Id: SelectionList.java 56582 2004-11-04 10:16:22Z sylvain $
+ */
+public interface SelectionList {
+    
+    public static final String SELECTION_LIST_EL = "selection-list";
+    public static final String ITEM_EL = "item";
+    public static final String LABEL_EL = "label";
+
+    Datatype getDatatype();
+
+    void generateSaxFragment(ContentHandler contentHandler, Locale locale) throws SAXException;
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/SelectionList.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/SelectionListBuilder.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/SelectionListBuilder.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/SelectionListBuilder.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/SelectionListBuilder.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,30 @@
+/*
+ * 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;
+
+import org.w3c.dom.Element;
+
+/**
+ * Builds {@link SelectionList}s from an XML description.
+ * 
+ * @version $Id: SelectionListBuilder.java 151179 2005-02-03 16:55:16Z tim $
+ */
+public interface SelectionListBuilder {
+    
+    static final String ROLE = SelectionListBuilder.class.getName();
+
+    SelectionList build(Element selectionListElement, Datatype datatype) throws Exception;
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/SelectionListBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/StaticSelectionList.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/StaticSelectionList.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/StaticSelectionList.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/StaticSelectionList.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,123 @@
+/*
+ * 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;
+
+import org.xml.sax.ContentHandler;
+import org.xml.sax.SAXException;
+import org.apache.cocoon.forms.FormsConstants;
+import org.apache.cocoon.forms.datatype.convertor.Convertor;
+import org.apache.cocoon.forms.datatype.convertor.DefaultFormatCache;
+import org.apache.cocoon.xml.AttributesImpl;
+import org.apache.cocoon.xml.XMLUtils;
+import org.apache.excalibur.xml.sax.XMLizable;
+
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.Locale;
+
+/**
+ * An implementation of a SelectionList. Create instances of this class by using
+ * the {@link SelectionListBuilder}. This implementation is called "Static" because
+ * the items in the list are build once from its source, and then list items are
+ * cached as part of this object. In contrast, the {@link DynamicSelectionList}
+ * will retrieve its content from its source each time it's needed.
+ *
+ * @version $Id: StaticSelectionList.java 326838 2005-10-20 06:26:53Z sylvain $
+ */
+public class StaticSelectionList implements SelectionList {
+    /**
+     * The datatype to which this selection list belongs
+     */
+    private Datatype datatype;
+
+    /**
+     * List of SelectionListItems
+     */
+    private List items;
+
+    public StaticSelectionList(Datatype datatype) {
+        this.datatype = datatype;
+        this.items = new ArrayList();
+    }
+
+    public Datatype getDatatype() {
+        return datatype;
+    }
+
+    public void generateSaxFragment(ContentHandler contentHandler, Locale locale) throws SAXException {
+        Convertor.FormatCache formatCache = new DefaultFormatCache();
+        contentHandler.startElement(FormsConstants.INSTANCE_NS, SELECTION_LIST_EL, FormsConstants.INSTANCE_PREFIX_COLON + SELECTION_LIST_EL, XMLUtils.EMPTY_ATTRIBUTES);
+
+        Iterator itemIt = this.items.iterator();
+        while (itemIt.hasNext()) {
+            final SelectionListItem item = (SelectionListItem) itemIt.next();
+            item.generateSaxFragment(contentHandler, locale, formatCache);
+        }
+
+        contentHandler.endElement(FormsConstants.INSTANCE_NS, SELECTION_LIST_EL, FormsConstants.INSTANCE_PREFIX_COLON + SELECTION_LIST_EL);
+    }
+
+    public List getItems() {
+        return this.items;
+    }
+
+    /**
+     * Adds a new item to this selection list.
+     * @param value a value of the correct type (i.e. the type with which this selectionlist is associated)
+     * @param label a SAX-fragment such as a {@link org.apache.cocoon.xml.SaxBuffer}, can be null
+     */
+    public void addItem(Object value, XMLizable label) {
+        this.items.add(new SelectionListItem(value, label));
+    }
+
+    public final class SelectionListItem {
+        private final Object value;
+        private final XMLizable label;
+
+        public SelectionListItem(Object value, XMLizable label) {
+            this.value = value;
+            this.label = label;
+        }
+
+        public Object getValue() {
+            return value;
+        }
+
+        public void generateSaxFragment(ContentHandler contentHandler, Locale locale, Convertor.FormatCache formatCache)
+        throws SAXException {
+            String stringValue;
+            if (this.value != null) {
+                stringValue = datatype.getConvertor().convertToString(this.value, locale, formatCache);
+            } else {
+                // Null value translates into the empty string
+                stringValue = "";
+            }
+
+            AttributesImpl attrs = new AttributesImpl();
+            attrs.addCDATAAttribute("value", stringValue);
+            contentHandler.startElement(FormsConstants.INSTANCE_NS, ITEM_EL, FormsConstants.INSTANCE_PREFIX_COLON + ITEM_EL, attrs);
+            contentHandler.startElement(FormsConstants.INSTANCE_NS, LABEL_EL, FormsConstants.INSTANCE_PREFIX_COLON + LABEL_EL, XMLUtils.EMPTY_ATTRIBUTES);
+            if (this.label != null) {
+                this.label.toSAX(contentHandler);
+            } else {
+                contentHandler.characters(stringValue.toCharArray(), 0, stringValue.length());
+            }
+            contentHandler.endElement(FormsConstants.INSTANCE_NS, LABEL_EL, FormsConstants.INSTANCE_PREFIX_COLON + LABEL_EL);
+            contentHandler.endElement(FormsConstants.INSTANCE_NS, ITEM_EL, FormsConstants.INSTANCE_PREFIX_COLON + ITEM_EL);
+        }
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/StaticSelectionList.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/ValidationRule.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/ValidationRule.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/ValidationRule.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/ValidationRule.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;
+
+import org.apache.cocoon.forms.validation.ValidationError;
+import org.outerj.expression.ExpressionContext;
+
+/**
+ * Interface for validation rules. Most {@link Datatype} implementations will
+ * perform their validation by checking a number of these validation rules
+ * (though strictly spoken this is not required).
+ * 
+ * @version $Id: ValidationRule.java 56582 2004-11-04 10:16:22Z sylvain $
+ */
+public interface ValidationRule {
+    /**
+     *
+     * @param value a value of a class supported by the ValidationRule implementation
+     * @param expressionContext many validation rules use the xReporter expression interpreter,
+     * the expressionContext allows to resolve variables used in these expressions.
+     */
+    ValidationError validate(Object value, ExpressionContext expressionContext);
+
+    /**
+     * Returns true if this ValidationRule supports validating objects of the same class
+     * as the one specified. If the flag 'arrayType' is true, this method will return true
+     * if this validation rule can validate arrays of these objects (i.e. the object passed
+     * to the validate method will then be an array).
+     */
+    boolean supportsType(Class clazz, boolean arrayType);
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/ValidationRule.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/ValidationRuleBuilder.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/ValidationRuleBuilder.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/ValidationRuleBuilder.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/ValidationRuleBuilder.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,30 @@
+/*
+ * 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;
+
+import org.w3c.dom.Element;
+
+/**
+ * Interface for classes that can build ValidationRules from an XML description.
+ * A ValidationRuleBuilder can be Serviceable.
+ * A ValidationRuleBuilder should be thread safe, only one instance of it
+ * will be created.
+ * 
+ * @version $Id: ValidationRuleBuilder.java 55391 2004-10-23 18:15:02Z cziegeler $
+ */
+public interface ValidationRuleBuilder {
+    public ValidationRule build(Element validationRuleElement) throws Exception;
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/ValidationRuleBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/BeanConvertor.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/convertor/BeanConvertor.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/BeanConvertor.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/BeanConvertor.java Thu Nov  3 05:41:06 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 versa.
+ * 
+ * <p>
+ * Sometimes the toString() method doesn't give a good representation of a
+ * Java Bean suited for selection list IDs. For this an optional  
+ * &lt;fd:id-path&gt;jx-path&lt;/fd:id-path&gt; attribute can be specified to 
+ * have this convertor to use a different string representation.
+ * </p>
+ *
+ * @author <a href="mailto:giacomo@apache.org">Giacomo Pati</a>
+ * @version $Id$
+ */
+public class BeanConvertor
+    implements Convertor
+{
+    //~ Instance fields --------------------------------------------------------
+
+    private Class m_class;
+
+    private Map m_objects = new WeakHashMap(  );
+
+    private String m_idPath;
+
+    //~ Constructors -----------------------------------------------------------
+
+    /**
+     * Construct a new BeanConvertor for a class
+     *
+     * @param className The package-qualified name of the class implementing
+     *        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 = Class.forName( className );
+        }
+        catch( ClassNotFoundException e )
+        {
+            throw new CascadingRuntimeException( "Class " + className +
+                                                 " not found", e );
+        }
+
+        m_idPath = idPath;
+    }
+
+    //~ Methods ----------------------------------------------------------------
+
+    /**
+     * @see org.apache.cocoon.forms.datatype.convertor.Convertor#getTypeClass()
+     */
+    public Class getTypeClass(  )
+    {
+        return m_class;
+    }
+
+    /**
+     * @see org.apache.cocoon.forms.datatype.convertor.Convertor#convertFromString(java.lang.String,
+     *      java.util.Locale,
+     *      org.apache.cocoon.forms.datatype.convertor.Convertor.FormatCache)
+     */
+    public ConversionResult convertFromString( final String value,
+                                               final Locale locale,
+                                               final FormatCache formatCache )
+    {
+        return new ConversionResult( m_objects.get( value ) );
+    }
+
+    /**
+     * @see org.apache.cocoon.forms.datatype.convertor.Convertor#convertToString(java.lang.Object,
+     *      java.util.Locale,
+     *      org.apache.cocoon.forms.datatype.convertor.Convertor.FormatCache)
+     */
+    public String convertToString( final Object value,
+                                   final Locale locale,
+                                   final FormatCache formatCache )
+    {
+        String idValue = "";
+
+        if( null != value )
+        {
+            if( m_idPath != null )
+            {
+                final JXPathContext ctx = JXPathContext.newContext( value );
+                idValue = ctx.getValue( m_idPath ).toString(  );
+            }
+            else
+            {
+                idValue = 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
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/BeanConvertor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/BeanConvertorBuilder.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/convertor/BeanConvertorBuilder.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/BeanConvertorBuilder.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/BeanConvertorBuilder.java Thu Nov  3 05:41:06 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.FormsConstants;
+import org.apache.cocoon.forms.util.DomHelper;
+
+import org.w3c.dom.Element;
+
+
+/**
+ * Creates {@link BeanConvertor}s
+ * 
+ * <p>
+ * The optional &lt;fd:bean&gt;FQCN&lt;/fd:bean&gt; attribute is used to give 
+ * 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.
+ * <p>
+ * Sometimes the toString() method doesn't give a good representation of a
+ * Java Bean suited for selection list IDs. For this an optional  
+ * &lt;fd:id-path&gt;jx-path&lt;/fd:id-path&gt; attribute can be specified to 
+ * have this convertor to use a different string representation.
+ * </p>
+ *
+ * @author <a href="mailto:giacomo@apache.org">Giacomo Pati</a>
+ * @version $Id$
+ */
+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 == null )
+        {
+            return null;
+        }
+
+        final Element beanEl =
+            DomHelper.getChildElement( configElement, FormsConstants.DEFINITION_NS,
+                                       "bean", false );
+        final String clazz =
+            ( ( beanEl == null ) ? Object.class.getName(  )
+              : beanEl.getFirstChild(  ).getNodeValue(  ) );
+        final Element idPathEl =
+            DomHelper.getChildElement( configElement, FormsConstants.DEFINITION_NS,
+                                       "id-path", false );
+        final String idPath =
+            ( ( idPathEl != null )
+              ? idPathEl.getFirstChild(  ).getNodeValue(  ) : null );
+        final BeanConvertor convertor = new BeanConvertor( clazz, idPath );
+
+        return convertor;
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/BeanConvertorBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/ConversionResult.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/convertor/ConversionResult.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/ConversionResult.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/ConversionResult.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,82 @@
+/*
+ * 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.validation.ValidationError;
+import org.apache.cocoon.forms.util.I18nMessage;
+import org.apache.cocoon.forms.FormsConstants;
+
+/**
+ * Object returned as result of {@link Convertor#convertFromString(java.lang.String, java.util.Locale, org.apache.cocoon.forms.datatype.convertor.Convertor.FormatCache)}.
+ */
+public class ConversionResult {
+    private ValidationError validationError;
+    private boolean successful;
+    private Object result;
+
+    /**
+     * Constructs a successful ConversionResult.
+     */
+    public ConversionResult(Object result) {
+        this.successful = true;
+        this.result = result;
+    }
+
+    /**
+     * Constructs an unsuccessful ConversionResult.
+     */
+    public ConversionResult(ValidationError validationError) {
+        this.successful = false;
+        this.validationError = validationError;
+    }
+
+    /**
+     * Constructs an unsuccessful ConversionResult. Will create
+     * a default ValidationError message using the given
+     * datatypeName.
+     *
+     * <p>Note: this is not done as a constructor because
+     * it would conflict with the constructor which takes
+     * an Object as argument.
+     */
+    public static ConversionResult create(String datatypeName) {
+        ValidationError validationError = new ValidationError(new I18nMessage(
+            "datatype.conversion-failed",
+            new String[] {"datatype." + datatypeName},
+            new boolean[] { true },
+            FormsConstants.I18N_CATALOGUE
+        ));
+        return new ConversionResult(validationError);
+    }
+
+    public boolean isSuccessful() {
+        return successful;
+    }
+
+    public ValidationError getValidationError() {
+        if (successful)
+            throw new IllegalStateException("Cannot call getValidationError() if conversion is successful.");
+
+        return validationError;
+    }
+
+    public Object getResult() {
+        if (!successful)
+            throw new IllegalStateException("Cannot call getResult() if conversion is not successful.");
+
+        return result;
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/ConversionResult.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/Convertor.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/convertor/Convertor.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/Convertor.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/Convertor.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.convertor;
+
+import org.xml.sax.SAXException;
+import org.xml.sax.ContentHandler;
+
+import java.util.Locale;
+
+/**
+ * The purpose of a Convertor is to convert between Object and String
+ * representations of the same thing. For example, convert
+ * {@link Long}s or {@link java.util.Date Date}s to strings, and vice
+ * versa. The behaviour of this conversion process can depend on the
+ * user's Locale.
+ *
+ * <p>If you need to do mass conversion of a lot of values, it may be
+ * beneficial to pass a {@link FormatCache} object to the convert methods.
+ * Some convertors need to build and configure parser or formatting objects,
+ * which can be expensive if it needs to be done repeatedly.
+ *
+ * @version $Id: Convertor.java 151179 2005-02-03 16:55:16Z tim $
+ */
+public interface Convertor {
+    
+    /**
+     * Converts string representation into the object of convertor's type.
+     *
+     * @param formatCache can be null if not needed
+     */
+    ConversionResult convertFromString(String value, Locale locale, FormatCache formatCache);
+
+    String convertToString(Object value, Locale locale, FormatCache formatCache);
+
+    Class getTypeClass();
+
+    /**
+     * Generates a bit of information about this convertor (optional).
+     */
+    void generateSaxFragment(ContentHandler contentHandler, Locale locale) throws SAXException;
+
+    public interface FormatCache {
+        public Object get();
+        public void store(Object object);
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/Convertor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/ConvertorBuilder.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/convertor/ConvertorBuilder.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/ConvertorBuilder.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/ConvertorBuilder.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,36 @@
+/*
+ * 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.w3c.dom.Element;
+
+/**
+ * Interface to be implemented by components that can build a Convertor
+ * based on a XML configuration (supplied as DOM Element).
+ *
+ * <p>The element will (should)
+ * always have the local name "convertor" and the cforms definition namespace,
+ * but attributes and content of the element can vary depending on the
+ * ConvertorBuilder implementation.
+ *
+ * @version $Id: ConvertorBuilder.java 151179 2005-02-03 16:55:16Z tim $
+ */
+public interface ConvertorBuilder {
+    /**
+     * @param configElement is allowed to be null!
+     */
+    Convertor build(Element configElement) throws Exception;
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/ConvertorBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/DefaultFormatCache.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/convertor/DefaultFormatCache.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/DefaultFormatCache.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/DefaultFormatCache.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.convertor;
+
+/**
+ *
+ * @version $Id: DefaultFormatCache.java 151179 2005-02-03 16:55:16Z tim $
+ */
+public class DefaultFormatCache implements Convertor.FormatCache {
+    private Object object;
+
+    public Object get() {
+        return object;
+    }
+
+    public void store(Object object) {
+        this.object = object;
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/DefaultFormatCache.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/DummyStringConvertor.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/convertor/DummyStringConvertor.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/DummyStringConvertor.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/DummyStringConvertor.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,45 @@
+/*
+ * 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.xml.sax.ContentHandler;
+import org.xml.sax.SAXException;
+
+import java.util.Locale;
+
+/**
+ * Convertor that converts between strings and strings, in other words,
+ * it does nothing.
+ *
+ * @version $Id: DummyStringConvertor.java 151179 2005-02-03 16:55:16Z tim $
+ */
+public class DummyStringConvertor implements Convertor {
+    public ConversionResult convertFromString(String value, Locale locale, Convertor.FormatCache formatCache) {
+        return new ConversionResult(value);
+    }
+
+    public String convertToString(Object value, Locale locale, Convertor.FormatCache formatCache) {
+        return (String)value;
+    }
+
+    public Class getTypeClass() {
+        return String.class;
+    }
+
+    public void generateSaxFragment(ContentHandler contentHandler, Locale locale) throws SAXException {
+        // intentionally empty
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/DummyStringConvertor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/DummyStringConvertorBuilder.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/convertor/DummyStringConvertorBuilder.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/DummyStringConvertorBuilder.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/DummyStringConvertorBuilder.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,29 @@
+/*
+ * 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.w3c.dom.Element;
+
+/**
+ * Builds {@link DummyStringConvertor}s.
+ *
+ * @version $Id: DummyStringConvertorBuilder.java 151179 2005-02-03 16:55:16Z tim $
+ */
+public class DummyStringConvertorBuilder implements ConvertorBuilder {
+    public Convertor build(Element configElement) throws Exception {
+        return new DummyStringConvertor();
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/DummyStringConvertorBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/EnumConvertor.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/convertor/EnumConvertor.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/EnumConvertor.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/EnumConvertor.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,118 @@
+/*
+ * 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 java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.Locale;
+
+import org.apache.avalon.framework.CascadingRuntimeException;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.SAXException;
+
+/**
+ * A {@link org.apache.cocoon.forms.datatype.convertor.Convertor Convertor}
+ * implementation for types implementing Joshua Bloch's
+ * <a href="http://developer.java.sun.com/developer/Books/shiftintojava/page1.html#replaceenums">
+ * typesafe enum</a> pattern.
+ * 
+ * @see org.apache.cocoon.forms.datatype.typeimpl.EnumType
+ * @version $Id: EnumConvertor.java 151179 2005-02-03 16:55:16Z tim $
+ */
+public class EnumConvertor implements Convertor {
+
+    private Class clazz;
+    
+    /**
+     * Construct a new EnumConvertor for a class
+     * @param className The package-qualified name of the class implementing
+     * the typesafe enum pattern.
+     */
+    public EnumConvertor(String className) {
+        try {
+            clazz = Class.forName(className);
+        }
+        catch (ClassNotFoundException e) {
+            throw new CascadingRuntimeException("Class " + className + " not found", e);
+        }
+    }
+    
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.forms.datatype.convertor.Convertor#convertFromString(java.lang.String, java.util.Locale, org.apache.cocoon.forms.datatype.convertor.Convertor.FormatCache)
+     */
+    public ConversionResult convertFromString(String value,
+									Locale locale,
+									FormatCache formatCache) {
+        try {
+            // If the enum provides a "fromString" method, use it
+            try {
+                Method method = getTypeClass().
+                    getMethod("fromString", new Class[] { String.class, Locale.class});
+                return new ConversionResult(method.invoke(null, new Object[] { value, locale}));
+            } catch(NoSuchMethodException nsme) {
+                // fromString method was not found, try to convert
+                // the value to a field via reflection.
+                // Strip the class name
+                int pos = value.lastIndexOf('.');
+                if (pos >= 0) {
+                    value = value.substring(pos + 1);
+                }
+                Class clazz = getTypeClass();
+                Field field = clazz.getField(value);
+                return new ConversionResult(field.get(null));
+            }
+        } catch (Exception e) {
+            throw new CascadingRuntimeException("Got exception trying to convert " + value, e);
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.forms.datatype.convertor.Convertor#convertToString(java.lang.Object, java.util.Locale, org.apache.cocoon.forms.datatype.convertor.Convertor.FormatCache)
+     */
+    public String convertToString(Object value,
+								  Locale locale,
+								  FormatCache formatCache) {
+        Class clazz = getTypeClass();
+        Field fields[] = clazz.getDeclaredFields();
+        for (int i = 0 ; i < fields.length ; ++i) {
+            try {
+                int mods = fields[i].getModifiers();
+                if (Modifier.isPublic(mods)
+                        && Modifier.isStatic(mods)
+                        && Modifier.isFinal(mods)
+                        && fields[i].get(null).equals(value)) {
+                    return clazz.getName() + "." + fields[i].getName();
+                }
+            } catch (Exception e) {
+                throw new CascadingRuntimeException("Got exception trying to get value of field " + fields[i], e);
+            }
+        }
+        // Fall back on toString
+        return value.toString();
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.forms.datatype.convertor.Convertor#getTypeClass()
+     */
+    public Class getTypeClass() {
+        return clazz;
+    }
+
+    public void generateSaxFragment(ContentHandler contentHandler, Locale locale) throws SAXException {
+        // intentionally empty
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/EnumConvertor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/EnumConvertorBuilder.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/convertor/EnumConvertorBuilder.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/EnumConvertorBuilder.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/EnumConvertorBuilder.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,42 @@
+/*
+ * 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.FormsConstants;
+import org.apache.cocoon.forms.util.DomHelper;
+import org.w3c.dom.Element;
+
+/**
+ * Builds {@link EnumConvertor}s.
+ * 
+ * @version $Id: EnumConvertorBuilder.java 326838 2005-10-20 06:26:53Z sylvain $
+ */
+public class EnumConvertorBuilder implements ConvertorBuilder {
+
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.form.datatype.convertor.ConvertorBuilder#build(org.w3c.dom.Element)
+     */
+    public Convertor build(Element configElement) throws Exception {
+        if (configElement == null) {
+            return null;
+        }
+        Element enumEl = DomHelper.getChildElement(configElement,
+                FormsConstants.DEFINITION_NS, "enum", true);
+        String clazz = enumEl.getFirstChild().getNodeValue();
+        return new EnumConvertor(clazz);
+    }
+
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/EnumConvertorBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/FormattingDateConvertor.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/convertor/FormattingDateConvertor.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/FormattingDateConvertor.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/FormattingDateConvertor.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,159 @@
+/*
+ * 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.xml.sax.ContentHandler;
+import org.xml.sax.SAXException;
+import org.apache.cocoon.forms.FormsConstants;
+import org.apache.cocoon.xml.AttributesImpl;
+
+import java.util.Locale;
+import java.util.Date;
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+
+/**
+ * A Convertor for {@link java.util.Date Date} objects backed by the
+ * {@link java.text.SimpleDateFormat SimpleDateFormat} class.
+ *
+ * <p>It can be configured to use one of three <strong>variants</strong>: date,
+ * time or datetime and one of four <strong>styles</strong>: long, full, medium or short.
+ *
+ * <p>Alternatively, a <strong>formatting pattern</strong> can be used. This can either be a locale-dependent
+ * or locale-independent formatting pattern. When looking up a formatting pattern, a mechansim
+ * similar to resource bundle lookup is used. Suppose the locale is nl-BE, then first a formatting
+ * pattern for nl-BE will be sought, then one for nl, and if that is not
+ * found, finally the locale-independent formatting pattern will be used.
+ *
+ * @version $Id: FormattingDateConvertor.java 326838 2005-10-20 06:26:53Z sylvain $
+ */
+public class FormattingDateConvertor implements Convertor {
+    /** See {@link #setStyle}. */
+    private int style;
+    /** See {@link #setVariant}. */
+    private String variant;
+    /** Locale-specific formatting patterns. */
+    private LocaleMap localizedPatterns;
+    /** Non-locale specific formatting pattern. */
+    private String nonLocalizedPattern;
+
+    public static final String DATE = "date";
+    public static final String TIME = "time";
+    public static final String DATE_TIME = "datetime";
+
+    public FormattingDateConvertor() {
+        this.style = DateFormat.SHORT;
+        this.variant = DATE;
+        this.localizedPatterns = new LocaleMap();
+    }
+
+    public ConversionResult convertFromString(String value, Locale locale, Convertor.FormatCache formatCache) {
+        SimpleDateFormat dateFormat = getDateFormat(locale, formatCache);
+        try {
+            return new ConversionResult(dateFormat.parse(value));
+        } catch (ParseException e) {
+            return ConversionResult.create("date." + this.variant);
+        }
+    }
+
+    public String convertToString(Object value, Locale locale, Convertor.FormatCache formatCache) {
+        SimpleDateFormat dateFormat = getDateFormat(locale, formatCache);
+        return dateFormat.format((Date)value);
+    }
+
+    private final SimpleDateFormat getDateFormat(Locale locale, Convertor.FormatCache formatCache) {
+        SimpleDateFormat dateFormat = null;
+        if (formatCache != null)
+            dateFormat = (SimpleDateFormat)formatCache.get();
+        if (dateFormat == null) {
+            dateFormat = getDateFormat(locale);
+            if (formatCache != null)
+                formatCache.store(dateFormat);
+        }
+        return dateFormat;
+    }
+
+    protected SimpleDateFormat getDateFormat(Locale locale) {
+        SimpleDateFormat dateFormat = null;
+
+        if (this.variant.equals(DATE)) {
+            //dateFormat = I18nSupport.getInstance().getDateFormat(style, locale);
+            dateFormat = (SimpleDateFormat)DateFormat.getDateInstance(style, locale);
+        } else if (this.variant.equals(TIME)) {
+            //dateFormat = I18nSupport.getInstance().getTimeFormat(style, locale);
+            dateFormat = (SimpleDateFormat)DateFormat.getTimeInstance(style, locale);
+        } else if (this.variant.equals(DATE_TIME)) {
+            //dateFormat = I18nSupport.getInstance().getDateTimeFormat(style, style, locale);
+            dateFormat = (SimpleDateFormat)DateFormat.getDateTimeInstance(style, style, locale);
+        }
+
+        String pattern = (String)localizedPatterns.get(locale);
+
+        if (pattern != null)
+            // Note: this was previously using applyLocalizedPattern() which allows to use
+            // a locale-specific pattern syntax, e.g. in french "j" (jour) for "d" and
+            // "a" (annee) for "y". But the localized pattern syntax is very little known and thus
+            // led to some weird pattern syntax error messages.
+            dateFormat.applyPattern(pattern);
+        else if (nonLocalizedPattern != null)
+            dateFormat.applyPattern(nonLocalizedPattern);
+
+        return dateFormat;
+    }
+
+    public Class getTypeClass() {
+        return Date.class;
+    }
+
+    /**
+     *
+     * @param style one of the constants FULL, LONG, MEDIUM or SHORT defined in the {@link Date} class.
+     */
+    public void setStyle(int style) {
+        this.style = style;
+    }
+
+    public void setVariant(String variant) {
+        if (DATE.equals(variant) || TIME.equals(variant) || DATE_TIME.equals(variant)) {
+            this.variant = variant;
+        } else {
+            throw new IllegalArgumentException("Invalid value for variant parameter.");
+        }
+    }
+
+    public void addFormattingPattern(Locale locale, String pattern) {
+        localizedPatterns.put(locale, pattern);
+    }
+
+    public void setNonLocalizedPattern(String pattern) {
+        this.nonLocalizedPattern = pattern;
+    }
+
+    private static final String CONVERTOR_EL = "convertor";
+
+    public void generateSaxFragment(ContentHandler contentHandler, Locale locale) throws SAXException {
+        String pattern = getDateFormat(locale).toPattern();
+
+        if (pattern != null) {
+            AttributesImpl attrs = new AttributesImpl();
+            attrs.addCDATAAttribute("pattern", pattern);
+            attrs.addCDATAAttribute("variant", this.variant);
+            contentHandler.startElement(FormsConstants.INSTANCE_NS, CONVERTOR_EL, FormsConstants.INSTANCE_PREFIX_COLON + CONVERTOR_EL, attrs);
+            contentHandler.endElement(FormsConstants.INSTANCE_NS, CONVERTOR_EL, FormsConstants.INSTANCE_PREFIX_COLON + CONVERTOR_EL);
+        }
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/FormattingDateConvertor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/FormattingDateConvertorBuilder.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/convertor/FormattingDateConvertorBuilder.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/FormattingDateConvertorBuilder.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/FormattingDateConvertorBuilder.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,82 @@
+/*
+ * 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.w3c.dom.Element;
+import org.apache.cocoon.forms.FormsConstants;
+import org.apache.cocoon.forms.util.DomHelper;
+import org.apache.cocoon.i18n.I18nUtils;
+
+import java.text.DateFormat;
+import java.util.Locale;
+
+/**
+ * Builds {@link FormattingDateConvertor}s.
+ *
+ * @version $Id: FormattingDateConvertorBuilder.java 326838 2005-10-20 06:26:53Z sylvain $
+ */
+public class FormattingDateConvertorBuilder implements ConvertorBuilder {
+    public Convertor build(Element configElement) throws Exception {
+        FormattingDateConvertor convertor = new FormattingDateConvertor();
+
+        if (configElement == null)
+            return convertor;
+
+        String style = configElement.getAttribute("style");
+        if (!style.equals("")) {
+            if (style.equals("short"))
+                convertor.setStyle(DateFormat.SHORT);
+            else if (style.equals("medium"))
+                convertor.setStyle(DateFormat.MEDIUM);
+            else if (style.equals("long"))
+                convertor.setStyle(DateFormat.LONG);
+            else if (style.equals("full"))
+                convertor.setStyle(DateFormat.FULL);
+            else
+                throw new Exception("Invalid value \"" + style + "\" for style attribute at " + DomHelper.getLocation(configElement));
+        }
+
+        String variant = configElement.getAttribute("variant");
+        if (!variant.equals("")) {
+            if (variant.equals(FormattingDateConvertor.DATE) ||
+                    variant.equals(FormattingDateConvertor.TIME) ||
+                    variant.equals(FormattingDateConvertor.DATE_TIME)) {
+                convertor.setVariant(variant);
+            } else {
+                throw new Exception("Invalid value \"" + variant + "\" for variant attribute at " + DomHelper.getLocation(configElement));
+            }
+        }
+
+        Element patternsEl = DomHelper.getChildElement(configElement, FormsConstants.DEFINITION_NS, "patterns", false);
+        if (patternsEl != null) {
+            Element patternEl[] = DomHelper.getChildElements(patternsEl, FormsConstants.DEFINITION_NS, "pattern");
+            for (int i = 0; i < patternEl.length; i++) {
+                String locale = patternEl[i].getAttribute("locale");
+                String pattern = DomHelper.getElementText(patternEl[i]);
+                if (pattern.equals(""))
+                    throw new Exception("pattern element does not contain any content at " + DomHelper.getLocation(patternEl[i]));
+                if (locale.equals(""))
+                    convertor.setNonLocalizedPattern(pattern);
+                else {
+                    Locale loc = I18nUtils.parseLocale(locale);
+                    convertor.addFormattingPattern(loc, pattern);
+                }
+            }
+        }
+
+        return convertor;
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/FormattingDateConvertorBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/FormattingDecimalConvertor.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/convertor/FormattingDecimalConvertor.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/FormattingDecimalConvertor.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/FormattingDecimalConvertor.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,160 @@
+/*
+ * 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.xml.sax.ContentHandler;
+import org.xml.sax.SAXException;
+
+import java.util.Locale;
+import java.text.DecimalFormat;
+import java.text.NumberFormat;
+import java.text.ParseException;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+
+/**
+ * A Convertor for {@link BigDecimal}s backed by the
+ * {@link java.text.DecimalFormat DecimalFormat} class.
+ *
+ * <p>It can be configured to use one of these variants: integer,
+ * number, currency or percent.
+ *
+ * <p>Alternatively, a <strong>formatting pattern</strong> can be used. This can either be a locale-dependent
+ * or locale-independent formatting pattern. When looking up a formatting pattern, a mechansim
+ * similar to resource bundle lookup is used. Suppose the locale is nl-BE, then first a formatting
+ * pattern for nl-BE will be sought, then one for nl, and if that is not
+ * found, finally the locale-independent formatting pattern will be used.
+ *
+ * @version $Id: FormattingDecimalConvertor.java 157080 2005-03-11 14:04:07Z sylvain $
+ */
+public class FormattingDecimalConvertor implements Convertor {
+    private int variant;
+    /** Locale-specific formatting patterns. */
+    private LocaleMap localizedPatterns;
+    /** Non-locale specific formatting pattern. */
+    private String nonLocalizedPattern;
+
+    public static final int INTEGER = 0;
+    public static final int NUMBER = 1;
+    public static final int CURRENCY = 2;
+    public static final int PERCENT = 3;
+
+    public FormattingDecimalConvertor() {
+        this.variant = getDefaultVariant();
+        this.localizedPatterns = new LocaleMap();
+    }
+
+    protected int getDefaultVariant() {
+        return NUMBER;
+    }
+
+    public ConversionResult convertFromString(String value, Locale locale, Convertor.FormatCache formatCache) {
+        // Some locales (e.g. "fr") produce non-breaking spaces sent back as space by the browser
+        value = value.replace(' ', (char)160);
+        DecimalFormat decimalFormat = getDecimalFormat(locale, formatCache);
+        Number decimalValue;
+        try {
+            decimalValue = decimalFormat.parse(value);
+        } catch (ParseException e) {
+            return ConversionResult.create("decimal");
+        }
+
+        if (decimalValue instanceof BigDecimal) {
+            // no need for conversion
+        } else if (decimalValue instanceof Integer) {
+            decimalValue = new BigDecimal(decimalValue.intValue());
+        } else if (decimalValue instanceof Long) {
+            decimalValue = new BigDecimal(decimalValue.longValue());
+        } else if (decimalValue instanceof Double) {
+            decimalValue = new BigDecimal(decimalValue.doubleValue());
+        } else if (decimalValue instanceof BigInteger) {
+            decimalValue = new BigDecimal((BigInteger)decimalValue);
+        } else {
+            return ConversionResult.create("decimal");
+        }
+        return new ConversionResult(decimalValue);
+    }
+
+    public String convertToString(Object value, Locale locale, Convertor.FormatCache formatCache) {
+        DecimalFormat decimalFormat = getDecimalFormat(locale, formatCache);
+        return decimalFormat.format(value);
+    }
+
+    protected final DecimalFormat getDecimalFormat(Locale locale, Convertor.FormatCache formatCache) {
+        DecimalFormat decimalFormat = null;
+        if (formatCache != null)
+            decimalFormat = (DecimalFormat)formatCache.get();
+        if (decimalFormat == null) {
+            decimalFormat = getDecimalFormat(locale);
+            if (formatCache != null)
+                formatCache.store(decimalFormat);
+        }
+        return decimalFormat;
+    }
+
+    private DecimalFormat getDecimalFormat(Locale locale) {
+        DecimalFormat decimalFormat = null;
+
+        switch (variant) {
+            case INTEGER:
+                decimalFormat = (DecimalFormat)NumberFormat.getNumberInstance(locale);
+                decimalFormat.setMaximumFractionDigits(0);
+                decimalFormat.setDecimalSeparatorAlwaysShown(false);
+                decimalFormat.setParseIntegerOnly(true);
+                break;
+            case NUMBER:
+                decimalFormat = (DecimalFormat)NumberFormat.getNumberInstance(locale);
+                break;
+            case CURRENCY:
+                decimalFormat = (DecimalFormat)NumberFormat.getCurrencyInstance(locale);
+                break;
+            case PERCENT:
+                decimalFormat = (DecimalFormat)NumberFormat.getPercentInstance(locale);
+                break;
+        }
+
+        String pattern = (String)localizedPatterns.get(locale);
+
+        if (pattern != null) {
+            decimalFormat.applyPattern(pattern);
+        } else if (nonLocalizedPattern != null) {
+            decimalFormat.applyPattern(nonLocalizedPattern);
+        }
+        return decimalFormat;
+    }
+
+    public void setVariant(int variant) {
+        if (variant != INTEGER && variant != NUMBER && variant != CURRENCY && variant != PERCENT)
+            throw new IllegalArgumentException("Invalid value for variant parameter.");
+        this.variant = variant;
+    }
+
+    public void addFormattingPattern(Locale locale, String pattern) {
+        localizedPatterns.put(locale, pattern);
+    }
+
+    public void setNonLocalizedPattern(String pattern) {
+        this.nonLocalizedPattern = pattern;
+    }
+
+    public Class getTypeClass() {
+        return java.math.BigDecimal.class;
+    }
+
+    public void generateSaxFragment(ContentHandler contentHandler, Locale locale) throws SAXException {
+        // intentionally empty
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/FormattingDecimalConvertor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/FormattingDecimalConvertorBuilder.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/convertor/FormattingDecimalConvertorBuilder.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/FormattingDecimalConvertorBuilder.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/FormattingDecimalConvertorBuilder.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,74 @@
+/*
+ * 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.w3c.dom.Element;
+import org.apache.cocoon.forms.FormsConstants;
+import org.apache.cocoon.forms.util.DomHelper;
+import org.apache.cocoon.i18n.I18nUtils;
+
+import java.util.Locale;
+
+/**
+ * Builds {@link FormattingDecimalConvertor}s.
+ *
+ * @version $Id: FormattingDecimalConvertorBuilder.java 326838 2005-10-20 06:26:53Z sylvain $
+ */
+public class FormattingDecimalConvertorBuilder implements ConvertorBuilder {
+    public Convertor build(Element configElement) throws Exception {
+        FormattingDecimalConvertor convertor = createConvertor();
+
+        if (configElement == null)
+            return convertor;
+
+        String variant = configElement.getAttribute("variant");
+        if (!variant.equals("")) {
+            if (variant.equals("integer"))
+                convertor.setVariant(FormattingDecimalConvertor.INTEGER);
+            else if (variant.equals("number"))
+                convertor.setVariant(FormattingDecimalConvertor.NUMBER);
+            else if (variant.equals("percent"))
+                convertor.setVariant(FormattingDecimalConvertor.PERCENT);
+            else if (variant.equals("currency"))
+                convertor.setVariant(FormattingDecimalConvertor.CURRENCY);
+            else
+                throw new Exception("Invalid value \"" + variant + "\" for variant attribute at " + DomHelper.getLocation(configElement));
+        }
+
+        Element patternsEl = DomHelper.getChildElement(configElement, FormsConstants.DEFINITION_NS, "patterns", false);
+        if (patternsEl != null) {
+            Element patternEl[] = DomHelper.getChildElements(patternsEl, FormsConstants.DEFINITION_NS, "pattern");
+            for (int i = 0; i < patternEl.length; i++) {
+                String locale = patternEl[i].getAttribute("locale");
+                String pattern = DomHelper.getElementText(patternEl[i]);
+                if (pattern.equals(""))
+                    throw new Exception("pattern element does not contain any content at " + DomHelper.getLocation(patternEl[i]));
+                if (locale.equals(""))
+                    convertor.setNonLocalizedPattern(pattern);
+                else {
+                    Locale loc = I18nUtils.parseLocale(locale);
+                    convertor.addFormattingPattern(loc, pattern);
+                }
+            }
+        }
+
+        return convertor;
+    }
+
+    protected FormattingDecimalConvertor createConvertor() {
+        return new FormattingDecimalConvertor();
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/FormattingDecimalConvertorBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/FormattingDoubleConvertor.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/convertor/FormattingDoubleConvertor.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/FormattingDoubleConvertor.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/FormattingDoubleConvertor.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,55 @@
+/*
+ * 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 java.util.Locale;
+import java.text.DecimalFormat;
+import java.text.ParseException;
+
+/**
+ * A Convertor for {@link Double}s backed by the
+ * {@link java.text.DecimalFormat DecimalFormat} class.
+ *
+ * <p>This class is mostly the same as the {@link FormattingDecimalConvertor},
+ * so see there for more information.
+ *
+ * @version $Id: FormattingDoubleConvertor.java 157080 2005-03-11 14:04:07Z sylvain $
+ */
+public class FormattingDoubleConvertor extends FormattingDecimalConvertor {
+
+    public FormattingDoubleConvertor() {
+        super();
+    }
+
+    public ConversionResult convertFromString(String value, Locale locale, Convertor.FormatCache formatCache) {
+        // Some locales (e.g. "fr") produce non-breaking spaces sent back as space by the browser
+        value = value.replace(' ', (char)160);
+        DecimalFormat decimalFormat = getDecimalFormat(locale, formatCache);
+        try {
+            Number decimalValue = decimalFormat.parse(value);
+            if (decimalValue instanceof Double)
+                return new ConversionResult(decimalValue);
+            else
+                return new ConversionResult(new Double(decimalValue.doubleValue()));
+        } catch (ParseException e) {
+            return ConversionResult.create("double");
+        }
+    }
+
+    public Class getTypeClass() {
+        return Double.class;
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/FormattingDoubleConvertor.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message