001: /*
002: * File : $Source: /usr/local/cvs/opencms/src/org/opencms/mail/CmsMailSettings.java,v $
003: * Date : $Date: 2008-02-27 12:05:41 $
004: * Version: $Revision: 1.12 $
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: import org.opencms.main.CmsLog;
035:
036: import java.util.ArrayList;
037: import java.util.Collections;
038: import java.util.List;
039:
040: import org.apache.commons.logging.Log;
041:
042: /**
043: * Contains the settings for the OpenCms mail service.<p>
044: *
045: * @author Alexander Kandzior
046: *
047: * @version $Revision: 1.12 $
048: *
049: * @since 6.0.0
050: */
051: public class CmsMailSettings {
052:
053: /** The default protocol for sending mail ("smtp"). */
054: public static final String MAIL_DEFAULT_PROTOCOL = "smtp";
055:
056: /** The default mail from address. */
057: public static final String MAIL_DEFAULT_SENDER = "opencms@unconfigured.com";
058:
059: /** The log object for this class. */
060: private static final Log LOG = CmsLog.getLog(CmsMailSettings.class);
061:
062: /** The default mail "from" sender address. */
063: private String m_mailFromDefault;
064:
065: /** The list of internal mail hosts. */
066: private List m_mailHosts;
067:
068: /** The default order if no order is given for a host. */
069: private int m_orderDefault;
070:
071: /**
072: * Empty constructor, required for configuration.<p>
073: */
074: public CmsMailSettings() {
075:
076: m_mailFromDefault = MAIL_DEFAULT_SENDER;
077: m_mailHosts = new ArrayList();
078: if (LOG.isDebugEnabled()) {
079: LOG.debug(Messages.get().getBundle().key(
080: Messages.LOG_EMPTY_CONSTRUCTOR_CALLED_1));
081: }
082: }
083:
084: /**
085: * Adds a new mail host to the internal list of mail hosts.<p>
086: *
087: * @param hostname the name of the mail host
088: * @param order the order in which the host is tried
089: * @param protocol the protocol to use (default "smtp")
090: * @param username the user name to use for authentication
091: * @param password the password to use for authentication
092: */
093: public void addMailHost(String hostname, String order,
094: String protocol, String username, String password) {
095:
096: m_orderDefault += 10;
097: Integer theOrder;
098: try {
099: theOrder = Integer.valueOf(order);
100: if (theOrder.intValue() > m_orderDefault) {
101: m_orderDefault = theOrder.intValue();
102: }
103: } catch (Throwable t) {
104: theOrder = new Integer(m_orderDefault);
105: }
106: CmsMailHost host = new CmsMailHost(hostname, theOrder,
107: protocol, username, password);
108: m_mailHosts.add(host);
109: if (CmsLog.INIT.isInfoEnabled()) {
110: CmsLog.INIT.info(Messages.get().getBundle().key(
111: Messages.LOG_ADD_HOST_1, host));
112: }
113: Collections.sort(m_mailHosts);
114: }
115:
116: /**
117: * Returns the default mail host.<p>
118: *
119: * @return the default mail host
120: */
121: public CmsMailHost getDefaultMailHost() {
122:
123: return (CmsMailHost) m_mailHosts.get(0);
124: }
125:
126: /**
127: * Returns the mail from default sender.<p>
128: *
129: * @return the mail from default sender
130: */
131: public String getMailFromDefault() {
132:
133: return m_mailFromDefault;
134: }
135:
136: /**
137: * Returns an unmodifiable sorted list of all configured mail hosts.<p>
138: *
139: * @return an unmodifiable sorted list of all configured mail hosts
140: */
141: public List getMailHosts() {
142:
143: return Collections.unmodifiableList(m_mailHosts);
144: }
145:
146: /**
147: * Sets the mail from default sender.<p>
148: *
149: * @param sender the mail from default sender to set
150: */
151: public void setMailFromDefault(String sender) {
152:
153: m_mailFromDefault = sender;
154: if (CmsLog.INIT.isInfoEnabled()) {
155: CmsLog.INIT.info(Messages.get().getBundle().key(
156: Messages.LOG_DEFAULT_SENDER_1, m_mailFromDefault));
157: }
158: }
159: }
|