KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > magnolia > cms > beans > runtime > MultipartForm


1 /**
2  *
3  * Magnolia and its source-code is licensed under the LGPL.
4  * You may copy, adapt, and redistribute this file for commercial or non-commercial use.
5  * When copying, adapting, or redistributing this document in keeping with the guidelines above,
6  * you are required to provide proper attribution to obinary.
7  * If you reproduce or distribute the document without making any substantive modifications to its content,
8  * please use the following attribution line:
9  *
10  * Copyright 1993-2005 obinary Ltd. (http://www.obinary.com) All rights reserved.
11  *
12  */

13 package info.magnolia.cms.beans.runtime;
14
15 import java.io.File JavaDoc;
16 import java.util.Hashtable JavaDoc;
17 import java.util.Map JavaDoc;
18
19 import org.apache.commons.lang.StringUtils;
20
21
22 /**
23  * @author Sameer Charles
24  * @version 1.1
25  */

26 public class MultipartForm {
27
28     /**
29      * The name of the request attribute containing a MultipartForm instance.
30      */

31     public static final String JavaDoc REQUEST_ATTRIBUTE_NAME = "multipartform"; //$NON-NLS-1$
32

33     private Map JavaDoc parameters;
34
35     private Map JavaDoc documents;
36
37     private Map JavaDoc parameterList;
38
39     public MultipartForm() {
40         this.parameters = new Hashtable JavaDoc();
41         this.documents = new Hashtable JavaDoc();
42         this.parameterList = new Hashtable JavaDoc();
43     }
44
45     public void addParameter(String JavaDoc name, Object JavaDoc value) {
46         this.parameters.put(name, value);
47     }
48
49     public void removeParameter(String JavaDoc name) {
50         this.parameters.remove(name);
51     }
52
53     public Map JavaDoc getParameters() {
54         return this.parameters;
55     }
56
57     public String JavaDoc getParameter(String JavaDoc name) {
58         try {
59             return (String JavaDoc) this.parameters.get(name);
60         }
61         catch (Exception JavaDoc e) {
62             return null;
63         }
64     }
65
66     public String JavaDoc[] getParameterValues(String JavaDoc name) {
67         try {
68             return ((String JavaDoc[]) this.parameterList.get(name));
69         }
70         catch (Exception JavaDoc e) {
71             return null;
72         }
73     }
74
75     public void addparameterValues(String JavaDoc name, String JavaDoc[] values) {
76         this.parameterList.put(name, values);
77     }
78
79     public void addDocument(String JavaDoc atomName, String JavaDoc fileName, String JavaDoc 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, ".")) { //$NON-NLS-1$
88
document.setExtention(StringUtils.EMPTY);
89             document.setFileName(fileName);
90         }
91         else {
92             document.setExtention(StringUtils.substringAfterLast(fileName, ".")); //$NON-NLS-1$
93
document.setFileName(StringUtils.substringBeforeLast(fileName, ".")); //$NON-NLS-1$
94
}
95         this.documents.put(atomName, document);
96     }
97
98     public Document getDocument(String JavaDoc name) {
99         return (Document) this.documents.get(name);
100     }
101
102     public Map JavaDoc getDocuments() {
103         return this.documents;
104     }
105 }
106
Popular Tags