KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > james > transport > mailets > AvalonListservManager


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.transport.mailets;
19
20 import org.apache.avalon.framework.component.ComponentException;
21 import org.apache.avalon.framework.component.ComponentManager;
22 import org.apache.james.Constants;
23 import org.apache.james.services.UsersRepository;
24 import org.apache.james.services.UsersStore;
25 import org.apache.mailet.MailAddress;
26
27 /**
28  * Adds or removes an email address to a listserv.
29  *
30  * <p>Sample configuration:
31  * <br>&lt;mailet match="CommandForListserv=james@list.working-dogs.com" class="AvalonListservManager"&gt;
32  * <br>&lt;repositoryName&gt;name of user repository configured in UsersStore block &lt;/repositoryName&gt;
33  * <br>&lt;/mailet&gt;
34  *
35  * @version This is $Revision: 1.6.4.3 $
36  */

37 public class AvalonListservManager extends GenericListservManager {
38
39     private UsersRepository members;
40
41     /**
42      * Initialize the mailet
43      */

44     public void init() {
45         ComponentManager compMgr = (ComponentManager)getMailetContext().getAttribute(Constants.AVALON_COMPONENT_MANAGER);
46         try {
47             UsersStore usersStore = (UsersStore) compMgr.lookup("org.apache.james.services.UsersStore");
48             String JavaDoc repName = getInitParameter("repositoryName");
49
50             members = (UsersRepository) usersStore.getRepository(repName);
51         } catch (ComponentException cnfe) {
52             log("Failed to retrieve Store component:" + cnfe.getMessage());
53         } catch (Exception JavaDoc e) {
54             log("Failed to retrieve Store component:" + e.getMessage());
55         }
56     }
57
58     /**
59      * Add an address to the list.
60      *
61      * @param address the address to add
62      *
63      * @return true if successful, false otherwise
64      */

65     public boolean addAddress(MailAddress address) {
66         members.addUser(address.toString(), "");
67         return true;
68     }
69
70     /**
71      * Remove an address from the list.
72      *
73      * @param address the address to remove
74      *
75      * @return true if successful, false otherwise
76      */

77     public boolean removeAddress(MailAddress address) {
78         members.removeUser(address.toString());
79         return true;
80     }
81
82     public boolean existsAddress(MailAddress address) {
83         return members.contains(address.toString());
84     }
85
86     /**
87      * Return a string describing this mailet.
88      *
89      * @return a string describing this mailet
90      */

91     public String JavaDoc getMailetInfo() {
92         return "AvalonListservManager Mailet";
93     }
94 }
95
96
Popular Tags