~ubuntu-branches/ubuntu/intrepid/tomcat5.5/intrepid

« back to all changes in this revision

Viewing changes to jasper/src/share/org/apache/jasper/tagplugins/jstl/core/Redirect.java

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2006-09-27 11:19:17 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20060927111917-wov6fmkz3x6rsl68
Tags: 5.5.17-1ubuntu1
(Build-) depend on libmx4j-java (>= 3.0).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 1999,2005 The Apache Software Foundation.
 
3
 * 
 
4
 * Licensed under the Apache License, Version 2.0 (the "License");
 
5
 * you may not use this file except in compliance with the License.
 
6
 * You may obtain a copy of the License at
 
7
 * 
 
8
 *      http://www.apache.org/licenses/LICENSE-2.0
 
9
 * 
 
10
 * Unless required by applicable law or agreed to in writing, software
 
11
 * distributed under the License is distributed on an "AS IS" BASIS,
 
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
13
 * See the License for the specific language governing permissions and
 
14
 * limitations under the License.
 
15
 */
 
16
 
 
17
 
 
18
package org.apache.jasper.tagplugins.jstl.core;
 
19
 
 
20
import org.apache.jasper.compiler.tagplugin.TagPlugin;
 
21
import org.apache.jasper.compiler.tagplugin.TagPluginContext;
 
22
 
 
23
public class Redirect implements TagPlugin {
 
24
    
 
25
    public void doTag(TagPluginContext ctxt) {
 
26
        
 
27
        //flag for the existence of the "context"
 
28
        boolean hasContext = ctxt.isAttributeSpecified("context");
 
29
        
 
30
        //names of the temp variables
 
31
        String urlName = ctxt.getTemporaryVariableName();
 
32
        String contextName = ctxt.getTemporaryVariableName();
 
33
        String baseUrlName = ctxt.getTemporaryVariableName();
 
34
        String resultName = ctxt.getTemporaryVariableName();
 
35
        String responseName = ctxt.getTemporaryVariableName();
 
36
        
 
37
        //get context
 
38
        ctxt.generateJavaSource("String " + contextName + " = null;");
 
39
        if(hasContext){
 
40
            ctxt.generateJavaSource(contextName + " = ");
 
41
            ctxt.generateAttribute("context");
 
42
            ctxt.generateJavaSource(";");
 
43
        }
 
44
        
 
45
        //get the url
 
46
        ctxt.generateJavaSource("String " + urlName + " = ");
 
47
        ctxt.generateAttribute("url");
 
48
        ctxt.generateJavaSource(";");
 
49
        
 
50
        //get the raw url according to "url" and "context"
 
51
        ctxt.generateJavaSource("String " + baseUrlName + " = " +
 
52
                "org.apache.jasper.tagplugins.jstl.Util.resolveUrl(" + urlName + ", " + contextName + ", pageContext);");
 
53
        ctxt.generateJavaSource("pageContext.setAttribute" +
 
54
                "(\"url_without_param\", " + baseUrlName + ");");
 
55
        
 
56
        //add params
 
57
        ctxt.generateBody();
 
58
        
 
59
        ctxt.generateJavaSource("String " + resultName + " = " +
 
60
        "(String)pageContext.getAttribute(\"url_without_param\");");
 
61
        ctxt.generateJavaSource("pageContext.removeAttribute" +
 
62
        "(\"url_without_param\");");
 
63
        
 
64
        //get the response object
 
65
        ctxt.generateJavaSource("HttpServletResponse " + responseName + " = " +
 
66
        "((HttpServletResponse) pageContext.getResponse());");
 
67
        
 
68
        //if the url is relative, encode it
 
69
        ctxt.generateJavaSource("if(!org.apache.jasper.tagplugins.jstl.Util.isAbsoluteUrl(" + resultName + ")){");
 
70
        ctxt.generateJavaSource("    " + resultName + " = "
 
71
                + responseName + ".encodeRedirectURL(" + resultName + ");");
 
72
        ctxt.generateJavaSource("}");
 
73
        
 
74
        //do redirect
 
75
        ctxt.generateJavaSource("try{");
 
76
        ctxt.generateJavaSource("    " + responseName + ".sendRedirect(" + resultName + ");");
 
77
        ctxt.generateJavaSource("}catch(java.io.IOException ex){");
 
78
        ctxt.generateJavaSource("    throw new JspTagException(ex.toString(), ex);");
 
79
        ctxt.generateJavaSource("}");
 
80
    }
 
81
    
 
82
}