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      private javax.servlet.http.HttpServletRequest _getHttpServletRequest()
49      {
50          return(javax.servlet.http.HttpServletRequest) super.getRequest();
51      }
52  
53  // HttpServletRequestWrapper overlay
54            
55      public java.lang.String getContentType()
56  	 {
57          String contentType = super.getContentType();
58  		return contentType;
59  	 }
60  
61  // ServletRequestWrapper overlay
62  
63      public String getParameter(String name) 
64      {
65          String[] values=(String[]) this.getParameterMap().get(name);
66          if (values!=null) {
67               return values[0];	
68          }
69          return null;
70      }
71      
72      public Map getParameterMap() 
73      {
74          //get control params
75          Map portletParameters = new HashMap();
76               
77          Iterator iterator = control.getRenderParamNames(portletWindow);
78          while (iterator.hasNext())
79          {
80              String name = (String)iterator.next();
81  
82              String[] values = control.getRenderParamValues(portletWindow, name);
83  
84              portletParameters.put(name, values );
85  
86          }
87  
88          //get request params      
89          String pid = control.getPIDValue();
90          String wid = portletWindow.getId().toString();
91          if (pid.equals(wid)) {
92              for (Enumeration parameters = super.getParameterNames(); parameters.hasMoreElements();) {
93                  String   paramName   = (String)parameters.nextElement();
94                  String[] paramValues = (String[])super.getParameterValues(paramName);
95                  String[] values      = (String[])portletParameters.get(paramName);
96      
97                  if (values != null) {
98                      String[] temp = new String[paramValues.length + values.length];
99                      System.arraycopy(paramValues, 0, temp, 0, paramValues.length);
100                     System.arraycopy(values, 0, temp, paramValues.length, values.length);
101                     paramValues = temp;
102                 }
103                 portletParameters.put(paramName, paramValues);
104             }
105         }
106 
107         return Collections.unmodifiableMap(portletParameters);
108     }
109     
110     public Enumeration getParameterNames() 
111     {
112         return Collections.enumeration(this.getParameterMap().keySet());
113     }
114 
115     public String[] getParameterValues(String name) 
116     {
117         return (String[]) this.getParameterMap().get(name);
118     }
119 
120 }
121 
122