1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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 }