You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by vg...@apache.org on 2003/12/10 18:53:26 UTC
cvs commit: cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/convertor Convertor.java PlainBooleanConvertor.java
vgritsenko 2003/12/10 09:53:26
Modified: . status.xml
src/blocks/woody/java/org/apache/cocoon/woody/datatype
DefaultSelectionListBuilder.java
DynamicSelectionList.java StaticSelectionList.java
src/blocks/woody/java/org/apache/cocoon/woody/datatype/convertor
Convertor.java PlainBooleanConvertor.java
Log:
Cocoon Forms (Woody) selection lists now allow empty value (which is
translated to the null object)
See also: http://marc.theaimsgroup.com/?t=107040285700001&r=1&w=2
Revision Changes Path
1.209 +5 -1 cocoon-2.1/status.xml
Index: status.xml
===================================================================
RCS file: /home/cvs/cocoon-2.1/status.xml,v
retrieving revision 1.208
retrieving revision 1.209
diff -u -r1.208 -r1.209
--- status.xml 10 Dec 2003 15:46:58 -0000 1.208
+++ status.xml 10 Dec 2003 17:53:26 -0000 1.209
@@ -190,6 +190,10 @@
<release version="@version@" date="@date@">
<action dev="VG" type="update">
+ Cocoon Forms (Woody) selection lists now allow empty value (which is
+ translated to the null object)
+ </action>
+ <action dev="VG" type="update">
Deprecate MirrorRecorder. It will be removed starting with Cocoon 2.2
</action>
<action dev="VG" type="add">
1.3 +13 -4 cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/DefaultSelectionListBuilder.java
Index: DefaultSelectionListBuilder.java
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/DefaultSelectionListBuilder.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- DefaultSelectionListBuilder.java 13 Nov 2003 13:19:09 -0000 1.2
+++ DefaultSelectionListBuilder.java 10 Dec 2003 17:53:26 -0000 1.3
@@ -125,9 +125,18 @@
}
Element element = (Element)node;
String stringValue = element.getAttribute("value");
- Object value = convertor.convertFromString(stringValue, Locale.US, formatCache);
- if (value == null)
- throw new Exception("Could not convert the value \"" + stringValue + "\" to the type " + datatype.getDescriptiveName() + ", defined at " + DomHelper.getLocation(element));
+ Object value;
+ if ("".equals(stringValue)) {
+ // Empty value translates into the null object
+ value = null;
+ } else {
+ value = convertor.convertFromString(stringValue, Locale.US, formatCache);
+ if (value == null) {
+ throw new Exception("Could not convert the value \"" + stringValue +
+ "\" to the type " + datatype.getDescriptiveName() +
+ ", defined at " + DomHelper.getLocation(element));
+ }
+ }
XMLizable label = null;
Element labelEl = DomHelper.getChildElement(element, Constants.WD_NS, "label");
1.6 +11 -6 cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/DynamicSelectionList.java
Index: DynamicSelectionList.java
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/DynamicSelectionList.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- DynamicSelectionList.java 3 Nov 2003 23:16:12 -0000 1.5
+++ DynamicSelectionList.java 10 Dec 2003 17:53:26 -0000 1.6
@@ -166,14 +166,19 @@
convertor = datatype.getConvertor();
}
hasLabel = false;
+
String unparsedValue = attributes.getValue("value");
- if (unparsedValue == null)
- throw new SAXException("Missing value attribute on " + qName + " element.");
- currentValue = convertor.convertFromString(unparsedValue, locale, fromFormatCache);
- if (currentValue == null)
- throw new SAXException("Could not interpret the following value: \"" + unparsedValue + "\".");
+ if (unparsedValue == null || "".equals(unparsedValue)) {
+ // Empty (or null) value translates into the empty string
+ currentValueAsString = "";
+ } else {
+ currentValue = convertor.convertFromString(unparsedValue, locale, fromFormatCache);
+ if (currentValue == null) {
+ throw new SAXException("Could not interpret the following value: \"" + unparsedValue + "\".");
+ }
+ currentValueAsString = datatype.getConvertor().convertToString(currentValue, locale, toFormatCache);
+ }
AttributesImpl attrs = new AttributesImpl();
- currentValueAsString = datatype.getConvertor().convertToString(currentValue, locale, toFormatCache);
attrs.addCDATAAttribute("value", currentValueAsString);
super.startElement(Constants.WI_NS, localName, Constants.WI_PREFIX_COLON + localName, attrs);
} else if (localName.equals("label")) {
1.8 +7 -1 cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/StaticSelectionList.java
Index: StaticSelectionList.java
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/StaticSelectionList.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- StaticSelectionList.java 13 Nov 2003 13:19:09 -0000 1.7
+++ StaticSelectionList.java 10 Dec 2003 17:53:26 -0000 1.8
@@ -124,7 +124,13 @@
throws SAXException
{
AttributesImpl itemAttrs = new AttributesImpl();
- String stringValue = datatype.getConvertor().convertToString(value, locale, formatCache);
+ String stringValue;
+ if (this.value == null) {
+ // Null value translates into the empty string
+ stringValue = "";
+ } else {
+ stringValue = datatype.getConvertor().convertToString(value, locale, formatCache);
+ }
itemAttrs.addCDATAAttribute("value", stringValue);
contentHandler.startElement(Constants.WI_NS, ITEM_EL, Constants.WI_PREFIX_COLON + ITEM_EL, itemAttrs);
contentHandler.startElement(Constants.WI_NS, LABEL_EL, Constants.WI_PREFIX_COLON + LABEL_EL, Constants.EMPTY_ATTRS);
1.3 +3 -1 cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/convertor/Convertor.java
Index: Convertor.java
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/convertor/Convertor.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Convertor.java 3 Sep 2003 12:26:23 -0000 1.2
+++ Convertor.java 10 Dec 2003 17:53:26 -0000 1.3
@@ -65,8 +65,10 @@
* which can be expensive if it needs to be done repeatedly.
*/
public interface Convertor {
+
/**
- * Returns null if conversion failes.
+ * Converts string representation into the object of convertor's type.
+ * Returns null if conversion fails.
*
* @param formatCache can be null if not needed
*/
1.3 +0 -3 cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/convertor/PlainBooleanConvertor.java
Index: PlainBooleanConvertor.java
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/convertor/PlainBooleanConvertor.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- PlainBooleanConvertor.java 2 Dec 2003 14:44:56 -0000 1.2
+++ PlainBooleanConvertor.java 10 Dec 2003 17:53:26 -0000 1.3
@@ -7,9 +7,6 @@
*/
public class PlainBooleanConvertor implements Convertor {
public Object convertFromString(String value, Locale locale, Convertor.FormatCache formatCache) {
- if (value == null || value.length() == 0) {
- return "";
- }
return Boolean.valueOf(value);
}