syncope-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ilgro...@apache.org
Subject [1/2] syncope git commit: Better name for console preference cookie
Date Thu, 21 Apr 2016 11:32:47 GMT
Repository: syncope
Updated Branches:
  refs/heads/master 0d745d434 -> c34416301


Better name for console preference cookie


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

Branch: refs/heads/master
Commit: c4be818f00cadc6ffe7eb92197e2c5f81301d9ad
Parents: 0d745d4
Author: Francesco Chicchiriccò <ilgrosso@apache.org>
Authored: Thu Apr 21 13:32:06 2016 +0200
Committer: Francesco Chicchiriccò <ilgrosso@apache.org>
Committed: Thu Apr 21 13:32:06 2016 +0200

----------------------------------------------------------------------
 .../client/console/PreferenceManager.java       | 26 +++++++++-----------
 1 file changed, 12 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/syncope/blob/c4be818f/client/console/src/main/java/org/apache/syncope/client/console/PreferenceManager.java
----------------------------------------------------------------------
diff --git a/client/console/src/main/java/org/apache/syncope/client/console/PreferenceManager.java
b/client/console/src/main/java/org/apache/syncope/client/console/PreferenceManager.java
index 03fab62..125be04 100644
--- a/client/console/src/main/java/org/apache/syncope/client/console/PreferenceManager.java
+++ b/client/console/src/main/java/org/apache/syncope/client/console/PreferenceManager.java
@@ -40,26 +40,24 @@ import org.slf4j.LoggerFactory;
 
 public class PreferenceManager implements Serializable {
 
+    private static final long serialVersionUID = 3581434664555284193L;
+
     private static final Logger LOG = LoggerFactory.getLogger(PreferenceManager.class);
 
-    private static final String PREFMAN_KEY = "prefMan";
+    private static final String COOKIE_NAME = "syncope2ConsolePrefs";
 
     private static final int ONE_YEAR_TIME = 60 * 60 * 24 * 365;
 
+    private static final ObjectMapper MAPPER = new ObjectMapper();
+
     private static final TypeReference<Map<String, String>> MAP_TYPE_REF = new
TypeReference<Map<String, String>>() {
     };
 
     private static final List<Integer> PAGINATOR_CHOICES = Arrays.asList(new Integer[]
{ 10, 25, 50 });
 
-    private static final long serialVersionUID = 1L;
-
-    private final ObjectMapper mapper;
-
     private final transient CookieUtils cookieUtils;
 
     public PreferenceManager() {
-        this.mapper = new ObjectMapper();
-
         CookieDefaults cookieDefaults = new CookieDefaults();
         cookieDefaults.setMaxAge(ONE_YEAR_TIME);
         this.cookieUtils = new CookieUtils(cookieDefaults);
@@ -73,7 +71,7 @@ public class PreferenceManager implements Serializable {
         Map<String, String> prefs;
         try {
             if (StringUtils.isNotBlank(value)) {
-                prefs = mapper.readValue(value, MAP_TYPE_REF);
+                prefs = MAPPER.readValue(value, MAP_TYPE_REF);
             } else {
                 throw new Exception("Invalid cookie value '" + value + "'");
             }
@@ -87,7 +85,7 @@ public class PreferenceManager implements Serializable {
 
     private String setPrefs(final Map<String, String> prefs) throws IOException {
         StringWriter writer = new StringWriter();
-        mapper.writeValue(writer, prefs);
+        MAPPER.writeValue(writer, prefs);
 
         return writer.toString();
     }
@@ -95,7 +93,7 @@ public class PreferenceManager implements Serializable {
     public String get(final Request request, final String key) {
         String result = null;
 
-        String prefString = cookieUtils.load(PREFMAN_KEY);
+        String prefString = cookieUtils.load(COOKIE_NAME);
         if (prefString != null) {
             final Map<String, String> prefs = getPrefs(new String(Base64.decodeBase64(prefString.getBytes())));
             result = prefs.get(key);
@@ -131,7 +129,7 @@ public class PreferenceManager implements Serializable {
     public void set(final Request request, final Response response, final Map<String,
List<String>> prefs) {
         Map<String, String> current = new HashMap<>();
 
-        String prefString = cookieUtils.load(PREFMAN_KEY);
+        String prefString = cookieUtils.load(COOKIE_NAME);
         if (prefString != null) {
             current.putAll(getPrefs(new String(Base64.decodeBase64(prefString.getBytes()))));
         }
@@ -142,14 +140,14 @@ public class PreferenceManager implements Serializable {
         }
 
         try {
-            cookieUtils.save(PREFMAN_KEY, new String(Base64.encodeBase64(setPrefs(current).getBytes())));
+            cookieUtils.save(COOKIE_NAME, new String(Base64.encodeBase64(setPrefs(current).getBytes())));
         } catch (IOException e) {
             LOG.error("Could not save {} info: {}", getClass().getSimpleName(), current,
e);
         }
     }
 
     public void set(final Request request, final Response response, final String key, final
String value) {
-        String prefString = cookieUtils.load(PREFMAN_KEY);
+        String prefString = cookieUtils.load(COOKIE_NAME);
 
         final Map<String, String> current = new HashMap<>();
         if (prefString != null) {
@@ -160,7 +158,7 @@ public class PreferenceManager implements Serializable {
         current.put(key, value);
 
         try {
-            cookieUtils.save(PREFMAN_KEY, new String(Base64.encodeBase64(setPrefs(current).getBytes())));
+            cookieUtils.save(COOKIE_NAME, new String(Base64.encodeBase64(setPrefs(current).getBytes())));
         } catch (IOException e) {
             LOG.error("Could not save {} info: {}", getClass().getSimpleName(), current,
e);
         }


Mime
View raw message