You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by er...@apache.org on 2012/02/08 11:38:09 UTC

svn commit: r1241853 - in /james/imap/trunk: api/src/main/java/org/apache/james/imap/api/display/ message/src/main/java/org/apache/james/imap/encode/main/ processor/src/main/java/org/apache/james/imap/processor/

Author: eric
Date: Wed Feb  8 10:38:08 2012
New Revision: 1241853

URL: http://svn.apache.org/viewvc?rev=1241853&view=rev
Log:
Improve human readable messages in GetACLProcessor, contributed by Jochen Gazda (IMAP-355)

Modified:
    james/imap/trunk/api/src/main/java/org/apache/james/imap/api/display/HumanReadableText.java
    james/imap/trunk/message/src/main/java/org/apache/james/imap/encode/main/DefaultLocalizer.java
    james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/GetACLProcessor.java

Modified: james/imap/trunk/api/src/main/java/org/apache/james/imap/api/display/HumanReadableText.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/api/src/main/java/org/apache/james/imap/api/display/HumanReadableText.java?rev=1241853&r1=1241852&r2=1241853&view=diff
==============================================================================
--- james/imap/trunk/api/src/main/java/org/apache/james/imap/api/display/HumanReadableText.java (original)
+++ james/imap/trunk/api/src/main/java/org/apache/james/imap/api/display/HumanReadableText.java Wed Feb  8 10:38:08 2012
@@ -156,6 +156,8 @@ public class HumanReadableText {
     public static final HumanReadableText QRESYNC_CLOSED = new HumanReadableText("org.apache.james.imap.QRESYNC_CLOSED", "");
     public static final HumanReadableText QRESYNC_VANISHED_WITHOUT_CHANGEDSINCE = new HumanReadableText("org.apache.james.imap.QRESYNC_VANISHED_WITHOUT_CHANGEDSINCE", "VANISHED used without CHANGEDSINCE");
 
+    public static final String UNSUFFICIENT_RIGHTS_KEY = "org.apache.james.imap.UNSUFFICIENT_RIGHTS";
+    public static final String UNSUFFICIENT_RIGHTS_DEFAULT_VALUE = "You need the ''{0}'' right to perform command ''{1}'' on mailbox ''{2}''.";
     
     private final String defaultValue;
 

Modified: james/imap/trunk/message/src/main/java/org/apache/james/imap/encode/main/DefaultLocalizer.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/message/src/main/java/org/apache/james/imap/encode/main/DefaultLocalizer.java?rev=1241853&r1=1241852&r2=1241853&view=diff
==============================================================================
--- james/imap/trunk/message/src/main/java/org/apache/james/imap/encode/main/DefaultLocalizer.java (original)
+++ james/imap/trunk/message/src/main/java/org/apache/james/imap/encode/main/DefaultLocalizer.java Wed Feb  8 10:38:08 2012
@@ -19,6 +19,9 @@
 
 package org.apache.james.imap.encode.main;
 
+import java.text.MessageFormat;
+import java.util.Locale;
+
 import org.apache.james.imap.api.display.HumanReadableText;
 import org.apache.james.imap.api.display.Locales;
 import org.apache.james.imap.api.display.Localizer;
@@ -33,11 +36,21 @@ public class DefaultLocalizer implements
      * @see Localizer#localize(HumanReadableText, Locales)
      */
     public String localize(HumanReadableText text, Locales locales) {
-        final String result;
+        
+        String result;
         if (text == null) {
             result = null;
         } else {
+            //FIXME implement the locale selection
+            final Locale chosenLocale = Locale.US;
+            //FIXME implement the localized value lookup depending on chosenLocale
             result = text.getDefaultValue();
+            
+            Object[] params = text.getParameters();
+            if (params != null && params.length > 0) {
+                MessageFormat messageFormat = new MessageFormat(result, chosenLocale);
+                result = messageFormat.format(params);
+            }
         }
         return result;
     }

Modified: james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/GetACLProcessor.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/GetACLProcessor.java?rev=1241853&r1=1241852&r2=1241853&view=diff
==============================================================================
--- james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/GetACLProcessor.java (original)
+++ james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/GetACLProcessor.java Wed Feb  8 10:38:08 2012
@@ -31,7 +31,6 @@ import org.apache.james.imap.api.process
 import org.apache.james.imap.api.process.ImapSession;
 import org.apache.james.imap.message.request.GetACLRequest;
 import org.apache.james.imap.message.response.ACLResponse;
-import org.apache.james.mailbox.InsufficientRightsException;
 import org.apache.james.mailbox.MailboxException;
 import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxNotFoundException;
@@ -40,6 +39,7 @@ import org.apache.james.mailbox.MessageM
 import org.apache.james.mailbox.MessageManager.MetaData;
 import org.apache.james.mailbox.MessageManager.MetaData.FetchGroup;
 import org.apache.james.mailbox.SimpleMailboxACL.Rfc4314Rights;
+import org.slf4j.Logger;
 
 /**
  * GETACL Processor.
@@ -58,8 +58,8 @@ public class GetACLProcessor extends Abs
 
         final MailboxManager mailboxManager = getMailboxManager();
         final MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session);
+        final String mailboxName = message.getMailboxName();
         try {
-            String mailboxName = message.getMailboxName();
 
             MessageManager messageManager = mailboxManager.getMailbox(buildFullPath(session, mailboxName), mailboxSession);
 
@@ -74,27 +74,33 @@ public class GetACLProcessor extends Abs
              * existence information, much less the mailbox’s ACL.
              */
             if (!messageManager.hasRight(Rfc4314Rights.l_Lookup_RIGHT, mailboxSession)) {
-                throw new MailboxNotFoundException(mailboxName);
+                no(command, tag, responder, HumanReadableText.MAILBOX_NOT_FOUND);
             }
-
             /* RFC 4314 section 4. */
-            if (!messageManager.hasRight(Rfc4314Rights.a_Administer_RIGHT, mailboxSession)) {
-                throw new InsufficientRightsException();
+            else if (!messageManager.hasRight(Rfc4314Rights.a_Administer_RIGHT, mailboxSession)) {
+                Object[] params = new Object[] {
+                        Rfc4314Rights.a_Administer_RIGHT.toString(),
+                        command.getName(),
+                        mailboxName
+                };
+                HumanReadableText text = new HumanReadableText(HumanReadableText.UNSUFFICIENT_RIGHTS_KEY, HumanReadableText.UNSUFFICIENT_RIGHTS_DEFAULT_VALUE, params);
+                no(command, tag, responder, text);
+            }
+            else {
+                MetaData metaData = messageManager.getMetaData(false, mailboxSession, FetchGroup.NO_COUNT);
+                ACLResponse aclResponse = new ACLResponse(mailboxName, metaData.getACL());
+                responder.respond(aclResponse);
+                okComplete(command, tag, responder);
+                // FIXME should we send unsolicited responses here?
+                // unsolicitedResponses(session, responder, false);
             }
-
-            MetaData metaData = messageManager.getMetaData(false, mailboxSession, FetchGroup.NO_COUNT);
-            ACLResponse aclResponse = new ACLResponse(mailboxName, metaData.getACL());
-            responder.respond(aclResponse);
-            okComplete(command, tag, responder);
-            // FIXME should we send unsolicited responses here?
-            // unsolicitedResponses(session, responder, false);
         } catch (MailboxNotFoundException e) {
             no(command, tag, responder, HumanReadableText.MAILBOX_NOT_FOUND);
-        } catch (InsufficientRightsException e) {
-            // FIXME: be more specific in the human readable text.
-            no(command, tag, responder, HumanReadableText.GENERIC_FAILURE_DURING_PROCESSING);
         } catch (MailboxException e) {
-            // FIXME: be more specific in the human readable text.
+            Logger log = session.getLog();
+            if (log.isInfoEnabled()) {
+                log.info(command.getName() +" failed for mailbox " + mailboxName, e);
+            }
             no(command, tag, responder, HumanReadableText.GENERIC_FAILURE_DURING_PROCESSING);
         }
 



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