KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > lenya > xml > Configuration


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */

17
18 /* $Id: Configuration.java 42598 2004-03-01 16:18:28Z gregor $ */
19
20 package org.apache.lenya.xml;
21
22 import java.net.URL JavaDoc;
23 import java.util.Properties JavaDoc;
24
25 import org.apache.log4j.Category;
26
27
28 /**
29  * Reads xpsconf.properties
30  * @deprecated replaced by config/ directory
31  */

32 public class Configuration {
33     static Category log = Category.getInstance(Configuration.class);
34     public static final String JavaDoc DEFAULT_CONFIGURATION_FILE = "org/apache/lenya/xml/xpsconf.properties";
35     public static final String JavaDoc DEFAULT_CONFIGURATION_KEY = "xps.configuration";
36     public static final String JavaDoc OVERRIDE_DEFAULT_CONFIGURATION_KEY = "override.xps.configuration";
37     public String JavaDoc cacheFolder = null;
38     public boolean cacheHTTP = false;
39     public String JavaDoc INCLUDE = null;
40     public String JavaDoc JAVA_ZONE = null;
41     public String JavaDoc proxyHost = null;
42     public String JavaDoc proxyPort = null;
43
44     /**
45      * Creates a new Configuration object.
46      */

47     public Configuration() {
48         getProperties(load());
49     }
50
51     /**
52      * http://www.artima.com/java/answers/Mar2001/messages/164.html export
53      * CLASSPATH=/home/lenya/src/xps/build/properties:... java
54      * -Doverride.xps.configuration=org/apache/lenya/xps/altconf.properties org.apache.lenya.xps.Configuration
55      *
56      * @param args DOCUMENT ME!
57      */

58     public static void main(String JavaDoc[] args) {
59         Configuration conf = new Configuration();
60
61         System.out.println("Caching directory: " + conf.cacheFolder);
62         System.out.println("Cache xml from http connections: " + conf.cacheHTTP);
63
64         if ((conf.proxyHost != null) && (conf.proxyHost != null)) {
65             System.out.println("Proxy set:");
66             System.out.println(conf.proxyHost);
67             System.out.println(conf.proxyPort);
68         } else {
69             System.out.println("No proxy set.");
70         }
71     }
72
73     /**
74      * DOCUMENT ME!
75      *
76      * @return DOCUMENT ME!
77      */

78     public static Properties JavaDoc load() {
79         String JavaDoc resourcePathRelativeToClasspath = System.getProperty(OVERRIDE_DEFAULT_CONFIGURATION_KEY);
80
81         if (resourcePathRelativeToClasspath == null) {
82             resourcePathRelativeToClasspath = System.getProperty(DEFAULT_CONFIGURATION_KEY,
83                     DEFAULT_CONFIGURATION_FILE);
84             log.debug(DEFAULT_CONFIGURATION_KEY + "=" + resourcePathRelativeToClasspath);
85         } else {
86             log.debug(OVERRIDE_DEFAULT_CONFIGURATION_KEY + "=" + resourcePathRelativeToClasspath);
87         }
88
89         ClassLoader JavaDoc cl = ClassLoader.getSystemClassLoader();
90
91         // FIXME:
92
URL JavaDoc url = org.apache.log4j.helpers.Loader.getResource("hallo");
93
94         if (url == null) {
95             //return null;
96
}
97
98         log.debug(url);
99
100         Properties JavaDoc properties = new Properties JavaDoc();
101
102         try {
103             properties.load(Configuration.class.getResourceAsStream("xpsconf.properties"));
104         } catch (Exception JavaDoc e) {
105             log.error(".load(): " + e);
106         }
107
108         return properties;
109     }
110
111     /**
112      * DOCUMENT ME!
113      *
114      * @param properties DOCUMENT ME!
115      */

116     public void getProperties(Properties JavaDoc properties) {
117         if (properties != null) {
118             cacheFolder = getProperty(properties,
119                     "org.apache.lenya.xps.XLinkInterpreter.cacheFolder");
120             cacheHTTP = false;
121             INCLUDE = getProperty(properties, "Include");
122             JAVA_ZONE = getProperty(properties, "JavaZone");
123             proxyHost = null;
124             proxyPort = null;
125         }
126     }
127
128     /**
129      * DOCUMENT ME!
130      *
131      * @param properties DOCUMENT ME!
132      * @param key DOCUMENT ME!
133      *
134      * @return DOCUMENT ME!
135      */

136     public String JavaDoc getProperty(Properties JavaDoc properties, String JavaDoc key) {
137         String JavaDoc value = properties.getProperty(key);
138
139         if (value != null) {
140             log.debug(key + "=" + value);
141
142             return value;
143         } else {
144             log.debug(".getProperty(): No such property: " + key);
145         }
146
147         return null;
148     }
149
150     /**
151      * DOCUMENT ME!
152      */

153     public static void register() {
154     }
155 }
156
Popular Tags