KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > james > imapserver > commands > AbstractAclCommand


1 /***********************************************************************
2  * Copyright (c) 2000-2004 The Apache Software Foundation. *
3  * All rights reserved. *
4  * ------------------------------------------------------------------- *
5  * Licensed under the Apache License, Version 2.0 (the "License"); you *
6  * may not use this file except in compliance with the License. You *
7  * may obtain a copy of the License at: *
8  * *
9  * http://www.apache.org/licenses/LICENSE-2.0 *
10  * *
11  * Unless required by applicable law or agreed to in writing, software *
12  * distributed under the License is distributed on an "AS IS" BASIS, *
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or *
14  * implied. See the License for the specific language governing *
15  * permissions and limitations under the License. *
16  ***********************************************************************/

17
18 package org.apache.james.imapserver.commands;
19
20 import org.apache.james.imapserver.AccessControlException;
21 import org.apache.james.imapserver.AuthorizationException;
22 import org.apache.james.util.Assert;
23 import org.apache.james.imapserver.ACLMailbox;
24 import org.apache.james.imapserver.ImapRequest;
25 import org.apache.james.imapserver.ImapSession;
26 import org.apache.james.imapserver.ImapSessionState;
27
28 import java.util.StringTokenizer JavaDoc;
29 import java.util.List JavaDoc;
30
31 abstract class AbstractAclCommand extends AuthenticatedSelectedStateCommand
32 {
33     protected abstract boolean checkUsage( int arguments, ImapSession session );
34         
35     protected abstract void doAclCommand( ImapRequest request, ImapSession session,
36                                           ACLMailbox target, String JavaDoc folder )
37             throws AccessControlException, AuthorizationException;
38
39     protected boolean doProcess( ImapRequest request, ImapSession session, List JavaDoc argValues )
40     {
41         Assert.fail();
42         return false;
43     }
44
45     public boolean process( ImapRequest request, ImapSession session )
46     {
47         int arguments = request.arguments();
48         StringTokenizer JavaDoc commandLine = request.getCommandLine();
49         String JavaDoc command = request.getCommand();
50
51         String JavaDoc folder;
52         ACLMailbox target = null;
53             
54         checkUsage( arguments, session );
55             
56         folder = readAstring( commandLine );
57             
58         target = getMailbox( session, folder, command );
59         if ( target == null ) return true;
60             
61         try {
62             doAclCommand( request, session, target, folder );
63         }
64         catch ( AccessControlException ace ) {
65             session.noResponse( command, "Unknown mailbox" );
66             session.logACE( ace );
67             return true;
68         }
69         catch ( AuthorizationException aze ) {
70             session.taggedResponse( AUTH_FAIL_MSG );
71             session.logAZE( aze );
72             return true;
73         }
74         if ( session.getState() == ImapSessionState.SELECTED ) {
75             session.checkSize();
76             session.checkExpunge();
77         }
78         return true;
79     }
80 }
81
Popular Tags