001: /*
002: * File : $Source: /usr/local/cvs/opencms/src/org/opencms/mail/CmsMailHost.java,v $
003: * Date : $Date: 2008-02-27 12:05:41 $
004: * Version: $Revision: 1.10 $
005: *
006: * This library is part of OpenCms -
007: * the Open Source Content Management System
008: *
009: * Copyright (c) 2002 - 2008 Alkacon Software GmbH (http://www.alkacon.com)
010: *
011: * This library is free software; you can redistribute it and/or
012: * modify it under the terms of the GNU Lesser General Public
013: * License as published by the Free Software Foundation; either
014: * version 2.1 of the License, or (at your option) any later version.
015: *
016: * This library is distributed in the hope that it will be useful,
017: * but WITHOUT ANY WARRANTY; without even the implied warranty of
018: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019: * Lesser General Public License for more details.
020: *
021: * For further information about Alkacon Software GmbH, please see the
022: * company website: http://www.alkacon.com
023: *
024: * For further information about OpenCms, please see the
025: * project website: http://www.opencms.org
026: *
027: * You should have received a copy of the GNU Lesser General Public
028: * License along with this library; if not, write to the Free Software
029: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
030: */
031:
032: package org.opencms.mail;
033:
034: /**
035: * Contains the configuration of an individual mail host.<p>
036: *
037: * @author Andreas Zahner
038: *
039: * @version $Revision: 1.10 $
040: *
041: * @since 6.0.0
042: */
043: public class CmsMailHost implements Comparable {
044:
045: /** The name of the mail host. */
046: private String m_hostname;
047:
048: /** The order of this mail host. */
049: private Integer m_order;
050:
051: /** The password to use for authentication. */
052: private String m_password;
053:
054: /** The protocol to use. */
055: private String m_protocol;
056:
057: /** The user name to use for authentication. */
058: private String m_username;
059:
060: /**
061: * Creates a new mail host.<p>
062: *
063: * @param hostname the name of the mail host
064: * @param order the order in which the host is tried
065: * @param protocol the protocol to use (default "smtp")
066: * @param username the user name to use for authentication
067: * @param password the password to use for authentication
068: */
069: public CmsMailHost(String hostname, Integer order, String protocol,
070: String username, String password) {
071:
072: m_hostname = hostname;
073: m_protocol = (protocol != null) ? protocol
074: : CmsMailSettings.MAIL_DEFAULT_PROTOCOL;
075: m_username = username;
076: m_password = password;
077: m_order = order;
078: }
079:
080: /**
081: * @see java.lang.Comparable#compareTo(java.lang.Object)
082: */
083: public int compareTo(Object obj) {
084:
085: if (obj == this ) {
086: return 0;
087: }
088: if (obj instanceof CmsMailHost) {
089: return m_order.compareTo(((CmsMailHost) obj).m_order);
090: }
091: return 0;
092: }
093:
094: /**
095: * @see java.lang.Object#equals(java.lang.Object)
096: */
097: public boolean equals(Object obj) {
098:
099: if (obj == this ) {
100: return true;
101: }
102: if (obj instanceof CmsMailHost) {
103: CmsMailHost other = (CmsMailHost) obj;
104: return m_hostname.equals(other.m_hostname)
105: && m_protocol.equals(other.m_protocol)
106: && m_username.equals(other.m_username);
107: }
108: return false;
109: }
110:
111: /**
112: * Returns the host name.<p>
113: *
114: * @return the host name
115: */
116: public String getHostname() {
117:
118: return m_hostname;
119: }
120:
121: /**
122: * Returns the order of this mail host.<p>
123: *
124: * @return the order of this mail host
125: */
126: public Integer getOrder() {
127:
128: return m_order;
129: }
130:
131: /**
132: * Returns the password used for authentication.<p>
133: *
134: * @return the password used for authentication
135: */
136: public String getPassword() {
137:
138: return m_password;
139: }
140:
141: /**
142: * Returns the protocol used for mail sending, default is "smtp".<p>
143: *
144: * @return the protocol used for mail sending
145: */
146: public String getProtocol() {
147:
148: return m_protocol;
149: }
150:
151: /**
152: * Returns the user name used for authentication.<p>
153: *
154: * @return the user name used for authentication
155: */
156: public String getUsername() {
157:
158: return m_username;
159: }
160:
161: /**
162: * @see java.lang.Object#hashCode()
163: */
164: public int hashCode() {
165:
166: return m_hostname.hashCode() * 1117 + m_protocol.hashCode()
167: * 2003 + m_username.hashCode();
168: }
169:
170: /**
171: * Returns <code>true</code> only if authentication is enabled,
172: * the default is <code>false</code>.<p>
173: *
174: * Authentication is enabled only if both "username" and "password"
175: * are not <code>null</code>.<p>
176: *
177: * @return <code>true</code> only if authentication is enabled
178: */
179: public boolean isAuthenticating() {
180:
181: return (m_username != null) && (m_password != null);
182: }
183:
184: /**
185: * @see java.lang.Object#toString()
186: */
187: public String toString() {
188:
189: StringBuffer buf = new StringBuffer(64);
190: buf.append(this .getClass().getName());
191: buf.append(" hostname=");
192: buf.append(getHostname());
193: buf.append(" order=");
194: buf.append(m_order);
195: buf.append(" protocol=");
196: buf.append(getProtocol());
197: if (isAuthenticating()) {
198: buf.append(" user=");
199: buf.append(getUsername());
200: buf.append(" password=");
201: buf.append(getPassword());
202: }
203: return buf.toString();
204: }
205: }
|