1 package jodd.bean.loaders; 2 3 import java.util.Enumeration; 4 5 import jodd.bean.BeanUtil; 6 import jodd.servlet.MultipartRequest; 7 import jodd.servlet.UploadedFile; 8 9 25 public class MultipartRequestLoader implements jodd.bean.Loader { 26 27 public void load(Object bean, Object request) { 28 if (request instanceof MultipartRequest) { 29 MultipartRequest mrequest = (MultipartRequest) request; 30 Enumeration paramNames = mrequest.getParameterNames(); 31 while (paramNames.hasMoreElements()) { 32 String paramName = (String) paramNames.nextElement(); 33 String[] paramValues = mrequest.getParameterValues(paramName); 34 if (paramValues == null) { 35 continue; 36 } 37 if (paramValues.length == 0) { 38 continue; 39 } 40 if (paramValues.length == 1) { 41 BeanUtil.setProperty(bean, paramName, paramValues[0]); 43 } else { 44 BeanUtil.setProperty(bean, paramName, paramValues); 46 } 47 } 48 49 paramNames = mrequest.getUploadedFileNames(); 50 while (paramNames.hasMoreElements()) { 51 String paramName = (String) paramNames.nextElement(); 52 UploadedFile uf = mrequest.getUploadedFile(paramName); 53 BeanUtil.setProperty(bean, paramName, uf); 54 } 55 } 56 return; 57 } 58 } 59 | Popular Tags |