1 64 65 package com.jcorporate.expresso.core.misc.upload; 66 67 120 122 import javax.servlet.http.HttpServletRequest ; 123 import java.util.Enumeration ; 124 import java.util.Vector ; 125 126 127 130 154 public class DefaultParameterParser 155 extends BaseValueParser 156 implements ParameterParser { 157 158 161 private HttpServletRequest request = null; 162 163 166 private byte[] uploadData = null; 167 private Vector fileItems = null; 168 169 176 public DefaultParameterParser() { 177 super(); 178 } 179 180 181 public boolean hasFileItem(String paramName) { 182 if (fileItems == null) { 183 return false; 184 } 185 186 String oneName = null; 187 188 for (Enumeration e = fileItems.elements(); e.hasMoreElements();) { 189 oneName = (String ) e.nextElement(); 190 191 if (oneName.equals(paramName)) { 192 return true; 193 } 194 } 195 196 return false; 197 } 198 199 209 public DefaultParameterParser(String characterEncoding) { 210 super(characterEncoding); 211 } 212 213 216 public void dispose() { 217 this.request = null; 218 this.uploadData = null; 219 super.dispose(); 220 } 221 222 227 public HttpServletRequest getRequest() { 228 return this.request; 229 } 230 231 public void setRequest(HttpServletRequest req) { 232 } 233 246 373 378 public void setUploadData(byte[] uploadData) { 379 this.uploadData = uploadData; 380 } 381 382 387 public byte[] setUploadData() { 388 return this.uploadData; 389 } 390 391 400 public void append(String name, FileItem value) { 401 FileItem[] items = this.getFileItems(name); 402 403 if (items == null) { 404 items = new FileItem[1]; 405 items[0] = value; 406 parameters.put(convert(name), items); 407 } else { 408 FileItem[] newItems = new FileItem[items.length + 1]; 409 System.arraycopy(items, 0, newItems, 0, items.length); 410 newItems[items.length] = value; 411 parameters.put(convert(name), newItems); 412 } 413 if (fileItems == null) { 414 fileItems = new Vector (); 415 } 416 417 fileItems.addElement(name); 418 } 419 420 427 public FileItem getFileItem(String name) { 428 try { 429 FileItem value = null; 430 Object object = parameters.get(convert(name)); 431 432 if (object != null) { 433 value = ((FileItem[]) object)[0]; 434 } 435 436 return value; 437 } catch (ClassCastException e) { 438 return null; 439 } 440 } 441 442 450 public FileItem[] getFileItems(String name) { 451 try { 452 return (FileItem[]) parameters.get(convert(name)); 453 } catch (ClassCastException e) { 454 return null; 455 } 456 } 457 } | Popular Tags |