KickJava   Java API By Example, From Geeks To Geeks.

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


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.dbtags.connection;
17
18 import javax.servlet.jsp.JspTagException JavaDoc;
19 import javax.servlet.jsp.tagext.BodyTagSupport JavaDoc;
20
21 /**
22  * <p>JSP tag password, sets the password for the
23  * enclosing connection tag. This tag is optional if the password has
24  * been encoded inside the database URL, or if the database does not
25  * require a password. The password is read from the indicated
26  * initParameter, if the parameter is set, or from the body of the tag
27  * if it is not.</p>
28  *
29  * <p>JSP Tag Lib Descriptor
30  * <pre>
31  * &lt;name>password&lt;/name>
32  * &lt;tagclass>org.apache.taglibs.dbtags.connection.PasswordTag&lt;/tagclass>
33  * &lt;bodycontent>JSP&lt;/bodycontent>
34  * &lt;info>JSP tag password, sets the password for the
35  * enclosing connection tag. This tag is optional if the password has
36  * been encoded inside the database URL, or if the database does not
37  * require a password. The password is read from the indicated
38  * initParameter, if the parameter is set, or from the body of the tag
39  * if it is not. The tag body will be trimmed.&lt;/info>
40  * &lt;attribute>
41  * &lt;name>initParameter&lt;/name>
42  * &lt;required>false&lt;/required>
43  * &lt;rtexprvalue>false&lt;/rtexprvalue>
44  * &lt;/attribute>
45  * </pre>
46  *
47  * @author Morgan Delagrange
48  * @see ConnectionTag
49  * @see DatabaseURLTag
50  */

51 public class PasswordTag extends BodyTagSupport JavaDoc {
52     
53   private String JavaDoc _password = null;
54
55   /**
56    * The name of the init parameter containing the database password.
57    *
58    * @param paramName database password
59    */

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