01: /*
02: * Created on 05-May-2005
03: *
04: */
05: package com.jofti.util;
06:
07: import java.io.InputStream;
08: import java.util.Properties;
09:
10: import org.apache.commons.logging.Log;
11: import org.apache.commons.logging.LogFactory;
12:
13: import com.jofti.exception.JoftiException;
14:
15: /**
16: * @author Steve Woodcock (steve@jofti.com)
17: *
18: * TODO To change the template for this generated type comment go to
19: * Window - Preferences - Java - Code Style - Code Templates
20: */
21: public class PropertyLoader {
22:
23: private static Log log = LogFactory.getLog(PropertyLoader.class);
24:
25: public static Properties loadProperties(String fileName)
26: throws JoftiException {
27:
28: InputStream in = null;
29: Properties props = new Properties();
30: try {
31: if (log.isDebugEnabled())
32: log.debug("Getting Config");
33: log.info("Getting stream for " + fileName);
34: in = PropertyLoader.class.getResourceAsStream(fileName);
35: if (in == null) {
36: throw new JoftiException("Unable to find " + fileName
37: + " ensure file is on classpath ");
38: }
39: log.info("Got stream for " + fileName);
40:
41: props.load(in);
42:
43: } catch (Exception e) {
44: log.error("Error loading " + fileName
45: + " ensure file is on classpath " + e);
46: throw new JoftiException(e);
47: } finally {
48: try {
49: if (in != null) {
50: in.close();
51: }
52: } catch (Exception e) {
53: log
54: .error("Error closing input stream for property load "
55: + e);
56: }
57: }
58: return props;
59: }
60: }
|