KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/mail/CmsMailHost.java,v $
3  * Date : $Date: 2005/06/27 23:22:25 $
4  * Version: $Revision: 1.7 $
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 /**
35  * Contains the configuration of an individual mail host.<p>
36  *
37  * @author Andreas Zahner
38  *
39  * @version $Revision: 1.7 $
40  *
41  * @since 6.0.0
42  */

43 public class CmsMailHost implements Comparable JavaDoc {
44
45     /** The name of the mail host. */
46     private String JavaDoc m_hostname;
47
48     /** The order of this mail host. */
49     private Integer JavaDoc m_order;
50
51     /** The password to use for authentication. */
52     private String JavaDoc m_password;
53
54     /** The protocol to use. */
55     private String JavaDoc m_protocol;
56
57     /** The user name to use for authentication. */
58     private String JavaDoc m_username;
59
60     /**
61      * Creates a new mail host.<p>
62      *
63      * @param hostname the name of the mail host
64      * @param order the order in which the host is tried
65      * @param protocol the protocol to use (default "smtp")
66      * @param username the user name to use for authentication
67      * @param password the password to use for authentication
68      */

69     public CmsMailHost(String JavaDoc hostname, Integer JavaDoc order, String JavaDoc protocol, String JavaDoc username, String JavaDoc password) {
70
71         m_hostname = hostname;
72         m_protocol = (protocol != null) ? protocol : CmsMailSettings.MAIL_DEFAULT_PROTOCOL;
73         m_username = username;
74         m_password = password;
75         m_order = order;
76     }
77
78     /**
79      * @see java.lang.Comparable#compareTo(java.lang.Object)
80      */

81     public int compareTo(Object JavaDoc obj) {
82
83         if (obj == this) {
84             return 0;
85         }
86         if (obj instanceof CmsMailHost) {
87             return m_order.compareTo(((CmsMailHost)obj).m_order);
88         }
89         return 0;
90     }
91
92     /**
93      * Returns the host name.<p>
94      *
95      * @return the host name
96      */

97     public String JavaDoc getHostname() {
98
99         return m_hostname;
100     }
101
102     /**
103      * Returns the order of this mail host.<p>
104      *
105      * @return the order of this mail host
106      */

107     public Integer JavaDoc getOrder() {
108
109         return m_order;
110     }
111
112     /**
113      * Returns the password used for authentication.<p>
114      *
115      * @return the password used for authentication
116      */

117     public String JavaDoc getPassword() {
118
119         return m_password;
120     }
121
122     /**
123      * Returns the protocol used for mail sending, default is "smtp".<p>
124      *
125      * @return the protocol used for mail sending
126      */

127     public String JavaDoc getProtocol() {
128
129         return m_protocol;
130     }
131
132     /**
133      * Returns the user name used for authentication.<p>
134      *
135      * @return the user name used for authentication
136      */

137     public String JavaDoc getUsername() {
138
139         return m_username;
140     }
141
142     /**
143      * Returns <code>true</code> only if authentication is enabled,
144      * the default is <code>false</code>.<p>
145      *
146      * Authentication is enabled only if both "username" and "password"
147      * are not <code>null</code>.<p>
148      *
149      * @return <code>true</code> only if authentication is enabled
150      */

151     public boolean isAuthenticating() {
152
153         return (m_username != null) && (m_password != null);
154     }
155
156     /**
157      * @see java.lang.Object#toString()
158      */

159     public String JavaDoc toString() {
160
161         StringBuffer JavaDoc buf = new StringBuffer JavaDoc(64);
162         buf.append(this.getClass().getName());
163         buf.append(" hostname=");
164         buf.append(getHostname());
165         buf.append(" order=");
166         buf.append(m_order);
167         buf.append(" protocol=");
168         buf.append(getProtocol());
169         if (isAuthenticating()) {
170             buf.append(" user=");
171             buf.append(getUsername());
172             buf.append(" password=");
173             buf.append(getPassword());
174         }
175         return buf.toString();
176     }
177 }
Popular Tags