001: /***
002: * jwma Java WebMail
003: * Copyright (c) 2000-2003 jwma team
004: *
005: * jwma is free software; you can distribute and use this source
006: * under the terms of the BSD-style license received along with
007: * the distribution.
008: ***/package dtw.webmail.util.config;
009:
010: import org.apache.log4j.Logger;
011:
012: import java.util.*;
013: import java.io.Serializable;
014:
015: /**
016: * Class implementing a wrapper for jwma's settings.
017: *
018: * @author Dieter Wimberger
019: * @version 0.9.7 07/02/2003
020: */
021: public class JwmaConfiguration implements Serializable {
022:
023: //logging
024: private static Logger log = Logger
025: .getLogger(JwmaConfiguration.class);
026:
027: //instance attributes
028: private boolean m_POAllowOverride = false;
029: private List m_PostOffices;
030: private MailTransportAgent m_MTA;
031: private Administration m_Administration;
032: private Internationalization m_I18N;
033: private Security m_Security;
034: private boolean m_AutoAccount = true;
035: private String m_DefaultMessageProcessor;
036: private String m_PreferencePersistencePlugin;
037: private String m_ContactManagementPlugin;
038: private String m_RandomAppendPlugin;
039: private String m_DefaultPostOffice;
040:
041: /**
042: * Constructs a new <tt>JwmaConfiguration</tt> instance.
043: */
044: public JwmaConfiguration() {
045: m_PostOffices = Collections.synchronizedList(new ArrayList(5));
046: }//constructor
047:
048: public Security getSecurity() {
049: return m_Security;
050: }//getSecurity
051:
052: public void setSecurity(Security security) {
053: m_Security = security;
054: }//setSecurity
055:
056: /*** Postoffice related **********************************************/
057:
058: public Iterator getPostOffices() {
059: return m_PostOffices.iterator();
060: }//getPostOffices
061:
062: public Collection getPostOfficeCollection() {
063: return m_PostOffices;
064: }//getPostOffices
065:
066: public void setPostOfficeCollection(Collection collection) {
067: m_PostOffices = Collections.synchronizedList(new ArrayList(
068: collection));
069: }//setPostOffices
070:
071: public void addPostOffice(PostOffice po) {
072: if (!existsPostOfficeByName(po.getName())) {
073: m_PostOffices.add(po);
074: }
075: }//addPostOffice
076:
077: public void removePostOffice(PostOffice po) {
078: m_PostOffices.remove(po);
079: }//removePostOffice
080:
081: public boolean existsPostOfficeByName(String name) {
082: for (Iterator iterator = m_PostOffices.iterator(); iterator
083: .hasNext();) {
084: if (((PostOffice) iterator.next()).getName().equals(name)) {
085: return true;
086: }
087: }
088: return false;
089: }//existsPostOfficeByName
090:
091: public PostOffice getPostOfficeByName(String name) {
092: for (Iterator iterator = m_PostOffices.iterator(); iterator
093: .hasNext();) {
094: PostOffice office = (PostOffice) iterator.next();
095: if (office.getName().equals(name)) {
096: return office;
097: }
098: }
099: return null;
100: }//getPostOfficeByName
101:
102: /**
103: * Tests if overriding the system's set postoffice is allowed.
104: *
105: * @return true if overriding is allowed, false otherwise.
106: */
107: public boolean getPostOfficeAllowOverride() {
108: return m_POAllowOverride;
109: }//getPostOfficeAllowOverride
110:
111: /**
112: * Sets the flag that controls if overriding the
113: * system's set postoffice is allowed or not.
114: *
115: * @param b true if the overriding is to be allowed,
116: * false otherwise.
117: */
118: public void setPostOfficeAllowOverride(boolean b) {
119: m_POAllowOverride = b;
120: }//setPostOfficeAllowOverride
121:
122: public PostOffice getDefaultPostOffice() {
123: for (Iterator iterator = m_PostOffices.iterator(); iterator
124: .hasNext();) {
125: PostOffice office = (PostOffice) iterator.next();
126: if (office.isDefault()) {
127: return office;
128: }
129: }
130: return null;
131: }//getDefaultPostOffice
132:
133: public void setDefaultPostOffice(PostOffice ndpo) {
134:
135: PostOffice odpo = getDefaultPostOffice();
136: odpo.setDefault(false);
137: ndpo.setDefault(true);
138: }//setDefaultPostOffice
139:
140: /*** END Postoffice related ******************************************/
141:
142: /*** Mail transport related ******************************************/
143:
144: public MailTransportAgent getMTA() {
145: return m_MTA;
146: }//getMTA
147:
148: public void setMTA(MailTransportAgent mta) {
149: m_MTA = mta;
150: }//setMTA
151:
152: /*** END Mail transport related **************************************/
153:
154: public boolean isSSLSetupRequired() {
155: if (m_MTA.isSecure()) {
156: return true;
157: }
158: for (Iterator iterator = m_PostOffices.iterator(); iterator
159: .hasNext();) {
160: if (((PostOffice) iterator.next()).isSecure()) {
161: return true;
162: }
163: }
164: return false;
165: }//isSSLSetupRequired
166:
167: /*** Admin related ***************************************************/
168:
169: public Administration getAdministration() {
170: return m_Administration;
171: }//getAdministration
172:
173: public void setAdministration(Administration administration) {
174: m_Administration = administration;
175: }//setAdministration
176:
177: /*** End admin related ***********************************************/
178:
179: /*** Account related *************************************************/
180:
181: /**
182: * Tests if creation of accounts is enabled.
183: *
184: * @return true if account creation is enabled, false otherwise.
185: */
186: public boolean isAccountCreationEnabled() {
187: return m_AutoAccount;
188: }//isAccountCreationEnabled
189:
190: /**
191: * Sets the flag that controls if the automatic creation of
192: * jwma accounts is enabled.
193: * This will cause jwma to create user specific data, if
194: * the user can be authenticated against the IMAP server.
195: *
196: * @param b true if account creation is enabled, false otherwise.
197: */
198: public void setAccountCreationEnabled(boolean b) {
199: m_AutoAccount = b;
200: }//setAccountCreationEnabled
201:
202: /*** End Account related *********************************************/
203:
204: /*** Processing related **********************************************/
205:
206: /**
207: * Returns a <tt>String</tt> representing the name of the default
208: * message processor.
209: *
210: * @return the name of the default message processor as
211: * <tt>String</tt>.
212: */
213: public String getDefaultMessageProcessor() {
214: return m_DefaultMessageProcessor;
215: }//getDefaultMessageProcessor
216:
217: /**
218: * Returns a <tt>String</tt> representing the name of the default
219: * message processor.
220: *
221: * @return the name of the default message processor as
222: * <tt>String</tt>.
223: */
224: public void setDefaultMessageProcessor(String name) {
225: m_DefaultMessageProcessor = name;
226: }//setDefaultMessageProcessor
227:
228: /*** END Processing related ******************************************/
229:
230: /*** i18n related ****************************************************/
231:
232: public Internationalization getI18N() {
233: return m_I18N;
234: }//getI18N
235:
236: public void setI18N(Internationalization i18N) {
237: m_I18N = i18N;
238: }//setI18N
239:
240: /*** END i18n related ************************************************/
241:
242: public String getPreferencePersistencePlugin() {
243: return m_PreferencePersistencePlugin;
244: }//getPreferencePersistencePlugin
245:
246: public void setPreferencePersistencePlugin(String classname) {
247: m_PreferencePersistencePlugin = classname;
248: }//setPreferencePersistencePlugin
249:
250: public String getContactManagementPlugin() {
251: return m_ContactManagementPlugin;
252: }//getContactManagementPlugin
253:
254: public void setContactManagementPlugin(String classname) {
255: m_ContactManagementPlugin = classname;
256: }//setContactManagementPlugin
257:
258: public String getRandomAppendPlugin() {
259: return m_RandomAppendPlugin;
260: }//getRandomAppendPlugin
261:
262: public void setRandomAppendPlugin(String classname) {
263: m_RandomAppendPlugin = classname;
264: }//setRandomApendPlugin
265:
266: /**
267: * Defines a name of the static jwma direcory architecture.
268: */
269: public static final String LOG_DIR = "logs";
270: public static final String ETC_DIR = "etc";
271: public static final String DATA_DIR = "data";
272: public static final String I18N_DIR = "i18n";
273: public static final String CONFIG_FILENAME = "configuration.xml";
274: public static final String LOG4J_CONFIG = "log4j.properties";
275: public static final String JTEXTPROC_CONFIG = "textproc.properties";
276: public static final String TEMPLATE_FILENAME = "site_template.xml";
277:
278: }//class JwmaConfiguration
|