001: // The contents of this file are subject to the Mozilla Public License Version
002: // 1.1
003: //(the "License"); you may not use this file except in compliance with the
004: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
005: //
006: //Software distributed under the License is distributed on an "AS IS" basis,
007: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
008: //for the specific language governing rights and
009: //limitations under the License.
010: //
011: //The Original Code is "The Columba Project"
012: //
013: //The Initial Developers of the Original Code are Frederik Dietz and Timo
014: // Stich.
015: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
016: //
017: //All Rights Reserved.
018: package org.columba.mail.config;
019:
020: import java.io.File;
021:
022: import org.columba.core.config.Config;
023: import org.columba.core.config.DefaultXmlConfig;
024: import org.columba.core.io.DiskIO;
025: import org.columba.core.xml.XmlElement;
026:
027: /**
028: * Configuration storage.
029: *
030: * @see org.columba.config.ConfigPersistence
031: *
032: * @author fdietz
033: */
034: public class MailConfig {
035:
036: public static final String MODULE_NAME = "mail";
037:
038: protected Config config;
039:
040: protected File path;
041:
042: protected File accountFile;
043:
044: protected File folderFile;
045:
046: protected File mainFrameOptionsFile;
047:
048: protected File pop3Directory;
049:
050: protected File popManageOptionsFile;
051:
052: protected File composerOptionsFile;
053:
054: private static MailConfig instance = new MailConfig(Config
055: .getInstance());
056:
057: private OptionsItem optionsItem;
058: private ComposerItem composerItem;
059:
060: /**
061: * @see java.lang.Object#Object()
062: */
063: public MailConfig(Config config) {
064: this .config = config;
065: path = new File(config.getConfigDirectory(), MODULE_NAME);
066: DiskIO.ensureDirectory(path);
067:
068: pop3Directory = new File(path, "pop3server");
069: DiskIO.ensureDirectory(pop3Directory);
070:
071: accountFile = new File(path, "account.xml");
072: registerPlugin(accountFile.getName(), new AccountXmlConfig(
073: accountFile));
074:
075: folderFile = new File(path, "tree.xml");
076: registerPlugin(folderFile.getName(), new FolderXmlConfig(
077: folderFile));
078:
079: mainFrameOptionsFile = new File(path, "options.xml");
080: registerPlugin(mainFrameOptionsFile.getName(),
081: new MainFrameOptionsXmlConfig(mainFrameOptionsFile));
082:
083: File mainToolBarFile = new File(path, "main_toolbar.xml");
084: registerPlugin(mainToolBarFile.getName(), new DefaultXmlConfig(
085: mainToolBarFile));
086:
087: File composerToolBarFile = new File(path,
088: "composer_toolbar.xml");
089: registerPlugin(composerToolBarFile.getName(),
090: new DefaultXmlConfig(composerToolBarFile));
091:
092: File messageframeToolBarFile = new File(path,
093: "messageframe_toolbar.xml");
094: registerPlugin(messageframeToolBarFile.getName(),
095: new DefaultXmlConfig(messageframeToolBarFile));
096:
097: composerOptionsFile = new File(path, "composer_options.xml");
098: registerPlugin(composerOptionsFile.getName(),
099: new ComposerOptionsXmlConfig(composerOptionsFile));
100:
101: }
102:
103: public File getConfigDirectory() {
104: return path;
105: }
106:
107: /**
108: * Returns the POP3 directory.
109: */
110: public File getPOP3Directory() {
111: return pop3Directory;
112: }
113:
114: /**
115: * Method registerPlugin.
116: *
117: * @param id
118: * @param plugin
119: */
120: protected void registerPlugin(String id, DefaultXmlConfig plugin) {
121: config.registerPlugin(MODULE_NAME, id, plugin);
122: }
123:
124: /**
125: * Method getPlugin.
126: *
127: * @param id
128: * @return DefaultXmlConfig
129: */
130: protected DefaultXmlConfig getPlugin(String id) {
131: return config.getPlugin(MODULE_NAME, id);
132: }
133:
134: /**
135: * Method getAccountList.
136: *
137: * @return AccountList
138: */
139: public AccountList getAccountList() {
140: return ((AccountXmlConfig) getPlugin(accountFile.getName()))
141: .getAccountList();
142: }
143:
144: public XmlElement get(String name) {
145: DefaultXmlConfig xml = getPlugin(name + ".xml");
146:
147: return xml.getRoot();
148: }
149:
150: /**
151: * Method getFolderConfig.
152: *
153: * @return FolderXmlConfig
154: */
155: public FolderXmlConfig getFolderConfig() {
156:
157: return (FolderXmlConfig) getPlugin(folderFile.getName());
158: }
159:
160: /**
161: * Method getMainFrameOptionsConfig.
162: *
163: * @return MainFrameOptionsXmlConfig
164: */
165: public MainFrameOptionsXmlConfig getMainFrameOptionsConfig() {
166:
167: return (MainFrameOptionsXmlConfig) getPlugin(mainFrameOptionsFile
168: .getName());
169: }
170:
171: public OptionsItem getOptionsItem() {
172: if (optionsItem == null) {
173: XmlElement xmlElement = getPlugin(
174: mainFrameOptionsFile.getName()).getRoot()
175: .getElement("options");
176: optionsItem = new OptionsItem(xmlElement);
177: }
178:
179: return optionsItem;
180: }
181:
182: public ComposerItem getComposerItem() {
183: if (composerItem == null) {
184: XmlElement xmlElement = getPlugin(
185: composerOptionsFile.getName()).getRoot()
186: .getElement("options");
187: composerItem = new ComposerItem(xmlElement);
188: }
189:
190: return composerItem;
191: }
192:
193: /**
194: * Method getComposerOptionsConfig.
195: *
196: * @return ComposerOptionsXmlConfig
197: */
198: public ComposerOptionsXmlConfig getComposerOptionsConfig() {
199:
200: return (ComposerOptionsXmlConfig) getPlugin(composerOptionsFile
201: .getName());
202: }
203:
204: /**
205: * @return Returns the instance.
206: */
207: public static MailConfig getInstance() {
208: return instance;
209: }
210: }
|