KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > taglibs > scrape > HeaderTag


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.scrape;
18
19 //import java.util.*;
20
import javax.servlet.jsp.*;
21 import javax.servlet.jsp.tagext.*;
22
23 /**
24  * HeaderTag - JSP tag <b>Header</b> is used to set http headers.
25  *
26  * <tag>
27  * <name>header</name>
28  * <tagclass>org.apache.taglibs.scrape.HeaderTag</tagclass>
29  * <bodycontent>JSP</bodycontent>
30  * <info>Set an http header</info>
31  *
32  * <attribute>
33  * <name>name</name>
34  * <required>true</required>
35  * <rtexprval>false</rtexprval>
36  * </attribute>
37  * <attribute>
38  * <name>value</name>
39  * <required>false</required>
40  * <rtexprval>false</rtexprval>
41  * </attribute>
42  * </tag>
43  *
44  * @author Rich Catlett
45  *
46  * @version 1.0
47  *
48  */

49
50 public class HeaderTag extends BodyTagSupport {
51
52     /**
53      * name of header to be set
54      */

55     String JavaDoc name;
56     /**
57      * value of header to be set
58      */

59     String JavaDoc value = null;
60
61     /**
62      * implementation of the method from the tag interface that tells the JSP
63      * page what to do after the body of this tag
64      *
65      * @throws JSPException thrown when an error occurs while processing the
66      * body of this method
67      *
68      * @return SKIP_BODY int telling the tag handler to not evaluate the body
69      * of this tag again
70      *
71      */

72     public final int doAfterBody() throws JspException {
73
74     // parent tag must be a PageTag, gives access to methods in parent
75
PageTag myparent = (PageTag)findAncestorWithClass(this, PageTag.class);
76
77     if (myparent == null) {
78         throw new JspException("header tag not nested within Page tag");
79         }
80         BodyContent body = getBodyContent();
81         if (value == null ) {
82             value = body.getString().trim();
83         }
84         // Clear the body since we only used it as input for the header value
85
body.clearBody();
86         if (value == null) {
87             throw new JspException("The header tag is empty");
88         }
89         myparent.setHeader(name,value); // set header in parent tag
90
return SKIP_BODY;
91     }
92
93     /**
94      * set the name of the header to be set
95      *
96      * @param value string that is the name of the header to be set
97      *
98      */

99     public final void setName(String JavaDoc value) {
100     name = value;
101     }
102
103     /**
104      * set the value of the header to be set
105      *
106      * @param value string that the value of the header to be set
107      *
108      */

109     public final void setValue(String JavaDoc value) {
110     this.value = value;
111     }
112 }
113
Popular Tags