01: package com.icesoft.faces.webapp.http.servlet;
02:
03: import com.icesoft.faces.webapp.http.common.Configuration;
04: import com.icesoft.faces.webapp.http.common.ConfigurationException;
05:
06: import javax.servlet.ServletContext;
07:
08: public class ServletContextConfiguration extends Configuration {
09: private final String name;
10: private ServletContext context;
11:
12: public ServletContextConfiguration(String prefix,
13: ServletContext context) {
14: this .name = prefix;
15: this .context = context;
16: }
17:
18: public String getName() {
19: return name;
20: }
21:
22: public Configuration getChild(String child)
23: throws ConfigurationException {
24: String childName = postfixWith(child);
25: String value = context.getInitParameter(childName);
26: if (value == null) {
27: throw new ConfigurationException("Cannot find parameter: "
28: + childName);
29: } else {
30: return new ServletContextConfiguration(childName, context);
31: }
32: }
33:
34: public Configuration[] getChildren(String name)
35: throws ConfigurationException {
36: return new Configuration[] { getChild(name) };
37: }
38:
39: public String getAttribute(String paramName)
40: throws ConfigurationException {
41: String attributeName = postfixWith(paramName);
42: String value = context.getInitParameter(attributeName);
43: if (value == null) {
44: throw new ConfigurationException("Cannot find parameter: "
45: + attributeName);
46: } else {
47: return value;
48: }
49: }
50:
51: public String getValue() throws ConfigurationException {
52: String value = context.getInitParameter(name);
53: if (value == null) {
54: throw new ConfigurationException("Cannot find parameter: "
55: + name);
56: } else {
57: return value;
58: }
59: }
60:
61: private String postfixWith(String child) {
62: return name + '.' + child;
63: }
64: }
|