1 13 package info.magnolia.cms.beans.runtime; 14 15 import java.io.File ; 16 import java.util.Hashtable ; 17 import java.util.Map ; 18 19 import org.apache.commons.lang.StringUtils; 20 21 22 26 public class MultipartForm { 27 28 31 public static final String REQUEST_ATTRIBUTE_NAME = "multipartform"; 33 private Map parameters; 34 35 private Map documents; 36 37 private Map parameterList; 38 39 public MultipartForm() { 40 this.parameters = new Hashtable (); 41 this.documents = new Hashtable (); 42 this.parameterList = new Hashtable (); 43 } 44 45 public void addParameter(String name, Object value) { 46 this.parameters.put(name, value); 47 } 48 49 public void removeParameter(String name) { 50 this.parameters.remove(name); 51 } 52 53 public Map getParameters() { 54 return this.parameters; 55 } 56 57 public String getParameter(String name) { 58 try { 59 return (String ) this.parameters.get(name); 60 } 61 catch (Exception e) { 62 return null; 63 } 64 } 65 66 public String [] getParameterValues(String name) { 67 try { 68 return ((String []) this.parameterList.get(name)); 69 } 70 catch (Exception e) { 71 return null; 72 } 73 } 74 75 public void addparameterValues(String name, String [] values) { 76 this.parameterList.put(name, values); 77 } 78 79 public void addDocument(String atomName, String fileName, String type, File file) { 80 if (StringUtils.isEmpty(fileName)) { 81 return; 82 } 83 Document document = new Document(); 84 document.setAtomName(atomName); 85 document.setType(type); 86 document.setFile(file); 87 if (!StringUtils.contains(fileName, ".")) { document.setExtention(StringUtils.EMPTY); 89 document.setFileName(fileName); 90 } 91 else { 92 document.setExtention(StringUtils.substringAfterLast(fileName, ".")); document.setFileName(StringUtils.substringBeforeLast(fileName, ".")); } 95 this.documents.put(atomName, document); 96 } 97 98 public Document getDocument(String name) { 99 return (Document) this.documents.get(name); 100 } 101 102 public Map getDocuments() { 103 return this.documents; 104 } 105 } 106 | Popular Tags |