bruno 2004/03/18 03:45:55
Modified: src/blocks/forms/conf forms-datatype.xconf
Added: src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor
FormattingDoubleConvertor.java
FormattingDoubleConvertorBuilder.java
PlainDoubleConvertor.java
PlainDoubleConvertorBuilder.java
src/blocks/forms/java/org/apache/cocoon/forms/datatype/typeimpl
DoubleType.java DoubleTypeBuilder.java
Log:
Added a double datatype
Revision Changes Path
1.2 +6 -0 cocoon-2.1/src/blocks/forms/conf/forms-datatype.xconf
Index: forms-datatype.xconf
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/blocks/forms/conf/forms-datatype.xconf,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- forms-datatype.xconf 9 Mar 2004 10:34:05 -0000 1.1
+++ forms-datatype.xconf 18 Mar 2004 11:45:55 -0000 1.2
@@ -51,6 +51,12 @@
<convertor name="formatting"
src="org.apache.cocoon.forms.datatype.convertor.FormattingFloatConvertorBuilder"/>
</convertors>
</datatype>
+ <datatype name="double"
src="org.apache.cocoon.forms.datatype.typeimpl.DoubleTypeBuilder">
+ <convertors default="formatting" plain="plain">
+ <convertor name="plain"
src="org.apache.cocoon.forms.datatype.convertor.PlainDoubleConvertorBuilder"/>
+ <convertor name="formatting"
src="org.apache.cocoon.forms.datatype.convertor.FormattingDoubleConvertorBuilder"/>
+ </convertors>
+ </datatype>
<datatype name="date"
src="org.apache.cocoon.forms.datatype.typeimpl.DateTypeBuilder">
<convertors default="formatting" plain="millis">
<convertor name="formatting"
src="org.apache.cocoon.forms.datatype.convertor.FormattingDateConvertorBuilder"/>
1.1
cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/FormattingDoubleConvertor.java
Index: FormattingDoubleConvertor.java
===================================================================
/*
* 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.outerj.i18n.DecimalFormat;
import java.util.Locale;
import java.text.ParseException;
/**
* A Convertor for [EMAIL PROTECTED] Double}s backed by the
* [EMAIL PROTECTED] java.text.DecimalFormat DecimalFormat} class.
*
* <p>This class is mostly the same as the [EMAIL PROTECTED]
FormattingDecimalConvertor},
* so see there for more information.
*
* @version CVS $Id: FormattingDoubleConvertor.java,v 1.1 2004/03/18 11:45:55
bruno Exp $
*/
public class FormattingDoubleConvertor extends FormattingDecimalConvertor {
public FormattingDoubleConvertor() {
super();
}
public Object convertFromString(String value, Locale locale,
Convertor.FormatCache formatCache) {
DecimalFormat decimalFormat = getDecimalFormat(locale, formatCache);
try {
Number decimalValue = decimalFormat.parse(value);
if (decimalValue instanceof Double)
return decimalValue;
else
return new Double(decimalValue.doubleValue());
} catch (ParseException e) {
return null;
}
}
public Class getTypeClass() {
return Double.class;
}
}
1.1
cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/FormattingDoubleConvertorBuilder.java
Index: FormattingDoubleConvertorBuilder.java
===================================================================
/*
* 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;
/**
* Builds [EMAIL PROTECTED] FormattingDoubleConvertor}s.
*
* @version CVS $Id: FormattingDoubleConvertorBuilder.java,v 1.1 2004/03/18
11:45:55 bruno Exp $
*/
public class FormattingDoubleConvertorBuilder extends
FormattingDecimalConvertorBuilder {
protected FormattingDecimalConvertor createConvertor() {
return new FormattingDoubleConvertor();
}
}
1.1
cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/PlainDoubleConvertor.java
Index: PlainDoubleConvertor.java
===================================================================
/*
* 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;
/**
* Convertor for java.lang.Doubles that does not do any (Locale-dependent)
* formatting. It simply uses String.valueOf() and Long.parseLong().
*
* @version CVS $Id: PlainDoubleConvertor.java,v 1.1 2004/03/18 11:45:55
bruno Exp $
*/
public class PlainDoubleConvertor implements Convertor {
public Object convertFromString(String value, Locale locale,
Convertor.FormatCache formatCache) {
try {
return new Double(Double.parseDouble(value));
} catch (NumberFormatException e) {
return null;
}
}
public String convertToString(Object value, Locale locale,
Convertor.FormatCache formatCache) {
return String.valueOf(value);
}
public Class getTypeClass() {
return Double.class;
}
}
1.1
cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/datatype/convertor/PlainDoubleConvertorBuilder.java
Index: PlainDoubleConvertorBuilder.java
===================================================================
/*
* 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;
/**
*
* @version CVS $Id: PlainDoubleConvertorBuilder.java,v 1.1 2004/03/18
11:45:55 bruno Exp $
*/
public class PlainDoubleConvertorBuilder implements ConvertorBuilder {
public Convertor build(Element configElement) throws Exception {
return new PlainDoubleConvertor();
}
}
1.1
cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/datatype/typeimpl/DoubleType.java
Index: DoubleType.java
===================================================================
/*
* Copyright 1999-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.cocoon.forms.datatype.typeimpl;
/**
* A [EMAIL PROTECTED] org.apache.cocoon.forms.datatype.Datatype Datatype}
implementation
* for double numbers (backed by the java.lang.Double class).
*
* @version $Id: DoubleType.java,v 1.1 2004/03/18 11:45:55 bruno Exp $
*/
public class DoubleType extends AbstractDatatype {
public Class getTypeClass() {
return Double.class;
}
public String getDescriptiveName() {
return "double";
}
}
1.1
cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/datatype/typeimpl/DoubleTypeBuilder.java
Index: DoubleTypeBuilder.java
===================================================================
/*
* Copyright 1999-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.cocoon.forms.datatype.typeimpl;
import org.apache.cocoon.forms.datatype.Datatype;
import org.apache.cocoon.forms.datatype.DatatypeManager;
import org.w3c.dom.Element;
/**
* Builds [EMAIL PROTECTED] DoubleType}s.
*
* @version $Id: DoubleTypeBuilder.java,v 1.1 2004/03/18 11:45:55 bruno Exp $
*/
public class DoubleTypeBuilder extends AbstractDatatypeBuilder {
public Datatype build(Element datatypeElement, boolean arrayType,
DatatypeManager datatypeManager) throws Exception {
DoubleType type = new DoubleType();
type.setArrayType(arrayType);
type.setBuilder(this);
buildValidationRules(datatypeElement, type, datatypeManager);
buildConvertor(datatypeElement, type);
return type;
}
}