1 5 package com.opensymphony.webwork.dispatcher.multipart; 6 7 import com.opensymphony.webwork.config.Configuration; 8 import http.utils.multipartrequest.ServletMultipartRequest; 9 10 import javax.servlet.http.HttpServletRequest ; 11 import java.io.File ; 12 import java.io.IOException ; 13 import java.io.UnsupportedEncodingException ; 14 import java.util.ArrayList ; 15 import java.util.Collections ; 16 import java.util.Enumeration ; 17 import java.util.List ; 18 19 20 26 public class PellMultiPartRequest extends MultiPartRequest { 27 29 private ServletMultipartRequest multi; 30 31 33 41 public PellMultiPartRequest(HttpServletRequest servletRequest, String saveDir, int maxSize) throws IOException { 42 synchronized (this) { 45 setEncoding(); 46 multi = new ServletMultipartRequest(servletRequest, saveDir, maxSize); 47 } 48 } 49 50 52 public Enumeration getFileParameterNames() { 53 return multi.getFileParameterNames(); 54 } 55 56 public String [] getContentType(String fieldName) { 57 return new String []{multi.getContentType(fieldName)}; 58 } 59 60 public File [] getFile(String fieldName) { 61 return new File []{multi.getFile(fieldName)}; 62 } 63 64 public String [] getFileNames(String fieldName) { 65 66 return new String []{multi.getFile(fieldName).getName()}; 70 } 71 72 public String [] getFilesystemName(String fieldName) { 73 return new String []{multi.getFileSystemName(fieldName)}; 74 } 75 76 public String getParameter(String name) { 77 return multi.getURLParameter(name); 78 } 79 80 public Enumeration getParameterNames() { 81 return multi.getParameterNames(); 82 } 83 84 public String [] getParameterValues(String name) { 85 Enumeration enumeration = multi.getURLParameters(name); 86 87 if (!enumeration.hasMoreElements()) { 88 return null; 89 } 90 91 List values = new ArrayList (); 92 93 while (enumeration.hasMoreElements()) { 94 values.add(enumeration.nextElement()); 95 } 96 97 return (String []) values.toArray(new String [values.size()]); 98 } 99 100 public List getErrors() { 101 return Collections.EMPTY_LIST; 102 } 103 104 111 private static void setEncoding() { 112 String encoding = null; 113 114 try { 115 encoding = Configuration.getString("webwork.i18n.encoding"); 116 117 if (encoding != null) { 118 http.utils.multipartrequest.MultipartRequest.setEncoding(encoding); 122 } else { 123 http.utils.multipartrequest.MultipartRequest.setEncoding("UTF-8"); 124 } 125 } catch (IllegalArgumentException e) { 126 log.info("Could not get encoding property 'webwork.i18n.encoding' for file upload. Using system default"); 127 } catch (UnsupportedEncodingException e) { 128 log.error("Encoding " + encoding + " is not a valid encoding. Please check your webwork.properties file."); 129 } 130 } 131 } 132 | Popular Tags |