You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by as...@apache.org on 2006/03/11 21:23:31 UTC
svn commit: r385151 - in
/cocoon/trunk/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/datatype:
convertor/CharConvertor.java convertor/CharConvertorBuilder.java
typeimpl/CharType.java typeimpl/CharTypeBuilder.java
Author: asavory
Date: Sat Mar 11 12:23:28 2006
New Revision: 385151
URL: http://svn.apache.org/viewcvs?rev=385151&view=rev
Log:
[COCOON-1789] add Char datatype to forms
Added:
cocoon/trunk/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/CharConvertor.java (with props)
cocoon/trunk/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/CharConvertorBuilder.java (with props)
cocoon/trunk/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/CharType.java (with props)
cocoon/trunk/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/CharTypeBuilder.java (with props)
Added: cocoon/trunk/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/CharConvertor.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/CharConvertor.java?rev=385151&view=auto
==============================================================================
--- cocoon/trunk/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/CharConvertor.java (added)
+++ cocoon/trunk/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/CharConvertor.java Sat Mar 11 12:23:28 2006
@@ -0,0 +1,52 @@
+/*
+ * 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 org.apache.cocoon.forms.datatype.convertor.ConversionResult;
+import org.apache.cocoon.forms.datatype.convertor.Convertor;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.SAXException;
+
+/**
+ * The CharConvertor converts a String to a Character object and viceversa.
+ *
+ * <p>Converting from char to String, returns a String only containing the input character
+ * Converting from String to char, returns a Character object created with the first char of the input String</p>
+ *
+ */
+public class CharConvertor implements Convertor {
+
+ public ConversionResult convertFromString(String value, Locale locale, Convertor.FormatCache formatCache) {
+ Character c = new Character(value.charAt(0));
+ return new ConversionResult(c);
+ }
+
+ public String convertToString(Object value, Locale locale, Convertor.FormatCache formatCache) {
+ Character c = (Character)value;
+ if (c.charValue() == 0) return "";
+ return c.toString();
+ }
+
+ public Class getTypeClass() {
+ return Character.class;
+ }
+
+ public void generateSaxFragment(ContentHandler contentHandler, Locale locale) throws SAXException {
+ // intentionally empty
+ }
+}
\ No newline at end of file
Propchange: cocoon/trunk/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/CharConvertor.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: cocoon/trunk/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/CharConvertorBuilder.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/CharConvertorBuilder.java?rev=385151&view=auto
==============================================================================
--- cocoon/trunk/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/CharConvertorBuilder.java (added)
+++ cocoon/trunk/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/CharConvertorBuilder.java Sat Mar 11 12:23:28 2006
@@ -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.convertor;
+
+import org.apache.cocoon.forms.datatype.convertor.Convertor;
+import org.apache.cocoon.forms.datatype.convertor.ConvertorBuilder;
+import org.w3c.dom.Element;
+
+/**
+ * The builder for the char default convertor.
+ *
+ * @author Maurizio Pillitu, Simone Gianni
+ */
+public class CharConvertorBuilder implements ConvertorBuilder {
+ public Convertor build(Element configElement) throws Exception {
+ return new CharConvertor();
+ }
+}
Propchange: cocoon/trunk/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/datatype/convertor/CharConvertorBuilder.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: cocoon/trunk/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/CharType.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/CharType.java?rev=385151&view=auto
==============================================================================
--- cocoon/trunk/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/CharType.java (added)
+++ cocoon/trunk/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/CharType.java Sat Mar 11 12:23:28 2006
@@ -0,0 +1,48 @@
+/*
+ * 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.DatatypeBuilder;
+import org.apache.cocoon.forms.datatype.convertor.Convertor;
+import org.apache.cocoon.forms.datatype.typeimpl.AbstractDatatype;
+
+/**
+ * The char datatype.
+ *
+ * <p>
+ * This datatype is useful when you are binding to a bean which have a char property. In that case you cannot use the
+ * string datatype, because JXPath will raise an error not being able to convert it.
+ * </p>
+ *
+ */
+public class CharType extends AbstractDatatype {
+
+ public Class getTypeClass() {
+ return java.lang.Character.class;
+ }
+ public String getDescriptiveName() {
+ return "char";
+ }
+ protected void setArrayType(boolean arrayType) {
+ super.setArrayType(arrayType);
+ }
+ public void setConvertor(Convertor convertor) {
+ super.setConvertor(convertor);
+ }
+ protected void setBuilder(DatatypeBuilder builder) {
+ super.setBuilder(builder);
+ }
+}
Propchange: cocoon/trunk/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/CharType.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: cocoon/trunk/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/CharTypeBuilder.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/CharTypeBuilder.java?rev=385151&view=auto
==============================================================================
--- cocoon/trunk/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/CharTypeBuilder.java (added)
+++ cocoon/trunk/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/CharTypeBuilder.java Sat Mar 11 12:23:28 2006
@@ -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.apache.cocoon.forms.datatype.typeimpl.AbstractDatatypeBuilder;
+import org.w3c.dom.Element;
+
+/**
+ * The builder for the char datatype.
+ *
+ */
+public class CharTypeBuilder extends AbstractDatatypeBuilder {
+
+ public Datatype build(Element datatypeElement, boolean arrayType, DatatypeManager datatypeManager)
+ throws Exception {
+ CharType type = new CharType();
+ type.setArrayType(arrayType);
+ type.setBuilder(this);
+ buildValidationRules(datatypeElement, type, datatypeManager);
+ buildConvertor(datatypeElement, type);
+ return type;
+ }
+
+}
\ No newline at end of file
Propchange: cocoon/trunk/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/datatype/typeimpl/CharTypeBuilder.java
------------------------------------------------------------------------------
svn:eol-style = native