KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > outerj > daisy > repository > testsupport > TestSupportConfig


1 /*
2  * Copyright 2004 Outerthought bvba and Schaubroeck nv
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 package org.outerj.daisy.repository.testsupport;
17
18 import java.util.Properties JavaDoc;
19 import java.io.File JavaDoc;
20 import java.io.FileInputStream JavaDoc;
21
22 public class TestSupportConfig extends Properties JavaDoc {
23     private static final String JavaDoc DEFAULTPROPS = "testsupport.properties";
24     private static final String JavaDoc USERPROPS = "local.testsupport.properties";
25
26     public TestSupportConfig() throws Exception JavaDoc {
27         File JavaDoc defaultProps = new File JavaDoc(DEFAULTPROPS);
28         if (defaultProps.exists()) {
29             load(new FileInputStream JavaDoc(defaultProps));
30             System.out.println("Finished reading properties from " + DEFAULTPROPS);
31         } else {
32             System.out.println("Did not find properties file " + DEFAULTPROPS);
33         }
34
35         File JavaDoc userProps = new File JavaDoc(USERPROPS);
36         if (userProps.exists()) {
37             load(new FileInputStream JavaDoc(userProps));
38             System.out.println("Finished reading properties from " + USERPROPS);
39         } else {
40             System.out.println("Did not find optional properties file " + USERPROPS);
41         }
42     }
43
44     public String JavaDoc getRequiredProperty(String JavaDoc key) throws Exception JavaDoc {
45         String JavaDoc value = getProperty(key);
46         if (value == null)
47             throw new Exception JavaDoc("Missing property " + key + ".");
48         return value;
49     }
50
51 }
52
Popular Tags