KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > addressbook > config > AddressbookConfig


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.addressbook.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 AddressbookConfig {
35
36     public static final String JavaDoc MODULE_NAME = "addressbook";
37
38     protected Config config;
39
40     protected File JavaDoc path;
41
42     //private File addressbookFile;
43
private File JavaDoc addressbookOptionsFile;
44
45     private File JavaDoc folderFile;
46
47     private static AddressbookConfig instance = new AddressbookConfig(Config.getInstance());
48     
49     /**
50      * @see java.lang.Object#Object()
51      */

52     public AddressbookConfig(Config config) {
53         this.config = config;
54         path = new File JavaDoc(config.getConfigDirectory(), MODULE_NAME);
55         DiskIO.ensureDirectory(path);
56
57         addressbookOptionsFile = new File JavaDoc(path, "options.xml");
58         registerPlugin(addressbookOptionsFile.getName(), new DefaultXmlConfig(
59                 addressbookOptionsFile));
60
61         folderFile = new File JavaDoc(path, "tree.xml");
62         registerPlugin(folderFile.getName(), new DefaultXmlConfig(folderFile));
63
64         File JavaDoc mainToolBarFile = new File JavaDoc(path, "main_toolbar.xml");
65         registerPlugin(mainToolBarFile.getName(), new DefaultXmlConfig(
66                 mainToolBarFile));
67     }
68
69     public File JavaDoc getConfigDirectory() {
70         return path;
71     }
72
73     /**
74      * Return top-level xml node from configuration
75      * file with specified name.
76      *
77      * @param name name of config-file without file-ending
78      * @return top-level xml node
79      */

80     public XmlElement get(String JavaDoc name) {
81         DefaultXmlConfig xml = getPlugin(name + ".xml");
82
83         return xml.getRoot();
84     }
85
86     /**
87      * Method registerPlugin.
88      *
89      * @param id
90      * @param plugin
91      */

92     protected void registerPlugin(String JavaDoc id, DefaultXmlConfig plugin) {
93         config.registerPlugin(MODULE_NAME, id, plugin);
94     }
95
96     /**
97      * Method getPlugin.
98      *
99      * @param id
100      * @return DefaultXmlConfig
101      */

102     protected DefaultXmlConfig getPlugin(String JavaDoc id) {
103         return config.getPlugin(MODULE_NAME, id);
104     }
105     
106     /**
107      * @return Returns the instance.
108      */

109     public static AddressbookConfig getInstance() {
110         return instance;
111     }
112 }
Popular Tags