KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > pluto > portalImpl > servlet > ServletRequestImpl


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 JavaDoc;
23 import java.util.Enumeration JavaDoc;
24 import java.util.HashMap JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import java.util.Map JavaDoc;
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 JavaDoc
33 {
34
35     PortalControlParameter control = null;
36     PortletWindow portletWindow = null;
37
38     public ServletRequestImpl(javax.servlet.http.HttpServletRequest JavaDoc 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 JavaDoc getContentType()
51      {
52         String JavaDoc contentType = super.getContentType();
53         return contentType;
54      }
55
56 // ServletRequestWrapper overlay
57

58     public String JavaDoc getParameter(String JavaDoc name)
59     {
60         String JavaDoc[] values=(String JavaDoc[]) this.getParameterMap().get(name);
61         if (values!=null) {
62              return values[0];
63         }
64         return null;
65     }
66     
67     public Map JavaDoc getParameterMap()
68     {
69         //get control params
70
Map JavaDoc portletParameters = new HashMap JavaDoc();
71              
72         Iterator JavaDoc iterator = control.getRenderParamNames(portletWindow);
73         while (iterator.hasNext())
74         {
75             String JavaDoc name = (String JavaDoc)iterator.next();
76
77             String JavaDoc[] values = control.getRenderParamValues(portletWindow, name);
78
79             portletParameters.put(name, values );
80
81         }
82
83         //get request params
84
String JavaDoc pid = control.getPIDValue();
85         String JavaDoc wid = portletWindow.getId().toString();
86         if (pid.equals(wid)) {
87             for (Enumeration JavaDoc parameters = super.getParameterNames(); parameters.hasMoreElements();) {
88                 String JavaDoc paramName = (String JavaDoc)parameters.nextElement();
89                 String JavaDoc[] paramValues = super.getParameterValues(paramName);
90                 String JavaDoc[] values = (String JavaDoc[])portletParameters.get(paramName);
91     
92                 if (values != null) {
93                     String JavaDoc[] temp = new String JavaDoc[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 JavaDoc getParameterNames()
106     {
107         return Collections.enumeration(this.getParameterMap().keySet());
108     }
109
110     public String JavaDoc[] getParameterValues(String JavaDoc name)
111     {
112         return (String JavaDoc[]) this.getParameterMap().get(name);
113     }
114
115 }
116
117
118
Popular Tags