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.addressbook.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 AddressbookConfig {
035:
036: public static final String MODULE_NAME = "addressbook";
037:
038: protected Config config;
039:
040: protected File path;
041:
042: //private File addressbookFile;
043: private File addressbookOptionsFile;
044:
045: private File folderFile;
046:
047: private static AddressbookConfig instance = new AddressbookConfig(
048: Config.getInstance());
049:
050: /**
051: * @see java.lang.Object#Object()
052: */
053: public AddressbookConfig(Config config) {
054: this .config = config;
055: path = new File(config.getConfigDirectory(), MODULE_NAME);
056: DiskIO.ensureDirectory(path);
057:
058: addressbookOptionsFile = new File(path, "options.xml");
059: registerPlugin(addressbookOptionsFile.getName(),
060: new DefaultXmlConfig(addressbookOptionsFile));
061:
062: folderFile = new File(path, "tree.xml");
063: registerPlugin(folderFile.getName(), new DefaultXmlConfig(
064: folderFile));
065:
066: File mainToolBarFile = new File(path, "main_toolbar.xml");
067: registerPlugin(mainToolBarFile.getName(), new DefaultXmlConfig(
068: mainToolBarFile));
069: }
070:
071: public File getConfigDirectory() {
072: return path;
073: }
074:
075: /**
076: * Return top-level xml node from configuration
077: * file with specified name.
078: *
079: * @param name name of config-file without file-ending
080: * @return top-level xml node
081: */
082: public XmlElement get(String name) {
083: DefaultXmlConfig xml = getPlugin(name + ".xml");
084:
085: return xml.getRoot();
086: }
087:
088: /**
089: * Method registerPlugin.
090: *
091: * @param id
092: * @param plugin
093: */
094: protected void registerPlugin(String id, DefaultXmlConfig plugin) {
095: config.registerPlugin(MODULE_NAME, id, plugin);
096: }
097:
098: /**
099: * Method getPlugin.
100: *
101: * @param id
102: * @return DefaultXmlConfig
103: */
104: protected DefaultXmlConfig getPlugin(String id) {
105: return config.getPlugin(MODULE_NAME, id);
106: }
107:
108: /**
109: * @return Returns the instance.
110: */
111: public static AddressbookConfig getInstance() {
112: return instance;
113: }
114: }
|