FileDocCategorySizeDatePackage
EmbeddedServletOptions.javaAPI DocGlassfish v2 API23171Fri May 04 22:32:52 BST 2007org.apache.jasper

EmbeddedServletOptions

public final class EmbeddedServletOptions extends Object implements Options
A class to hold all init parameters specific to the JSP engine.
author
Anil K. Vijendran
author
Hans Bergsten
author
Pierre Delisle

Fields Summary
private static com.sun.org.apache.commons.logging.Log
log
private Properties
settings
private boolean
development
Is Jasper being used in development mode?
public boolean
fork
Should Ant fork its java compiles of JSP pages.
private boolean
keepGenerated
Do you want to keep the generated Java files around?
private boolean
saveBytecode
If class files are generated as byte arrays, should they be saved to disk at the end of compilations?
private boolean
trimSpaces
Should white spaces between directives or actions be trimmed?
private boolean
isPoolingEnabled
Determines whether tag handler pooling is enabled.
private boolean
mappedFile
Do you want support for "mapped" files? This will generate servlet that has a print statement per line of the JSP file. This seems like a really nice feature to have for debugging.
private boolean
sendErrorToClient
Do you want stack traces and such displayed in the client's browser? If this is false, such messages go to the standard error or a log file if the standard error is redirected.
private boolean
classDebugInfo
Do we want to include debugging information in the class file?
private int
checkInterval
Background compile thread check interval in seconds.
private boolean
isSmapSuppressed
Is the generation of SMAP info for JSR45 debuggin suppressed?
private boolean
isSmapDumped
Should SMAP info for JSR45 debugging be dumped to a file?
private boolean
genStringAsCharArray
Are Text strings to be generated as char arrays?
private boolean
genStringAsByteArray
private boolean
defaultBufferNone
private boolean
errorOnUseBeanInvalidClassAttribute
private File
scratchDir
I want to see my generated servlets. Which directory are they in?
private String
ieClassId
Need to have this as is for versions 4 and 5 of IE. Can be set from the initParams so if it changes in the future all that is needed is to have a jsp initParam of type ieClassId=""
private String
classpath
What classpath should I use while compiling generated servlets?
private String
sysClassPath
private String
compiler
Compiler to use.
private String
compilerTargetVM
Compiler target VM.
private String
compilerSourceVM
The compiler source VM.
private org.apache.jasper.compiler.TldLocationsCache
tldLocationsCache
Cache for the TLD locations
private org.apache.jasper.compiler.JspConfig
jspConfig
Jsp config information
private org.apache.jasper.compiler.TagPluginManager
tagPluginManager
TagPluginManager
private String
javaEncoding
Java platform encoding to generate the JSP page servlet.
private int
modificationTestInterval
Modification test interval.
private boolean
xpoweredBy
Is generation of X-Powered-By response header enabled/disabled?
private boolean
usePrecompiled
private boolean
isValidationEnabled
private int
initialCapacity
Constructors Summary
public EmbeddedServletOptions(ServletConfig config, ServletContext context)
Create an EmbeddedServletOptions object using data available from ServletConfig and ServletContext.


        // JVM version numbers
        try {
            if (Float.parseFloat(System.getProperty("java.specification.version")) > 1.4) {
                compilerSourceVM = compilerTargetVM = "1.5";
            } else {
                compilerSourceVM = compilerTargetVM = "1.4";
            }
        } catch (NumberFormatException e) {
            // Ignore
        }

        Enumeration enumeration=config.getInitParameterNames();
        while( enumeration.hasMoreElements() ) {
            String k=(String)enumeration.nextElement();
            String v=config.getInitParameter( k );
            setProperty( k, v);
        }

        /* SJSAS 6384538
        // quick hack
        String validating=config.getInitParameter( "validating");
        if( "false".equals( validating )) ParserUtils.validating=false;
        */
        // START SJSAS 6384538
        String validating=config.getInitParameter("validating");
        if ("true".equals(validating)) {
            isValidationEnabled = true;
        }
        validating = config.getInitParameter("enableTldValidation");
        if ("true".equals(validating)) {
            isValidationEnabled = true;
        }
        // END SJSAS 6384538

        // keepgenerated default is false for JDK6 for later, true otherwise
        keepGenerated = getBoolean(config, ! isJDK6(), "keepgenerated");
        saveBytecode = getBoolean(config, saveBytecode, "saveBytecode");
        trimSpaces = getBoolean(config, trimSpaces, "trimSpaces");
        isPoolingEnabled = getBoolean(config, isPoolingEnabled, "enablePooling");
        mappedFile = getBoolean(config, mappedFile, "mappedfile");
        sendErrorToClient = getBoolean(config, sendErrorToClient, "sendErrToClient");
        classDebugInfo = getBoolean(config, classDebugInfo, "classdebuginfo");
        development = getBoolean(config, development, "development");
        isSmapSuppressed = getBoolean(config, isSmapSuppressed, "suppressSmap");
        isSmapDumped = getBoolean(config, isSmapDumped, "dumpSmap");
        genStringAsCharArray = getBoolean(config, genStringAsCharArray, "genStrAsCharArray");
        genStringAsByteArray = getBoolean(config, genStringAsByteArray, "genStrAsByteArray");
        defaultBufferNone = getBoolean(config, defaultBufferNone, "defaultBufferNone");
        errorOnUseBeanInvalidClassAttribute = getBoolean(config, errorOnUseBeanInvalidClassAttribute, "errorOnUseBeanInvalidClassAttribute");
        fork = getBoolean(config, fork, "fork");
        xpoweredBy = getBoolean(config, xpoweredBy, "xpoweredBy");

        String checkIntervalStr = config.getInitParameter("checkInterval");
        if (checkIntervalStr != null) {
            parseCheckInterval(checkIntervalStr);
        }

        String modificationTestIntervalStr =
            config.getInitParameter("modificationTestInterval");
        if (modificationTestIntervalStr != null) {
            parseModificationTestInterval(modificationTestIntervalStr);
        }

        String ieClassId = config.getInitParameter("ieClassId");
        if (ieClassId != null)
            this.ieClassId = ieClassId;

        String classpath = config.getInitParameter("classpath");
        if (classpath != null)
            this.classpath = classpath;

        // START PWC 1.2 6311155
        String sysClassPath = config.getInitParameter(
                                    "com.sun.appserv.jsp.classpath");
        if (sysClassPath != null)
            this.sysClassPath = sysClassPath;
        // END PWC 1.2 6311155

	/*
	 * scratchdir
	 */
        String dir = config.getInitParameter("scratchdir"); 
        if (dir != null) {
            scratchDir = new File(dir);
        } else {
            // First try the Servlet 2.2 javax.servlet.context.tempdir property
            scratchDir = (File) context.getAttribute(Constants.TMP_DIR);
            if (scratchDir == null) {
                // Not running in a Servlet 2.2 container.
                // Try to get the JDK 1.2 java.io.tmpdir property
                dir = System.getProperty("java.io.tmpdir");
                if (dir != null)
                    scratchDir = new File(dir);
            }
        }      
        if (this.scratchDir == null) {
            log.fatal(Localizer.getMessage("jsp.error.no.scratch.dir"));
            return;
        }
            
        if (!(scratchDir.exists() && scratchDir.canRead() &&
              scratchDir.canWrite() && scratchDir.isDirectory()))
            log.fatal(Localizer.getMessage("jsp.error.bad.scratch.dir",
					   scratchDir.getAbsolutePath()));
                                  
        this.compiler = config.getInitParameter("compiler");

        String compilerTargetVM = config.getInitParameter("compilerTargetVM");
        if(compilerTargetVM != null) {
            this.compilerTargetVM = compilerTargetVM;
        }
        
        String compilerSourceVM = config.getInitParameter("compilerSourceVM");
        if(compilerSourceVM != null) {
            this.compilerSourceVM = compilerSourceVM;
        }

        String javaEncoding = config.getInitParameter("javaEncoding");
        if (javaEncoding != null) {
            this.javaEncoding = javaEncoding;
        }

        String reloadIntervalString =
            config.getInitParameter("reload-interval");
        if (reloadIntervalString != null) {                   
            int reloadInterval = 0;
            try {
                reloadInterval = Integer.parseInt(reloadIntervalString);
            } catch (NumberFormatException e) {
                if (log.isWarnEnabled()) {
                    log.warn(Localizer.getMessage("jsp.warning.reloadInterval"));
                }
            }
            if (reloadInterval == -1) {
                // Never check JSPs for modifications, and disable
                // recompilation
                this.development = false;
                this.checkInterval = 0;
            } else {
                // Check JSPs for modifications at specified interval in
                // both (development and non-development) modes
                parseCheckInterval(reloadIntervalString);
                parseModificationTestInterval(reloadIntervalString);
            }
        } 

        // BEGIN S1AS 6181923
        String usePrecompiled = config.getInitParameter("usePrecompiled"); 
        if (usePrecompiled == null) {
            usePrecompiled = config.getInitParameter("use-precompiled"); 
        }
        if (usePrecompiled != null) {
            if (usePrecompiled.equalsIgnoreCase("true")) {
                this.usePrecompiled = true;
            } else if (usePrecompiled.equalsIgnoreCase("false")) {
                this.usePrecompiled = false;
            } else {
                if (log.isWarnEnabled()) {
		    log.warn(Localizer.getMessage("jsp.warning.usePrecompiled"));
		}
	    }
        }
        // END S1AS 6181923

        // START SJSWS
        String capacity = config.getInitParameter("initialCapacity");
        if (capacity == null) {
            capacity = config.getInitParameter("initial-capacity");
        }
        if (capacity != null) {
            try {
                initialCapacity = Integer.parseInt(capacity);
                // Find a value that is power of 2 and >= the specified 
                // initial capacity, in order to make Hashtable indexing
                // more efficient.
                int value = Constants.DEFAULT_INITIAL_CAPACITY;
                while (value < initialCapacity) {
                    value *= 2;
                }
                initialCapacity = value;
            } catch (NumberFormatException nfe) {
                if (log.isWarnEnabled()) {
                    String msg = Localizer.getMessage(
                        "jsp.warning.initialcapacity");
                    msg = MessageFormat.format(
                        msg,
                        new Object[] {
                            capacity,
                            Integer.valueOf(Constants.DEFAULT_INITIAL_CAPACITY)});
                    log.warn(msg);
                }
            }
        }

        String jspCompilerPlugin = config.getInitParameter("javaCompilerPlugin");
        if (jspCompilerPlugin != null) {
            if ("org.apache.jasper.compiler.JikesJavaCompiler".equals(
                    jspCompilerPlugin)) {
                this.compiler = "jikes";
            } else if ("org.apache.jasper.compiler.SunJava14Compiler".equals(
                    jspCompilerPlugin)) {
                // use default, do nothing
            } else {
                // use default, issue warning
                if (log.isWarnEnabled()) {
                    String msg = Localizer.getMessage(
                        "jsp.warning.unsupportedJavaCompiler");
                    msg = MessageFormat.format(msg,
                                               new Object[]
                                                   { jspCompilerPlugin });
                    log.warn(msg);
                }
            }
        }
        // END SJSWS

	// Setup the global Tag Libraries location cache for this
	// web-application.
        /* SJSAS 6384538
        tldLocationsCache = new TldLocationsCache(context);
        */
        // START SJSAS 6384538
        tldLocationsCache = new TldLocationsCache(context, this);
        // END SJSAS 6384538

	// Setup the jsp config info for this web app.
        /* SJSAS 6384538
	jspConfig = new JspConfig(context);
        */
        // START SJSAS 6384538
        jspConfig = new JspConfig(context, this);
        // END SJSAS 6384538

	// Create a Tag plugin instance
	tagPluginManager = new TagPluginManager(context);
    
Methods Summary
public booleangenStringAsByteArray()

        return this.genStringAsByteArray;
    
public booleangenStringAsCharArray()
Are Text strings to be generated as char arrays?

        return this.genStringAsCharArray;
    
private booleangetBoolean(javax.servlet.ServletConfig config, boolean init, java.lang.String param)

    
        String sParam = config.getInitParameter(param);
        if (sParam != null) {
            if (sParam.equalsIgnoreCase("true")) {
                return true;
            }
            if (sParam.equalsIgnoreCase("false")) {
                return false;
            }
            if (log.isWarnEnabled()) {
                log.warn(Localizer.getMessage("jsp.warning.boolean", param,
                     (init? "true": "false")));
            }
        }
        return init;
    
public intgetCheckInterval()
Background JSP compile thread check intervall

        return checkInterval;
    
public booleangetClassDebugInfo()
Should class files be compiled with debug information?

        return classDebugInfo;
    
public java.lang.StringgetClassPath()
What classpath should I use while compiling the servlets generated from JSP files?

        return classpath;
    
public java.lang.StringgetCompiler()
Compiler to use.

        return compiler;
    
public java.lang.StringgetCompilerSourceVM()

see
Options#getCompilerSourceVM

        return compilerSourceVM;
    
public java.lang.StringgetCompilerTargetVM()

see
Options#getCompilerTargetVM

        return compilerTargetVM;
    
public booleangetDevelopment()
Is Jasper being used in development mode?

        return development;
    
public booleangetErrorOnUseBeanInvalidClassAttribute()

        return errorOnUseBeanInvalidClassAttribute;
    
public booleangetFork()

        return fork;
    
public java.lang.StringgetIeClassId()
Class ID for use in the plugin tag when the browser is IE.

        return ieClassId;
    
public intgetInitialCapacity()
Gets initial capacity of HashMap which maps JSPs to their corresponding servlets.

        return initialCapacity;
    
public java.lang.StringgetJavaEncoding()

	return javaEncoding;
    
public org.apache.jasper.compiler.JspConfiggetJspConfig()

	return jspConfig;
    
public booleangetKeepGenerated()
Are we keeping generated code around?

        return keepGenerated;
    
public booleangetMappedFile()
Are we supporting HTML mapped servlets?

        return mappedFile;
    
public intgetModificationTestInterval()
Modification test interval.

        return modificationTestInterval;
    
public java.lang.StringgetProperty(java.lang.String name)

    // END SJSWS

         
        return settings.getProperty( name );
    
public booleangetSaveBytecode()

        return this.saveBytecode;
    
public java.io.FilegetScratchDir()
What is my scratch dir?

        return scratchDir;
    
public booleangetSendErrorToClient()
Should errors be sent to client or thrown into stderr?

        return sendErrorToClient;
    
public java.lang.StringgetSystemClassPath()
Gets the system class path.

return
The system class path

        return sysClassPath;
    
public org.apache.jasper.compiler.TagPluginManagergetTagPluginManager()

	return tagPluginManager;
    
public org.apache.jasper.compiler.TldLocationsCachegetTldLocationsCache()

	return tldLocationsCache;
    
public booleangetTrimSpaces()
Should white spaces between directives or actions be trimmed?

        return trimSpaces;
    
public booleangetUsePrecompiled()
Returns the value of the usePrecompiled (or use-precompiled) init param.

        return usePrecompiled;
    
public booleanisDefaultBufferNone()

        return defaultBufferNone;
    
private booleanisJDK6()

        try {
            Class.forName("javax.tools.ToolProvider");
            return true;
        } catch (ClassNotFoundException ex) {
        }
        return false;
    
public booleanisPoolingEnabled()

	return isPoolingEnabled;
    
public booleanisSmapDumped()
Should SMAP info for JSR45 debugging be dumped to a file?

        return isSmapDumped;
    
public booleanisSmapSuppressed()
Is the generation of SMAP info for JSR45 debuggin suppressed?

        return isSmapSuppressed;
    
public booleanisValidationEnabled()

        return isValidationEnabled;
    
public booleanisXpoweredBy()
Is generation of X-Powered-By response header enabled/disabled?

        return xpoweredBy;
    
private voidparseCheckInterval(java.lang.String param)

        try {
            this.checkInterval = Integer.parseInt(param);
        } catch(NumberFormatException ex) {
            if (log.isWarnEnabled()) {
                log.warn(Localizer.getMessage("jsp.warning.checkInterval"));
            }
        }
    
private voidparseModificationTestInterval(java.lang.String param)

        try {
            this.modificationTestInterval = Integer.parseInt(param);
        } catch(NumberFormatException ex) {
            if (log.isWarnEnabled()) {
                log.warn(Localizer.getMessage("jsp.warning.modificationTestInterval"));
            }
        }
    
public voidsetErrorOnUseBeanInvalidClassAttribute(boolean b)

        errorOnUseBeanInvalidClassAttribute = b;
    
public voidsetProperty(java.lang.String name, java.lang.String value)

        if (name != null && value != null){ 
            settings.setProperty( name, value );
        }
    
public voidsetTldLocationsCache(org.apache.jasper.compiler.TldLocationsCache tldC)

        tldLocationsCache = tldC;