View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.myfaces.webapp.filter.portlet;
20  
21  import java.util.ArrayList;
22  import java.util.Enumeration;
23  import java.util.HashMap;
24  import java.util.List;
25  import java.util.Map;
26  import javax.portlet.PortletRequest;
27  
28  import org.apache.myfaces.webapp.filter.servlet.AbstractAttributeMap;
29  
30  /**
31   * PortletRequest header values (multi-value headers) as Map of String[].
32   * <p>
33   * NOTE: This class was copied from myfaces impl 
34   * org.apache.myfaces.context.portlet and it is
35   * used by TomahawkFacesContextWrapper. By that reason, it could change
36   * in the future.
37   * </p>
38   * 
39   * @since 1.1.7
40   * @author  Stan Silvert (latest modification by $Author: lu4242 $)
41   * @version $Revision: 691871 $ $Date: 2008-09-03 23:32:08 -0500 (Wed, 03 Sep 2008) $
42   */
43  public class RequestHeaderValuesMap extends AbstractAttributeMap
44  {
45      private final PortletRequest _portletRequest;
46      private final Map            _valueCache = new HashMap();
47  
48      RequestHeaderValuesMap(PortletRequest portletRequest)
49      {
50          _portletRequest = portletRequest;
51      }
52  
53      protected Object getAttribute(String key)
54      {
55          Object ret = _valueCache.get(key);
56          if (ret == null)
57          {
58              _valueCache.put(key, ret = toArray(_portletRequest
59                  .getProperties(key)));
60          }
61  
62          return ret;
63      }
64  
65      protected void setAttribute(String key, Object value)
66      {
67          throw new UnsupportedOperationException(
68              "Cannot set PortletRequest Properties");
69      }
70  
71      protected void removeAttribute(String key)
72      {
73          throw new UnsupportedOperationException(
74              "Cannot remove PortletRequest Properties");
75      }
76  
77      protected Enumeration getAttributeNames()
78      {
79          return _portletRequest.getPropertyNames();
80      }
81  
82      private String[] toArray(Enumeration e)
83      {
84          List ret = new ArrayList();
85  
86          while (e.hasMoreElements())
87          {
88              ret.add(e.nextElement());
89          }
90  
91          return (String[]) ret.toArray(new String[ret.size()]);
92      }
93  }