View Javadoc

1   /*
2    * $Header: /cvsroot/jdbforms/dbforms/src/org/dbforms/taglib/DbBaseHandlerFactory.java,v 1.5 2005/11/28 21:10:56 hkollmann Exp $
3    * $Revision: 1.5 $
4    * $Date: 2005/11/28 21:10:56 $
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.PageContextBuffer;
27  
28  import javax.servlet.Servlet;
29  import javax.servlet.jsp.JspException;
30  import javax.servlet.jsp.PageContext;
31  import javax.servlet.jsp.tagext.BodyTagSupport;
32  import javax.servlet.jsp.tagext.Tag;
33  
34  
35  
36  /***
37   * Factory class to render buttons. Can be used to include a button into
38   * another tag.  see DbFilterTag for example
39   *
40   * @author Henner Kollmann
41   */
42  public class DbBaseHandlerFactory {
43     private AbstractDbBaseHandlerTag  tag;
44     private PageContextBuffer pageContext;
45  
46     /***
47      * Creates a new DbBaseButtonFactory object.
48      *
49      * @param parentContext parentContext to send to new tag
50      * @param parent parent tag to send to new tag
51      * @param clazz the button class to generate
52      *
53      * @throws JspException exception
54      */
55     public DbBaseHandlerFactory(PageContext    parentContext,
56                                 BodyTagSupport parent,
57                                 Class          clazz) throws JspException {
58        try {
59           tag         = (AbstractDbBaseHandlerTag) clazz.newInstance();
60           pageContext = new PageContextBuffer();
61           pageContext.initialize((Servlet) parentContext.getPage(),
62                                  parentContext.getRequest(),
63                                  parentContext.getResponse(), null, true, 0, true);
64           tag.setPageContext(pageContext);
65           tag.setParent(parent);
66        } catch (Exception e) {
67           throw new JspException(e);
68        }
69     }
70  
71     /***
72      * gets the generated button tag
73      *
74      * @return the button tag
75      */
76     public AbstractDbBaseHandlerTag getTag() {
77        return tag;
78     }
79  
80  
81     /***
82      * renders the generated button tag into StringBuffer
83      *
84      * @return the StringBuffer
85      *
86      * @throws JspException thrown exception
87      */
88     public StringBuffer render() throws JspException {
89        if (tag.doStartTag() != Tag.SKIP_BODY) {
90           tag.doEndTag();
91        }
92  
93        return pageContext.getBuffer();
94     }
95  }