KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > webwork > webFlow > collectors > ArbitraryXMLConfigurationProvider


1 /*
2  * Created on Aug 12, 2004 by mgreer
3  */

4 package com.opensymphony.webwork.webFlow.collectors;
5
6 import com.opensymphony.util.FileManager;
7 import com.opensymphony.xwork.config.providers.XmlConfigurationProvider;
8 import org.apache.commons.logging.Log;
9 import org.apache.commons.logging.LogFactory;
10
11 import java.io.File JavaDoc;
12 import java.io.FileInputStream JavaDoc;
13 import java.io.FileNotFoundException JavaDoc;
14 import java.io.InputStream JavaDoc;
15
16 /**
17  * Override Xwork class so we cn use an arbitrary config file
18  */

19 public class ArbitraryXMLConfigurationProvider extends XmlConfigurationProvider {
20
21     private static final Log LOG = LogFactory.getLog(ArbitraryXMLConfigurationProvider.class);
22     private String JavaDoc configFileName = "xwork.xml";
23     private String JavaDoc basePathString = "";
24
25     public ArbitraryXMLConfigurationProvider() {
26     }
27
28     public ArbitraryXMLConfigurationProvider(String JavaDoc filename) {
29         this.configFileName = filename;
30         this.basePathString = new File JavaDoc(filename).getParent() + "/";
31     }
32
33     /**
34      * Override Xwork method so we cn use an arbitrary config file
35      *
36      * @see com.opensymphony.xwork.config.providers.XmlConfigurationProvider#getInputStream(java.lang.String)
37      */

38     protected InputStream JavaDoc getInputStream(String JavaDoc fileName) {
39         InputStream JavaDoc is = null;
40         if (LOG.isDebugEnabled())
41             LOG.debug("fileName=" + this.basePathString + fileName);
42         try {
43             is = new FileInputStream JavaDoc(this.basePathString + fileName);
44         } catch (FileNotFoundException JavaDoc e) {
45             // ok, try to check the ClassLoader
46
is = FileManager.loadFile(fileName, this.getClass());
47         }
48
49         return is;
50     }
51 }
Popular Tags