KickJava   Java API By Example, From Geeks To Geeks.

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


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 userid, sets the database user id for the
23  * enclosing connection tag. This tag is optional if the user name has
24  * been encoded inside the database URL, or if the database does not
25  * require a user name. The user name is read from the indicated
26  * initParameter, if the attribute is set, or from the body of the tag
27  * if it is not. The tag body <i>will</i> be trimmed.</p>
28  *
29  * <p>JSP Tag Lib Descriptor
30  * <pre>
31  * &lt;name>userId&lt;/name>
32  * &lt;tagclass>org.apache.taglibs.dbtags.connection.UserIdTag&lt;/tagclass>
33  * &lt;bodycontent>JSP&lt;/bodycontent>
34  * &lt;info>JSP tag userid, sets the database user id for the
35  * enclosing connection tag. This tag is optional if the user name has
36  * been encoded inside the database URL, or if the database does not
37  * require a user name. The user name is read from the indicated
38  * initParameter, if the attribute 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 UserIdTag extends BodyTagSupport JavaDoc {
52     
53   private String JavaDoc _userId = null;
54
55   /**
56    * The name of the init parameter containing the database user id.
57    *
58    * @param paramName database user id
59    */

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