1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.jelly.tags.jetty;
18
19 import org.apache.commons.jelly.JellyTagException;
20 import org.apache.commons.jelly.TagSupport;
21 import org.apache.commons.jelly.XMLOutput;
22
23 import org.mortbay.http.HttpResponse;
24
25 /***
26 * Set a response header in the request handler of a Jetty http server
27 *
28 * @author rtl
29 */
30 public class ResponseHeaderTag extends TagSupport {
31
32 /*** parameter name */
33 private String _name;
34
35 /*** parameter value */
36 private String _value;
37
38 /***
39 * Perform the tag functionality. In this case, set a header in the
40 * http response found in the jelly context
41 *
42 * @param xmlOutput where to send output
43 * @throws Exception when an error occurs
44 */
45 public void doTag(XMLOutput xmlOutput) throws JellyTagException {
46
47 if (null == getName()) {
48 throw new JellyTagException("<responseHeader> tag must have a name");
49 }
50
51
52 HttpResponse httpResponse = (HttpResponse) getContext().getVariable("response");
53 if (null == httpResponse) {
54 throw new JellyTagException("HttpResponse variable not available in Jelly context");
55 }
56
57
58
59 if (null != getValue()) {
60 httpResponse.setField(getName(), getValue());
61 } else {
62 httpResponse.removeField(getName());
63 }
64
65 }
66
67
68
69
70
71 /***
72 * Getter for property context path.
73 *
74 * @return value of property context path.
75 */
76 public String getName() {
77 return _name;
78 }
79
80 /***
81 * Setter for property context path.
82 *
83 * @param path New value of property context path.
84 */
85 public void setName(String name) {
86 _name = name;
87 }
88
89 /***
90 * Getter for property value.
91 *
92 * @return value of property value.
93 */
94 public String getValue() {
95 return _value;
96 }
97
98 /***
99 * Setter for property value.
100 *
101 * @param value New value of property value.
102 */
103 public void setValue(String value) {
104 _value = value;
105 }
106
107 }
108