KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > taglibs > response > AddHeaderTag


1 /*
2  * Copyright 1999,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.taglibs.response;
18
19 import java.util.*;
20 import javax.servlet.*;
21 import javax.servlet.http.*;
22 import javax.servlet.jsp.*;
23 import javax.servlet.jsp.tagext.*;
24
25 /**
26  * JSP Tag <b>addHeader</b>, used to add a header for the HTTP Response.
27  * <p>
28  * The header value is set to the content of the body of the <b>addHeader</b> tag.
29  * <p>
30  * JSP Tag Lib Descriptor
31  * <p><pre>
32  * &lt;name&gt;addHeader&lt;/name&gt;
33  * &lt;tagclass&gt;org.apache.taglibs.response.AddHeaderTag&lt;/tagclass&gt;
34  * &lt;bodycontent&gt;JSP&lt;/bodycontent&gt;
35  * &lt;info&gt;Add a single HTTP header.&lt;/info&gt;
36  * &lt;attribute&gt;
37  * &lt;name&gt;name&lt;/name&gt;
38  * &lt;required&gt;true&lt;/required&gt;
39  * &lt;rtexprvalue&gt;false&lt;/rtexprvalue&gt;
40  * &lt;/attribute&gt;
41  * </pre>
42  *
43  * @author Glenn Nielsen
44  */

45
46 public class AddHeaderTag extends BodyTagSupport
47 {
48     private String JavaDoc name = null;
49
50     /**
51      * Method called at start of tag, just returns EVAL_BODY_TAG
52      *
53      * @return EVAL_BODY_TAG
54      */

55     public final int doStartTag() throws JspException
56     {
57     return EVAL_BODY_TAG;
58     }
59
60     /**
61      * Read the body of the addHeader tag to obtain the header value.
62      *
63      * @return SKIP_BODY
64      */

65     public final int doAfterBody() throws JspException
66     {
67         // Use the body of the tag as header value
68
BodyContent body = getBodyContent();
69         String JavaDoc s = body.getString().trim();
70         // Clear the body since we only used it as input for the header
71
// value
72
body.clearBody();
73
74     ((HttpServletResponse)pageContext.getResponse()).addHeader(name,s);
75         return SKIP_BODY;
76     }
77
78     /**
79      * Required attribute, name of the header.
80      *
81      * @param String name
82      */

83     public final void setName(String JavaDoc nam)
84     {
85     name = nam;
86     }
87
88 }
89
Popular Tags