Author: bpapez
Date: Mon Aug  6 17:51:51 2007
New Revision: 18146

URL: https://svndev.jahia.net/websvn/listing.php?sc=3D1&rev=3D18146&repname=
=3Djahia
Log:
put getSimpleDateFormat back in case legacy templates are using it

Modified:
    branches/JAHIA-4-1-BRANCH/src/java/org/jahia/data/fields/JahiaDateField=
Util.java

Modified: branches/JAHIA-4-1-BRANCH/src/java/org/jahia/data/fields/JahiaDat=
eFieldUtil.java
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/branches/JAHIA-4-1-BR=
ANCH/src/java/org/jahia/data/fields/JahiaDateFieldUtil.java&rev=3D18146&rep=
name=3Djahia
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/JAHIA-4-1-BRANCH/src/java/org/jahia/data/fields/JahiaDateField=
Util.java (original)
+++ branches/JAHIA-4-1-BRANCH/src/java/org/jahia/data/fields/JahiaDateField=
Util.java Mon Aug  6 17:51:51 2007
@@ -17,50 +17,47 @@
  * =

  * @author Sergiy Shyrkov
  */
-public class JahiaDateFieldUtil
-{
+public class JahiaDateFieldUtil {
   /**
    * The date value container.
    *
    * @author Sergiy Shyrkov
    */
-  public static class DateValues implements Serializable
-  {
-    private Object valueObject;
-    private String valueString;
-
-    /**
-     * Initializes an instance of this class.
-     * =

-     * @param strValue the string value
-     * @param objValue the object value
-     */
-    DateValues(String strValue, Object objValue)
-    {
-      valueString =3D strValue;
-      valueObject =3D objValue;
-    }
+  public static class DateValues implements Serializable {
+        private Object valueObject;
+        private String valueString;
+
+        /**
+         * Initializes an instance of this class.
+         * =

+         * @param strValue
+         *                the string value
+         * @param objValue
+         *                the object value
+         */
+        DateValues(String strValue, Object objValue) {
+            valueString =3D strValue;
+            valueObject =3D objValue;
+        }
 =

-    /**
-     * @return the valueObject
-     */
-    public Object getValueObject()
-    {
-      return valueObject;
-    }
+        /**
+         * @return the valueObject
+         */
+        public Object getValueObject() {
+            return valueObject;
+        }
 =

-    /**
-     * @return the valueString
-     */
-    public String getValueString()
-    {
-      return valueString;
-    }
+        /**
+         * @return the valueString
+         */
+        public String getValueString() {
+            return valueString;
+        }
 =

-  }
+    }
 =

-  private static final String DEFAULT_PATTERN =3D new SimpleDateFormat()
-    .toPattern();
+    private static final String DEFAULT_PATTERN =3D new SimpleDateFormat()
+            .toPattern();
 =

   /**
    * Returns the date format for the specified locale and default time zon=
e,
@@ -68,19 +65,58 @@
    * <code><jahia_calendar[dd.MM.yyyy / HH:mm]></code>.
    * =

    * @param defaultValue the default value string
+   * @param defaultFormat a default format
    * @param locale the current locale
    * @return the date format for the specified locale, created using the f=
ormat,
    *         parsed from the default field value
+   * @deprecated use getDateFormat(String, Locale) instead
    */
-  public static FastDateFormat getDateFormat(String defaultValue, Locale l=
ocale)
-  {
-    String pattern =3D null;
-    if (defaultValue !=3D null && defaultValue.length() > 0)
-      pattern =3D parseDatePattern(defaultValue);
-
-    return FastDateFormat.getInstance(pattern !=3D null ? pattern
-      : DEFAULT_PATTERN, locale);
-  }
+  public static SimpleDateFormat getSimpleDateFormat(String defaultValue,
+          String defaultFormat, Locale locale) {
+      SimpleDateFormat sdf =3D null;
+      String pattern =3D null;
+      if (defaultValue !=3D null && defaultValue.length() > 0)
+          pattern =3D parseDatePattern(defaultValue);
+      try {
+          sdf =3D new SimpleDateFormat(pattern !=3D null ? pattern
+                  : DEFAULT_PATTERN, locale);
+      } catch (Throwable t) {
+      }
+      if (sdf =3D=3D null || "".equals(sdf.toPattern())) {
+          sdf =3D new SimpleDateFormat(defaultFormat, locale);
+      }        =

+      if (sdf =3D=3D null || "".equals(sdf.toPattern())) {
+          sdf =3D new SimpleDateFormat(DEFAULT_PATTERN, locale);
+      }
+      return sdf;
+  }    =

+  =

+  /**
+   * Returns the date format for the specified locale and default time zon=
e,
+   * created using the format, parsed from the default field value, e.g. f=
rom
+   * <code><jahia_calendar[dd.MM.yyyy / HH:mm]></code>.
+   * =

+   * @param defaultValue the default value string
+   * @param locale the current locale
+   * @return the date format for the specified locale, created using the f=
ormat,
+   *         parsed from the default field value
+   */
+  public static FastDateFormat getDateFormat(String defaultValue,
+          Locale locale) {
+      FastDateFormat fdf =3D null;
+      String pattern =3D null;
+      if (defaultValue !=3D null && defaultValue.length() > 0)
+          pattern =3D parseDatePattern(defaultValue);
+      try {
+          FastDateFormat.getInstance(pattern !=3D null ? pattern
+                  : DEFAULT_PATTERN, locale);
+      } catch (Throwable t) {
+      }
+      if (fdf =3D=3D null || "".equals(fdf.getPattern())) {
+          fdf =3D FastDateFormat.getInstance(DEFAULT_PATTERN, locale);
+      }
+      return fdf;
+  } =

 =

   /**
    * Returns the default date parsed from the default date marker of the f=
orm
@@ -96,68 +132,60 @@
    * @return the default date parsed from the default date marker
    */
   public static final DateValues parseDateDefaultValue(
-    String defaultValueMarker, String languageCode)
-  {
-    DateValues values =3D null;
-    String format =3D parseDatePattern(defaultValueMarker);
-    if (format !=3D null)
-    {
-      if (defaultValueMarker.lastIndexOf(">") !=3D -1
-        && defaultValueMarker.lastIndexOf(">") < defaultValueMarker.length=
() - 1)
-      {
-        String defaultValueString =3D defaultValueMarker
-          .substring(defaultValueMarker.lastIndexOf(">") + 1);
-        String defaultValueLower =3D defaultValueString.toLowerCase();
-        // special case --> current date marker is used
-        if (defaultValueLower.indexOf("now") !=3D -1)
-        {
-          if ("now".equals(defaultValueLower))
-          {
-            Date now =3D new Date();
-            values =3D new DateValues(FastDateFormat.getInstance(format,
-              new Locale(languageCode)).format(now), String.valueOf(now
-              .getTime()));
-          }
-          else
-          {
-            try
-            {
-              Expression expr =3D ExpressionFactory
-                .createExpression(defaultValueLower);
-              JexlContext ctx =3D JexlHelper.createContext();
-              ctx.getVars().put("now", new Long(System.currentTimeMillis()=
));
-              long evaluationResult =3D ((Long)expr.evaluate(ctx)).longVal=
ue();
-
-              values =3D new DateValues(FastDateFormat.getInstance(format,
-                new Locale(languageCode)).format(new Date(evaluationResult=
)),
-                String.valueOf(evaluationResult));
-            }
-            catch (Exception ex)
-            {
-              throw new IllegalArgumentException(
-                "Unable to parse the default date value marker: " + ex);
+            String defaultValueMarker, String languageCode) {
+        DateValues values =3D null;
+        String format =3D parseDatePattern(defaultValueMarker);
+        if (format !=3D null) {
+            if (defaultValueMarker.lastIndexOf(">") !=3D -1
+                    && defaultValueMarker.lastIndexOf(">") < defaultValueM=
arker
+                            .length() - 1) {
+                String defaultValueString =3D defaultValueMarker
+                        .substring(defaultValueMarker.lastIndexOf(">") + 1=
);
+                String defaultValueLower =3D defaultValueString.toLowerCas=
e();
+                // special case --> current date marker is used
+                if (defaultValueLower.indexOf("now") !=3D -1) {
+                    if ("now".equals(defaultValueLower)) {
+                        Date now =3D new Date();
+                        values =3D new DateValues(FastDateFormat.getInstan=
ce(
+                                format, new Locale(languageCode)).format(n=
ow),
+                                String.valueOf(now.getTime()));
+                    } else {
+                        try {
+                            Expression expr =3D ExpressionFactory
+                                    .createExpression(defaultValueLower);
+                            JexlContext ctx =3D JexlHelper.createContext();
+                            ctx.getVars().put("now",
+                                    new Long(System.currentTimeMillis()));
+                            long evaluationResult =3D ((Long) expr.evaluat=
e(ctx))
+                                    .longValue();
+
+                            values =3D new DateValues(FastDateFormat.getIn=
stance(
+                                    format, new Locale(languageCode)).form=
at(
+                                    new Date(evaluationResult)), String
+                                    .valueOf(evaluationResult));
+                        } catch (Exception ex) {
+                            throw new IllegalArgumentException(
+                                    "Unable to parse the default date valu=
e marker: "
+                                            + ex);
+                        }
+                    }
+                } else {
+                    try {
+                        Date parsedDate =3D new SimpleDateFormat(format,
+                                new Locale(languageCode))
+                                .parse(defaultValueString);
+                        values =3D new DateValues(defaultValueString, Stri=
ng
+                                .valueOf(parsedDate.getTime()));
+                    } catch (ParseException ex) {
+                        throw new IllegalArgumentException(
+                                "Unable to parse the default date value ma=
rker: "
+                                        + ex);
+                    }
+                }
             }
-          }
         }
-        else
-        {
-          try
-          {
-            Date parsedDate =3D new SimpleDateFormat(format, new Locale(
-              languageCode)).parse(defaultValueString);
-            values =3D new DateValues(defaultValueString, String
-              .valueOf(parsedDate.getTime()));
-          }
-          catch (ParseException ex)
-          {
-            throw new IllegalArgumentException(
-              "Unable to parse the default date value marker: " + ex);
-          }
-        }
-      }
+        return values;
     }
-    return values;
-  }
 =

   /**
    * Returns the date format pattern parsed from the default field value, =
i.e.
@@ -166,16 +194,14 @@
    * @param defaultValue the default field value
    * @return the date format pattern parsed from the default field value
    */
-  private static final String parseDatePattern(String defaultValue)
-  {
-    String format =3D null;
-    if (defaultValue.toLowerCase().indexOf("jahia_calendar") !=3D -1
-      && defaultValue.indexOf("[") !=3D -1)
-    {
-      format =3D defaultValue.substring(defaultValue.indexOf("[") + 1,
-        defaultValue.indexOf("]"));
+  private static final String parseDatePattern(String defaultValue) {
+        String format =3D null;
+        if (defaultValue.toLowerCase().indexOf("jahia_calendar") !=3D -1
+                && defaultValue.indexOf("[") !=3D -1) {
+            format =3D defaultValue.substring(defaultValue.indexOf("[") + =
1,
+                    defaultValue.indexOf("]"));
+        }
+        return format;
     }
-    return format;
-  }
 =

 }

_______________________________________________
cvs_list mailing list
[email protected]
http://lists.jahia.org/cgi-bin/mailman/listinfo/cvs_list

Reply via email to