dion 2004/09/02 00:14:14
Modified: jelly/src/java/org/apache/commons/jelly Jelly.java
Log:
Refactor property loading
Revision Changes Path
1.31 +27 -19
jakarta-commons/jelly/src/java/org/apache/commons/jelly/Jelly.java
Index: Jelly.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/jelly/src/java/org/apache/commons/jelly/Jelly.java,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -r1.30 -r1.31
--- Jelly.java 31 Aug 2004 06:50:03 -0000 1.30
+++ Jelly.java 2 Sep 2004 07:14:14 -0000 1.31
@@ -239,26 +239,10 @@
String userDir = System.getProperty("user.home");
File f = new File(userDir + File.separator + "jelly.properties");
- try {
- if (f.exists()) {
- is = new FileInputStream(f);
- loadProperties(is);
- }
- }
- catch (Exception e) {
- log.error( "Caught exception while loading: " + f.getName() + ".
Reason: " + e, e );
- }
+ loadProperties(f);
f = new File("jelly.properties");
- try {
- if (f.exists()) {
- is = new FileInputStream(f);
- loadProperties(is);
- }
- }
- catch (Exception e) {
- log.error( "Caught exception while loading: " + f.getName() + ".
Reason: " + e, e );
- }
+ loadProperties(f);
is = getClass().getClassLoader().getResourceAsStream("jelly.properties");
@@ -268,6 +252,30 @@
}
catch (Exception e) {
log.error( "Caught exception while loading jelly.properties from
the classpath. Reason: " + e, e );
+ }
+ }
+ }
+
+ /**
+ * Load properties from a file into the context
+ * @param f
+ */
+ private void loadProperties(File f) {
+ InputStream is = null;
+ try {
+ if (f.exists()) {
+ is = new FileInputStream(f);
+ loadProperties(is);
+ }
+ } catch (Exception e) {
+ log.error( "Caught exception while loading: " + f.getName() + ".
Reason: " + e, e );
+ } finally {
+ if (is != null) {
+ try {
+ is.close();
+ } catch (IOException e) {
+ if (log.isDebugEnabled()) log.debug("error closing property
input stream", e);
+ }
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]