You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by il...@apache.org on 2016/02/02 11:50:18 UTC
syncope git commit: Replacing SimpleDateFormat with FastDateFormat
everywhere possible
Repository: syncope
Updated Branches:
refs/heads/master 16ffd3ef9 -> 22599aac5
Replacing SimpleDateFormat with FastDateFormat everywhere possible
Project: http://git-wip-us.apache.org/repos/asf/syncope/repo
Commit: http://git-wip-us.apache.org/repos/asf/syncope/commit/22599aac
Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/22599aac
Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/22599aac
Branch: refs/heads/master
Commit: 22599aac548a3bf54f32812420f4f84c6725855c
Parents: 16ffd3e
Author: Francesco Chicchiriccò <il...@apache.org>
Authored: Tue Feb 2 11:50:12 2016 +0100
Committer: Francesco Chicchiriccò <il...@apache.org>
Committed: Tue Feb 2 11:50:12 2016 +0100
----------------------------------------------------------------------
.../markup/html/form/AjaxDateFieldPanel.java | 59 +++++++++-----------
.../rest/api/DateParamConverterProvider.java | 16 ++----
.../src/main/webapp/cacheStats.jsp | 10 ++--
.../org/apache/syncope/fit/core/UserITCase.java | 15 ++---
4 files changed, 39 insertions(+), 61 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/syncope/blob/22599aac/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/form/AjaxDateFieldPanel.java
----------------------------------------------------------------------
diff --git a/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/form/AjaxDateFieldPanel.java b/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/form/AjaxDateFieldPanel.java
index b81a1ba..0cb5118 100644
--- a/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/form/AjaxDateFieldPanel.java
+++ b/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/form/AjaxDateFieldPanel.java
@@ -27,11 +27,11 @@ import de.agilecoders.wicket.extensions.markup.html.bootstrap.icon.FontAwesomeIc
import java.io.Serializable;
import java.text.DateFormat;
import java.text.ParseException;
-import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Locale;
+import org.apache.commons.lang3.time.FastDateFormat;
import org.apache.syncope.client.console.SyncopeConsoleSession;
import org.apache.syncope.common.lib.SyncopeConstants;
import org.apache.wicket.markup.html.list.ListItem;
@@ -53,46 +53,37 @@ public class AjaxDateFieldPanel extends FieldPanel<Date> {
this.datePattern = pattern == null ? SyncopeConstants.DEFAULT_DATE_PATTERN : pattern;
if (this.datePattern.contains("H")) {
- field = new DatetimePicker("date", model, new DatetimePickerConfig()
- .withFormat(this.datePattern.replaceAll("'", ""))
- .setShowToday(true)
- .useSideBySide(true)
- .with(new DatetimePickerIconConfig()
+ field = new DatetimePicker("date", model, new DatetimePickerConfig().
+ withFormat(this.datePattern.replaceAll("'", "")).
+ setShowToday(true).
+ useSideBySide(true).
+ with(new DatetimePickerIconConfig()
.useDateIcon(FontAwesomeIconType.calendar)
.useTimeIcon(FontAwesomeIconType.clock_o)
.useUpIcon(FontAwesomeIconType.arrow_up)
.useDownIcon(FontAwesomeIconType.arrow_down)
)) {
- private static final long serialVersionUID = 1L;
+ private static final long serialVersionUID = -6308790460702853262L;
- // T0DO: trying to resolve issue 730.
- @Override
- @SuppressWarnings("unchecked")
- public <C> IConverter<C> getConverter(final Class<C> type) {
- return (IConverter<C>) new DateConverter() {
-
- private static final long serialVersionUID = 1L;
-
- @Override
- public DateFormat getDateFormat(final Locale locale) {
- return new SimpleDateFormat(
- datePattern,
- locale == null ? SyncopeConsoleSession.get().getLocale() : locale) {
+ // T0DO: trying to fix SYNCOPE-730
+ // Check if SimpleDateFormat can be replaced by FastDateFormat (see usage below)
+ @Override
+ @SuppressWarnings("unchecked")
+ public <C> IConverter<C> getConverter(final Class<C> type) {
+ return (IConverter<C>) new DateConverter() {
- private static final long serialVersionUID = 1L;
+ private static final long serialVersionUID = 8025900377461981157L;
- @Override
- public Date parse(final String text, final ParsePosition pos) {
- return super.parse(text, pos);
- }
-
- };
- }
- };
+ @Override
+ public DateFormat getDateFormat(final Locale locale) {
+ return new SimpleDateFormat(
+ datePattern,
+ locale == null ? SyncopeConsoleSession.get().getLocale() : locale);
}
-
};
+ }
+ };
} else {
field = new DateTextField("date", model, new DateTextFieldConfig()
.withFormat(this.datePattern)
@@ -154,9 +145,11 @@ public class AjaxDateFieldPanel 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());
+ final FastDateFormat formatter = datePattern == null
+ ? FastDateFormat.getInstance(
+ SyncopeConstants.DEFAULT_DATE_PATTERN, SyncopeConsoleSession.get().getLocale())
+ : FastDateFormat.getInstance(
+ datePattern, SyncopeConsoleSession.get().getLocale());
IModel<Date> model = new Model<Date>() {
http://git-wip-us.apache.org/repos/asf/syncope/blob/22599aac/common/rest-api/src/main/java/org/apache/syncope/common/rest/api/DateParamConverterProvider.java
----------------------------------------------------------------------
diff --git a/common/rest-api/src/main/java/org/apache/syncope/common/rest/api/DateParamConverterProvider.java b/common/rest-api/src/main/java/org/apache/syncope/common/rest/api/DateParamConverterProvider.java
index b7e3c52..1a826fd 100644
--- a/common/rest-api/src/main/java/org/apache/syncope/common/rest/api/DateParamConverterProvider.java
+++ b/common/rest-api/src/main/java/org/apache/syncope/common/rest/api/DateParamConverterProvider.java
@@ -21,30 +21,22 @@ package org.apache.syncope.common.rest.api;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.text.ParseException;
-import java.text.SimpleDateFormat;
import java.util.Date;
import javax.ws.rs.ext.ParamConverter;
import javax.ws.rs.ext.ParamConverterProvider;
+import org.apache.commons.lang3.time.FastDateFormat;
import org.apache.syncope.common.lib.SyncopeConstants;
public class DateParamConverterProvider implements ParamConverterProvider {
- 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 FastDateFormat DATE_FORMAT = FastDateFormat.getInstance(SyncopeConstants.DEFAULT_DATE_PATTERN);
private static class DateParamConverter implements ParamConverter<Date> {
@Override
public Date fromString(final String value) {
try {
- return DATE_FORMAT.get().parse(value);
+ return DATE_FORMAT.parse(value);
} catch (final ParseException e) {
throw new IllegalArgumentException("Unparsable date: " + value, e);
}
@@ -52,7 +44,7 @@ public class DateParamConverterProvider implements ParamConverterProvider {
@Override
public String toString(final Date value) {
- return DATE_FORMAT.get().format(value);
+ return DATE_FORMAT.format(value);
}
}
http://git-wip-us.apache.org/repos/asf/syncope/blob/22599aac/fit/core-reference/src/main/webapp/cacheStats.jsp
----------------------------------------------------------------------
diff --git a/fit/core-reference/src/main/webapp/cacheStats.jsp b/fit/core-reference/src/main/webapp/cacheStats.jsp
index ba380c5..16063db 100644
--- a/fit/core-reference/src/main/webapp/cacheStats.jsp
+++ b/fit/core-reference/src/main/webapp/cacheStats.jsp
@@ -16,13 +16,13 @@ KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
--%>
-<%@page import="org.springframework.beans.factory.support.DefaultListableBeanFactory"%>
-<%@page import="org.apache.syncope.common.lib.SyncopeConstants"%>
-<%@page import="org.apache.syncope.core.misc.spring.ApplicationContextProvider"%>
<%@page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
-<%@page import="java.text.SimpleDateFormat"%>
+<%@page import="org.springframework.beans.factory.support.DefaultListableBeanFactory"%>
+<%@page import="org.apache.syncope.common.lib.SyncopeConstants"%>
+<%@page import="org.apache.syncope.core.misc.spring.ApplicationContextProvider"%>
+<%@page import="org.apache.commons.lang3.time.FastDateFormat"%>
<%@page import="java.util.Date"%>
<%@page import="org.apache.openjpa.datacache.CacheStatisticsImpl"%>
<%@page import="javax.persistence.EntityManagerFactory"%>
@@ -98,7 +98,7 @@ under the License.
info.append("Statistics cleared\n");
}
- SimpleDateFormat sdf = new SimpleDateFormat(SyncopeConstants.DEFAULT_DATE_PATTERN);
+ FastDateFormat sdf = FastDateFormat.getInstance(SyncopeConstants.DEFAULT_DATE_PATTERN);
if (info.length() > 0) {
%>
<p/><div class="success">
http://git-wip-us.apache.org/repos/asf/syncope/blob/22599aac/fit/core-reference/src/test/java/org/apache/syncope/fit/core/UserITCase.java
----------------------------------------------------------------------
diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/UserITCase.java b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/UserITCase.java
index 00de99b..bdd0fbf 100644
--- a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/UserITCase.java
+++ b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/UserITCase.java
@@ -30,7 +30,6 @@ import static org.junit.Assert.fail;
import java.io.IOException;
import java.security.AccessControlException;
-import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
@@ -44,6 +43,8 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.collections4.Transformer;
+import org.apache.commons.lang3.time.DateFormatUtils;
+import org.apache.commons.lang3.time.FastDateFormat;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.cxf.common.util.Base64Utility;
import org.apache.cxf.helpers.IOUtils;
@@ -111,15 +112,7 @@ import org.springframework.jdbc.core.JdbcTemplate;
@FixMethodOrder(MethodSorters.JVM)
public class UserITCase extends AbstractITCase {
- private static final ThreadLocal<SimpleDateFormat> DATE_FORMAT = new ThreadLocal<SimpleDateFormat>() {
-
- @Override
- protected SimpleDateFormat initialValue() {
- SimpleDateFormat sdf = new SimpleDateFormat();
- sdf.applyPattern("yyyy-MM-dd");
- return sdf;
- }
- };
+ private static final FastDateFormat DATE_FORMAT = DateFormatUtils.ISO_DATE_FORMAT;
private boolean getBooleanAttribute(final ConnObjectTO connObjectTO, final String attrName) {
return Boolean.parseBoolean(connObjectTO.getPlainAttrMap().get(attrName).getValues().get(0));
@@ -141,7 +134,7 @@ public class UserITCase extends AbstractITCase {
userTO.getPlainAttrs().add(attrTO("type", "a type"));
userTO.getPlainAttrs().add(attrTO("userId", email));
userTO.getPlainAttrs().add(attrTO("email", email));
- userTO.getPlainAttrs().add(attrTO("loginDate", DATE_FORMAT.get().format(new Date())));
+ userTO.getPlainAttrs().add(attrTO("loginDate", DATE_FORMAT.format(new Date())));
userTO.getDerAttrs().add(attrTO("cn", null));
return userTO;
}