KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > mail > config > MailConfig


1 // The contents of this file are subject to the Mozilla Public License Version
2
// 1.1
3
//(the "License"); you may not use this file except in compliance with the
4
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
5
//
6
//Software distributed under the License is distributed on an "AS IS" basis,
7
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
8
//for the specific language governing rights and
9
//limitations under the License.
10
//
11
//The Original Code is "The Columba Project"
12
//
13
//The Initial Developers of the Original Code are Frederik Dietz and Timo
14
// Stich.
15
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
16
//
17
//All Rights Reserved.
18
package org.columba.mail.config;
19
20 import java.io.File JavaDoc;
21
22 import org.columba.core.config.Config;
23 import org.columba.core.config.DefaultXmlConfig;
24 import org.columba.core.io.DiskIO;
25 import org.columba.core.xml.XmlElement;
26
27 /**
28  * Configuration storage.
29  *
30  * @see org.columba.config.ConfigPersistence
31  *
32  * @author fdietz
33  */

34 public class MailConfig {
35
36     public static final String JavaDoc MODULE_NAME = "mail";
37
38     protected Config config;
39
40     protected File JavaDoc path;
41
42     protected File JavaDoc accountFile;
43
44     protected File JavaDoc folderFile;
45
46     protected File JavaDoc mainFrameOptionsFile;
47
48     protected File JavaDoc pop3Directory;
49
50     protected File JavaDoc popManageOptionsFile;
51
52     protected File JavaDoc composerOptionsFile;
53
54     private static MailConfig instance = new MailConfig(Config.getInstance());
55
56     private OptionsItem optionsItem;
57     private ComposerItem composerItem;
58
59     /**
60      * @see java.lang.Object#Object()
61      */

62     public MailConfig(Config config) {
63         this.config = config;
64         path = new File JavaDoc(config.getConfigDirectory(), MODULE_NAME);
65         DiskIO.ensureDirectory(path);
66
67         pop3Directory = new File JavaDoc(path, "pop3server");
68         DiskIO.ensureDirectory(pop3Directory);
69
70         accountFile = new File JavaDoc(path, "account.xml");
71         registerPlugin(accountFile.getName(), new AccountXmlConfig(accountFile));
72
73         folderFile = new File JavaDoc(path, "tree.xml");
74         registerPlugin(folderFile.getName(), new FolderXmlConfig(folderFile));
75
76         mainFrameOptionsFile = new File JavaDoc(path, "options.xml");
77         registerPlugin(mainFrameOptionsFile.getName(),
78                 new MainFrameOptionsXmlConfig(mainFrameOptionsFile));
79
80         File JavaDoc mainToolBarFile = new File JavaDoc(path, "main_toolbar.xml");
81         registerPlugin(mainToolBarFile.getName(), new DefaultXmlConfig(
82                 mainToolBarFile));
83
84         File JavaDoc composerToolBarFile = new File JavaDoc(path, "composer_toolbar.xml");
85         registerPlugin(composerToolBarFile.getName(), new DefaultXmlConfig(
86                 composerToolBarFile));
87
88         File JavaDoc messageframeToolBarFile = new File JavaDoc(path,
89                 "messageframe_toolbar.xml");
90         registerPlugin(messageframeToolBarFile.getName(), new DefaultXmlConfig(
91                 messageframeToolBarFile));
92
93         composerOptionsFile = new File JavaDoc(path, "composer_options.xml");
94         registerPlugin(composerOptionsFile.getName(),
95                 new ComposerOptionsXmlConfig(composerOptionsFile));
96
97     }
98
99     public File JavaDoc getConfigDirectory() {
100         return path;
101     }
102
103     /**
104      * Returns the POP3 directory.
105      */

106     public File JavaDoc getPOP3Directory() {
107         return pop3Directory;
108     }
109
110     /**
111      * Method registerPlugin.
112      *
113      * @param id
114      * @param plugin
115      */

116     protected void registerPlugin(String JavaDoc id, DefaultXmlConfig plugin) {
117         config.registerPlugin(MODULE_NAME, id, plugin);
118     }
119
120     /**
121      * Method getPlugin.
122      *
123      * @param id
124      * @return DefaultXmlConfig
125      */

126     protected DefaultXmlConfig getPlugin(String JavaDoc id) {
127         return config.getPlugin(MODULE_NAME, id);
128     }
129
130     /**
131      * Method getAccountList.
132      *
133      * @return AccountList
134      */

135     public AccountList getAccountList() {
136         return ((AccountXmlConfig) getPlugin(accountFile.getName()))
137                 .getAccountList();
138     }
139
140     public XmlElement get(String JavaDoc name) {
141         DefaultXmlConfig xml = getPlugin(name + ".xml");
142
143         return xml.getRoot();
144     }
145
146     /**
147      * Method getFolderConfig.
148      *
149      * @return FolderXmlConfig
150      */

151     public FolderXmlConfig getFolderConfig() {
152
153         return (FolderXmlConfig) getPlugin(folderFile.getName());
154     }
155
156     /**
157      * Method getMainFrameOptionsConfig.
158      *
159      * @return MainFrameOptionsXmlConfig
160      */

161     public MainFrameOptionsXmlConfig getMainFrameOptionsConfig() {
162
163         return (MainFrameOptionsXmlConfig) getPlugin(mainFrameOptionsFile
164                 .getName());
165     }
166
167     public OptionsItem getOptionsItem() {
168         if (optionsItem == null) {
169             XmlElement xmlElement = getPlugin(mainFrameOptionsFile.getName())
170                     .getRoot().getElement("options");
171             optionsItem = new OptionsItem(xmlElement);
172         }
173
174         return optionsItem;
175     }
176     
177     public ComposerItem getComposerItem() {
178         if (composerItem == null) {
179             XmlElement xmlElement = getPlugin(composerOptionsFile.getName())
180                     .getRoot().getElement("options");
181             composerItem = new ComposerItem(xmlElement);
182         }
183
184         return composerItem;
185     }
186
187     /**
188      * Method getComposerOptionsConfig.
189      *
190      * @return ComposerOptionsXmlConfig
191      */

192     public ComposerOptionsXmlConfig getComposerOptionsConfig() {
193
194         return (ComposerOptionsXmlConfig) getPlugin(composerOptionsFile
195                 .getName());
196     }
197
198     /**
199      * @return Returns the instance.
200      */

201     public static MailConfig getInstance() {
202         return instance;
203     }
204 }
Popular Tags