01: /*
02: * Title: Config
03: * Description:
04: *
05: * This software is published under the terms of the OpenSymphony Software
06: * License version 1.1, of which a copy has been included with this
07: * distribution in the LICENSE.txt file.
08: */
09:
10: package com.opensymphony.module.sitemesh;
11:
12: import javax.servlet.FilterConfig;
13: import javax.servlet.ServletConfig;
14: import javax.servlet.ServletContext;
15:
16: /**
17: * Common interface to ServletConfig and FilterConfig
18: * (since javax.servlet.Config was removed from 2.3 spec).
19: *
20: * @author <a href="mailto:joe@truemesh.com">Joe Walnes</a>
21: * @version $Revision: 1.2 $
22: */
23: public class Config {
24: private ServletConfig servletConfig;
25: private FilterConfig filterConfig;
26: private String configFile;
27:
28: public Config(ServletConfig servletConfig) {
29: if (servletConfig == null)
30: throw new NullPointerException(
31: "ServletConfig cannot be null");
32: this .servletConfig = servletConfig;
33: this .configFile = servletConfig.getInitParameter("configFile");
34: }
35:
36: public Config(FilterConfig filterConfig) {
37: if (filterConfig == null)
38: throw new NullPointerException(
39: "FilterConfig cannot be null");
40: this .filterConfig = filterConfig;
41: this .configFile = filterConfig.getInitParameter("configFile");
42: }
43:
44: public ServletContext getServletContext() {
45: return servletConfig != null ? servletConfig
46: .getServletContext() : filterConfig.getServletContext();
47: }
48:
49: public String getConfigFile() {
50: return configFile;
51: }
52: }
|