%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.commons.jelly.tags.jetty.ResponseHeaderTag |
|
|
1 | /* |
|
2 | * Copyright 2002,2004 The Apache Software Foundation. |
|
3 | * |
|
4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 | * you may not use this file except in compliance with the License. |
|
6 | * You may obtain a copy of the License at |
|
7 | * |
|
8 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
9 | * |
|
10 | * Unless required by applicable law or agreed to in writing, software |
|
11 | * distributed under the License is distributed on an "AS IS" BASIS, |
|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
13 | * See the License for the specific language governing permissions and |
|
14 | * limitations under the License. |
|
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 | 3 | 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 | 3 | if (null == getName()) { |
48 | 0 | throw new JellyTagException("<responseHeader> tag must have a name"); |
49 | } |
|
50 | ||
51 | // get the response from the context |
|
52 | 3 | HttpResponse httpResponse = (HttpResponse) getContext().getVariable("response"); |
53 | 3 | if (null == httpResponse) { |
54 | 0 | throw new JellyTagException("HttpResponse variable not available in Jelly context"); |
55 | } |
|
56 | ||
57 | // if value is valid then set it |
|
58 | // otherwise remove the field |
|
59 | 3 | if (null != getValue()) { |
60 | 3 | httpResponse.setField(getName(), getValue()); |
61 | } else { |
|
62 | 0 | httpResponse.removeField(getName()); |
63 | } |
|
64 | ||
65 | 3 | } |
66 | ||
67 | //-------------------------------------------------------------------------- |
|
68 | // Property accessors/mutators |
|
69 | //-------------------------------------------------------------------------- |
|
70 | ||
71 | /** |
|
72 | * Getter for property context path. |
|
73 | * |
|
74 | * @return value of property context path. |
|
75 | */ |
|
76 | public String getName() { |
|
77 | 6 | 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 | 3 | _name = name; |
87 | 3 | } |
88 | ||
89 | /** |
|
90 | * Getter for property value. |
|
91 | * |
|
92 | * @return value of property value. |
|
93 | */ |
|
94 | public String getValue() { |
|
95 | 6 | 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 | 3 | _value = value; |
105 | 3 | } |
106 | ||
107 | } |
|
108 |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |