syncope-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ilgro...@apache.org
Subject syncope git commit: [SYNCOPE-156] FastDateFormat everywhere
Date Thu, 12 May 2016 08:29:07 GMT
Repository: syncope
Updated Branches:
  refs/heads/master 34dad8da7 -> b822bd75f


[SYNCOPE-156] FastDateFormat everywhere


Project: http://git-wip-us.apache.org/repos/asf/syncope/repo
Commit: http://git-wip-us.apache.org/repos/asf/syncope/commit/b822bd75
Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/b822bd75
Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/b822bd75

Branch: refs/heads/master
Commit: b822bd75f4205db8458be6e97aac8e8af3273d31
Parents: 34dad8d
Author: Francesco Chicchiriccò <ilgrosso@apache.org>
Authored: Thu May 12 10:29:00 2016 +0200
Committer: Francesco Chicchiriccò <ilgrosso@apache.org>
Committed: Thu May 12 10:29:00 2016 +0200

----------------------------------------------------------------------
 .../wicket/markup/html/form/DateFieldPanel.java | 30 +++++++-------------
 1 file changed, 10 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/syncope/blob/b822bd75/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/form/DateFieldPanel.java
----------------------------------------------------------------------
diff --git a/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/form/DateFieldPanel.java
b/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/form/DateFieldPanel.java
index 2d18b44..4ae788e 100644
--- a/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/form/DateFieldPanel.java
+++ b/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/form/DateFieldPanel.java
@@ -20,11 +20,10 @@ package org.apache.syncope.client.console.wicket.markup.html.form;
 
 import java.io.Serializable;
 import java.text.ParseException;
-import java.text.SimpleDateFormat;
 import java.util.Date;
 import java.util.List;
-import java.util.Locale;
-import org.apache.syncope.common.lib.SyncopeConstants;
+import org.apache.commons.lang3.time.FastDateFormat;
+import org.apache.syncope.client.console.SyncopeConsoleSession;
 import org.apache.wicket.markup.html.list.ListItem;
 import org.apache.wicket.model.IModel;
 import org.apache.wicket.model.Model;
@@ -34,22 +33,17 @@ public class DateFieldPanel extends FieldPanel<Date> {
 
     private static final long serialVersionUID = -428975732068281726L;
 
-    protected final String name;
-
-    protected final String datePattern;
+    protected final FastDateFormat fmt;
 
     protected DateFieldPanel(final String id, final String name, final IModel<Date>
model, final String datePattern) {
         super(id, name, model);
-        this.name = name;
-        this.datePattern = datePattern;
+        fmt = datePattern == null
+                ? SyncopeConsoleSession.get().getDateFormat()
+                : FastDateFormat.getInstance(datePattern);
     }
 
     @Override
     public FieldPanel<Date> setNewModel(final List<Serializable> list) {
-        final SimpleDateFormat formatter = datePattern == null
-                ? new SimpleDateFormat(SyncopeConstants.DEFAULT_DATE_PATTERN, Locale.getDefault())
-                : new SimpleDateFormat(datePattern, Locale.getDefault());
-
         setNewModel(new Model<Date>() {
 
             private static final long serialVersionUID = 527651414610325237L;
@@ -61,7 +55,7 @@ public class DateFieldPanel extends FieldPanel<Date> {
                 if (list != null && !list.isEmpty() && StringUtils.hasText(list.get(0).toString()))
{
                     try {
                         // Parse string using datePattern
-                        date = formatter.parse(list.get(0).toString());
+                        date = fmt.parse(list.get(0).toString());
                     } catch (ParseException e) {
                         LOG.error("invalid parse exception", e);
                     }
@@ -74,7 +68,7 @@ public class DateFieldPanel extends FieldPanel<Date> {
             public void setObject(final Date object) {
                 list.clear();
                 if (object != null) {
-                    list.add(formatter.format(object));
+                    list.add(fmt.format(object));
                 }
             }
         });
@@ -85,10 +79,6 @@ public class DateFieldPanel extends FieldPanel<Date> {
     @SuppressWarnings("rawtypes")
     @Override
     public FieldPanel<Date> setNewModel(final ListItem item) {
-        final SimpleDateFormat formatter = datePattern == null
-                ? new SimpleDateFormat(SyncopeConstants.DEFAULT_DATE_PATTERN, Locale.getDefault())
-                : new SimpleDateFormat(datePattern, Locale.getDefault());
-
         IModel<Date> model = new Model<Date>() {
 
             private static final long serialVersionUID = 6799404673615637845L;
@@ -103,7 +93,7 @@ public class DateFieldPanel extends FieldPanel<Date> {
                     if (obj instanceof String) {
                         // Parse string using datePattern
                         try {
-                            date = formatter.parse(obj.toString());
+                            date = fmt.parse(obj.toString());
                         } catch (ParseException e) {
                             LOG.error("While parsing date", e);
                         }
@@ -122,7 +112,7 @@ public class DateFieldPanel extends FieldPanel<Date> {
             @Override
             @SuppressWarnings("unchecked")
             public void setObject(final Date object) {
-                item.setModelObject(object != null ? formatter.format(object) : null);
+                item.setModelObject(object != null ? fmt.format(object) : null);
             }
         };
 


Mime
View raw message