View Javadoc

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