You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by ad...@apache.org on 2009/11/12 03:32:00 UTC
svn commit: r835197 - in /ofbiz/trunk/framework/base/src/org/ofbiz/base:
conversion/DateTimeConverters.java conversion/NumberConverters.java
util/ObjectType.java
Author: adrianc
Date: Thu Nov 12 02:31:59 2009
New Revision: 835197
URL: http://svn.apache.org/viewvc?rev=835197&view=rev
Log:
More converter improvements. Better handling of strings supplied to formatting classes.
Modified:
ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/DateTimeConverters.java
ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/NumberConverters.java
ofbiz/trunk/framework/base/src/org/ofbiz/base/util/ObjectType.java
Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/DateTimeConverters.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/DateTimeConverters.java?rev=835197&r1=835196&r2=835197&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/DateTimeConverters.java (original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/DateTimeConverters.java Thu Nov 12 02:31:59 2009
@@ -283,7 +283,8 @@
}
public Calendar convert(String obj, Locale locale, TimeZone timeZone, String formatString) throws ConversionException {
- if (obj.length() == 0) {
+ String trimStr = obj.trim();
+ if (trimStr.length() == 0) {
return null;
}
DateFormat df = null;
@@ -293,7 +294,7 @@
df = UtilDateTime.toDateTimeFormat(formatString, timeZone, locale);
}
try {
- java.util.Date date = df.parse(obj);
+ java.util.Date date = df.parse(trimStr);
return UtilDateTime.toCalendar(date, timeZone, locale);
} catch (ParseException e) {
throw new ConversionException(e);
@@ -309,7 +310,8 @@
}
public java.util.Date convert(String obj, Locale locale, TimeZone timeZone, String formatString) throws ConversionException {
- if (obj.length() == 0) {
+ String trimStr = obj.trim();
+ if (trimStr.length() == 0) {
return null;
}
DateFormat df = null;
@@ -319,7 +321,7 @@
df = UtilDateTime.toDateTimeFormat(formatString, timeZone, locale);
}
try {
- return df.parse(obj);
+ return df.parse(trimStr);
} catch (ParseException e) {
throw new ConversionException(e);
}
@@ -346,7 +348,8 @@
}
public java.sql.Date convert(String obj, Locale locale, TimeZone timeZone, String formatString) throws ConversionException {
- if (obj.length() == 0) {
+ String trimStr = obj.trim();
+ if (trimStr.length() == 0) {
return null;
}
DateFormat df = null;
@@ -356,7 +359,7 @@
df = UtilDateTime.toDateFormat(formatString, timeZone, locale);
}
try {
- return new java.sql.Date(df.parse(obj).getTime());
+ return new java.sql.Date(df.parse(trimStr).getTime());
} catch (ParseException e) {
throw new ConversionException(e);
}
@@ -371,7 +374,8 @@
}
public java.sql.Time convert(String obj, Locale locale, TimeZone timeZone, String formatString) throws ConversionException {
- if (obj.length() == 0) {
+ String trimStr = obj.trim();
+ if (trimStr.length() == 0) {
return null;
}
DateFormat df = null;
@@ -381,7 +385,7 @@
df = UtilDateTime.toTimeFormat(formatString, timeZone, locale);
}
try {
- return new java.sql.Time(df.parse(obj).getTime());
+ return new java.sql.Time(df.parse(trimStr).getTime());
} catch (ParseException e) {
throw new ConversionException(e);
}
@@ -396,7 +400,8 @@
}
public java.sql.Timestamp convert(String obj, Locale locale, TimeZone timeZone, String formatString) throws ConversionException {
- if (obj.length() == 0) {
+ String trimStr = obj.trim();
+ if (trimStr.length() == 0) {
return null;
}
DateFormat df = null;
@@ -406,7 +411,7 @@
df = UtilDateTime.toDateTimeFormat(formatString, timeZone, locale);
}
try {
- return new java.sql.Timestamp(df.parse(obj).getTime());
+ return new java.sql.Timestamp(df.parse(trimStr).getTime());
} catch (ParseException e) {
throw new ConversionException(e);
}
Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/NumberConverters.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/NumberConverters.java?rev=835197&r1=835196&r2=835197&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/NumberConverters.java (original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/NumberConverters.java Thu Nov 12 02:31:59 2009
@@ -26,6 +26,8 @@
import java.util.Set;
import java.util.TimeZone;
+import org.ofbiz.base.util.StringUtil;
+
import javolution.util.FastList;
import javolution.util.FastSet;
@@ -520,7 +522,11 @@
}
public BigDecimal convert(String obj, Locale locale, TimeZone timeZone) throws ConversionException {
- return BigDecimal.valueOf(this.fromString(obj, locale).doubleValue());
+ String trimStr = StringUtil.removeSpaces(obj);
+ if (trimStr.length() == 0) {
+ return null;
+ }
+ return BigDecimal.valueOf(this.fromString(trimStr, locale).doubleValue());
}
}
@@ -532,7 +538,11 @@
}
public Double convert(String obj, Locale locale, TimeZone timeZone) throws ConversionException {
- return this.fromString(obj, locale).doubleValue();
+ String trimStr = StringUtil.removeSpaces(obj);
+ if (trimStr.length() == 0) {
+ return null;
+ }
+ return this.fromString(trimStr, locale).doubleValue();
}
}
@@ -544,7 +554,11 @@
}
public Float convert(String obj, Locale locale, TimeZone timeZone) throws ConversionException {
- return this.fromString(obj, locale).floatValue();
+ String trimStr = StringUtil.removeSpaces(obj);
+ if (trimStr.length() == 0) {
+ return null;
+ }
+ return this.fromString(trimStr, locale).floatValue();
}
}
@@ -556,7 +570,11 @@
}
public Integer convert(String obj, Locale locale, TimeZone timeZone) throws ConversionException {
- return this.fromString(obj, locale).intValue();
+ String trimStr = StringUtil.removeSpaces(obj);
+ if (trimStr.length() == 0) {
+ return null;
+ }
+ return this.fromString(trimStr, locale).intValue();
}
}
@@ -568,7 +586,11 @@
}
public Long convert(String obj, Locale locale, TimeZone timeZone) throws ConversionException {
- return this.fromString(obj, locale).longValue();
+ String trimStr = StringUtil.removeSpaces(obj);
+ if (trimStr.length() == 0) {
+ return null;
+ }
+ return this.fromString(trimStr, locale).longValue();
}
}
Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/ObjectType.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/ObjectType.java?rev=835197&r1=835196&r2=835197&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/ObjectType.java (original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/ObjectType.java Thu Nov 12 02:31:59 2009
@@ -18,25 +18,15 @@
*******************************************************************************/
package org.ofbiz.base.util;
-import java.lang.reflect.Array;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
-import java.math.BigDecimal;
-import java.nio.Buffer;
-import java.text.DateFormat;
-import java.text.NumberFormat;
-import java.text.ParseException;
import java.util.Collection;
-import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.Map;
-import java.util.Set;
import java.util.TimeZone;
-import javolution.util.FastList;
import javolution.util.FastMap;
-import javolution.util.FastSet;
import org.ofbiz.base.conversion.ConversionException;
import org.ofbiz.base.conversion.Converter;