KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > packtag > util > Configuration


1 /**
2  * Project pack:tag >> http://packtag.sf.net
3  *
4  * This software is published under the terms of the LGPL
5  * License version 2.1, a copy of which has been included with this
6  * distribution in the 'lgpl.txt' file.
7  *
8  * Creation date: 08.07.2007 - 19:52:09
9  * Last author: $Author: danielgalan $
10  * Last modified: $Date: 2007/07/11 23:01:31 $
11  * Revision: $Revision: 1.1 $
12  *
13  * $Log: Configuration.java,v $
14  * Revision 1.1 2007/07/11 23:01:31 danielgalan
15  * - 2.2
16  * - enhancement: caching header improved (servlet)
17  * - servlet url-mapping can be changed now (you have to set "packtag.cache.servlet.path" to the same value)
18  * - enhancement: polished the reference at http://www.galan.de/projects/packtag
19  *
20  */

21 package net.sf.packtag.util;
22
23 import java.io.File JavaDoc;
24 import java.io.FileReader JavaDoc;
25 import java.io.IOException JavaDoc;
26 import java.util.Properties JavaDoc;
27
28
29
30 /**
31  * Keeps track of the configuration settings in the pack.properties file.
32  * Not used yet.
33  *
34  * @author Daniel Galán y Martins
35  * @version $Revision: 1.1 $
36  */

37 public class Configuration {
38
39     private static Configuration instance;
40     private Properties JavaDoc configuration;
41
42
43     private static Configuration getInstance() {
44         if (instance == null) {
45             synchronized (Configuration.class) {
46                 if (instance == null) {
47                     instance = new Configuration();
48                 }
49             }
50         }
51         return instance;
52     }
53
54
55     public static String JavaDoc getCacheType() {
56         getInstance().getConfigurationCacheType();
57         return null;
58     }
59
60
61     private Configuration() {
62         configuration = new Properties JavaDoc(getDefaults());
63         File JavaDoc f = new File JavaDoc("packtag.properties");
64         if (f.exists()) {
65             try {
66                 FileReader JavaDoc fr = new FileReader JavaDoc(f);
67                 configuration.load(fr);
68             }
69             catch (IOException JavaDoc e) {
70                 e.printStackTrace();
71             }
72         }
73     }
74
75
76     private Properties JavaDoc getDefaults() {
77         Properties JavaDoc defaults = new Properties JavaDoc();
78         defaults.setProperty("cache.type", "file");
79         defaults.setProperty("cache.file.path", "pack");
80         defaults.setProperty("cache.servlet.path", "/PackServlet");
81         defaults.setProperty("resources.checktimestamps", "true");
82         defaults.setProperty("hide.errors", "false");
83         return defaults;
84     }
85
86
87     protected Properties JavaDoc getConfiguration() {
88         return configuration;
89     }
90
91
92     public String JavaDoc getConfigurationCacheType() {
93         return (String JavaDoc)getConfiguration().get("cache.type");
94     }
95 }
96
Popular Tags