KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dbforms > taglib > SetCustomFormatterTag


1 /*
2  * $Header: /cvsroot/jdbforms/dbforms/src/org/dbforms/taglib/SetCustomFormatterTag.java,v 1.6 2004/10/20 10:52:03 hkollmann Exp $
3  * $Revision: 1.6 $
4  * $Date: 2004/10/20 10:52:03 $
5  *
6  * DbForms - a Rapid Application Development Framework
7  * Copyright (C) 2001 Joachim Peer <joepeer@excite.com>
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22  */

23
24 package org.dbforms.taglib;
25
26 import org.dbforms.util.ICustomFormat;
27
28 import java.util.HashMap JavaDoc;
29
30 import javax.servlet.http.HttpSession JavaDoc;
31 import javax.servlet.jsp.JspException JavaDoc;
32
33 import org.dbforms.util.ReflectionUtil;
34
35 /**
36  * DOCUMENT ME!
37  *
38  * @author Neal Katz &lt;db:setCustomFormater name="foo" class="" arg=""
39  * reset="" &gt; arg and reset are optional
40  */

41 public class SetCustomFormatterTag extends TagSupportWithScriptHandler
42    implements javax.servlet.jsp.tagext.TryCatchFinally JavaDoc {
43    
44    static final String JavaDoc sessionKey = "dbforms.org.tag.CustomFormatterTag";
45    
46    Object JavaDoc arg = null;
47    String JavaDoc className = null;
48    String JavaDoc name = null;
49
50    /**
51     * optional argument passed to CustomFormatter instance init()
52     *
53     * @param obj
54     */

55    public void setArg(Object JavaDoc obj) {
56       this.arg = obj;
57    }
58
59
60    /**
61     * classname of a class implementing the CustomFormatter Interface
62     *
63     * @param className
64     */

65    public void setClassName(String JavaDoc className) {
66       this.className = className;
67    }
68
69
70    /**
71     * name to use, other tags will use this as the value for the
72     * customFormatter attribute
73     *
74     * @param name
75     */

76    public void setName(String JavaDoc name) {
77       this.name = name;
78    }
79
80
81    /* (non-Javadoc)
82     * @see javax.servlet.jsp.tagext.TryCatchFinally#doCatch(java.lang.Throwable)
83     */

84    public void doCatch(Throwable JavaDoc t) throws Throwable JavaDoc {
85       throw t;
86    }
87
88
89    /**
90     * DOCUMENT ME!
91     *
92     * @return DOCUMENT ME!
93     */

94    public int doEndTag() throws JspException JavaDoc {
95       if ((name != null) && (name.length() > 0)) {
96          HttpSession JavaDoc session = pageContext.getSession();
97          HashMap JavaDoc hm = (HashMap JavaDoc) session.getAttribute(sessionKey);
98          if (hm == null) {
99             hm = new HashMap JavaDoc();
100             session.setAttribute(sessionKey, hm);
101          }
102          try {
103             ICustomFormat cf = (ICustomFormat) hm.get(name);
104             if (cf == null) {
105                cf = (ICustomFormat) ReflectionUtil.newInstance(className);
106                cf.setArg(arg.toString());
107                hm.put(name, cf);
108             }
109          } catch (Exception JavaDoc e) {
110             throw new JspException JavaDoc(e.getLocalizedMessage());
111          }
112       }
113       return EVAL_PAGE;
114    }
115
116
117    /**
118     * DOCUMENT ME!
119     */

120    public void doFinally() {
121       this.arg = null;
122       this.className = null;
123       this.name = null;
124       super.doFinally();
125    }
126
127
128    /**
129     * DOCUMENT ME!
130     *
131     * @return DOCUMENT ME!
132     *
133     * @throws javax.servlet.jsp.JspException DOCUMENT ME!
134     */

135    public int doStartTag() throws javax.servlet.jsp.JspException JavaDoc {
136       return SKIP_BODY;
137    }
138 }
139
Popular Tags