KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > jstl > rt > CoreRedirectTag


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source 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, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  * Free SoftwareFoundation, Inc.
23  * 59 Temple Place, Suite 330
24  * Boston, MA 02111-1307 USA
25  *
26  * @author Scott Ferguson
27  */

28
29 package com.caucho.jstl.rt;
30
31 import com.caucho.jstl.NameValueTag;
32 import com.caucho.util.CharBuffer;
33 import com.caucho.util.L10N;
34
35 import javax.servlet.http.HttpServletResponse JavaDoc;
36 import javax.servlet.jsp.JspException JavaDoc;
37 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
38 import java.io.IOException JavaDoc;
39
40 public class CoreRedirectTag extends TagSupport JavaDoc implements NameValueTag {
41   private static L10N L = new L10N(CoreRedirectTag.class);
42   
43   private String JavaDoc _value;
44   private String JavaDoc _context;
45
46   private CharBuffer _url;
47
48   /**
49    * Sets the URL to be imported.
50    */

51   public void setURL(String JavaDoc value)
52   {
53     _value = value;
54   }
55   
56   /**
57    * Sets the external context for the import.
58    */

59   public void setContext(String JavaDoc context)
60   {
61     _context = context;
62   }
63
64   /**
65    * Adds a parameter.
66    */

67   public void addParam(String JavaDoc name, String JavaDoc value)
68   {
69     String JavaDoc encoding = this.pageContext.getResponse().getCharacterEncoding();
70     
71     CoreUrlTag.addParam(_url, name, value, encoding);
72   }
73
74   public int doStartTag() throws JspException JavaDoc
75   {
76     _url = CoreUrlTag.normalizeURL(pageContext, _value, _context);
77
78     return EVAL_BODY_INCLUDE;
79   }
80       
81   public int doEndTag() throws JspException JavaDoc
82   {
83     String JavaDoc value = CoreUrlTag.encodeURL(pageContext, _url);
84
85     try {
86       HttpServletResponse JavaDoc response;
87       ((HttpServletResponse JavaDoc) pageContext.getResponse()).sendRedirect(value);
88     } catch (IOException JavaDoc e) {
89       throw new JspException JavaDoc(e);
90     }
91
92     return SKIP_PAGE;
93   }
94 }
95
Popular Tags