View Javadoc

1   /*
2    * $Header: /cvsroot/jdbforms/dbforms/src/org/dbforms/taglib/DbDeleteButtonTag.java,v 1.27 2006/01/13 13:38:50 hkollmann Exp $
3    * $Revision: 1.27 $
4    * $Date: 2006/01/13 13:38:50 $
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.apache.commons.logging.Log;
27  import org.apache.commons.logging.LogFactory;
28  
29  import org.dbforms.config.GrantedPrivileges;
30  import org.dbforms.config.ResultSetVector;
31  
32  import org.dbforms.util.MessageResources;
33  
34  import javax.servlet.http.HttpServletRequest;
35  import javax.servlet.jsp.JspException;
36  
37  
38  
39  /***
40   * <p>
41   * This tag renders a Delete Button
42   * </p>
43   *
44   * @author Joachim Peer
45   */
46  public class DbDeleteButtonTag extends AbstractDbBaseButtonTag
47     implements javax.servlet.jsp.tagext.TryCatchFinally {
48     private static Log logCat   = LogFactory.getLog(DbDeleteButtonTag.class);
49  
50     private String associatedRadio;
51     private String confirmMessage = null;
52  
53     /***
54      * DOCUMENT ME!
55      *
56      * @param associatedRadio DOCUMENT ME!
57      */
58     public void setAssociatedRadio(String associatedRadio) {
59        this.associatedRadio = associatedRadio;
60     }
61  
62  
63     /***
64      * DOCUMENT ME!
65      *
66      * @return DOCUMENT ME!
67      */
68     public String getAssociatedRadio() {
69        return associatedRadio;
70     }
71  
72  
73     /***
74      * DOCUMENT ME!
75      *
76      * @param confirmMessage DOCUMENT ME!
77      */
78     public void setConfirmMessage(String confirmMessage) {
79        this.confirmMessage = confirmMessage;
80     }
81  
82  
83     /***
84      * DOCUMENT ME!
85      *
86      * @return DOCUMENT ME!
87      */
88     public String getConfirmMessage() {
89        return confirmMessage;
90     }
91  
92  
93     /***
94      * DOCUMENT ME!
95      */
96     public void doFinally() {
97        confirmMessage  = null;
98        associatedRadio = null;
99        super.doFinally();
100    }
101 
102 
103    /***
104     * DOCUMENT ME!
105     *
106     * @return DOCUMENT ME!
107     *
108     * @throws javax.servlet.jsp.JspException DOCUMENT ME!
109     * @throws JspException DOCUMENT ME!
110     */
111    public int doStartTag() throws javax.servlet.jsp.JspException {
112       super.doStartTag();
113 
114       /*
115        * 2005-12-12
116        * Philip Grunikiewicz
117        * 
118        * Check table priviledges, if user is not allowed to delete table - don't show button
119        */
120       if ((getTable() != null) && !getTable().hasUserPrivileg((HttpServletRequest)this.pageContext.getRequest(), GrantedPrivileges.PRIVILEG_DELETE)){
121     	  return SKIP_BODY; 
122       }
123 
124       if (getConfirmMessage() != null) {
125          String onclick = (getOnClick() != null) ? getOnClick()
126                                                  : "";
127 
128          if (onclick.lastIndexOf(";") != (onclick.length() - 1)) {
129             onclick += ";"; // be sure javascript end with ";"
130          }
131 
132          String message = getConfirmMessage();
133 
134          if (getParentForm()
135                       .hasCaptionResourceSet()) {
136             try {
137                message = MessageResources.getMessage((HttpServletRequest) pageContext
138                                                      .getRequest(),
139                                                      getConfirmMessage());
140             } catch (Exception e) {
141                logCat.debug("confirm(" + getCaption() + ") Exception : "
142                             + e.getMessage());
143             }
144          }
145 
146          setOnClick(onclick + "return confirm('" + message + "');");
147       }
148 
149       if (getParentForm()
150                    .isFooterReached()
151                 && ResultSetVector.isNull(getParentForm().getResultSetVector())) {
152          // 20030521 HKK: Bug fixing, thanks to Michael Slack! 
153          return SKIP_BODY;
154       }
155 
156       try {
157          // first, determinate the name of the button tag
158          StringBuffer tagNameBuf = new StringBuffer("ac_delete");
159 
160          if (associatedRadio != null) {
161             tagNameBuf.append("ar");
162          }
163 
164          tagNameBuf.append("_");
165          tagNameBuf.append(getTable().getId());
166 
167          if (associatedRadio == null) {
168             tagNameBuf.append("_");
169             tagNameBuf.append(getParentForm().getPositionPath());
170          }
171 
172          // PG - Render the name unique
173          tagNameBuf.append("_");
174          tagNameBuf.append(getUniqueID());
175 
176          String tagName = tagNameBuf.toString();
177 
178          // then render it and its associtated data-tags
179          StringBuffer tagBuf = new StringBuffer();
180 
181          if (associatedRadio != null) {
182             tagBuf.append(getDataTag(tagName, "arname", associatedRadio));
183          }
184 
185          if (getFollowUp() != null) {
186             tagBuf.append(getDataTag(tagName, "fu", getFollowUp()));
187          }
188 
189          if (getFollowUpOnError() != null) {
190             tagBuf.append(getDataTag(tagName, "fue", getFollowUpOnError()));
191          }
192 
193          tagBuf.append(getButtonBegin());
194          tagBuf.append(" name=\"");
195          tagBuf.append(tagName);
196          tagBuf.append(getButtonEnd());
197 
198          pageContext.getOut()
199                     .write(tagBuf.toString());
200       } catch (java.io.IOException ioe) {
201          throw new JspException("IO Error: " + ioe.getMessage());
202       }
203 
204       if (getChoosenFlavor() == FLAVOR_MODERN) {
205          return EVAL_BODY_BUFFERED;
206       } else {
207          return SKIP_BODY;
208       }
209    }
210 }