View Javadoc

1   /*
2    * Copyright 2003,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  /* 
17  
18   */
19  
20  package org.apache.pluto.portalImpl.servlet;
21  
22  import java.util.Collections;
23  import java.util.Enumeration;
24  import java.util.HashMap;
25  import java.util.Iterator;
26  import java.util.Map;
27  
28  import org.apache.pluto.om.window.PortletWindow;
29  import org.apache.pluto.portalImpl.core.PortalControlParameter;
30  import org.apache.pluto.portalImpl.core.PortalEnvironment;
31  
32  public class ServletRequestImpl extends javax.servlet.http.HttpServletRequestWrapper 
33  {
34  
35      PortalControlParameter control = null;
36      PortletWindow portletWindow = null;
37  
38      public ServletRequestImpl(javax.servlet.http.HttpServletRequest servletRequest, PortletWindow window)
39      {
40          super(servletRequest);
41  
42          this.portletWindow = window;
43          control = new PortalControlParameter(
44              PortalEnvironment.getPortalEnvironment(servletRequest).getRequestedPortalURL());
45  
46      }
47  
48  // HttpServletRequestWrapper overlay
49            
50      public java.lang.String getContentType()
51  	 {
52          String contentType = super.getContentType();
53  		return contentType;
54  	 }
55  
56  // ServletRequestWrapper overlay
57  
58      public String getParameter(String name) 
59      {
60          String[] values=(String[]) this.getParameterMap().get(name);
61          if (values!=null) {
62               return values[0];	
63          }
64          return null;
65      }
66      
67      public Map getParameterMap() 
68      {
69          //get control params
70          Map portletParameters = new HashMap();
71               
72          Iterator iterator = control.getRenderParamNames(portletWindow);
73          while (iterator.hasNext())
74          {
75              String name = (String)iterator.next();
76  
77              String[] values = control.getRenderParamValues(portletWindow, name);
78  
79              portletParameters.put(name, values );
80  
81          }
82  
83          //get request params      
84          String pid = control.getPIDValue();
85          String wid = portletWindow.getId().toString();
86          if (pid.equals(wid)) {
87              for (Enumeration parameters = super.getParameterNames(); parameters.hasMoreElements();) {
88                  String   paramName   = (String)parameters.nextElement();
89                  String[] paramValues = super.getParameterValues(paramName);
90                  String[] values      = (String[])portletParameters.get(paramName);
91      
92                  if (values != null) {
93                      String[] temp = new String[paramValues.length + values.length];
94                      System.arraycopy(paramValues, 0, temp, 0, paramValues.length);
95                      System.arraycopy(values, 0, temp, paramValues.length, values.length);
96                      paramValues = temp;
97                  }
98                  portletParameters.put(paramName, paramValues);
99              }
100         }
101 
102         return Collections.unmodifiableMap(portletParameters);
103     }
104     
105     public Enumeration getParameterNames() 
106     {
107         return Collections.enumeration(this.getParameterMap().keySet());
108     }
109 
110     public String[] getParameterValues(String name) 
111     {
112         return (String[]) this.getParameterMap().get(name);
113     }
114 
115 }
116 
117