1 package org.columba.mail.config; 19 20 import java.io.File ; 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 34 public class MailConfig { 35 36 public static final String MODULE_NAME = "mail"; 37 38 protected Config config; 39 40 protected File path; 41 42 protected File accountFile; 43 44 protected File folderFile; 45 46 protected File mainFrameOptionsFile; 47 48 protected File pop3Directory; 49 50 protected File popManageOptionsFile; 51 52 protected File composerOptionsFile; 53 54 private static MailConfig instance = new MailConfig(Config.getInstance()); 55 56 private OptionsItem optionsItem; 57 private ComposerItem composerItem; 58 59 62 public MailConfig(Config config) { 63 this.config = config; 64 path = new File (config.getConfigDirectory(), MODULE_NAME); 65 DiskIO.ensureDirectory(path); 66 67 pop3Directory = new File (path, "pop3server"); 68 DiskIO.ensureDirectory(pop3Directory); 69 70 accountFile = new File (path, "account.xml"); 71 registerPlugin(accountFile.getName(), new AccountXmlConfig(accountFile)); 72 73 folderFile = new File (path, "tree.xml"); 74 registerPlugin(folderFile.getName(), new FolderXmlConfig(folderFile)); 75 76 mainFrameOptionsFile = new File (path, "options.xml"); 77 registerPlugin(mainFrameOptionsFile.getName(), 78 new MainFrameOptionsXmlConfig(mainFrameOptionsFile)); 79 80 File mainToolBarFile = new File (path, "main_toolbar.xml"); 81 registerPlugin(mainToolBarFile.getName(), new DefaultXmlConfig( 82 mainToolBarFile)); 83 84 File composerToolBarFile = new File (path, "composer_toolbar.xml"); 85 registerPlugin(composerToolBarFile.getName(), new DefaultXmlConfig( 86 composerToolBarFile)); 87 88 File messageframeToolBarFile = new File (path, 89 "messageframe_toolbar.xml"); 90 registerPlugin(messageframeToolBarFile.getName(), new DefaultXmlConfig( 91 messageframeToolBarFile)); 92 93 composerOptionsFile = new File (path, "composer_options.xml"); 94 registerPlugin(composerOptionsFile.getName(), 95 new ComposerOptionsXmlConfig(composerOptionsFile)); 96 97 } 98 99 public File getConfigDirectory() { 100 return path; 101 } 102 103 106 public File getPOP3Directory() { 107 return pop3Directory; 108 } 109 110 116 protected void registerPlugin(String id, DefaultXmlConfig plugin) { 117 config.registerPlugin(MODULE_NAME, id, plugin); 118 } 119 120 126 protected DefaultXmlConfig getPlugin(String id) { 127 return config.getPlugin(MODULE_NAME, id); 128 } 129 130 135 public AccountList getAccountList() { 136 return ((AccountXmlConfig) getPlugin(accountFile.getName())) 137 .getAccountList(); 138 } 139 140 public XmlElement get(String name) { 141 DefaultXmlConfig xml = getPlugin(name + ".xml"); 142 143 return xml.getRoot(); 144 } 145 146 151 public FolderXmlConfig getFolderConfig() { 152 153 return (FolderXmlConfig) getPlugin(folderFile.getName()); 154 } 155 156 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 192 public ComposerOptionsXmlConfig getComposerOptionsConfig() { 193 194 return (ComposerOptionsXmlConfig) getPlugin(composerOptionsFile 195 .getName()); 196 } 197 198 201 public static MailConfig getInstance() { 202 return instance; 203 } 204 } | Popular Tags |