Author: jleroux
Date: Sat Aug 11 11:40:45 2007
New Revision: 564957

URL: http://svn.apache.org/viewvc?view=rev&rev=564957
Log:
A patch from Adrian Crum "Improved Time Zone Support, Part 2" 
(https://issues.apache.org/jira/browse/OFBIZ-1164)
Please see comments in Jira issue.


Modified:
    ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/ObjectType.java
    ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilDateTime.java
    
ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/string/FlexibleStringExpander.java
    
ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/template/FreeMarkerWorker.java
    ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelService.java
    ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/CoreEvents.java
    
ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/ServiceEventHandler.java
    
ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/ServiceMultiEventHandler.java
    ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java

Modified: 
ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/ObjectType.java
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/ObjectType.java?view=diff&rev=564957&r1=564956&r2=564957
==============================================================================
--- ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/ObjectType.java 
(original)
+++ ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/ObjectType.java Sat 
Aug 11 11:40:45 2007
@@ -25,7 +25,6 @@
 import java.text.DateFormat;
 import java.text.NumberFormat;
 import java.text.ParseException;
-import java.text.SimpleDateFormat;
 import java.util.*;
 
 import javolution.util.FastList;
@@ -426,19 +425,24 @@
         }
     }
 
+    public static Object simpleTypeConvert(Object obj, String type, String 
format, Locale locale, boolean noTypeFail) throws GeneralException {
+        return simpleTypeConvert(obj, type, format, TimeZone.getDefault(), 
locale, noTypeFail);
+    }
+
     /** 
      * Converts the passed object to the named simple type; supported types
      * include: String, Boolean, Double, Float, Long, Integer, Date 
(java.sql.Date),
-     * Time, Timestamp;
+     * Time, Timestamp, TimeZone;
      * @param obj Object to convert
      * @param type Name of type to convert to
      * @param format Optional (can be null) format string for Date, Time, 
Timestamp
+     * @param timeZone Optional (can be null) TimeZone for converting dates 
and times
      * @param locale Optional (can be null) Locale for formatting and parsing 
Double, Float, Long, Integer
      * @param noTypeFail Fail (Exception) when no type conversion is 
available, false will return the primary object
      * @return
      * @throws GeneralException
      */
-    public static Object simpleTypeConvert(Object obj, String type, String 
format, Locale locale, boolean noTypeFail) throws GeneralException {
+    public static Object simpleTypeConvert(Object obj, String type, String 
format, TimeZone timeZone, Locale locale, boolean noTypeFail) throws 
GeneralException {
         if (obj == null) {
             return null;
         }
@@ -488,6 +492,13 @@
                 } else {
                     throw new GeneralException("Could not convert " + str + " 
to " + type + ": ");    
                 }
+            } else if ("TimeZone".equals(type) || 
"java.util.TimeZone".equals(type)) {
+                TimeZone tz = UtilDateTime.toTimeZone(str);
+                if (tz != null) {
+                    return tz;
+                } else {
+                    throw new GeneralException("Could not convert " + str + " 
to " + type + ": ");    
+                }
             } else if ("BigDecimal".equals(type) || 
"java.math.BigDecimal".equals(type)) {
                 str = StringUtil.removeSpaces(str);
                 try {
@@ -565,87 +576,47 @@
                     throw new GeneralException("Could not convert " + str + " 
to " + type + ": ", e);
                 }
             } else if ("Date".equals(type) || "java.sql.Date".equals(type)) {
+                DateFormat df = null;
                 if (format == null || format.length() == 0) {
-                    try {
-                        return java.sql.Date.valueOf(str);
-                    } catch (Exception e) {
-                        try {
-                            DateFormat df = null;
-                            if (locale != null) {
-                                df = 
DateFormat.getDateInstance(DateFormat.SHORT, locale);
-                            } else {
-                                df = 
DateFormat.getDateInstance(DateFormat.SHORT);
-                            }
-                            Date fieldDate = df.parse(str);
-
-                            return new java.sql.Date(fieldDate.getTime());
-                        } catch (ParseException e1) {
-                            throw new GeneralException("Could not convert " + 
str + " to " + type + ": ", e);
-                        }
-                    }
+                    df = UtilDateTime.toDateFormat(UtilDateTime.DATE_FORMAT, 
timeZone, null);
                 } else {
-                    try {
-                        SimpleDateFormat sdf = new SimpleDateFormat(format);
-                        java.util.Date fieldDate = sdf.parse(str);
-                        return new java.sql.Date(fieldDate.getTime());
-                    } catch (ParseException e) {
-                        throw new GeneralException("Could not convert " + str 
+ " to " + type + ": ", e);
-                    }
+                    df = UtilDateTime.toDateFormat(format, timeZone, null);
+                }
+                try {
+                    Date fieldDate = df.parse(str);
+                    return new java.sql.Date(fieldDate.getTime());
+                } catch (ParseException e1) {
+                    throw new GeneralException("Could not convert " + str + " 
to " + type + ": ", e1);
                 }
             } else if ("Time".equals(type) || "java.sql.Time".equals(type)) {
+                DateFormat df = null;
                 if (format == null || format.length() == 0) {
-                    try {
-                        return java.sql.Time.valueOf(str);
-                    } catch (Exception e) {
-                        try {
-                            DateFormat df = null;
-                            if (locale != null) {
-                                df = 
DateFormat.getTimeInstance(DateFormat.SHORT, locale);
-                            } else {
-                                df = 
DateFormat.getTimeInstance(DateFormat.SHORT);
-                            }
-                            Date fieldDate = df.parse(str);
-
-                            return new java.sql.Time(fieldDate.getTime());
-                        } catch (ParseException e1) {
-                            throw new GeneralException("Could not convert " + 
str + " to " + type + ": ", e);
-                        }
-                    }
+                    df = UtilDateTime.toTimeFormat(UtilDateTime.TIME_FORMAT, 
timeZone, null);
                 } else {
-                    try {
-                        SimpleDateFormat sdf = new SimpleDateFormat(format);
-                        java.util.Date fieldDate = sdf.parse(str);
-                        return new java.sql.Time(fieldDate.getTime());
-                    } catch (ParseException e) {
-                        throw new GeneralException("Could not convert " + str 
+ " to " + type + ": ", e);
-                    }
+                    df = UtilDateTime.toTimeFormat(format, timeZone, null);
+                }
+                try {
+                    Date fieldDate = df.parse(str);
+                    return new java.sql.Time(fieldDate.getTime());
+                } catch (ParseException e1) {
+                    throw new GeneralException("Could not convert " + str + " 
to " + type + ": ", e1);
                 }
             } else if ("Timestamp".equals(type) || 
"java.sql.Timestamp".equals(type)) {
+                DateFormat df = null;
                 if (format == null || format.length() == 0) {
-                    try {
-                        return java.sql.Timestamp.valueOf(str);
-                    } catch (Exception e) {
-                        try {
-                            DateFormat df = null;
-                            if (locale != null) {
-                                df = 
DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, locale);
-                            } else {
-                                df = 
DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
-                            }
-                            Date fieldDate = df.parse(str);
-                            return new java.sql.Timestamp(fieldDate.getTime());
-                        } catch (ParseException e1) {
-                            throw new GeneralException("Could not convert " + 
str + " to " + type + ": ", e);
-                        }
+                    df = 
UtilDateTime.toDateTimeFormat(UtilDateTime.DATE_TIME_FORMAT, timeZone, null);
+                    // hack to mimic Timestamp.valueOf() method
+                    if (str.length() > 0 && !str.contains(".")) {
+                        str = str + ".0";
                     }
                 } else {
-                    try {
-                        SimpleDateFormat sdf = new SimpleDateFormat(format);
-                        java.util.Date fieldDate = sdf.parse(str);
-                        return new java.sql.Timestamp(fieldDate.getTime());
-                    } catch (ParseException e) {
-                        throw new GeneralException("Could not convert " + str 
+ " to " + type + ": ", e);
-                    }
+                    df = UtilDateTime.toDateTimeFormat(format, timeZone, null);
+                }
+                try {
+                    Date fieldDate = df.parse(str);
+                    return new java.sql.Timestamp(fieldDate.getTime());
+                } catch (ParseException e1) {
+                    throw new GeneralException("Could not convert " + str + " 
to " + type + ": ", e1);
                 }
             } else if ("List".equals(type) || "java.util.List".equals(type)) {
                 if (str.startsWith("[") && str.endsWith("]")) {
@@ -837,12 +808,13 @@
             fromType = "Date";
             java.sql.Date dte = (java.sql.Date) obj;
             if ("String".equals(type) || "java.lang.String".equals(type)) {
+                DateFormat df = null;
                 if (format == null || format.length() == 0) {
-                    return dte.toString();
+                    df = UtilDateTime.toDateFormat(UtilDateTime.DATE_FORMAT, 
timeZone, null);
                 } else {
-                    SimpleDateFormat sdf = new SimpleDateFormat(format);
-                    return sdf.format(new java.util.Date(dte.getTime()));
+                    df = UtilDateTime.toDateFormat(format, timeZone, null);
                 }
+                return df.format(new java.util.Date(dte.getTime()));
             } else if ("Date".equals(type) || "java.sql.Date".equals(type)) {
                 return obj;
             } else if ("Time".equals(type) || "java.sql.Time".equals(type)) {
@@ -865,13 +837,13 @@
             java.sql.Time tme = (java.sql.Time) obj;
 
             if ("String".equals(type) || "java.lang.String".equals(type)) {
+                DateFormat df = null;
                 if (format == null || format.length() == 0) {
-                    return tme.toString();
+                    df = UtilDateTime.toTimeFormat(UtilDateTime.TIME_FORMAT, 
timeZone, null);
                 } else {
-                    SimpleDateFormat sdf = new SimpleDateFormat(format);
-
-                    return sdf.format(new java.util.Date(tme.getTime()));
+                    df = UtilDateTime.toTimeFormat(format, timeZone, null);
                 }
+                return df.format(new java.util.Date(tme.getTime()));
             } else if ("Date".equals(type) || "java.sql.Date".equals(type)) {
                 throw new GeneralException("Conversion from " + fromType + " 
to " + type + " not currently supported");
             } else if ("Time".equals(type) || "java.sql.Time".equals(type)) {
@@ -894,13 +866,13 @@
             java.sql.Timestamp tme = (java.sql.Timestamp) obj;
 
             if ("String".equals(type) || "java.lang.String".equals(type)) {
+                DateFormat df = null;
                 if (format == null || format.length() == 0) {
-                    return tme.toString();
+                    df = 
UtilDateTime.toDateTimeFormat(UtilDateTime.DATE_TIME_FORMAT, timeZone, null);
                 } else {
-                    SimpleDateFormat sdf = new SimpleDateFormat(format);
-
-                    return sdf.format(new java.util.Date(tme.getTime()));
+                    df = UtilDateTime.toDateTimeFormat(format, timeZone, null);
                 }
+                return df.format(new java.util.Date(tme.getTime()));
             } else if ("Date".equals(type) || "java.sql.Date".equals(type)) {
                 return new java.sql.Date(tme.getTime());
             } else if ("Time".equals(type) || "java.sql.Time".equals(type)) {
@@ -949,6 +921,16 @@
                 return loc;
             } else if ("String".equals(type) || 
"java.lang.String".equals(type)) {
                 return loc.toString();
+            } else {
+                throw new GeneralException("Conversion from " + fromType + " 
to " + type + " not currently supported");
+            }
+        } else if (obj instanceof java.util.TimeZone) {
+            fromType = "TimeZone";
+            TimeZone tz = (TimeZone) obj;
+            if ("TimeZone".equals(type) || "java.util.TimeZone".equals(type)) {
+                return tz;
+            } else if ("String".equals(type) || 
"java.lang.String".equals(type)) {
+                return tz.getID();
             } else {
                 throw new GeneralException("Conversion from " + fromType + " 
to " + type + " not currently supported");
             }

Modified: 
ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilDateTime.java
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilDateTime.java?view=diff&rev=564957&r1=564956&r2=564957
==============================================================================
--- ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilDateTime.java 
(original)
+++ ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilDateTime.java 
Sat Aug 11 11:40:45 2007
@@ -58,6 +58,18 @@
     };
 
     public static final DecimalFormat df = new DecimalFormat("0.00;-0.00");
+    /**
+     * JDBC escape format for java.sql.Date conversions.
+     */
+    public static final String DATE_FORMAT = "yyyy-MM-dd";
+    /**
+     * JDBC escape format for java.sql.Timestamp conversions.
+     */
+    public static final String DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss.S";
+    /**
+     * JDBC escape format for java.sql.Time conversions.
+     */
+    public static final String TIME_FORMAT = "HH:mm:ss";
 
     public static double getInterval(Date from, Date thru) {
         return thru != null ? thru.getTime() - from.getTime() : 0;
@@ -884,22 +896,87 @@
     }
 
     /**
+     * Returns an initialized DateFormat object.
+     * @param dateFormat optional format string
+     * @param tz
+     * @param locale can be null if dateFormat is not null
+     * @return DateFormat object
+     */
+    public static DateFormat toDateFormat(String dateFormat, TimeZone tz, 
Locale locale) {
+        DateFormat df = null;
+        if (dateFormat == null) {
+            df = DateFormat.getDateInstance(DateFormat.SHORT, locale);
+        } else {
+            df = new SimpleDateFormat(dateFormat);
+        }
+        df.setTimeZone(tz);
+        return df;
+    }
+
+    /**
+     * Returns an initialized DateFormat object.
+     * @param dateTimeFormat optional format string
+     * @param tz
+     * @param locale can be null if dateTimeFormat is not null
+     * @return DateFormat object
+     */
+    public static DateFormat toDateTimeFormat(String dateTimeFormat, TimeZone 
tz, Locale locale) {
+        DateFormat df = null;
+        if (dateTimeFormat == null) {
+            df = DateFormat.getDateTimeInstance(DateFormat.SHORT, 
DateFormat.MEDIUM, locale);
+        } else {
+            df = new SimpleDateFormat(dateTimeFormat);
+        }
+        df.setTimeZone(tz);
+        return df;
+    }
+
+    /**
+     * Returns an initialized DateFormat object.
+     * @param timeFormat optional format string
+     * @param tz
+     * @param locale can be null if timeFormat is not null
+     * @return DateFormat object
+     */
+    public static DateFormat toTimeFormat(String timeFormat, TimeZone tz, 
Locale locale) {
+        DateFormat df = null;
+        if (timeFormat == null) {
+            df = DateFormat.getDateInstance(DateFormat.MEDIUM, locale);
+        } else {
+            df = new SimpleDateFormat(timeFormat);
+        }
+        df.setTimeZone(tz);
+        return df;
+    }
+
+    /**
      * Localized String to Timestamp conversion. To be used in tandem with 
timeStampToString().
-     * 
      */
     public static Timestamp stringToTimeStamp(String dateTimeString, TimeZone 
tz, Locale locale) throws ParseException {
-        DateFormat dateFormat = 
DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM, locale);
-        dateFormat.setTimeZone(tz);
+        return stringToTimeStamp(dateTimeString, null, tz, locale);
+    }
+
+    /**
+     * Localized String to Timestamp conversion. To be used in tandem with 
timeStampToString().
+     */
+    public static Timestamp stringToTimeStamp(String dateTimeString, String 
dateTimeFormat, TimeZone tz, Locale locale) throws ParseException {
+        DateFormat dateFormat = toDateTimeFormat(dateTimeFormat, tz, locale);
         Date parsedDate = dateFormat.parse(dateTimeString);
         return new Timestamp(parsedDate.getTime());
     }
 
     /**
      * Localized Timestamp to String conversion. To be used in tandem with 
stringToTimeStamp().
-     * 
      */
     public static String timeStampToString(Timestamp stamp, TimeZone tz, 
Locale locale) {
-        DateFormat dateFormat = 
DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM, locale);
+        return timeStampToString(stamp, null, tz, locale);
+    }
+
+    /**
+     * Localized Timestamp to String conversion. To be used in tandem with 
stringToTimeStamp().
+     */
+    public static String timeStampToString(Timestamp stamp, String 
dateTimeFormat, TimeZone tz, Locale locale) {
+        DateFormat dateFormat = toDateTimeFormat(dateTimeFormat, tz, locale);
         dateFormat.setTimeZone(tz);
         return dateFormat.format(stamp);
     }

Modified: 
ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/string/FlexibleStringExpander.java
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/string/FlexibleStringExpander.java?view=diff&rev=564957&r1=564956&r2=564957
==============================================================================
--- 
ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/string/FlexibleStringExpander.java
 (original)
+++ 
ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/string/FlexibleStringExpander.java
 Sat Aug 11 11:40:45 2007
@@ -19,14 +19,17 @@
 package org.ofbiz.base.util.string;
 
 import java.io.Serializable;
+import java.text.DateFormat;
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
+import java.util.TimeZone;
 
 import org.ofbiz.base.util.BshUtil;
 import org.ofbiz.base.util.Debug;
+import org.ofbiz.base.util.UtilDateTime;
 import org.ofbiz.base.util.collections.FlexibleMapAccessor;
 import org.ofbiz.base.util.UtilFormatOut;
 import org.ofbiz.base.util.UtilMisc;
@@ -50,7 +53,7 @@
     protected String original;
     protected List stringElements = new LinkedList();
     protected static boolean localizeCurrency = false;
-    protected static String currencyCode = null;            
+    protected static String currencyCode = null;
     
     public FlexibleStringExpander(String original) {
         this.original = original;
@@ -142,6 +145,25 @@
      * @return The original String expanded by replacing varaible place 
holders.
      */
     public static String expandString(String original, Map context, Locale 
locale) {
+        return expandString(original, context, null, locale);
+    }
+    
+    /**
+     * Does on-the-fly parsing and expansion of the original String using
+     * varaible values from the passed context. Variables are denoted with
+     * the "${}" syntax and the variable name inside the curly-braces can use
+     * the "." (dot) syntax to access sub-Map entries and the "[]" square-brace
+     * syntax to access List elements.
+     * It Also supports the execution of bsh files by using the 'bsh:' prefix.
+     * Further it is possible to control the output by specifying the suffix 
+     *     '?currency(XXX)' to format the output according the current locale
+     *     and specified (XXX) currency
+     * 
+     * @param original The original String that will be expanded
+     * @param context A context Map containing the variable values
+     * @return The original String expanded by replacing varaible place 
holders.
+     */
+    public static String expandString(String original, Map context, TimeZone 
timeZone, Locale locale) {
         // if null or less than 3 return original; 3 chars because that is the 
minimum necessary for a ${}
         if (original == null || original.length() < 3) {
             return original;
@@ -166,14 +188,21 @@
         if (locale == null && context.containsKey("autoUserLogin")) {
             locale = UtilMisc.ensureLocale(((Map) 
context.get("autoUserLogin")).get("lastLocale"));
         }
+        
+        if (timeZone == null) {
+            timeZone = (TimeZone) context.get("timeZone");
+            if (timeZone == null) {
+                timeZone = TimeZone.getDefault();
+            }
+        }
 
         StringBuffer expanded = new StringBuffer();
         // TODO: for performance to save object build up and tear down times 
we should use Javolution to make OnTheFlyHandler reusable and use a factory 
methods instead of constructor
-        ParseElementHandler handler = new OnTheFlyHandler(expanded, context, 
locale);
+        ParseElementHandler handler = new OnTheFlyHandler(expanded, context, 
timeZone, locale);
         parseString(original, handler);
         
         //call back into this method with new String to take care of any/all 
nested expands
-        return expandString(expanded.toString(), context, locale);
+        return expandString(expanded.toString(), context, timeZone, locale);
     }
     
     public static void parseString(String original, ParseElementHandler 
handler) {
@@ -314,10 +343,12 @@
         protected StringBuffer targetBuffer;
         protected Map context;
         protected Locale locale;
+        protected TimeZone timeZone;
         
-        public OnTheFlyHandler(StringBuffer targetBuffer, Map context, Locale 
locale) {
+        public OnTheFlyHandler(StringBuffer targetBuffer, Map context, 
TimeZone timeZone, Locale locale) {
             this.targetBuffer = targetBuffer;
             this.context = context;
+            this.timeZone = timeZone;
             this.locale = locale;
         }
         
@@ -346,7 +377,19 @@
             FlexibleMapAccessor fma = new FlexibleMapAccessor(envName);
             Object envVal = fma.get(context, locale);
             if (envVal != null) {
-                if (localizeCurrency) {
+                if (envVal instanceof java.sql.Date) {
+                    DateFormat df = 
UtilDateTime.toDateFormat(UtilDateTime.DATE_FORMAT, timeZone, null);
+                    targetBuffer.append(df.format((java.util.Date) envVal));
+                } else if (envVal instanceof java.sql.Time) {
+                    DateFormat df = 
UtilDateTime.toTimeFormat(UtilDateTime.TIME_FORMAT, timeZone, null);
+                    targetBuffer.append(df.format((java.util.Date) envVal));
+                } else if (envVal instanceof java.sql.Timestamp) {
+                    DateFormat df = 
UtilDateTime.toDateTimeFormat(UtilDateTime.DATE_TIME_FORMAT, timeZone, null);
+                    targetBuffer.append(df.format((java.util.Date) envVal));
+                } else if (envVal instanceof java.util.Date) {
+                    DateFormat df = UtilDateTime.toDateTimeFormat("EEE MMM dd 
hh:mm:ss z yyyy", timeZone, null);
+                    targetBuffer.append(df.format((java.util.Date) envVal));
+                } else if (localizeCurrency) {
                     targetBuffer.append(UtilFormatOut.formatCurrency(new 
Double(envVal.toString()), currencyCode, locale));
                 } else {
                     targetBuffer.append(envVal.toString());

Modified: 
ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/template/FreeMarkerWorker.java
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/template/FreeMarkerWorker.java?view=diff&rev=564957&r1=564956&r2=564957
==============================================================================
--- 
ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/template/FreeMarkerWorker.java
 (original)
+++ 
ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/template/FreeMarkerWorker.java
 Sat Aug 11 11:40:45 2007
@@ -195,12 +195,11 @@
         }
         env.setLocale(locale);
 
-        /* uncomment code block when framework time zone support is implemented
         TimeZone timeZone = (TimeZone) context.get("timeZone");
         if (timeZone == null) {
             timeZone = TimeZone.getDefault();
         }
-        env.setTimeZone(timeZone); */
+        env.setTimeZone(timeZone);
     }
 
     public static Configuration getDefaultOfbizConfig() throws 
TemplateException, IOException {

Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelService.java
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelService.java?view=diff&rev=564957&r1=564956&r2=564957
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelService.java 
(original)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelService.java Sat 
Aug 11 11:40:45 2007
@@ -707,7 +707,7 @@
      * @param mode The mode which to build the new map
      */
     public Map makeValid(Map source, String mode) {
-        return makeValid(source, mode, true, null, null);
+        return makeValid(source, mode, true, null);
     }
 
     /**
@@ -727,9 +727,22 @@
      * @param source The source map
      * @param mode The mode which to build the new map
      * @param includeInternal When false will exclude internal fields
-     * @param locale locale to use to do some type conversion
+     * @param locale Locale to use to do some type conversion
      */
     public Map makeValid(Map source, String mode, boolean includeInternal, 
List errorMessages, Locale locale) {
+        return makeValid(source, mode, includeInternal, errorMessages, null, 
locale);
+    }
+
+    /**
+     * Creates a new Map based from an existing map with just valid parameters.
+     * Tries to convert parameters to required type.
+     * @param source The source map
+     * @param mode The mode which to build the new map
+     * @param includeInternal When false will exclude internal fields
+     * @param tz TimeZone to use to do some type conversion
+     * @param locale Locale to use to do some type conversion
+     */
+    public Map makeValid(Map source, String mode, boolean includeInternal, 
List errorMessages, TimeZone timeZone, Locale locale) {
         Map target = new HashMap();
 
         if (source == null) {
@@ -741,6 +754,21 @@
         if (contextInfo.size() == 0) {
             return target;
         }
+
+        if (locale == null) {
+            locale = (Locale) source.get("locale");
+            if (locale == null) {
+                locale = Locale.getDefault();
+            }
+        }
+        
+        if (timeZone == null) {
+            timeZone = (TimeZone) source.get("timeZone");
+            if (timeZone == null) {
+                timeZone = TimeZone.getDefault();
+            }
+        }
+        
         Iterator i = contextParamList.iterator();
 
         while (i.hasNext()) {
@@ -770,7 +798,7 @@
 
                             try {
                                 // no need to fail on type conversion; the 
validator will catch this
-                                value = ObjectType.simpleTypeConvert(value, 
param.type, null, locale, false);
+                                value = ObjectType.simpleTypeConvert(value, 
param.type, null, timeZone, locale, false);
                             } catch (GeneralException e) {
                                 String errMsg = "Type conversion of field [" + 
key + "] to type [" + param.type + "] failed for value \"" + value + "\": " + 
e.toString();
                                 Debug.logWarning("[ModelService.makeValid] : " 
+ errMsg, module);

Modified: 
ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/CoreEvents.java
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/CoreEvents.java?view=diff&rev=564957&r1=564956&r2=564957
==============================================================================
--- ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/CoreEvents.java 
(original)
+++ ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/CoreEvents.java Sat 
Aug 11 11:40:45 2007
@@ -30,6 +30,7 @@
 import java.util.Locale;
 import java.util.Map;
 import java.util.Set;
+import java.util.TimeZone;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
@@ -201,6 +202,7 @@
         LocalDispatcher dispatcher = (LocalDispatcher) 
request.getAttribute("dispatcher");
         //GenericDelegator delegator = (GenericDelegator) 
request.getAttribute("delegator");
         Locale locale = UtilHttp.getLocale(request);
+        TimeZone timeZone = UtilHttp.getTimeZone(request);
         
         Map params = UtilHttp.getParameterMap(request);
         // get the schedule parameters
@@ -291,7 +293,7 @@
             // set even if null so that values will get nulled in the db later 
on
             serviceContext.put(name, value);
         }     
-        serviceContext = modelService.makeValid(serviceContext, 
ModelService.IN_PARAM, true, null, locale);
+        serviceContext = modelService.makeValid(serviceContext, 
ModelService.IN_PARAM, true, null, timeZone, locale);
         
         if (userLogin != null) {
             serviceContext.put("userLogin", userLogin);                        
     

Modified: 
ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/ServiceEventHandler.java
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/ServiceEventHandler.java?view=diff&rev=564957&r1=564956&r2=564957
==============================================================================
--- 
ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/ServiceEventHandler.java
 (original)
+++ 
ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/ServiceEventHandler.java
 Sat Aug 11 11:40:45 2007
@@ -294,7 +294,7 @@
         // get only the parameters for this service - converted to proper type
         // TODO: pass in a list for error messages, like could not convert 
type or not a proper X, return immediately with messages if there are any
         List errorMessages = new LinkedList();
-        serviceContext = model.makeValid(serviceContext, 
ModelService.IN_PARAM, true, errorMessages, locale);
+        serviceContext = model.makeValid(serviceContext, 
ModelService.IN_PARAM, true, errorMessages, timeZone, locale);
         if (errorMessages.size() > 0) {
             // uh-oh, had some problems...
             request.setAttribute("_ERROR_MESSAGE_LIST_", errorMessages);

Modified: 
ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/ServiceMultiEventHandler.java
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/ServiceMultiEventHandler.java?view=diff&rev=564957&r1=564956&r2=564957
==============================================================================
--- 
ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/ServiceMultiEventHandler.java
 (original)
+++ 
ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/ServiceMultiEventHandler.java
 Sat Aug 11 11:40:45 2007
@@ -23,6 +23,7 @@
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
+import java.util.TimeZone;
 
 import javax.servlet.ServletContext;
 import javax.servlet.http.HttpServletRequest;
@@ -110,6 +111,7 @@
 
         // some needed info for when running the service
         Locale locale = UtilHttp.getLocale(request);
+        TimeZone timeZone = UtilHttp.getTimeZone(request);
         HttpSession session = request.getSession();
         GenericValue userLogin = (GenericValue) 
session.getAttribute("userLogin");
 
@@ -207,6 +209,8 @@
                     if ("userLogin".equals(paramName)) continue;
                     // don't include locale, that is also taken care of below
                     if ("locale".equals(paramName)) continue;
+                    // don't include timeZone, that is also taken care of below
+                    if ("timeZone".equals(paramName)) continue;
 
                     Object value = null;
                     if (modelParam.stringMapPrefix != null && 
modelParam.stringMapPrefix.length() > 0) {
@@ -273,7 +277,7 @@
                 }
 
                 // get only the parameters for this service - converted to 
proper type
-                serviceContext = modelService.makeValid(serviceContext, 
ModelService.IN_PARAM, true, null, locale);
+                serviceContext = modelService.makeValid(serviceContext, 
ModelService.IN_PARAM, true, null, timeZone, locale);
 
                 // include the UserLogin value object
                 if (userLogin != null) {
@@ -283,6 +287,11 @@
                 // include the Locale object
                 if (locale != null) {
                     serviceContext.put("locale", locale);
+                }
+
+                // include the TimeZone object
+                if (timeZone != null) {
+                    serviceContext.put("timeZone", timeZone);
                 }
 
                 // Debug.logInfo("ready to call " + serviceName + " with 
context " + serviceContext, module);

Modified: 
ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java?view=diff&rev=564957&r1=564956&r2=564957
==============================================================================
--- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java 
(original)
+++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java 
Sat Aug 11 11:40:45 2007
@@ -19,6 +19,7 @@
 package org.ofbiz.widget.form;
 
 import java.math.BigDecimal;
+import java.text.DateFormat;
 import java.text.NumberFormat;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -27,6 +28,7 @@
 import java.util.Locale;
 import java.util.Map;
 import java.util.StringTokenizer;
+import java.util.TimeZone;
 
 import javolution.util.FastList;
 
@@ -615,6 +617,8 @@
         
         Locale locale = (Locale) context.get("locale");
         if (locale == null) locale = Locale.getDefault();
+        TimeZone timeZone = (TimeZone) context.get("timeZone");
+        if (timeZone == null) timeZone = TimeZone.getDefault();
         
         // if useRequestParameters is TRUE then parameters will always be 
used, if FALSE then parameters will never be used
         // if isError is TRUE and useRequestParameters is not FALSE (ie is 
null or TRUE) then parameters will be used
@@ -667,11 +671,23 @@
             }
 
             if (retVal != null) {
-                // format number based on the user's locale
+                // format string based on the user's locale and time zone
                 if (retVal instanceof Double || retVal instanceof Float || 
retVal instanceof BigDecimal) {
                     NumberFormat nf = NumberFormat.getInstance(locale);
                     nf.setMaximumFractionDigits(10);
                     return nf.format(retVal);
+                } else if (retVal instanceof java.sql.Date) {
+                    DateFormat df = 
UtilDateTime.toDateFormat(UtilDateTime.DATE_FORMAT, timeZone, null);
+                    return df.format((java.util.Date) retVal);
+                } else if (retVal instanceof java.sql.Time) {
+                    DateFormat df = 
UtilDateTime.toTimeFormat(UtilDateTime.TIME_FORMAT, timeZone, null);
+                    return df.format((java.util.Date) retVal);
+                } else if (retVal instanceof java.sql.Timestamp) {
+                    DateFormat df = 
UtilDateTime.toDateTimeFormat(UtilDateTime.DATE_TIME_FORMAT, timeZone, null);
+                    return df.format((java.util.Date) retVal);
+                } else if (retVal instanceof java.util.Date) {
+                    DateFormat df = UtilDateTime.toDateTimeFormat("EEE MMM dd 
hh:mm:ss z yyyy", timeZone, null);
+                    return df.format((java.util.Date) retVal);
                 } else {
                     return retVal.toString();
                 }


Reply via email to