01: /*
02: * Created on Aug 12, 2004 by mgreer
03: */
04: package com.opensymphony.webwork.sitegraph.collectors;
05:
06: import com.opensymphony.util.FileManager;
07: import com.opensymphony.xwork.config.providers.XmlConfigurationProvider;
08: import org.apache.commons.logging.Log;
09: import org.apache.commons.logging.LogFactory;
10:
11: import java.io.File;
12: import java.io.FileInputStream;
13: import java.io.FileNotFoundException;
14: import java.io.InputStream;
15:
16: /**
17: * Override Xwork class so we cn use an arbitrary config file
18: */
19: public class ArbitraryXMLConfigurationProvider extends
20: XmlConfigurationProvider {
21:
22: private static final Log LOG = LogFactory
23: .getLog(ArbitraryXMLConfigurationProvider.class);
24: private String configFileName = "xwork.xml";
25: private String basePathString = "";
26:
27: public ArbitraryXMLConfigurationProvider() {
28: }
29:
30: public ArbitraryXMLConfigurationProvider(String filename) {
31: this .configFileName = filename;
32: this .basePathString = new File(filename).getParent() + "/";
33: }
34:
35: /**
36: * Override Xwork method so we cn use an arbitrary config file
37: *
38: * @see com.opensymphony.xwork.config.providers.XmlConfigurationProvider#getInputStream(java.lang.String)
39: */
40: protected InputStream getInputStream(String fileName) {
41: InputStream is = null;
42: if (LOG.isDebugEnabled())
43: LOG.debug("fileName=" + this .basePathString + fileName);
44: try {
45: is = new FileInputStream(this .basePathString + fileName);
46: } catch (FileNotFoundException e) {
47: // ok, try to check the ClassLoader
48: is = FileManager.loadFile(fileName, this.getClass());
49: }
50:
51: return is;
52: }
53: }
|