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