KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > taglibs > dbtags > connection > DatabaseURLTag


1
2 /*
3  * Copyright 1999,2004 The Apache Software Foundation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 package org.apache.taglibs.dbtags.connection;
19
20 import javax.servlet.jsp.JspTagException JavaDoc;
21 import javax.servlet.jsp.tagext.BodyTagSupport JavaDoc;
22
23 /**
24  * <p>JSP tag url, sets the database URL for the enclosing connection
25  * tag. The URL is read from the indicated initParameter, if the
26  * parameter is set, or from the body of the tag if it is not.</p>
27  *
28  * <p>JSP Tag Lib Descriptor
29  * <pre>
30  * &lt;name>url&lt;/name>
31  * &lt;tagclass>org.apache.taglibs.dbtags.connection.DatabaseURLTag&lt;/tagclass>
32  * &lt;bodycontent>JSP&lt;/bodycontent>
33  * &lt;info>Sets the database URL of the enclosing connection tag
34  * according to the initParameter, if specified, or the body of
35  * the tag. The tag body will be trimmed.&lt;/info>
36  * &lt;attribute>
37  * &lt;name>initParameter&lt;/name>
38  * &lt;required>false&lt;/required>
39  * &lt;rtexprvalue>false&lt;/rtexprvalue>
40  * &lt;/attribute>
41  * </pre>
42  *
43  * @author Morgan Delagrange
44  * @see ConnectionTag
45  */

46 public class DatabaseURLTag extends BodyTagSupport JavaDoc {
47     
48   private String JavaDoc _url = null;
49
50   /**
51    * The name of the init parameter containing the database URL.
52    *
53    * @param paramName init parameter name
54    */

55   public void setInitParameter(String JavaDoc paramName) {
56     _url = pageContext.getServletContext().getInitParameter(paramName);
57   }
58
59   public int doEndTag() throws JspTagException JavaDoc {
60     try {
61       ConnectionTag connTag =
62         (ConnectionTag) findAncestorWithClass(this, Class.forName("org.apache.taglibs.dbtags.connection.ConnectionTag"));
63       
64       if (_url == null) {
65         _url = getBodyContent().getString().trim();
66       }
67       connTag.setUrl(_url);
68     }
69      catch (ClassNotFoundException JavaDoc e) {
70       throw new JspTagException JavaDoc(e.toString());
71     }
72     return EVAL_PAGE;
73   }
74
75   public void release() {
76     _url = null;
77   }
78   
79 }
80
Popular Tags