View Javadoc

1   /*
2    * $Header: /cvsroot/jdbforms/dbforms/src/org/dbforms/taglib/DbRedirectURLTag.java,v 1.4 2006/01/13 13:38:51 hkollmann Exp $
3    * $Revision: 1.4 $
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.apache.commons.logging.Log;
27  import org.apache.commons.logging.LogFactory;
28  
29  import javax.servlet.http.HttpServletResponse;
30  import javax.servlet.jsp.JspException;
31  
32  
33  
34  /***
35   * <p>
36   * the 3 examples below produce all the same result
37   * </p>
38   *
39   * <p>
40   * &lt;linkURL href="customer.jsp" table="customer" position="1:2:12-3:4:1992"
41   * /&gt;
42   * </p>
43   *
44   * <p>
45   * &lt;linkURL href="customer.jsp" table="customer" position="&lt;%= currentKey
46   * %&gt;" /&gt;
47   * </p>
48   *
49   * <p>
50   * &lt;linkURL href="customer.jsp" table="customer" /&gt; &lt;position
51   * fieldName="id" value="103" /&gt; &lt;position fieldName="cust_lang"
52   * value="2" /&gt; &lt;/linkURL&gt;
53   * </p>
54   *
55   * <p>
56   * result (off course without the line feeds)
57   * </p>
58   * <pre>/servlet/control?
59   * ac_goto_x=t&
60   * data_ac_goto_x_fu=/customer.jsp&
61   * data_ac_goto_x_destTable=17&
62   * data_ac_goto_x_destPos=103~2</pre>
63   *
64   * <p>
65   * Use it like this:
66   * </p>
67   * <pre><a href="&lt;linkURL href="customer.jsp" tableName="customer" position="103~2" /&gt;"> some text </a></pre>
68   *
69   * @author Neal Katz , based on work from Joachim Peer
70   */
71  public class DbRedirectURLTag extends DbLinkURLTag
72     implements javax.servlet.jsp.tagext.TryCatchFinally {
73     private static Log logCat = LogFactory.getLog(DbRedirectURLTag.class.getName());
74  
75     /***
76      * DOCUMENT ME!
77      *
78      * @return DOCUMENT ME!
79      *
80      * @throws JspException thrown when error occurs in processing the body of
81      *         this method
82      */
83     public int doBodyEndTag() throws javax.servlet.jsp.JspException {
84        return super.doBodyEndTag();
85     }
86  
87  
88     /***
89      * DOCUMENT ME!
90      *
91      * @return DOCUMENT ME!
92      *
93      * @throws JspException thrown when error occurs in processing the body of
94      *         this method
95      */
96     public int doEndTag() throws javax.servlet.jsp.JspException {
97        try {
98           HttpServletResponse response = (HttpServletResponse) pageContext
99                                          .getResponse();
100          String              s = makeUrl();
101          s = response.encodeURL(s);
102          response.sendRedirect(s);
103       } catch (java.io.IOException ioe) {
104          throw new JspException("IO Error: " + ioe.getMessage());
105       } catch (Exception e) {
106          throw new JspException("Error: " + e.getMessage());
107       }
108 
109       return SKIP_PAGE;
110    }
111 
112 
113    /***
114     * DOCUMENT ME!
115     */
116    public void doFinally() {
117       logCat.info("doFinally called");
118       super.doFinally();
119    }
120 
121 
122    // logging category for this class
123 
124    /***
125     * DOCUMENT ME!
126     *
127     * @return DOCUMENT ME!
128     *
129     * @throws JspException thrown when error occurs in processing the body of
130     *         this method
131     * @throws IllegalArgumentException thrown when some parameters are missing.
132     */
133    public int doStartTag() throws javax.servlet.jsp.JspException {
134       return super.doStartTag();
135    }
136 }