1 16 17 package org.apache.commons.configuration.web; 18 19 import java.util.Iterator ; 20 import java.util.List ; 21 import javax.servlet.Servlet ; 22 import javax.servlet.ServletContext ; 23 24 import org.apache.commons.collections.iterators.EnumerationIterator; 25 import org.apache.commons.configuration.AbstractConfiguration; 26 import org.apache.commons.configuration.PropertyConverter; 27 28 37 public class ServletContextConfiguration extends AbstractConfiguration 38 { 39 protected ServletContext context; 40 41 47 public ServletContextConfiguration(Servlet servlet) 48 { 49 this.context = servlet.getServletConfig().getServletContext(); 50 } 51 52 58 public ServletContextConfiguration(ServletContext context) 59 { 60 this.context = context; 61 } 62 63 public Object getProperty(String key) 64 { 65 Object value = context.getInitParameter(key); 66 List list = PropertyConverter.split((String ) value, getDelimiter()); 67 68 return list.size() > 1 ? list : value; 69 } 70 71 77 protected void addPropertyDirect(String key, Object obj) 78 { 79 throw new UnsupportedOperationException ("Read only configuration"); 80 } 81 82 public boolean isEmpty() 83 { 84 return !getKeys().hasNext(); 85 } 86 87 public boolean containsKey(String key) 88 { 89 return getProperty(key) != null; 90 } 91 92 98 public void clearProperty(String key) 99 { 100 throw new UnsupportedOperationException ("Read only configuration"); 101 } 102 103 public Iterator getKeys() 104 { 105 return new EnumerationIterator(context.getInitParameterNames()); 106 } 107 } 108 | Popular Tags |