james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject svn commit: r1720567 - /james/project/trunk/protocols/managesieve/src/main/java/org/apache/james/managesieve/core/CoreProcessor.java
Date Thu, 17 Dec 2015 14:53:14 GMT
Author: btellier
Date: Thu Dec 17 14:53:14 2015
New Revision: 1720567

URL: http://svn.apache.org/viewvc?rev=1720567&view=rev
Log:
JAMES-1618 Capabilities should not be recalculated per requests

Modified:
    james/project/trunk/protocols/managesieve/src/main/java/org/apache/james/managesieve/core/CoreProcessor.java

Modified: james/project/trunk/protocols/managesieve/src/main/java/org/apache/james/managesieve/core/CoreProcessor.java
URL: http://svn.apache.org/viewvc/james/project/trunk/protocols/managesieve/src/main/java/org/apache/james/managesieve/core/CoreProcessor.java?rev=1720567&r1=1720566&r2=1720567&view=diff
==============================================================================
--- james/project/trunk/protocols/managesieve/src/main/java/org/apache/james/managesieve/core/CoreProcessor.java
(original)
+++ james/project/trunk/protocols/managesieve/src/main/java/org/apache/james/managesieve/core/CoreProcessor.java
Thu Dec 17 14:53:14 2015
@@ -21,6 +21,7 @@
 package org.apache.james.managesieve.core;
 
 import com.google.common.base.Throwables;
+import com.google.common.collect.Maps;
 import org.apache.commons.io.IOUtils;
 import org.apache.james.managesieve.api.AuthenticationRequiredException;
 import org.apache.james.managesieve.api.ManageSieveRuntimeException;
@@ -53,29 +54,20 @@ public class CoreProcessor implements Co
     private final SieveRepository sieveRepository;
     private final UsersRepository usersRepository;
     private final SieveParser parser;
+    private final Map<Capabilities, String> capabilitiesBase;
 
     public CoreProcessor(SieveRepository repository, UsersRepository usersRepository, SieveParser
parser) {
         this.sieveRepository = repository;
         this.usersRepository = usersRepository;
         this.parser = parser;
+        this.capabilitiesBase = precomputeCapabilitiesBase(parser);
     }
 
     public Map<Capabilities, String> capability(Session session) {
-        Map<Capabilities, String> capabilities = new HashMap<Capabilities, String>();
-        capabilities.put(Capabilities.IMPLEMENTATION, IMPLEMENTATION_DESCRIPTION);
-        capabilities.put(Capabilities.VERSION, MANAGE_SIEVE_VERSION);
-        StringBuilder builder = new StringBuilder();
-        for (String extension : parser.getExtensions()) {
-            builder.append(extension).append(' ');
-        }
-        String extensions = builder.toString().trim();
-        if (!extensions.isEmpty()) {
-            capabilities.put(Capabilities.SIEVE, extensions);
-        }
+        Map<Capabilities, String> capabilities = Maps.newHashMap(capabilitiesBase);
         if (session.isAuthenticated()) {
             capabilities.put(Capabilities.OWNER, session.getUser());
         }
-        capabilities.put(Capabilities.GETACTIVE, null);
         return capabilities;
     }
 
@@ -188,4 +180,24 @@ public class CoreProcessor implements Co
         }
     }
 
+
+    private String buildExtensions(SieveParser parser) {
+        StringBuilder builder = new StringBuilder();
+        for (String extension : parser.getExtensions()) {
+            builder.append(extension).append(' ');
+        }
+        return builder.toString().trim();
+    }
+
+    private Map<Capabilities, String> precomputeCapabilitiesBase(SieveParser parser)
{
+        String extensions = buildExtensions(parser);
+        Map<Capabilities, String> capabilitiesBase = new HashMap<Capabilities, String>();
+        capabilitiesBase.put(Capabilities.IMPLEMENTATION, IMPLEMENTATION_DESCRIPTION);
+        capabilitiesBase.put(Capabilities.VERSION, MANAGE_SIEVE_VERSION);
+        if (!extensions.isEmpty()) {
+            capabilitiesBase.put(Capabilities.SIEVE, extensions);
+        }
+        capabilitiesBase.put(Capabilities.GETACTIVE, null);
+        return capabilitiesBase;
+    }
 }
\ No newline at end of file



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message