View Javadoc

1   /*
2    * $Id: BaseXButtonTag.java 130 2004-11-28 13:00:44Z josem $
3    *
4    * Tarsis
5    * Copyright (C) 2002 Talika Open Source Group
6    *
7    * This program is free software; you can redistribute it and/or modify
8    * it under the terms of the GNU General Public License as published by
9    * the Free Software Foundation; either version 2 of the License, or
10   * (at your option) any later version.
11   *
12   * This program is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   * GNU General Public License for more details.
16   *
17   * You should have received a copy of the GNU General Public License
18   * along with this program; if not, write to the Free Software
19   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20   *
21   */
22  
23  package org.talika.tarsis.taglib.form;
24  
25  import java.io.IOException;
26  
27  import javax.servlet.jsp.JspException;
28  
29  /**
30   * Base implementation for button form control tags.
31   *
32   * @author  Jose M. Palomar
33   * @version $Revision: 130 $
34   */
35  public class BaseXButtonTag extends BaseControlTag {
36  
37      // Fields
38      /**
39       * Button type.
40       */
41      private String type;
42  
43      // Constructors
44      /**
45       * Creates a new <code>BaseXButtonTag</code> object.
46       */
47      public BaseXButtonTag() {
48      }
49  
50      /**
51       * Creates a new <code>BaseXButtonTag</code> object for given type.
52       *
53       * @param type String button type.
54       */
55      protected BaseXButtonTag(String type) {
56          this.type = type;
57      }
58  
59      // Methods
60      /**
61       * Process the start tag for this instance.
62       *
63       * @return int EVAL_BODY_INCLUDE.
64       * @throws JspException if somethign goes wrong during processing.
65       * @see javax.servlet.jsp.tagext.Tag#doStartTag()
66       */
67      public int doStartTag() throws JspException {
68  
69          try {
70              pageContext.getOut().print(renderButtonStartElement());
71          }
72          catch (IOException ioe) {
73              // Bad luck
74          }
75  
76          return EVAL_BODY_INCLUDE;
77  
78      }
79  
80      /**
81       * Process the end tag for this instance.
82       *
83       * @return int EVAL_PAGE.
84       * @throws JspException if somethign goes wrong during processing.
85       * @see javax.servlet.jsp.tagext.Tag#doEndTag()
86       */
87      public int doEndTag() throws JspException {
88  
89          try {
90              pageContext.getOut().print(renderButtonEndElement());
91          }
92          catch (IOException ioe) {
93              // Bad luck
94          }
95  
96          return EVAL_PAGE;
97      }
98  
99      // Renderer
100     /**
101      * Renders button start tag.
102      *
103      * @return String a string with rendered button start tag.
104      */
105     public final String renderButtonStartElement() {
106 
107         StringBuffer element = new StringBuffer();
108 
109         element.append("<button");
110 
111         element.append(baseAttributes());
112 
113         element.append(" type=\"");
114         element.append(type);
115         element.append("\"");
116 
117         element.append(controlName());
118         element.append(controlValue());
119         element.append(controlAttributes());
120         element.append(controlEvents());
121         element.append(intrinsicEvents());
122 
123         element.append(">");
124 
125         return element.toString();
126 
127     }
128 
129     /**
130      * Renders button end tag.
131      *
132      * @return String a string with rendered button end tag.
133      */
134     public final String renderButtonEndElement() {
135         return "</button>";
136     }
137 
138 }