View Javadoc

1   /*
2    * $Header: /cvsroot/jdbforms/dbforms/src/org/dbforms/taglib/DbFileTag.java,v 1.20 2006/01/13 13:38:50 hkollmann Exp $
3    * $Revision: 1.20 $
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 javax.servlet.jsp.*;
30  
31  
32  
33  /***
34   * <p>
35   * This tag renders a HTML TextArea - Element
36   * </p>
37   * this tag renders a dabase-datadriven textArea, which is an active element -
38   * the user can change data
39   *
40   * @author Joachim Peer
41   */
42  public class DbFileTag extends AbstractDbBaseInputTag
43     implements javax.servlet.jsp.tagext.TryCatchFinally {
44     private static Log logCat = LogFactory.getLog(DbFileTag.class.getName());
45     private String     accept;
46  
47     /***
48      * DOCUMENT ME!
49      *
50      * @param accept DOCUMENT ME!
51      */
52     public void setAccept(String accept) {
53        this.accept = accept;
54     }
55  
56  
57     /***
58      * DOCUMENT ME!
59      *
60      * @return DOCUMENT ME!
61      */
62     public String getAccept() {
63        return accept;
64     }
65  
66  
67     /***
68      * DOCUMENT ME!
69      *
70      * @return DOCUMENT ME!
71      *
72      * @throws javax.servlet.jsp.JspException DOCUMENT ME!
73      * @throws JspException DOCUMENT ME!
74      */
75     public int doEndTag() throws javax.servlet.jsp.JspException {
76        try {
77           StringBuffer tagBuf = new StringBuffer();
78  
79           if (hasReadOnlySet() || getParentForm()
80                                            .hasReadOnlySet()) {
81              // if read-only, remove the browse button (for netscape problem)
82              tagBuf.append("<input type=\"text\"");
83           } else {
84              tagBuf.append("<input type=\"file\"");
85           }
86  
87           tagBuf.append(prepareName());
88  
89           if (accept != null) {
90              tagBuf.append(" accept=\"");
91              tagBuf.append(accept);
92              tagBuf.append("\"");
93           }
94  
95           tagBuf.append(prepareSize());
96           tagBuf.append(prepareKeys());
97           tagBuf.append(prepareStyles());
98           tagBuf.append(prepareEventHandlers());
99           tagBuf.append("/>");
100 
101          // Writes out the old field value
102          // Joe Peer: this is deadly for FileTags
103          //writeOutSpecialValues();
104          pageContext.getOut()
105                     .write(tagBuf.toString());
106       } catch (java.io.IOException ioe) {
107          throw new JspException("IO Error: " + ioe.getMessage());
108       }
109 
110       return EVAL_PAGE;
111    }
112 
113 
114    /***
115     * DOCUMENT ME!
116     */
117    public void doFinally() {
118       accept = null;
119       super.doFinally();
120    }
121 
122 
123    /***
124     * DOCUMENT ME!
125     *
126     * @return DOCUMENT ME!
127     *
128     * @throws javax.servlet.jsp.JspException DOCUMENT ME!
129     * @throws JspException DOCUMENT ME!
130     */
131    public int doStartTag() throws javax.servlet.jsp.JspException {
132       super.doStartTag();
133 
134       if (!getParentForm()
135                     .hasMultipartSet()) {
136          logCat.warn("DbFileTag is used but DbFormTag.multipart is not set (FALSE)");
137          throw new JspException("DbFileTag is used but DbFormTag.multipart is not set (it is set to \"FALSE\"). you must set it to \"TRUE\" to enable file uploads!");
138       }
139 
140       return SKIP_BODY;
141    }
142 }