KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > taglibs > standard > tag > common > fmt > ParamSupport


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.standard.tag.common.fmt;
18
19 import javax.servlet.jsp.JspException JavaDoc;
20 import javax.servlet.jsp.JspTagException JavaDoc;
21 import javax.servlet.jsp.tagext.BodyTagSupport JavaDoc;
22 import javax.servlet.jsp.tagext.Tag JavaDoc;
23
24 import org.apache.taglibs.standard.resources.Resources;
25
26 /**
27  * Support for tag handlers for <param>, the message argument
28  * subtag in JSTL 1.0 which supplies an argument for parametric replacement
29  * to its parent <message> tag.
30  *
31  * @see MessageSupport
32  * @author Jan Luehe
33  */

34
35 public abstract class ParamSupport extends BodyTagSupport JavaDoc {
36
37     //*********************************************************************
38
// Protected state
39

40     protected Object JavaDoc value; // 'value' attribute
41
protected boolean valueSpecified; // status
42

43
44     //*********************************************************************
45
// Constructor and initialization
46

47     public ParamSupport() {
48     super();
49     init();
50     }
51
52     private void init() {
53     value = null;
54     valueSpecified = false;
55     }
56
57
58     //*********************************************************************
59
// Tag logic
60

61     // Supply our value to our parent <fmt:message> tag
62
public int doEndTag() throws JspException JavaDoc {
63     Tag JavaDoc t = findAncestorWithClass(this, MessageSupport.class);
64     if (t == null) {
65         throw new JspTagException JavaDoc(Resources.getMessage(
66                             "PARAM_OUTSIDE_MESSAGE"));
67     }
68     MessageSupport parent = (MessageSupport) t;
69
70     /*
71      * Get argument from 'value' attribute or body, as appropriate, and
72      * add it to enclosing <fmt:message> tag, even if it is null or equal
73      * to "".
74      */

75     Object JavaDoc input = null;
76         // determine the input by...
77
if (valueSpecified) {
78         // ... reading 'value' attribute
79
input = value;
80     } else {
81         // ... retrieving and trimming our body (TLV has ensured that it's
82
// non-empty)
83
input = bodyContent.getString().trim();
84     }
85     parent.addParam(input);
86
87     return EVAL_PAGE;
88     }
89
90     // Releases any resources we may have (or inherit)
91
public void release() {
92     init();
93     }
94 }
95
Popular Tags