View Javadoc

1   /*
2    * $Header: /cvsroot/jdbforms/dbforms/src/org/dbforms/taglib/DbNavNewButtonTag.java,v 1.30 2006/01/13 13:38:51 hkollmann Exp $
3    * $Revision: 1.30 $
4    * $Date: 2006/01/13 13:38:51 $
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.config.GrantedPrivileges;
27  import org.dbforms.config.ResultSetVector;
28  
29  import org.dbforms.event.eventtype.EventType;
30  
31  import org.dbforms.util.Util;
32  
33  import javax.servlet.http.HttpServletRequest;
34  import javax.servlet.jsp.JspException;
35  
36  
37  
38  /***
39   * this tag renders an "new"-button.
40   *
41   * @author Joachim Peer
42   */
43  public class DbNavNewButtonTag extends AbstractDbBaseButtonTag
44     implements javax.servlet.jsp.tagext.TryCatchFinally {
45     private String destTable;
46  
47     /*** Holds value of property showAlwaysInFooter. */
48     private String showAlwaysInFooter = "true";
49  
50     /***
51      * Sets the destTable
52      *
53      * @param destTable The destTable to set
54      */
55     public void setDestTable(String destTable) {
56        this.destTable = destTable;
57     }
58  
59  
60     /***
61      * Gets the destTable
62      *
63      * @return Returns a String
64      */
65     public String getDestTable() {
66        return destTable;
67     }
68  
69  
70     /***
71      * Setter for property showAlwaysInFooter.
72      *
73      * @param showAlwaysInFooter New value of property showAlwaysInFooter.
74      */
75     public void setShowAlwaysInFooter(String showAlwaysInFooter) {
76        this.showAlwaysInFooter = showAlwaysInFooter;
77     }
78  
79  
80     /***
81      * Getter for property showAlwaysInFooter.
82      *
83      * @return Value of property showAlwaysInFooter.
84      */
85     public String getShowAlwaysInFooter() {
86        return this.showAlwaysInFooter;
87     }
88  
89  
90     /***
91      * DOCUMENT ME!
92      */
93     public void doFinally() {
94        destTable          = null;
95        showAlwaysInFooter = "true";
96        super.doFinally();
97     }
98  
99  
100    /***
101     * DOCUMENT ME!
102     *
103     * @return DOCUMENT ME!
104     *
105     * @throws javax.servlet.jsp.JspException DOCUMENT ME!
106     * @throws JspException DOCUMENT ME!
107     */
108    public int doStartTag() throws javax.servlet.jsp.JspException {
109       super.doStartTag();
110       /*
111        * 2005-12-12
112        * Philip Grunikiewicz
113        * 
114        * Check table priviledges, if user is not allowed to insert into table - don't show button
115        */
116       if ((getTable() != null) && !getTable().hasUserPrivileg((HttpServletRequest)this.pageContext.getRequest(), GrantedPrivileges.PRIVILEG_INSERT)){
117     	  return SKIP_BODY; 
118       }
119 
120       if (getParentForm()
121                    .isFooterReached()
122                 && ResultSetVector.isNull(getParentForm().getResultSetVector())
123                 && !Util.getTrue(showAlwaysInFooter)) {
124          // 20030521 HKK: Bug fixing, thanks to Michael Slack! 
125          return SKIP_BODY;
126       }
127 
128       try {
129          StringBuffer tagBuf = new StringBuffer();
130 
131          // Allow navNewButton to specify a table for insertion other than the
132          // parent table. (Contrib. John Madsen)		  
133          int tableId = ((destTable != null) && (destTable.length() != 0))
134                        ? getConfig()
135                             .getTableByName(destTable)
136                             .getId()
137                        : getTable()
138                             .getId();
139 
140          String tagName = EventType.EVENT_NAVIGATION_TRANSFER_NEW + tableId
141                           + "_" + Integer.toString(getUniqueID());
142 
143          if (getFollowUp() != null) {
144             tagBuf.append(getDataTag(tagName, "fu", getFollowUp()));
145          }
146 
147          if (getFollowUpOnError() != null) {
148             tagBuf.append(getDataTag(tagName, "fue", getFollowUpOnError()));
149          }
150 
151          tagBuf.append(getButtonBegin());
152          tagBuf.append(" name=\"");
153          tagBuf.append(tagName);
154          tagBuf.append(getButtonEnd());
155 
156          pageContext.getOut()
157                     .write(tagBuf.toString());
158       } catch (java.io.IOException ioe) {
159          throw new JspException("IO Error: " + ioe.getMessage());
160       }
161 
162       if (getChoosenFlavor() == FLAVOR_MODERN) {
163          return EVAL_BODY_BUFFERED;
164       } else {
165          return SKIP_BODY;
166       }
167    }
168 }