1 /*
2 * $Header: /u/cvs/Projects/EnhydraOrg/enhydra3x/Enhydra/modules/Tomcat/src/share/org/apache/jasper/compiler/IncludeGenerator.java,v 1.2 2000/02/26 02:31:59 shawn Exp $
3 * $Revision: 1.2 $
4 * $Date: 2000/02/26 02:31:59 $
5 *
6 * ====================================================================
7 *
8 * The Apache Software License, Version 1.1
9 *
10 * Copyright (c) 1999 The Apache Software Foundation. All rights
11 * reserved.
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
15 * are met:
16 *
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 *
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in
22 * the documentation and/or other materials provided with the
23 * distribution.
24 *
25 * 3. The end-user documentation included with the redistribution, if
26 * any, must include the following acknowlegement:
27 * "This product includes software developed by the
28 * Apache Software Foundation (http://www.apache.org/)."
29 * Alternately, this acknowlegement may appear in the software itself,
30 * if and wherever such third-party acknowlegements normally appear.
31 *
32 * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
33 * Foundation" must not be used to endorse or promote products derived
34 * from this software without prior written permission. For written
35 * permission, please contact apache@apache.org.
36 *
37 * 5. Products derived from this software may not be called "Apache"
38 * nor may "Apache" appear in their names without prior written
39 * permission of the Apache Group.
40 *
41 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
42 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
43 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
44 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
45 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
46 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
47 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
48 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
49 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
50 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
51 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
52 * SUCH DAMAGE.
53 * ====================================================================
54 *
55 * This software consists of voluntary contributions made by many
56 * individuals on behalf of the Apache Software Foundation. For more
57 * information on the Apache Software Foundation, please see
58 * <http://www.apache.org/>.
59 *
60 */
61
62 package org.apache.jasper.compiler;
63
64 import java.util.Hashtable;
65 import java.util.Enumeration;
66 import java.io.File;
67
68 import org.apache.jasper.JasperException;
69 import org.apache.jasper.Constants;
70
71
72
73
74
75
76 /**
77 * Generator for <jsp:include.../>
78 *
79 *
80 * @author Anil K. Vijendran
81 * @author Mandar Raje
82 */
83 public class IncludeGenerator
84 extends GeneratorBase
85 implements ServiceMethodPhase
86 {
87 String page;
88 boolean isExpression = false;
89 Hashtable params;
90
91 public IncludeGenerator(Hashtable attrs, Hashtable param)
92 throws JasperException
93 {
94 if (attrs.size() != 2)
95 throw new JasperException(Constants.getString("jsp.error.include.tag"));
96
97 page = (String) attrs.get("page");
98 if (page == null)
99 throw new JasperException(Constants.getString("jsp.error.include.tag"));
100
101 String flush = (String) attrs.get("flush");
102 if (flush == null)
103 throw new JasperException(Constants.getString("jsp.error.include.noflush"));
104
105 if (!flush.equals("true"))
106 throw new JasperException(Constants.getString("jsp.error.include.badflush"));
107
108 this.params = param;
109 isExpression = JspUtil.isExpression (page);
110 }
111
112 public void generate(ServletWriter writer, Class phase) {
113 boolean initial = true;
114 String sep = "?";
115 writer.println("{");
116 writer.pushIndent();
117 writer.println("String _jspx_qStr = \"\";");
118 writer.println("out.flush();");
119
120 if (params.size() > 0) {
121 Enumeration en = params.keys();
122 while (en.hasMoreElements()) {
123 String key = (String) en.nextElement();
124 String []value = (String []) params.get(key);
125 if (initial == true) {
126 sep = "?";
127 initial = false;
128 } else sep = "&";
129
130 if (value.length == 1 && JspUtil.isExpression(value[0])) {
131 writer.println("_jspx_qStr = _jspx_qStr + \"" + sep +
132 key + "=\" + " + JspUtil.getExpr(value[0]) + ";");
133 } else {
134 if (value.length == 1) {
135 writer.println("_jspx_qStr = _jspx_qStr + \"" + sep +
136 key + "=\" + \"" + value[0] + "\";");
137 } else {
138 writer.println("String [] _tmpS = new String[" + value.length +"];");
139 for (int i = 0; i < value.length; i++) {
140 if (!JspUtil.isExpression(value[i]))
141 writer.println("_jspx_qStr = _jspx_qStr + \"" + sep +
142 key + "=\" + \"" + value[i] + "\";");
143 else
144 writer.println("_jspx_qStr = _jspx_qStr + \"" + sep +
145 key + "=\" +" + JspUtil.getExpr(value[i])+ ";");
146 if (sep.equals("?")) sep = "&";
147
148 }
149 }
150 }
151 }
152 }
153 if (!isExpression)
154 writer.println("pageContext.include(" +
155 writer.quoteString(page) + " + _jspx_qStr);");
156 else
157 writer.println ("pageContext.include(" +
158 JspUtil.getExpr(page) + " + _jspx_qStr);");
159
160 writer.popIndent();
161 writer.println("}");
162 }
163 }