KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > myfaces > context > servlet > RequestHeaderValuesMap


1 /*
2  * Copyright 2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.myfaces.context.servlet;
17
18 import java.util.ArrayList JavaDoc;
19 import java.util.Enumeration JavaDoc;
20 import java.util.HashMap JavaDoc;
21 import java.util.List JavaDoc;
22 import java.util.Map JavaDoc;
23
24 import javax.servlet.http.HttpServletRequest JavaDoc;
25
26
27 /**
28  * HttpServletRequest header values (multi-value headers) as Map of String[].
29  *
30  * @author Anton Koinov (latest modification by $Author: matze $)
31  * @version $Revision: 1.9 $ $Date: 2004/10/13 11:51:00 $
32  */

33 public class RequestHeaderValuesMap extends AbstractAttributeMap
34 {
35     private final HttpServletRequest JavaDoc _httpServletRequest;
36     private final Map JavaDoc _valueCache = new HashMap JavaDoc();
37
38     RequestHeaderValuesMap(HttpServletRequest JavaDoc httpServletRequest)
39     {
40         _httpServletRequest = httpServletRequest;
41     }
42
43     protected Object JavaDoc getAttribute(String JavaDoc key)
44     {
45         Object JavaDoc 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 JavaDoc key, Object JavaDoc value)
56     {
57         throw new UnsupportedOperationException JavaDoc(
58             "Cannot set HttpServletRequest HeaderValues");
59     }
60
61     protected void removeAttribute(String JavaDoc key)
62     {
63         throw new UnsupportedOperationException JavaDoc(
64             "Cannot remove HttpServletRequest HeaderValues");
65     }
66
67     protected Enumeration JavaDoc getAttributeNames()
68     {
69         return _httpServletRequest.getHeaderNames();
70     }
71
72     private String JavaDoc[] toArray(Enumeration JavaDoc e)
73     {
74         List JavaDoc ret = new ArrayList JavaDoc();
75
76         while (e.hasMoreElements())
77         {
78             ret.add(e.nextElement());
79         }
80
81         return (String JavaDoc[]) ret.toArray(new String JavaDoc[ret.size()]);
82     }
83 }
Popular Tags