1 16 package org.apache.cocoon.portal.pluto.servlet; 17 18 import java.io.UnsupportedEncodingException ; 19 import java.util.Collections ; 20 import java.util.Enumeration ; 21 import java.util.HashMap ; 22 import java.util.Iterator ; 23 import java.util.Map ; 24 25 import javax.servlet.http.HttpServletRequest ; 26 import javax.servlet.http.HttpServletRequestWrapper ; 27 28 import org.apache.cocoon.portal.pluto.PortletURLProviderImpl; 29 import org.apache.pluto.om.window.PortletWindow; 30 31 37 public class ServletRequestImpl extends HttpServletRequestWrapper { 38 39 40 protected Map portletParameterMap; 41 42 43 protected HttpServletRequest cachedRequest; 44 45 46 final protected HttpServletRequest originalRequest; 47 48 final protected PortletURLProviderImpl provider; 49 50 protected PortletWindow window; 51 52 public ServletRequestImpl(HttpServletRequest request, 53 PortletURLProviderImpl provider) { 54 super(request); 55 this.provider = provider; 56 this.originalRequest = request; 57 } 58 59 public ServletRequestImpl(HttpServletRequest request, 60 PortletURLProviderImpl provider, 61 PortletWindow window) { 62 super(request); 63 this.provider = provider; 64 this.window = window; 65 this.originalRequest = request; 66 } 67 68 public ServletRequestImpl getRequest(PortletWindow window) { 69 return new ServletRequestImpl((HttpServletRequest )this.getRequest(), provider, window); 70 } 71 72 75 public void setCharacterEncoding(String arg0) 76 throws UnsupportedEncodingException { 77 } 79 80 83 public String getContentType() { 84 String contentType = "text/html"; 85 if (getCharacterEncoding() != null) { 86 contentType += ";" + getCharacterEncoding(); 87 } 88 return contentType; 89 } 90 91 94 public String getParameter(String name) { 95 final String [] values = (String [])this.getParameterMap().get(name); 96 if ( values != null && values.length > 0 ) { 97 return values[0]; 98 } 99 return null; 100 101 } 102 103 106 public Map getParameterMap() { 107 HttpServletRequest currentRequest = (HttpServletRequest )this.getRequest(); 108 if ( this.portletParameterMap == null 109 || currentRequest != this.cachedRequest ) { 110 this.cachedRequest = currentRequest; 111 112 this.portletParameterMap = new HashMap (); 114 115 if (this.provider != null 116 && this.provider.getPortletWindow().equals(this.window)) { 117 Iterator i = this.provider.getParameters().entrySet().iterator(); 119 while (i.hasNext()) { 120 Map.Entry entry = (Map.Entry ) i.next(); 121 if (entry.getValue() instanceof String ) { 123 this.portletParameterMap.put( 124 entry.getKey(), 125 new String [] {(String ) entry.getValue()}); 126 } else { 127 this.portletParameterMap.put( 128 entry.getKey(), 129 entry.getValue()); 130 } 131 } 132 133 Enumeration parameters = currentRequest.getParameterNames(); 136 while (parameters.hasMoreElements()) { 137 String paramName = (String ) parameters.nextElement(); 138 String [] paramValues = this.getRequest().getParameterValues(paramName); 139 String [] values = (String []) this.portletParameterMap.get(paramName); 140 141 if ( !paramName.startsWith("cocoon-") ) { 142 if (values != null) { 143 String [] temp = new String [paramValues.length + values.length]; 144 System.arraycopy(paramValues, 0, temp, 0, paramValues.length); 145 System.arraycopy(values, 0, temp, paramValues.length, values.length); 146 paramValues = temp; 147 } 148 this.portletParameterMap.put(paramName, paramValues); 149 } 150 } 151 } 152 } 153 154 return this.portletParameterMap; 155 } 156 157 160 public Enumeration getParameterNames() { 161 return Collections.enumeration(this.getParameterMap().keySet()); 162 } 163 164 167 public String [] getParameterValues(String name) { 168 return (String []) this.getParameterMap().get(name); 169 } 170 174 public String getProtocol() { 175 return null; 176 } 177 178 182 public String getRemoteAddr() { 183 return null; 184 } 185 186 190 public String getRemoteHost() { 191 return null; 192 } 193 194 198 public StringBuffer getRequestURL() { 199 return null; 200 } 201 202 206 public String getPathInfo() { 207 String attr = (String )super.getAttribute("javax.servlet.include.path_info"); 208 return (attr != null) ? attr : super.getPathInfo(); 209 } 210 211 215 public String getPathTranslated() { 216 return null; 219 } 220 221 225 public String getQueryString() { 226 String attr = (String )super.getAttribute("javax.servlet.include.query_string"); 227 return (attr != null) ? attr : super.getQueryString(); 228 } 229 230 234 public String getRequestURI() { 235 String attr = (String )super.getAttribute("javax.servlet.include.request_uri"); 236 return (attr != null) ? attr : super.getRequestURI(); 237 } 238 239 243 public String getServletPath() { 244 String attr = (String )super.getAttribute("javax.servlet.include.servlet_path"); 245 return (attr != null) ? attr : super.getServletPath(); 246 } 247 248 252 public String getContextPath() { 253 String attr = (String )super.getAttribute("javax.servlet.include.context_path"); 254 return (attr != null) ? attr : super.getContextPath(); 255 } 256 } 257 | Popular Tags |