View Javadoc

    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  You may obtain a copy of the License at
    8    *
    9    *      http://www.apache.org/licenses/LICENSE-2.0
    10   *
    11   * Unless required by applicable law or agreed to in writing, software
    12   * distributed under the License is distributed on an "AS IS" BASIS,
    13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14   * See the License for the specific language governing permissions and
    15   * limitations under the License.
    16   */
    17  package org.apache.portals.bridges.jsf;
    18
    19  import java.util.ArrayList;
    20  import java.util.Enumeration;
    21  import java.util.HashMap;
    22  import java.util.List;
    23  import java.util.Map;
    24
    25  import javax.portlet.PortletRequest;
    26
    27
    28  /***
    29   * <p>
    30   * This must be the set of properties available via the javax.portlet.PortletRequest methods getProperties()
    31   * and getPropertyNames(). As such, HTTP headers will only be included if they were provided by the portlet
    32   * container, and additional properties provided by the portlet container may also be included.
    33   * </p>
    34   * <p>
    35   * See MyFaces project for servlet implementation.
    36   * </p>
    37   *
    38   * @author <a href="dlestrat@apache.org">David Le Strat </a>
    39   */
    40  public class RequestHeaderValuesMap extends AbstractAttributeMap
    41  {
    42      /*** The portlet request. */
    43      private final PortletRequest portletRequest;
    44
    45      /*** Value cache. */
    46      private final Map valueCache = new HashMap();
    47
    48      /***
    49       * @param portletRequest The {@link PortletRequest}.
    50       */
    51      RequestHeaderValuesMap(PortletRequest portletRequest)
    52      {
    53          this.portletRequest = portletRequest;
    54      }
    55
    56      /***
    57       * @see org.apache.portals.bridges.jsf.AbstractAttributeMap#getAttribute(java.lang.String)
    58       */
    59      protected Object getAttribute(String key)
    60      {
    61          Object ret = valueCache.get(key);
    62          if (ret == null)
    63          {
    64              valueCache.put(key, ret = toArray(portletRequest.getProperties(key)));
    65          }
    66          return ret;
    67      }
    68
    69      /***
    70       * @see org.apache.portals.bridges.jsf.AbstractAttributeMap#setAttribute(java.lang.String, java.lang.Object)
    71       */
    72      protected void setAttribute(String key, Object value)
    73      {
    74          throw new UnsupportedOperationException(
    75              "Cannot set PortletRequest Properties");
    76      }
    77
    78      /***
    79       * @see org.apache.portals.bridges.jsf.AbstractAttributeMap#removeAttribute(java.lang.String)
    80       */
    81      protected void removeAttribute(String key)
    82      {
    83          throw new UnsupportedOperationException(
    84              "Cannot remove PortletRequest Properties");
    85      }
    86
    87      /***
    88       * @see org.apache.portals.bridges.jsf.AbstractAttributeMap#getAttributeNames()
    89       */
    90      protected Enumeration getAttributeNames()
    91      {
    92          return portletRequest.getPropertyNames();
    93      }
    94
    95      /***
    96       * @param e The enumeration.
    97       * @return An array of strings.
    98       */
    99      private String[] toArray(Enumeration e)
    100     {
    101         List ret = new ArrayList();
    102
    103         while (e.hasMoreElements())
    104         {
    105             ret.add(e.nextElement());
    106         }
    107
    108         return (String[]) ret.toArray(new String[ret.size()]);
    109     }
    110 }