KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jdon > util > PropsUtil


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

16
17 package com.jdon.util;
18
19 import java.io.*;
20 import com.jdon.util.jdom.*;
21
22 /**
23  * @author banq
24  */

25
26 public class PropsUtil {
27
28   public final static String JavaDoc module = PropsUtil.class.getName();
29
30   public static String JavaDoc ENCODING = "UTF-8";
31
32   private XMLProperties properties;
33   
34   private FileLocator fileLocator = new FileLocator();
35
36  
37   public PropsUtil(String JavaDoc configureFile) {
38       loadProperties(configureFile);
39   }
40
41   public void loadProperties(String JavaDoc configName) {
42     InputStream pathCongfgName = fileLocator.getConfStream(configName);
43     if (pathCongfgName == null) {
44         System.out.println(" cann't load config file:-->" + configName);
45         return;
46     }
47     this.properties = new XMLProperties(pathCongfgName);
48   }
49
50
51   public String JavaDoc getProperty(String JavaDoc name) {
52     String JavaDoc res = properties.getProperty(name);
53     if (res == null)
54       res = "";
55     return res;
56   }
57
58
59   public void setProperty(String JavaDoc name, String JavaDoc value) {
60     properties.setProperty(name, value);
61   }
62
63 }
64
Popular Tags