1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.jelly.tags.http;
18
19 import org.apache.commons.jelly.JellyTagException;
20 import org.apache.commons.jelly.TagSupport;
21 import org.apache.commons.jelly.XMLOutput;
22 import org.apache.commons.httpclient.methods.multipart.StringPart;
23
24 /***
25 * A tag to hold a part of a multiPartPost
26 *
27 */
28 public class PartTag extends TagSupport {
29 /*** parameter name */
30 private String _name;
31 /*** parameter value */
32 private String _value;
33 /*** parameter type (like text/plain) */
34 private String _contentType = "text/plain";
35
36 /*** Creates a new instance of PartTag */
37 public PartTag() {
38 }
39
40 /***
41 * Extend StringPart so that I can specify the content type (ex: text/plain)
42 */
43 private class MyStringPart extends StringPart {
44 String _contentType;
45 public MyStringPart(String name, String value, String contentType) {
46 super(name, value, "utf-8");
47 _contentType=contentType;
48 }
49 public String getContentType() { return _contentType; }
50 }
51
52 /***
53 * Perform the tag functionality. In this case, store this parameter
54 * in the <mppost> tag above me
55 *
56 * @param xmlOutput where to send output
57 * @throws Exception when an error occurs
58 */
59 public void doTag(XMLOutput xmlOutput) throws JellyTagException {
60 MultipartPostTag http = (MultipartPostTag) findAncestorWithClass(MultipartPostTag.class);
61 StringPart sp = new MyStringPart(getName(), getValue(), getContentType());
62 http.addPart(sp);
63 invokeBody(xmlOutput);
64 }
65
66
67
68
69 /***
70 * Getter for property name.
71 *
72 * @return Value of property name.
73 */
74 public String getName() {
75 return _name;
76 }
77
78 /***
79 * Setter for property name.
80 *
81 * @param name New value of property name.
82 */
83 public void setName(String name) {
84 _name = name;
85 }
86
87 /***
88 * Getter for property value.
89 *
90 * @return Value of property value.
91 */
92 public String getValue() {
93 return _value;
94 }
95
96 /***
97 * Setter for property value.
98 *
99 * @param value New value of property value.
100 */
101 public void setValue(String value) {
102 _value = value;
103 }
104
105 /***
106 * Getter for property contentType.
107 *
108 * @return Value of contentType.
109 */
110 public String getContentType() {
111 return _contentType;
112 }
113
114 /***
115 * Setter for property contentType.
116 *
117 * @param value New value of contentType.
118 */
119 public void setContentType(String contentType) {
120 _contentType = contentType;
121 }
122
123 }