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.Enumeration;
    20
    21  import javax.portlet.PortletRequest;
    22
    23  import org.apache.portals.bridges.jsf.AbstractAttributeMap;
    24
    25  /***
    26   * <p>{@link PortletRequest} parameters as Map.</p>
    27   * <p>
    28   * See MyFaces project for servlet implementation.
    29   * </p>
    30   *
    31   * @author <a href="dlestrat@apache.org">David Le Strat</a>
    32   */
    33  public class RequestParameterMap extends AbstractAttributeMap
    34  {
    35  	/*** Illegal argument exception message. */
    36  	final private static String ILLEGAL_ARGUMENT = "Only PortletContext supported";
    37  	/*** The {@link PortletRequest}. */
    38  	private final PortletRequest portletRequest;
    39
    40      /***
    41       * @param request The request.
    42       */
    43      public RequestParameterMap(Object request)
    44      {
    45          if (request instanceof PortletRequest)
    46          {
    47          	this.portletRequest = (PortletRequest) request;
    48          }
    49          else
    50          {
    51          	throw new IllegalArgumentException(ILLEGAL_ARGUMENT);
    52          }
    53      }
    54
    55      /***
    56       * @see org.apache.portals.bridges.jsf.AbstractAttributeMap#getAttribute(java.lang.String)
    57       */
    58      public Object getAttribute(String key)
    59      {
    60          if (null != this.portletRequest)
    61          {
    62          	return this.portletRequest.getParameter(key);
    63          }
    64          else
    65          {
    66          	throw new IllegalArgumentException(ILLEGAL_ARGUMENT);
    67          }
    68      }
    69
    70      /***
    71       * @see org.apache.portals.bridges.jsf.AbstractAttributeMap#setAttribute(java.lang.String, java.lang.Object)
    72       */
    73      public void setAttribute(String key, Object value)
    74      {
    75          throw new UnsupportedOperationException("Cannot set PortletRequest Parameter");
    76      }
    77
    78      /***
    79       * @see org.apache.portals.bridges.jsf.AbstractAttributeMap#removeAttribute(java.lang.String)
    80       */
    81      public void removeAttribute(String key)
    82      {
    83          throw new UnsupportedOperationException("Cannot remove PortletRequest Parameter");
    84      }
    85
    86      /***
    87       * @see org.apache.portals.bridges.jsf.AbstractAttributeMap#getAttributeNames()
    88       */
    89      public Enumeration getAttributeNames()
    90      {
    91          if (null != this.portletRequest)
    92          {
    93          	return this.portletRequest.getParameterNames();
    94          }
    95          else
    96          {
    97          	throw new IllegalArgumentException(ILLEGAL_ARGUMENT);
    98          }
    99      }
    100 }