KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > mail > CmsMailSettings


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/mail/CmsMailSettings.java,v $
3  * Date : $Date: 2006/03/27 14:52:27 $
4  * Version: $Revision: 1.10 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31
32 package org.opencms.mail;
33
34 import org.opencms.main.CmsLog;
35
36 import java.util.ArrayList JavaDoc;
37 import java.util.Collections JavaDoc;
38 import java.util.List JavaDoc;
39
40 import org.apache.commons.logging.Log;
41
42 /**
43  * Contains the settings for the OpenCms mail service.<p>
44  *
45  * @author Alexander Kandzior
46  *
47  * @version $Revision: 1.10 $
48  *
49  * @since 6.0.0
50  */

51 public class CmsMailSettings {
52
53     /** The default protocol for sending mail ("smtp"). */
54     public static final String JavaDoc MAIL_DEFAULT_PROTOCOL = "smtp";
55
56     /** The default mail from address. */
57     public static final String JavaDoc MAIL_DEFAULT_SENDER = "opencms@unconfigured.com";
58
59     /** The log object for this class. */
60     private static final Log LOG = CmsLog.getLog(CmsMailSettings.class);
61
62     /** The default mail "from" sender address. */
63     private String JavaDoc m_mailFromDefault;
64
65     /** The list of internal mail hosts. */
66     private List JavaDoc m_mailHosts;
67
68     /** The default order if no order is given for a host. */
69     private int m_orderDefault;
70
71     /**
72      * Empty constructor, required for configuration.<p>
73      */

74     public CmsMailSettings() {
75
76         m_mailFromDefault = MAIL_DEFAULT_SENDER;
77         m_mailHosts = new ArrayList JavaDoc();
78         if (LOG.isDebugEnabled()) {
79             LOG.debug(Messages.get().getBundle().key(Messages.LOG_EMPTY_CONSTRUCTOR_CALLED_1));
80         }
81     }
82
83     /**
84      * Adds a new mail host to the internal list of mail hosts.<p>
85      *
86      * @param hostname the name of the mail host
87      * @param order the order in which the host is tried
88      * @param protocol the protocol to use (default "smtp")
89      * @param username the user name to use for authentication
90      * @param password the password to use for authentication
91      */

92     public void addMailHost(String JavaDoc hostname, String JavaDoc order, String JavaDoc protocol, String JavaDoc username, String JavaDoc password) {
93
94         m_orderDefault += 10;
95         Integer JavaDoc theOrder;
96         try {
97             theOrder = Integer.valueOf(order);
98             if (theOrder.intValue() > m_orderDefault) {
99                 m_orderDefault = theOrder.intValue();
100             }
101         } catch (Throwable JavaDoc t) {
102             theOrder = new Integer JavaDoc(m_orderDefault);
103         }
104         CmsMailHost host = new CmsMailHost(hostname, theOrder, protocol, username, password);
105         m_mailHosts.add(host);
106         if (CmsLog.INIT.isInfoEnabled()) {
107             CmsLog.INIT.info(Messages.get().getBundle().key(Messages.LOG_ADD_HOST_1, host));
108         }
109         Collections.sort(m_mailHosts);
110     }
111
112     /**
113      * Returns the default mail host.<p>
114      *
115      * @return the default mail host
116      */

117     public CmsMailHost getDefaultMailHost() {
118
119         return (CmsMailHost)m_mailHosts.get(0);
120     }
121
122     /**
123      * Returns the mail from default sender.<p>
124      *
125      * @return the mail from default sender
126      */

127     public String JavaDoc getMailFromDefault() {
128
129         return m_mailFromDefault;
130     }
131
132     /**
133      * Returns an unmodifiable sorted list of all configured mail hosts.<p>
134      *
135      * @return an unmodifiable sorted list of all configured mail hosts
136      */

137     public List JavaDoc getMailHosts() {
138
139         return Collections.unmodifiableList(m_mailHosts);
140     }
141
142     /**
143      * Sets the mail from default sender.<p>
144      *
145      * @param sender the mail from default sender to set
146      */

147     public void setMailFromDefault(String JavaDoc sender) {
148
149         m_mailFromDefault = sender;
150         if (CmsLog.INIT.isInfoEnabled()) {
151             CmsLog.INIT.info(Messages.get().getBundle().key(Messages.LOG_DEFAULT_SENDER_1, m_mailFromDefault));
152         }
153     }
154 }
155
Popular Tags