1 24 package org.riotfamily.forms.request; 25 26 import java.util.Collection ; 27 import java.util.Collections ; 28 import java.util.Iterator ; 29 import java.util.Map ; 30 31 import org.springframework.util.StringUtils; 32 import org.springframework.web.multipart.MultipartFile; 33 34 38 public class SimpleFormRequest implements FormRequest { 39 40 private Map params; 41 42 public SimpleFormRequest(Map params) { 43 this.params = params != null ? params : Collections.EMPTY_MAP; 44 } 45 46 public MultipartFile getFile(String name) { 47 Object value = params.get(name); 48 if (value instanceof MultipartFile) { 49 return (MultipartFile) value; 50 } 51 return null; 52 } 53 54 public String getParameter(String name) { 55 Object value = params.get(name); 56 if (value instanceof String []) { 57 String [] values = (String []) value; 58 return values.length > 0 ? values[0] : null; 59 } 60 if (value instanceof Collection ) { 61 Iterator it = ((Collection ) value).iterator(); 62 return it.hasNext() ? (String ) it.next() : null; 63 } 64 if (value instanceof String ) { 65 return (String ) value; 66 } 67 return null; 68 } 69 70 public String [] getParameterValues(String name) { 71 Object value = params.get(name); 72 if (value instanceof String []) { 73 return (String []) value; 74 } 75 if (value instanceof Collection ) { 76 return StringUtils.toStringArray((Collection ) value); 77 } 78 if (value instanceof String ) { 79 return new String [] { (String ) value }; 80 } 81 return null; 82 } 83 84 } 85 | Popular Tags |