1 16 package org.apache.cocoon.environment.wrapper; 17 18 import java.security.Principal ; 19 import java.util.Enumeration ; 20 import java.util.HashSet ; 21 import java.util.Iterator ; 22 import java.util.Locale ; 23 import java.util.Map ; 24 import java.util.Set ; 25 26 import org.apache.cocoon.environment.Cookie; 27 import org.apache.cocoon.environment.Environment; 28 import org.apache.cocoon.environment.Request; 29 import org.apache.cocoon.environment.Session; 30 31 39 public final class RequestWrapper implements Request { 40 41 42 private final Request req; 43 44 45 private String queryString; 46 47 48 private final RequestParameters parameters ; 49 50 51 private final Environment environment; 52 53 54 private final boolean rawMode; 55 56 57 private String requestURI; 58 59 62 public RequestWrapper(Request request, 63 String requestURI, 64 String queryString, 65 Environment env) { 66 this(request, requestURI, queryString, env, false); 67 } 68 69 72 public RequestWrapper(Request request, 73 String requestURI, 74 String queryString, 75 Environment env, 76 boolean rawMode) { 77 this.environment = env; 78 this.req = request; 79 this.queryString = queryString; 80 this.parameters = new RequestParameters(queryString); 81 this.rawMode = rawMode; 82 if (this.req.getQueryString() != null && this.rawMode == false) { 83 if (this.queryString == null) 84 this.queryString = this.req.getQueryString(); 85 else 86 this.queryString += '&' + this.req.getQueryString(); 87 } 88 this.requestURI = this.req.getRequestURI(); 89 } 90 91 public Object get(String name) { 92 return this.req.get(name); 93 } 94 95 public Object getAttribute(String name) { 96 return this.req.getAttribute(name); 97 } 98 99 public Enumeration getAttributeNames() { 100 return this.req.getAttributeNames(); 101 } 102 103 public String getCharacterEncoding() { 104 return this.req.getCharacterEncoding(); 105 } 106 107 public void setCharacterEncoding(String enc) 108 throws java.io.UnsupportedEncodingException { 109 this.req.setCharacterEncoding(enc); 110 } 111 112 public int getContentLength() { 113 return this.req.getContentLength(); 114 } 115 116 public String getContentType() { 117 return this.req.getContentType(); 118 } 119 120 public String getParameter(String name) { 121 String value = this.parameters.getParameter(name); 122 if (value == null && this.rawMode == false) 123 return this.req.getParameter(name); 124 else 125 return value; 126 } 127 128 public Enumeration getParameterNames() { 129 if ( this.rawMode == false ) { 130 Set parameterNames = new HashSet (); 132 Enumeration names = this.parameters.getParameterNames(); 133 while (names.hasMoreElements()) { 134 parameterNames.add(names.nextElement()); 135 } 136 names = this.req.getParameterNames(); 137 while (names.hasMoreElements()) { 138 parameterNames.add(names.nextElement()); 139 } 140 return new EnumerationFromIterator(parameterNames.iterator()); 141 } else { 142 return this.parameters.getParameterNames(); 143 } 144 } 145 146 static final class EnumerationFromIterator implements Enumeration { 147 private Iterator iter; 148 EnumerationFromIterator(Iterator iter) { 149 this.iter = iter; 150 } 151 152 public boolean hasMoreElements() { 153 return iter.hasNext(); 154 } 155 public Object nextElement() { return iter.next(); } 156 } 157 158 public String [] getParameterValues(String name) { 159 if ( this.rawMode == false) { 160 String [] values = this.parameters.getParameterValues(name); 161 String [] inherited = this.req.getParameterValues(name); 162 if (inherited == null) return values; 163 if (values == null) return inherited; 164 String [] allValues = new String [values.length + inherited.length]; 165 System.arraycopy(values, 0, allValues, 0, values.length); 166 System.arraycopy(inherited, 0, allValues, values.length, inherited.length); 167 return allValues; 168 } else { 169 return this.parameters.getParameterValues(name); 170 } 171 } 172 173 public String getProtocol() { 174 return this.req.getProtocol(); 175 } 176 177 public String getScheme() { 178 return this.req.getScheme(); 179 } 180 181 public String getServerName() { 182 return this.req.getServerName(); 183 } 184 185 public int getServerPort() { 186 return this.req.getServerPort(); 187 } 188 189 public String getRemoteAddr() { 190 return this.req.getRemoteAddr(); 191 } 192 193 public String getRemoteHost() { 194 return this.req.getRemoteHost(); 195 } 196 197 public void setAttribute(String name, Object o) { 198 this.req.setAttribute(name, o); 199 } 200 201 204 public void removeAttribute(String name) { 205 this.req.removeAttribute(name); 206 } 207 208 public Locale getLocale() { 209 return this.req.getLocale(); 210 } 211 212 public Enumeration getLocales() { 213 return this.req.getLocales(); 214 } 215 216 public boolean isSecure() { 217 return this.req.isSecure(); 218 } 219 220 public Cookie[] getCookies() { 221 return this.req.getCookies(); 222 } 223 224 public Map getCookieMap() { 225 return this.req.getCookieMap(); 226 } 227 228 public long getDateHeader(String name) { 229 return this.req.getDateHeader(name); 230 } 231 232 public String getHeader(String name) { 233 return this.req.getHeader(name); 234 } 235 236 public Enumeration getHeaders(String name) { 237 return this.req.getHeaders(name); 238 } 239 240 public Enumeration getHeaderNames() { 241 return this.req.getHeaderNames(); 242 } 243 244 public String getMethod() { 245 return this.req.getMethod(); 246 } 247 248 public String getPathInfo() { 249 return this.req.getPathInfo(); 250 } 251 252 public String getPathTranslated() { 253 return this.req.getPathTranslated(); 254 } 255 256 public String getContextPath() { 257 return this.req.getContextPath(); 258 } 259 260 public String getQueryString() { 261 return this.queryString; 262 } 263 264 public String getRemoteUser() { 265 return this.req.getRemoteUser(); 266 } 267 268 public String getRequestedSessionId() { 269 return this.req.getRequestedSessionId(); 270 } 271 272 public String getRequestURI() { 273 return this.requestURI; 274 } 275 276 public String getSitemapURI() { 277 return this.environment.getURI(); 278 } 279 280 public String getSitemapURIPrefix() { 281 return this.environment.getURIPrefix(); 282 } 283 284 public String getServletPath() { 285 return this.req.getServletPath(); 286 } 287 288 public Session getSession(boolean create) { 289 return this.req.getSession(create); 290 } 291 292 public Session getSession() { 293 return this.req.getSession(); 294 } 295 296 public boolean isRequestedSessionIdValid() { 297 return this.req.isRequestedSessionIdValid(); 298 } 299 300 public boolean isRequestedSessionIdFromCookie() { 301 return this.req.isRequestedSessionIdFromCookie(); 302 } 303 304 public boolean isRequestedSessionIdFromURL() { 305 return this.req.isRequestedSessionIdFromURL(); 306 } 307 308 public boolean isRequestedSessionIdFromUrl() { 309 return this.req.isRequestedSessionIdFromURL(); 310 } 311 312 public Principal getUserPrincipal() { 313 return this.req.getUserPrincipal(); 314 } 315 316 public boolean isUserInRole(String role) { 317 return this.req.isUserInRole(role); 318 } 319 320 public String getAuthType() { 321 return this.req.getAuthType(); 322 } 323 324 public void setRequestURI(String prefix, String uri) { 325 StringBuffer buffer = new StringBuffer (this.getContextPath()); 326 buffer.append('/'); 327 buffer.append(prefix); 328 buffer.append(uri); 329 this.requestURI = buffer.toString(); 330 } 331 } 332 | Popular Tags |