KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > taglibs > regexp > TextTag


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.regexp;
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>text</b>, used to create a script variable for the
27  * text that a regexp will be used on.
28  * <p>
29  * The body of the tag is used as the text for a regular expression.
30  * <p>
31  * JSP Tag Lib Descriptor
32  * <p><pre>
33  * &lt;name&gt;regexp&lt;/name&gt;
34  * &lt;tagclass&gt;org.apache.taglibs.regexp.TextTag&lt;/tagclass&gt;
35  * &lt;bodycontent&gt;JSP&lt;/bodycontent&gt;
36  * &lt;info&gt;Create a script variable for a text string for use with a regular expression.&lt;/info&gt;
37  * &lt;attribute&gt;
38  * &lt;name&gt;id&lt;/name&gt;
39  * &lt;required&gt;true&lt;/required&gt;
40  * &lt;rtexprvalue&gt;false&lt;/rtexprvalue&gt;
41  * &lt;/attribute&gt;
42  * </pre>
43  *
44  * @see TextData
45  *
46  * @author Glenn Nielsen
47  */

48
49 public class TextTag extends BodyTagSupport
50 {
51
52     /**
53      * Returns EVAL_BODY_TAG so the body of the tag can be evaluated.
54      *
55      * @return EVAL_BODY_TAG
56      */

57     public final int doStartTag() throws JspException
58     {
59     return EVAL_BODY_TAG;
60     }
61
62     /**
63      * Read the body of the regexp tag to obtain a text string for
64      * use with a regular expression.
65      *
66      * @return SKIP_BODY
67      */

68     public final int doAfterBody() throws JspException
69     {
70     // Use the body of the tag as regular expression
71
BodyContent body = getBodyContent();
72     String JavaDoc text = body.getString();
73     // Clear the body since we only used it as input as the
74
// text string for a regular expression
75
body.clearBody();
76
77     // Make sure we have some text for the regexp
78
if( text == null )
79         throw new JspException(
80         "regexp tag text could not find a text string in body of tag.");
81
82     TextData td = new TextData(text);
83     pageContext.setAttribute(id,td,PageContext.PAGE_SCOPE);
84     return SKIP_BODY;
85     }
86
87 }
88
Popular Tags