View Javadoc

1   /*
2    * $Header: /cvsroot/jdbforms/dbforms/src/org/dbforms/taglib/DbBlobURLTag.java,v 1.14 2006/01/13 13:38:50 hkollmann Exp $
3    * $Revision: 1.14 $
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 javax.servlet.http.HttpServletRequest;
27  import javax.servlet.jsp.JspException;
28  import org.dbforms.util.Util;
29  
30  
31  
32  /***
33   * #fixme docu to come
34   *
35   * @author Joe Peer
36   *
37   */
38  public class DbBlobURLTag extends AbstractDbBaseHandlerTag
39     implements javax.servlet.jsp.tagext.TryCatchFinally {
40     /*** DOCUMENT ME! */
41     protected String nameField;
42  
43     /***
44      * DOCUMENT ME!
45      *
46      * @param nameField DOCUMENT ME!
47      */
48     public void setNameField(String nameField) {
49        this.nameField = nameField;
50     }
51  
52  
53     /***
54      * DOCUMENT ME!
55      *
56      * @return DOCUMENT ME!
57      */
58     public String getNameField() {
59        return nameField;
60     }
61  
62  
63  
64     // --------------------------------------------------------- Public Methods
65     // DbForms specific
66  
67     /***
68      * Description of the Method
69      *
70      * @return Description of the Return Value
71      *
72      * @exception javax.servlet.jsp.JspException Description of the Exception
73      */
74     public int doEndTag() throws javax.servlet.jsp.JspException {
75        try {
76           StringBuffer tagBuf = new StringBuffer(((HttpServletRequest) pageContext
77                                                   .getRequest()).getContextPath());
78  
79           tagBuf.append("/servlet/file?tf=")
80                 .append(getTableFieldCode())
81                 .append("&keyval=")
82                 .append(getKeyVal());
83  
84           // JPEer 03/2004
85           if (this.nameField != null) {
86              tagBuf.append("&nf=");
87              tagBuf.append(nameField);
88           }
89  
90           // append the defaultValue parameter;
91           if (getDefaultValue() != null) {
92              tagBuf.append("&defaultValue=" + getDefaultValue());
93  
94              //logCat.info("::doEndTag - defaultValue set to [" + defaultValue + "]");
95           }
96  
97  		 // fix issue where DbBlobURLTag does not work properly when more 
98  		 // than 1 connection defined in dbforms-config.xml . Nic Parise 10/2005
99  		 String dbConnectionName = getParentForm().getDbConnectionName();         
100 		 if (!Util.isNull(dbConnectionName)) {
101 	       tagBuf.append("&invname_"+getParentForm().getTable().getId());
102 		   tagBuf.append("=").append(dbConnectionName);
103 		 }
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       super.doFinally();
119    }
120 
121 
122    /***
123     * Gets the keyVal attribute of the DbBlobURLTag object
124     *
125     * @return The keyVal value
126     */
127    protected String getKeyVal() {
128       return getParentForm()
129                 .getTable()
130                 .getKeyPositionString(getParentForm().getResultSetVector());
131    }
132 
133 
134    // ------------------------------------------------------ Protected Methods
135    // DbForms specific
136 
137    /***
138     * Generates the decoded name.
139     *
140     * @return The tableFieldCode value
141     */
142    private String getTableFieldCode() {
143       StringBuffer buf = new StringBuffer();
144 
145       buf.append(getParentForm().getTable().getId());
146       buf.append("_");
147       buf.append(getField().getId());
148 
149       return buf.toString();
150    }
151 }