KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > taglibs > standard > tag > common > sql > ParamTagSupport


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 package org.apache.taglibs.standard.tag.common.sql;
17
18 import javax.servlet.jsp.JspException JavaDoc;
19 import javax.servlet.jsp.JspTagException JavaDoc;
20 import javax.servlet.jsp.jstl.sql.SQLExecutionTag;
21 import javax.servlet.jsp.tagext.BodyTagSupport JavaDoc;
22
23 import org.apache.taglibs.standard.resources.Resources;
24
25
26 /**
27  * <p>Tag handler for &lt;Param&gt; in JSTL, used to set
28  * parameter values for a SQL statement.</p>
29  *
30  * @author Hans Bergsten
31  */

32
33 public abstract class ParamTagSupport extends BodyTagSupport JavaDoc {
34     protected Object JavaDoc value;
35
36     //*********************************************************************
37
// Tag logic
38

39     public int doEndTag() throws JspException JavaDoc {
40     SQLExecutionTag parent = (SQLExecutionTag)
41         findAncestorWithClass(this, SQLExecutionTag.class);
42     if (parent == null) {
43         throw new JspTagException JavaDoc(
44                 Resources.getMessage("SQL_PARAM_OUTSIDE_PARENT"));
45     }
46
47     Object JavaDoc paramValue = null;
48     if (value != null) {
49         paramValue = value;
50     }
51     else if (bodyContent != null) {
52         paramValue = bodyContent.getString().trim();
53         if (((String JavaDoc) paramValue).trim().length() == 0) {
54         paramValue = null;
55         }
56     }
57
58     parent.addSQLParameter(paramValue);
59     return EVAL_PAGE;
60     }
61 }
62
Popular Tags