1 16 package org.apache.cocoon.portlet.multipart; 17 18 import org.apache.cocoon.servlet.multipart.PartOnDisk; 19 20 import javax.portlet.ActionRequest; 21 import javax.portlet.PortalContext; 22 import javax.portlet.PortletMode; 23 import javax.portlet.PortletPreferences; 24 import javax.portlet.PortletSession; 25 import javax.portlet.WindowState; 26 27 import java.io.BufferedReader ; 28 import java.io.File ; 29 import java.io.IOException ; 30 import java.io.InputStream ; 31 import java.io.UnsupportedEncodingException ; 32 import java.security.Principal ; 33 import java.util.Enumeration ; 34 import java.util.Hashtable ; 35 import java.util.Locale ; 36 import java.util.Map ; 37 import java.util.Vector ; 38 39 45 public class MultipartActionRequest implements ActionRequest { 46 47 48 private ActionRequest request = null; 49 50 51 private Hashtable values = null; 52 53 57 public MultipartActionRequest(ActionRequest request, Hashtable values) { 58 this.request = request; 59 this.values = values; 60 } 61 62 65 public void cleanup() throws IOException { 66 Enumeration e = getParameterNames(); 67 while (e.hasMoreElements()) { 68 Object o = get((String ) e.nextElement()); 69 if (o instanceof PartOnDisk) { 70 File file = ((PartOnDisk) o).getFile(); 71 file.delete(); 72 } 73 } 74 } 75 76 81 public Object get(String name) { 82 Object result = null; 83 84 if (values != null) { 85 result = values.get(name); 86 87 if (result instanceof Vector ) { 88 if (((Vector ) result).size() == 1) { 89 return ((Vector ) result).elementAt(0); 90 } else { 91 return result; 92 } 93 } 94 } 95 96 if (result == null) { 98 String [] array = request.getParameterValues(name); 99 Vector vec = new Vector (); 100 101 if (array != null) { 102 for (int i = 0; i < array.length; i++) { 103 vec.addElement(array[i]); 104 } 105 106 if (vec.size() == 1) { 107 result = vec.elementAt(0); 108 } else { 109 result = vec; 110 } 111 } 112 } 113 114 return result; 115 } 116 117 120 public Enumeration getParameterNames() { 121 if (values != null) { 122 return values.keys(); 123 } else { 124 return request.getParameterNames(); 125 } 126 } 127 128 133 public String getParameter(String name) { 134 Object value = get(name); 135 String result = null; 136 137 if (value != null) { 138 if (value instanceof Vector ) { 139 value = ((Vector ) value).elementAt(0); 140 } 141 142 result = value.toString(); 143 } 144 145 return result; 146 } 147 148 153 public String [] getParameterValues(String name) { 154 if (values != null) { 155 Object value = get(name); 156 157 if (value != null) { 158 if (value instanceof Vector ) { 159 String [] results = new String [((Vector ) value).size()]; 160 for (int i = 0; i < ((Vector ) value).size(); i++) { 161 results[i] = ((Vector ) value).elementAt(i).toString(); 162 } 163 return results; 164 165 } else { 166 return new String []{value.toString()}; 167 } 168 } 169 170 return null; 171 } else { 172 return request.getParameterValues(name); 173 } 174 } 175 176 181 public Object getAttribute(String name) { 182 return request.getAttribute(name); 183 } 184 185 188 public Enumeration getAttributeNames() { 189 return request.getAttributeNames(); 190 } 191 192 195 public String getCharacterEncoding() { 196 return request.getCharacterEncoding(); 197 } 198 199 202 public int getContentLength() { 203 return request.getContentLength(); 204 } 205 206 209 public String getContentType() { 210 return request.getContentType(); 211 } 212 213 218 public InputStream getInputStream() throws IOException { 219 return request.getPortletInputStream(); 220 } 221 222 225 public String getScheme() { 226 return request.getScheme(); 227 } 228 229 232 public String getServerName() { 233 return request.getServerName(); 234 } 235 236 239 public int getServerPort() { 240 return request.getServerPort(); 241 } 242 243 248 public BufferedReader getReader() throws IOException { 249 return request.getReader(); 250 } 251 252 258 public void setAttribute(String name, Object o) { 259 request.setAttribute(name, o); 260 } 261 262 267 public void removeAttribute(String name) { 268 request.removeAttribute(name); 269 } 270 271 274 public Locale getLocale() { 275 return request.getLocale(); 276 } 277 278 281 public Enumeration getLocales() { 282 return request.getLocales(); 283 } 284 285 288 public boolean isSecure() { 289 return request.isSecure(); 290 } 291 292 295 public String getAuthType() { 296 return request.getAuthType(); 297 } 298 299 302 public String getContextPath() { 303 return request.getContextPath(); 304 } 305 306 310 public String getRemoteUser() { 311 return request.getRemoteUser(); 312 } 313 314 319 public boolean isUserInRole(String role) { 320 return request.isUserInRole(role); 321 } 322 323 326 public Principal getUserPrincipal() { 327 return request.getUserPrincipal(); 328 } 329 330 333 public String getRequestedSessionId() { 334 return request.getRequestedSessionId(); 335 } 336 337 342 public PortletSession getPortletSession(boolean create) { 343 return request.getPortletSession(create); 344 } 345 346 349 public PortletSession getPortletSession() { 350 return request.getPortletSession(); 351 } 352 353 356 public boolean isRequestedSessionIdValid() { 357 return request.isRequestedSessionIdValid(); 358 } 359 360 361 364 public InputStream getPortletInputStream() throws IOException { 365 return request.getPortletInputStream(); 366 } 367 368 371 public void setCharacterEncoding(String enc) throws UnsupportedEncodingException { 372 request.setCharacterEncoding(enc); 373 } 374 375 378 public Map getParameterMap() { 379 return request.getParameterMap(); 380 } 381 382 385 public PortalContext getPortalContext() { 386 return request.getPortalContext(); 387 } 388 389 392 public PortletMode getPortletMode() { 393 return request.getPortletMode(); 394 } 395 396 399 public PortletPreferences getPreferences() { 400 return request.getPreferences(); 401 } 402 403 406 public Enumeration getProperties(String name) { 407 return request.getProperties(name); 408 } 409 410 413 public String getProperty(String name) { 414 return request.getProperty(name); 415 } 416 417 420 public Enumeration getPropertyNames() { 421 return request.getPropertyNames(); 422 } 423 424 427 public String getResponseContentType() { 428 return request.getResponseContentType(); 429 } 430 431 434 public Enumeration getResponseContentTypes() { 435 return request.getResponseContentTypes(); 436 } 437 438 441 public WindowState getWindowState() { 442 return request.getWindowState(); 443 } 444 445 448 public boolean isPortletModeAllowed(PortletMode mode) { 449 return request.isPortletModeAllowed(mode); 450 } 451 452 455 public boolean isWindowStateAllowed(WindowState state) { 456 return request.isWindowStateAllowed(state); 457 } 458 } 459 | Popular Tags |