1 16 package org.apache.myfaces.context.servlet; 17 18 import java.util.ArrayList ; 19 import java.util.Enumeration ; 20 import java.util.HashMap ; 21 import java.util.List ; 22 import java.util.Map ; 23 24 import javax.servlet.http.HttpServletRequest ; 25 26 27 33 public class RequestHeaderValuesMap extends AbstractAttributeMap 34 { 35 private final HttpServletRequest _httpServletRequest; 36 private final Map _valueCache = new HashMap (); 37 38 RequestHeaderValuesMap(HttpServletRequest httpServletRequest) 39 { 40 _httpServletRequest = httpServletRequest; 41 } 42 43 protected Object getAttribute(String key) 44 { 45 Object ret = _valueCache.get(key); 46 if (ret == null) 47 { 48 _valueCache.put(key, ret = toArray(_httpServletRequest 49 .getHeaders(key))); 50 } 51 52 return ret; 53 } 54 55 protected void setAttribute(String key, Object value) 56 { 57 throw new UnsupportedOperationException ( 58 "Cannot set HttpServletRequest HeaderValues"); 59 } 60 61 protected void removeAttribute(String key) 62 { 63 throw new UnsupportedOperationException ( 64 "Cannot remove HttpServletRequest HeaderValues"); 65 } 66 67 protected Enumeration getAttributeNames() 68 { 69 return _httpServletRequest.getHeaderNames(); 70 } 71 72 private String [] toArray(Enumeration e) 73 { 74 List ret = new ArrayList (); 75 76 while (e.hasMoreElements()) 77 { 78 ret.add(e.nextElement()); 79 } 80 81 return (String []) ret.toArray(new String [ret.size()]); 82 } 83 } | Popular Tags |