1 16 17 package org.apache.commons.configuration.web; 18 19 import java.util.Iterator ; 20 import java.util.Arrays ; 21 import javax.servlet.ServletRequest ; 22 23 import org.apache.commons.collections.iterators.EnumerationIterator; 24 import org.apache.commons.configuration.AbstractConfiguration; 25 26 35 public class ServletRequestConfiguration extends AbstractConfiguration 36 { 37 protected ServletRequest request; 38 39 44 public ServletRequestConfiguration(ServletRequest request) 45 { 46 this.request = request; 47 } 48 49 public Object getProperty(String key) 50 { 51 String values[] = request.getParameterValues(key); 52 53 if (values == null || values.length == 0) 54 { 55 return null; 56 } 57 else if (values.length == 1) 58 { 59 return values[0]; 60 } 61 else 62 { 63 return Arrays.asList(values); 64 } 65 } 66 67 73 protected void addPropertyDirect(String key, Object obj) 74 { 75 throw new UnsupportedOperationException ("Read only configuration"); 76 } 77 78 public boolean isEmpty() 79 { 80 return !getKeys().hasNext(); 81 } 82 83 public boolean containsKey(String key) 84 { 85 return getProperty(key) != null; 86 } 87 88 94 public void clearProperty(String key) 95 { 96 throw new UnsupportedOperationException ("Read only configuration"); 97 } 98 99 public Iterator getKeys() 100 { 101 return new EnumerationIterator(request.getParameterNames()); 102 } 103 } 104 | Popular Tags |