001: /*
002: * The Apache Software License, Version 1.1
003: *
004: * Copyright (c) 1999 The Apache Software Foundation. All rights
005: * reserved.
006: *
007: * Redistribution and use in source and binary forms, with or without
008: * modification, are permitted provided that the following conditions
009: * are met:
010: *
011: * 1. Redistributions of source code must retain the above copyright
012: * notice, this list of conditions and the following disclaimer.
013: *
014: * 2. Redistributions in binary form must reproduce the above copyright
015: * notice, this list of conditions and the following disclaimer in
016: * the documentation and/or other materials provided with the
017: * distribution.
018: *
019: * 3. The end-user documentation included with the redistribution, if
020: * any, must include the following acknowlegement:
021: * "This product includes software developed by the
022: * Apache Software Foundation (http://www.apache.org/)."
023: * Alternately, this acknowlegement may appear in the software itself,
024: * if and wherever such third-party acknowlegements normally appear.
025: *
026: * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
027: * Foundation" must not be used to endorse or promote products derived
028: * from this software without prior written permission. For written
029: * permission, please contact apache@apache.org.
030: *
031: * 5. Products derived from this software may not be called "Apache"
032: * nor may "Apache" appear in their names without prior written
033: * permission of the Apache Group.
034: *
035: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
036: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
037: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
038: * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
039: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
040: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
041: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
042: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
043: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
044: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
045: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
046: * SUCH DAMAGE.
047: * ====================================================================
048: *
049: * This software consists of voluntary contributions made by many
050: * individuals on behalf of the Apache Software Foundation. For more
051: * information on the Apache Software Foundation, please see
052: * <http://www.apache.org/>.
053: *
054: */
055:
056: package com.sun.portal.providers.jsp.jasper3.jasper;
057:
058: import com.sun.portal.log.common.PortalLogger;
059:
060: import java.io.File;
061: import java.util.logging.Logger;
062: import java.util.logging.Level;
063:
064: import javax.servlet.ServletConfig;
065: import javax.servlet.ServletContext;
066:
067: /**
068: * A class to hold all init parameters specific to the JSP engine.
069: *
070: * @author Anil K. Vijendran
071: * @author Hans Bergsten
072: */
073: public final class EmbededServletOptions implements Options {
074: /**
075: * Do you want to keep the generated Java files around?
076: */
077: public boolean keepGenerated = true;
078:
079: /**
080: * Do you want support for "large" files? What this essentially
081: * means is that we generated code so that the HTML data in a JSP
082: * file is stored separately as opposed to those constant string
083: * data being used literally in the generated servlet.
084: */
085: public boolean largeFile = false;
086:
087: /**
088: * Do you want support for "mapped" files? This will generate
089: * servlet that has a print statement per line of the JSP file.
090: * This seems like a really nice feature to have for debugging.
091: */
092: public boolean mappedFile = false;
093:
094: /**
095: * Do you want stack traces and such displayed in the client's
096: * browser? If this is false, such messages go to the standard
097: * error or a log file if the standard error is redirected.
098: */
099: public boolean sendErrorToClient = false;
100:
101: /**
102: * Do we want to include debugging information in the class file?
103: */
104: public boolean classDebugInfo = false;
105:
106: /**
107: * I want to see my generated servlets. Which directory are they
108: * in?
109: */
110: public File scratchDir;
111: /**
112: * When used with a Securitymanager, what ProtectionDomain to use.
113: */
114: private Object protectionDomain;
115:
116: /**
117: * Need to have this as is for versions 4 and 5 of IE. Can be set from
118: * the initParams so if it changes in the future all that is needed is
119: * to have a jsp initParam of type ieClassId="<value>"
120: */
121: public String ieClassId = null;
122:
123: /**
124: * What classpath should I use while compiling generated servlets?
125: */
126: public String classpath = null;
127:
128: /**
129: * Plugin class to use to compile JSP pages.
130: */
131: public Class jspCompilerPlugin = null;
132:
133: /**
134: * Path of the compiler to use for compiling JSP pages.
135: */
136: public String jspCompilerPath = null;
137:
138: /**
139: * Java platform encoding to generate the JSP
140: * page servlet.
141: */
142: private String javaEncoding;
143:
144: private static Logger logger = PortalLogger
145: .getLogger(EmbededServletOptions.class);
146:
147: /**
148: * Are we keeping generated code around?
149: */
150: public boolean getKeepGenerated() {
151: return keepGenerated;
152: }
153:
154: /**
155: * Are we supporting large files?
156: */
157: public boolean getLargeFile() {
158: return largeFile;
159: }
160:
161: /**
162: * Are we supporting HTML mapped servlets?
163: */
164: public boolean getMappedFile() {
165: return mappedFile;
166: }
167:
168: /**
169: * Should errors be sent to client or thrown into stderr?
170: */
171: public boolean getSendErrorToClient() {
172: return sendErrorToClient;
173: }
174:
175: /**
176: * Should class files be compiled with debug information?
177: */
178: public boolean getClassDebugInfo() {
179: return classDebugInfo;
180: }
181:
182: /**
183: * Class ID for use in the plugin tag when the browser is IE.
184: */
185: public String getIeClassId() {
186: return ieClassId;
187: }
188:
189: /**
190: * What is my scratch dir?
191: */
192: public File getScratchDir() {
193: return scratchDir;
194: }
195:
196: /**
197: * ProtectionDomain for this JSP Context when using a SecurityManager
198: */
199: public final Object getProtectionDomain() {
200: return protectionDomain;
201: }
202:
203: /**
204: * What classpath should I use while compiling the servlets
205: * generated from JSP files?
206: */
207: public String getClassPath() {
208: return classpath;
209: }
210:
211: /**
212: * What compiler plugin should I use to compile the servlets
213: * generated from JSP files?
214: */
215: public Class getJspCompilerPlugin() {
216: return jspCompilerPlugin;
217: }
218:
219: /**
220: * Path of the compiler to use for compiling JSP pages.
221: */
222: public String getJspCompilerPath() {
223: return jspCompilerPath;
224: }
225:
226: public String getJavaEncoding() {
227: return javaEncoding;
228: }
229:
230: /**
231: * Create an EmbededServletOptions object using data available from
232: * ServletConfig and ServletContext.
233: */
234: public EmbededServletOptions(ServletConfig config,
235: ServletContext context) {
236: String keepgen = config.getInitParameter("keepgenerated");
237: if (keepgen != null) {
238: if (keepgen.equalsIgnoreCase("true"))
239: this .keepGenerated = true;
240: else if (keepgen.equalsIgnoreCase("false"))
241: this .keepGenerated = false;
242: else
243: logger.finest("PSDT_CSPPJJJ0001");
244: }
245:
246: String largeFile = config.getInitParameter("largefile");
247: if (largeFile != null) {
248: if (largeFile.equalsIgnoreCase("true"))
249: this .largeFile = true;
250: else if (largeFile.equalsIgnoreCase("false"))
251: this .largeFile = false;
252: else
253: logger.finest("PSDT_CSPPJJJ0002");
254: }
255:
256: String mapFile = config.getInitParameter("mappedfile");
257: if (mapFile != null) {
258: if (mapFile.equalsIgnoreCase("true"))
259: this .mappedFile = true;
260: else if (mapFile.equalsIgnoreCase("false"))
261: this .mappedFile = false;
262: else
263: logger.finest("PSDT_CSPPJJJ0003");
264: }
265:
266: String debugInfo = config.getInitParameter("classdebuginfo");
267: if (debugInfo != null) {
268: if (debugInfo.equalsIgnoreCase("true"))
269: this .classDebugInfo = true;
270: else if (debugInfo.equalsIgnoreCase("false"))
271: this .classDebugInfo = false;
272: else
273: logger.finest("PSDT_CSPPJJJ0004");
274: }
275:
276: String ieClassId = config.getInitParameter("ieClassId");
277: if (ieClassId != null)
278: this .ieClassId = ieClassId;
279:
280: String classpath = config.getInitParameter("classpath");
281: if (classpath != null)
282: this .classpath = classpath;
283:
284: String dir = config.getInitParameter("scratchdir");
285:
286: if (dir != null)
287: scratchDir = new File(dir);
288: else {
289: // First we try the Servlet 2.2 javax.servlet.context.tempdir property
290: scratchDir = (File) context.getAttribute(Constants.TMP_DIR);
291: if (scratchDir == null) {
292: // Not running in a Servlet 2.2 container.
293: // Try to get the JDK 1.2 java.io.tmpdir property
294: dir = System.getProperty("java.io.tmpdir");
295: if (dir != null)
296: scratchDir = new File(dir);
297: }
298: }
299:
300: // Get the ProtectionDomain for this Context in case
301: // we are using a SecurityManager
302: protectionDomain = context
303: .getAttribute(Constants.ATTRIB_JSP_ProtectionDomain);
304: if (this .scratchDir == null) {
305: logger.warning("PSDT_CSPPJJJ0005");
306: return;
307: }
308:
309: if (!(scratchDir.exists() && scratchDir.canRead()
310: && scratchDir.canWrite() && scratchDir.isDirectory()))
311: logger.warning("PSDT_CSPPJJJ0006");
312:
313: String jspCompilerPath = config
314: .getInitParameter("jspCompilerPath");
315: if (jspCompilerPath != null) {
316: if (new File(jspCompilerPath).exists()) {
317: this .jspCompilerPath = jspCompilerPath;
318: } else {
319: logger.log(Level.WARNING, "PSDT_CSPPJJJ0007",
320: new Object[] { jspCompilerPath });
321: }
322: }
323:
324: String jspCompilerPlugin = config
325: .getInitParameter("jspCompilerPlugin");
326: if (jspCompilerPlugin != null) {
327: try {
328: this .jspCompilerPlugin = Class
329: .forName(jspCompilerPlugin);
330: } catch (ClassNotFoundException cnfe) {
331: logger.log(Level.WARNING, "PSDT_CSPPJJJ0008",
332: new Object[] { jspCompilerPlugin });
333: }
334: }
335:
336: this .javaEncoding = config.getInitParameter("javaEncoding");
337: }
338: }
|