syncope-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ilgro...@apache.org
Subject svn commit: r1451182 - in /syncope/trunk: console/src/main/java/org/apache/syncope/console/wicket/markup/html/form/ core/src/main/java/org/apache/syncope/core/persistence/beans/ core/src/main/java/org/apache/syncope/core/report/ core/src/main/java/org/...
Date Thu, 28 Feb 2013 12:32:17 GMT
Author: ilgrosso
Date: Thu Feb 28 12:32:17 2013
New Revision: 1451182

URL: http://svn.apache.org/r1451182
Log:
[SYNCOPE-327] Fixing ThreadLocal messages related to SimpleDateFormat and DecimalFormat

Added:
    syncope/trunk/core/src/main/java/org/apache/syncope/core/util/DataFormat.java   (with
props)
Modified:
    syncope/trunk/console/src/main/java/org/apache/syncope/console/wicket/markup/html/form/DateTimeFieldPanel.java
    syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/AbstractAttrValue.java
    syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/AbstractBaseBean.java
    syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/AbstractSchema.java
    syncope/trunk/core/src/main/java/org/apache/syncope/core/report/AbstractReportlet.java
    syncope/trunk/core/src/main/java/org/apache/syncope/core/report/StaticReportlet.java
    syncope/trunk/core/src/main/java/org/apache/syncope/core/report/UserReportlet.java
    syncope/trunk/core/src/main/java/org/apache/syncope/core/util/ImportExport.java
    syncope/trunk/core/src/main/java/org/apache/syncope/core/util/JexlUtil.java

Modified: syncope/trunk/console/src/main/java/org/apache/syncope/console/wicket/markup/html/form/DateTimeFieldPanel.java
URL: http://svn.apache.org/viewvc/syncope/trunk/console/src/main/java/org/apache/syncope/console/wicket/markup/html/form/DateTimeFieldPanel.java?rev=1451182&r1=1451181&r2=1451182&view=diff
==============================================================================
--- syncope/trunk/console/src/main/java/org/apache/syncope/console/wicket/markup/html/form/DateTimeFieldPanel.java
(original)
+++ syncope/trunk/console/src/main/java/org/apache/syncope/console/wicket/markup/html/form/DateTimeFieldPanel.java
Thu Feb 28 12:32:17 2013
@@ -18,12 +18,8 @@
  */
 package org.apache.syncope.console.wicket.markup.html.form;
 
-import java.text.SimpleDateFormat;
 import java.util.Calendar;
 import java.util.Date;
-import java.util.Locale;
-
-import org.apache.syncope.common.SyncopeConstants;
 import org.apache.wicket.AttributeModifier;
 import org.apache.wicket.ajax.AjaxRequestTarget;
 import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
@@ -42,14 +38,6 @@ public class DateTimeFieldPanel extends 
 
     private Form form = null;
 
-    protected static final ThreadLocal<SimpleDateFormat> DATE_FORMAT = new ThreadLocal<SimpleDateFormat>()
{
-
-        @Override
-        protected SimpleDateFormat initialValue() {
-            return new SimpleDateFormat(SyncopeConstants.DEFAULT_DATE_PATTERN, Locale.getDefault());
-        }
-    };
-
     public DateTimeFieldPanel(final String id, final String name, final IModel<Date>
model, final String datePattern) {
 
         super(id, name, model, datePattern);

Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/AbstractAttrValue.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/AbstractAttrValue.java?rev=1451182&r1=1451181&r2=1451182&view=diff
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/AbstractAttrValue.java
(original)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/AbstractAttrValue.java
Thu Feb 28 12:32:17 2013
@@ -18,8 +18,6 @@
  */
 package org.apache.syncope.core.persistence.beans;
 
-import java.text.DateFormat;
-import java.text.DecimalFormat;
 import java.util.Date;
 import javax.persistence.Basic;
 import javax.persistence.MappedSuperclass;
@@ -29,11 +27,10 @@ import javax.validation.constraints.Max;
 import javax.validation.constraints.Min;
 import org.apache.commons.lang.builder.ReflectionToStringBuilder;
 import org.apache.commons.lang.builder.ToStringStyle;
-import org.apache.commons.lang.time.DateUtils;
-import org.apache.syncope.common.SyncopeConstants;
 import org.apache.syncope.common.types.AttributeSchemaType;
 import org.apache.syncope.core.persistence.validation.attrvalue.ParsingValidationException;
 import org.apache.syncope.core.persistence.validation.entity.AttrValueCheck;
+import org.apache.syncope.core.util.DataFormat;
 
 @MappedSuperclass
 @AttrValueCheck
@@ -118,12 +115,9 @@ public abstract class AbstractAttrValue 
 
             case Long:
                 try {
-                    if (schema.getFormatter() == null) {
-                        this.setLongValue(Long.valueOf(value));
-                    } else {
-                        this.setLongValue(Long.valueOf(
-                                ((DecimalFormat) schema.getFormatter()).parse(value).longValue()));
-                    }
+                    this.setLongValue(schema.getConversionPattern() == null
+                            ? Long.valueOf(value)
+                            : DataFormat.parseNumber(value, schema.getConversionPattern()).longValue());
                 } catch (Exception pe) {
                     exception = pe;
                 }
@@ -131,12 +125,9 @@ public abstract class AbstractAttrValue 
 
             case Double:
                 try {
-                    if (schema.getFormatter() == null) {
-                        this.setDoubleValue(Double.valueOf(value));
-                    } else {
-                        this.setDoubleValue(Double.valueOf(
-                                ((DecimalFormat) schema.getFormatter()).parse(value).doubleValue()));
-                    }
+                    this.setDoubleValue(schema.getConversionPattern() == null
+                            ? Double.valueOf(value)
+                            : DataFormat.parseNumber(value, schema.getConversionPattern()).doubleValue());
                 } catch (Exception pe) {
                     exception = pe;
                 }
@@ -144,11 +135,9 @@ public abstract class AbstractAttrValue 
 
             case Date:
                 try {
-                    if (schema.getFormatter() == null) {
-                        this.setDateValue(DateUtils.parseDate(value, SyncopeConstants.DATE_PATTERNS));
-                    } else {
-                        this.setDateValue(new Date(((DateFormat) schema.getFormatter()).parse(value).getTime()));
-                    }
+                    this.setDateValue(schema.getConversionPattern() == null
+                            ? DataFormat.parseDate(value)
+                            : new Date(DataFormat.parseDate(value, schema.getConversionPattern()).getTime()));
                 } catch (Exception pe) {
                     exception = pe;
                 }
@@ -195,27 +184,21 @@ public abstract class AbstractAttrValue 
                 break;
 
             case Long:
-                if (getAttribute().getSchema().getFormatter() == null) {
-                    result = getLongValue().toString();
-                } else {
-                    result = getAttribute().getSchema().getFormatter().format(getLongValue());
-                }
+                result = getAttribute().getSchema().getConversionPattern() == null
+                        ? getLongValue().toString()
+                        : DataFormat.format(getLongValue(), getAttribute().getSchema().getConversionPattern());
                 break;
 
             case Double:
-                if (getAttribute().getSchema().getFormatter() == null) {
-                    result = getDoubleValue().toString();
-                } else {
-                    result = getAttribute().getSchema().getFormatter().format(getDoubleValue());
-                }
+                result = getAttribute().getSchema().getConversionPattern() == null
+                        ? getDoubleValue().toString()
+                        : DataFormat.format(getDoubleValue(), getAttribute().getSchema().getConversionPattern());
                 break;
 
             case Date:
-                if (getAttribute().getSchema().getFormatter() == null) {
-                    result = DATE_FORMAT.get().format(getDateValue());
-                } else {
-                    result = getAttribute().getSchema().getFormatter().format(getDateValue());
-                }
+                result = getAttribute().getSchema().getConversionPattern() == null
+                        ? DataFormat.format(getDateValue())
+                        : DataFormat.format(getDateValue(), false, getAttribute().getSchema().getConversionPattern());
                 break;
 
             default:

Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/AbstractBaseBean.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/AbstractBaseBean.java?rev=1451182&r1=1451181&r2=1451182&view=diff
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/AbstractBaseBean.java
(original)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/AbstractBaseBean.java
Thu Feb 28 12:32:17 2013
@@ -21,14 +21,11 @@ package org.apache.syncope.core.persiste
 import java.beans.PropertyDescriptor;
 import java.io.Serializable;
 import java.lang.reflect.Method;
-import java.text.DecimalFormat;
-import java.text.SimpleDateFormat;
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.Set;
 import org.apache.commons.lang.builder.EqualsBuilder;
 import org.apache.commons.lang.builder.HashCodeBuilder;
-import org.apache.syncope.common.SyncopeConstants;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.BeanUtils;
@@ -40,30 +37,8 @@ public abstract class AbstractBaseBean i
      */
     protected static final Logger LOG = LoggerFactory.getLogger(AbstractBaseBean.class);
 
-    protected static final ThreadLocal<SimpleDateFormat> DATE_FORMAT = new ThreadLocal<SimpleDateFormat>()
{
-
-        @Override
-        protected SimpleDateFormat initialValue() {
-            return new SimpleDateFormat(SyncopeConstants.DEFAULT_DATE_PATTERN);
-        }
-    };
-
-    protected static final ThreadLocal<DecimalFormat> DECIMAL_FORMAT = new ThreadLocal<DecimalFormat>()
{
-
-        @Override
-        protected DecimalFormat initialValue() {
-            return new DecimalFormat();
-        }
-    };
-
     private static final long serialVersionUID = -9017214159540857901L;
 
-    public final SimpleDateFormat getDateFormatter() {
-        final SimpleDateFormat dateFormatter = DATE_FORMAT.get();
-        dateFormatter.setLenient(false);
-        return dateFormatter;
-    }
-
     /**
      * @param property the integer representing a boolean value
      * @return the boolean value corresponding to the property param

Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/AbstractSchema.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/AbstractSchema.java?rev=1451182&r1=1451181&r2=1451182&view=diff
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/AbstractSchema.java
(original)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/AbstractSchema.java
Thu Feb 28 12:32:17 2013
@@ -21,9 +21,6 @@ package org.apache.syncope.core.persiste
 import static javax.persistence.EnumType.STRING;
 
 import java.lang.reflect.Constructor;
-import java.text.DecimalFormat;
-import java.text.Format;
-import java.text.SimpleDateFormat;
 import javax.persistence.Basic;
 import javax.persistence.Column;
 import javax.persistence.Enumerated;
@@ -208,39 +205,4 @@ public abstract class AbstractSchema ext
 
         this.conversionPattern = conversionPattern;
     }
-
-    @SuppressWarnings("unchecked")
-    public <T extends Format> T getFormatter() {
-        T result = null;
-
-        if (getConversionPattern() != null) {
-            switch (getType()) {
-                case Long:
-                    DecimalFormat longFormatter = DECIMAL_FORMAT.get();
-                    longFormatter.applyPattern(getConversionPattern());
-
-                    result = (T) longFormatter;
-                    break;
-
-                case Double:
-                    DecimalFormat doubleFormatter = DECIMAL_FORMAT.get();
-                    doubleFormatter.applyPattern(getConversionPattern());
-
-                    result = (T) doubleFormatter;
-                    break;
-
-                case Date:
-                    SimpleDateFormat dateFormatter = DATE_FORMAT.get();
-                    dateFormatter.applyPattern(getConversionPattern());
-                    dateFormatter.setLenient(false);
-
-                    result = (T) dateFormatter;
-                    break;
-
-                default:
-            }
-        }
-
-        return result;
-    }
 }

Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/report/AbstractReportlet.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/report/AbstractReportlet.java?rev=1451182&r1=1451181&r2=1451182&view=diff
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/report/AbstractReportlet.java
(original)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/report/AbstractReportlet.java
Thu Feb 28 12:32:17 2013
@@ -23,9 +23,6 @@ import static org.apache.syncope.core.re
 import static org.apache.syncope.core.report.ReportXMLConst.ELEMENT_REPORTLET;
 import static org.apache.syncope.core.report.ReportXMLConst.XSD_STRING;
 
-import java.text.SimpleDateFormat;
-
-import org.apache.syncope.common.SyncopeConstants;
 import org.apache.syncope.common.report.AbstractReportletConf;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -41,14 +38,6 @@ public abstract class AbstractReportlet<
      */
     protected static final Logger LOG = LoggerFactory.getLogger(AbstractReportlet.class);
 
-    protected static final ThreadLocal<SimpleDateFormat> DATE_FORMAT = new ThreadLocal<SimpleDateFormat>()
{
-
-        @Override
-        protected SimpleDateFormat initialValue() {
-            return new SimpleDateFormat(SyncopeConstants.DEFAULT_DATE_PATTERN);
-        }
-    };
-
     protected T conf;
 
     public T getConf() {

Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/report/StaticReportlet.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/report/StaticReportlet.java?rev=1451182&r1=1451181&r2=1451182&view=diff
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/report/StaticReportlet.java (original)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/report/StaticReportlet.java Thu
Feb 28 12:32:17 2013
@@ -19,6 +19,7 @@
 package org.apache.syncope.core.report;
 
 import org.apache.syncope.common.report.StaticReportletConf;
+import org.apache.syncope.core.util.DataFormat;
 import org.springframework.util.StringUtils;
 import org.xml.sax.ContentHandler;
 import org.xml.sax.SAXException;
@@ -51,7 +52,7 @@ public class StaticReportlet extends Abs
 
         if (conf.getDateField() != null) {
             handler.startElement("", "", "date", null);
-            String printed = DATE_FORMAT.get().format(conf.getDateField());
+            String printed = DataFormat.format(conf.getDateField());
             handler.characters(printed.toCharArray(), 0, printed.length() - 1);
             handler.endElement("", "", "date");
         }

Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/report/UserReportlet.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/report/UserReportlet.java?rev=1451182&r1=1451181&r2=1451182&view=diff
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/report/UserReportlet.java (original)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/report/UserReportlet.java Thu
Feb 28 12:32:17 2013
@@ -44,6 +44,7 @@ import org.apache.syncope.core.persisten
 import org.apache.syncope.core.rest.data.RoleDataBinder;
 import org.apache.syncope.core.rest.data.UserDataBinder;
 import org.apache.syncope.core.util.AttributableUtil;
+import org.apache.syncope.core.util.DataFormat;
 import org.apache.syncope.core.util.EntitlementUtil;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.xml.sax.ContentHandler;
@@ -164,7 +165,7 @@ public class UserReportlet extends Abstr
                     }
                 } else {
                     LOG.debug("{} not found for {}[{}]", attrName,
-                                attributableTO.getClass().getSimpleName(), attributableTO.getId());
+                            attributableTO.getClass().getSimpleName(), attributableTO.getId());
                 }
 
                 handler.endElement("", "", "derivedAttribute");
@@ -190,7 +191,7 @@ public class UserReportlet extends Abstr
                     }
                 } else {
                     LOG.debug("{} not found for {}[{}]", attrName,
-                                attributableTO.getClass().getSimpleName(), attributableTO.getId());
+                            attributableTO.getClass().getSimpleName(), attributableTO.getId());
                 }
 
                 handler.endElement("", "", "virtualAttribute");
@@ -234,21 +235,21 @@ public class UserReportlet extends Abstr
                         type = XSD_DATETIME;
                         value = user.getCreationDate() == null
                                 ? ""
-                                : DATE_FORMAT.get().format(user.getCreationDate());
+                                : DataFormat.format(user.getCreationDate());
                         break;
 
                     case lastLoginDate:
                         type = XSD_DATETIME;
                         value = user.getLastLoginDate() == null
                                 ? ""
-                                : DATE_FORMAT.get().format(user.getLastLoginDate());
+                                : DataFormat.format(user.getLastLoginDate());
                         break;
 
                     case changePwdDate:
                         type = XSD_DATETIME;
                         value = user.getChangePwdDate() == null
                                 ? ""
-                                : DATE_FORMAT.get().format(user.getChangePwdDate());
+                                : DataFormat.format(user.getChangePwdDate());
                         break;
 
                     case passwordHistorySize:

Added: syncope/trunk/core/src/main/java/org/apache/syncope/core/util/DataFormat.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/util/DataFormat.java?rev=1451182&view=auto
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/util/DataFormat.java (added)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/util/DataFormat.java Thu Feb
28 12:32:17 2013
@@ -0,0 +1,132 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.syncope.core.util;
+
+import java.text.DecimalFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import org.apache.commons.lang.time.DateUtils;
+import org.apache.syncope.common.SyncopeConstants;
+
+/**
+ * Utility class for parsing / formatting date and numbers.
+ */
+public final class DataFormat {
+
+    private static final ThreadLocal<SimpleDateFormat> DATE_FORMAT = new ThreadLocal<SimpleDateFormat>()
{
+
+        @Override
+        protected SimpleDateFormat initialValue() {
+            SimpleDateFormat sdf = new SimpleDateFormat();
+            sdf.applyPattern(SyncopeConstants.DEFAULT_DATE_PATTERN);
+            return sdf;
+        }
+    };
+
+    private static final ThreadLocal<DecimalFormat> DECIMAL_FORMAT = new ThreadLocal<DecimalFormat>()
{
+
+        @Override
+        protected DecimalFormat initialValue() {
+            return new DecimalFormat();
+        }
+    };
+
+    public static String format(final Date date) {
+        return format(date, true);
+    }
+
+    public static String format(final Date date, final boolean lenient) {
+        return format(date, lenient, null);
+    }
+
+    public static String format(final Date date, final boolean lenient, final String conversionPattern)
{
+        try {
+            SimpleDateFormat sdf = DATE_FORMAT.get();
+            if (conversionPattern != null) {
+                sdf.applyPattern(conversionPattern);
+            }
+            sdf.setLenient(lenient);
+            return sdf.format(date);
+        } finally {
+            DATE_FORMAT.remove();
+        }
+    }
+
+    public static String format(final long number) {
+        return format(number, null);
+    }
+
+    public static String format(final long number, final String conversionPattern) {
+        try {
+            DecimalFormat df = DECIMAL_FORMAT.get();
+            if (conversionPattern != null) {
+                df.applyPattern(conversionPattern);
+            }
+            return df.format(number);
+        } finally {
+            DECIMAL_FORMAT.remove();
+        }
+    }
+
+    public static String format(final double number) {
+        return format(number, null);
+    }
+
+    public static String format(final double number, final String conversionPattern) {
+        try {
+            DecimalFormat df = DECIMAL_FORMAT.get();
+            if (conversionPattern != null) {
+                df.applyPattern(conversionPattern);
+            }
+            return df.format(number);
+        } finally {
+            DECIMAL_FORMAT.remove();
+        }
+    }
+
+    public static Date parseDate(final String source) throws ParseException {
+        return DateUtils.parseDate(source, SyncopeConstants.DATE_PATTERNS);
+    }
+
+    public static Date parseDate(final String source, final String conversionPattern) throws
ParseException {
+        try {
+            SimpleDateFormat sdf = DATE_FORMAT.get();
+            sdf.applyPattern(conversionPattern);
+            sdf.setLenient(false);
+            return sdf.parse(source);
+        } finally {
+            DATE_FORMAT.remove();
+        }
+    }
+
+    public static Number parseNumber(final String source, final String conversionPattern)
throws ParseException {
+        try {
+            DecimalFormat df = DECIMAL_FORMAT.get();
+            df.applyPattern(conversionPattern);
+            return df.parse(source);
+        } finally {
+            DECIMAL_FORMAT.remove();
+        }
+    }
+
+    private DataFormat() {
+        // private empty constructor
+    }
+}

Propchange: syncope/trunk/core/src/main/java/org/apache/syncope/core/util/DataFormat.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: syncope/trunk/core/src/main/java/org/apache/syncope/core/util/DataFormat.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: syncope/trunk/core/src/main/java/org/apache/syncope/core/util/DataFormat.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/util/ImportExport.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/util/ImportExport.java?rev=1451182&r1=1451181&r2=1451182&view=diff
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/util/ImportExport.java (original)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/util/ImportExport.java Thu Feb
28 12:32:17 2013
@@ -21,7 +21,6 @@ package org.apache.syncope.core.util;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
-import java.lang.String;
 import java.sql.Blob;
 import java.sql.Connection;
 import java.sql.DatabaseMetaData;
@@ -32,7 +31,6 @@ import java.sql.SQLException;
 import java.sql.Timestamp;
 import java.sql.Types;
 import java.text.ParseException;
-import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
@@ -57,7 +55,6 @@ import javax.xml.transform.sax.Transform
 import javax.xml.transform.stream.StreamResult;
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang.StringUtils;
-import org.apache.commons.lang.time.DateUtils;
 import org.apache.syncope.common.SyncopeConstants;
 import org.apache.syncope.core.util.multiparent.MultiParentNode;
 import org.apache.syncope.core.util.multiparent.MultiParentNodeOp;
@@ -81,14 +78,6 @@ public class ImportExport extends Defaul
 
     private static final String ROOT_ELEMENT = "dataset";
 
-    private static final ThreadLocal<SimpleDateFormat> DATE_FORMAT = new ThreadLocal<SimpleDateFormat>()
{
-
-        @Override
-        protected SimpleDateFormat initialValue() {
-            return new SimpleDateFormat(SyncopeConstants.DEFAULT_DATE_PATTERN);
-        }
-    };
-
     @Autowired
     private EntityManager entityManager;
 
@@ -97,8 +86,8 @@ public class ImportExport extends Defaul
 
     private final static Set<String> TABLE_PREFIXES_TO_BE_EXCLUDED =
             new HashSet<String>(Arrays.asList(new String[]{"QRTZ_", "LOGGING", "REPORTEXEC",
"TASKEXEC",
-                "SYNCOPEUSER", "UATTR", "UATTRVALUE", "UATTRUNIQUEVALUE", "UDERATTR", "UVIRATTR",
-                "MEMBERSHIP", "MATTR", "MATTRVALUE", "MATTRUNIQUEVALUE", "MDERATTR", "MVIRATTR",
"USERREQUEST"}));
+        "SYNCOPEUSER", "UATTR", "UATTRVALUE", "UATTRUNIQUEVALUE", "UDERATTR", "UVIRATTR",
+        "MEMBERSHIP", "MATTR", "MATTRVALUE", "MATTRUNIQUEVALUE", "MDERATTR", "MVIRATTR",
"USERREQUEST"}));
 
     private final static Map<String, String> TABLES_TO_BE_FILTERED =
             Collections.singletonMap("TASK", "DTYPE <> 'PropagationTask'");
@@ -229,8 +218,7 @@ public class ImportExport extends Defaul
                 case Types.TIME:
                 case Types.TIMESTAMP:
                     try {
-                        query.setParameter(i + 1, DateUtils.parseDate(
-                                attrs.getValue(i), SyncopeConstants.DATE_PATTERNS), TemporalType.TIMESTAMP);
+                        query.setParameter(i + 1, DataFormat.parseDate(attrs.getValue(i)),
TemporalType.TIMESTAMP);
                     } catch (ParseException e) {
                         LOG.error("Unparsable Date '{}'", attrs.getValue(i));
                         query.setParameter(i + 1, attrs.getValue(i));
@@ -587,7 +575,7 @@ public class ImportExport extends Defaul
                 case Types.TIMESTAMP:
                     final Timestamp timestamp = rs.getTimestamp(columnName);
                     if (timestamp != null) {
-                        res = DATE_FORMAT.get().format(new Date(timestamp.getTime()));
+                        res = DataFormat.format(new Date(timestamp.getTime()));
                     }
                     break;
 

Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/util/JexlUtil.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/util/JexlUtil.java?rev=1451182&r1=1451181&r2=1451182&view=diff
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/util/JexlUtil.java (original)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/util/JexlUtil.java Thu Feb 28
12:32:17 2013
@@ -33,7 +33,6 @@ import org.apache.commons.lang.StringUti
 import org.apache.syncope.common.to.AbstractAttributableTO;
 import org.apache.syncope.common.to.AttributeTO;
 import org.apache.syncope.core.persistence.beans.AbstractAttr;
-import org.apache.syncope.core.persistence.beans.AbstractBaseBean;
 import org.apache.syncope.core.persistence.beans.AbstractDerAttr;
 import org.apache.syncope.core.persistence.beans.AbstractVirAttr;
 import org.slf4j.Logger;
@@ -110,7 +109,7 @@ public class JexlUtil {
                     context.set(fieldName, fieldValue == null
                             ? ""
                             : (field.getType().equals(Date.class)
-                            ? ((AbstractBaseBean) attributable).getDateFormatter().format(fieldValue)
+                            ? DataFormat.format((Date) fieldValue, false)
                             : fieldValue));
 
                     LOG.debug("Add field {} with value {}", fieldName, fieldValue);



Mime
View raw message