package org.jboss.web.tomcat.tc5.jasper;
import java.util.Properties;
import java.util.Enumeration;
import java.util.ArrayList;
import java.io.File;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import org.apache.jasper.Options;
import org.apache.jasper.Constants;
import org.apache.jasper.xmlparser.ParserUtils;
import org.apache.jasper.compiler.TldLocationsCache;
import org.apache.jasper.compiler.JspConfig;
import org.apache.jasper.compiler.TagPluginManager;
import org.apache.jasper.compiler.Localizer;
import org.jboss.logging.Logger;
public class JspServletOptions
implements Options
{
static Logger log = Logger.getLogger(JspServletOptions.class);
private Properties settings = new Properties();
private boolean development = true;
public boolean fork = true;
private boolean keepGenerated = true;
private boolean trimSpaces = false;
private boolean isPoolingEnabled = true;
private boolean mappedFile = true;
private boolean sendErrorToClient = false;
private boolean classDebugInfo = true;
private int checkInterval = 0;
private boolean isSmapSuppressed = false;
private boolean isSmapDumped = false;
private boolean genStringAsCharArray = false;
private boolean errorOnUseBeanInvalidClassAttribute = true;
private File scratchDir;
private String ieClassId = "clsid:8AD9C840-044E-11D1-B3E9-00805F499D93";
private String classpath = null;
private String compiler = null;
private String compilerTargetVM = "1.4";
private String compilerSourceVM = "1.4";
private TldLocationsCache tldLocationsCache = null;
private JspConfig jspConfig = null;
private TagPluginManager tagPluginManager = null;
private String javaEncoding = "UTF8";
private int modificationTestInterval = 4;
private boolean xpoweredBy;
public String getProperty(String name)
{
return settings.getProperty(name);
}
public void setProperty(String name, String value)
{
if (name != null && value != null)
{
settings.setProperty(name, value);
}
}
public boolean getKeepGenerated()
{
return keepGenerated;
}
public boolean getTrimSpaces()
{
return trimSpaces;
}
public boolean isPoolingEnabled()
{
return isPoolingEnabled;
}
public boolean getMappedFile()
{
return mappedFile;
}
public boolean getSendErrorToClient()
{
return sendErrorToClient;
}
public boolean getClassDebugInfo()
{
return classDebugInfo;
}
public int getCheckInterval()
{
return checkInterval;
}
public int getModificationTestInterval()
{
return modificationTestInterval;
}
public boolean getDevelopment()
{
return development;
}
public boolean isSmapSuppressed()
{
return isSmapSuppressed;
}
public boolean isSmapDumped()
{
return isSmapDumped;
}
public boolean genStringAsCharArray()
{
return this.genStringAsCharArray;
}
public String getIeClassId()
{
return ieClassId;
}
public File getScratchDir()
{
return scratchDir;
}
public String getClassPath()
{
return classpath;
}
public boolean isXpoweredBy()
{
return xpoweredBy;
}
public String getCompiler()
{
return compiler;
}
public String getCompilerTargetVM()
{
return compilerTargetVM;
}
public String getCompilerSourceVM()
{
return compilerSourceVM;
}
public boolean getErrorOnUseBeanInvalidClassAttribute()
{
return errorOnUseBeanInvalidClassAttribute;
}
public void setErrorOnUseBeanInvalidClassAttribute(boolean b)
{
errorOnUseBeanInvalidClassAttribute = b;
}
public TldLocationsCache getTldLocationsCache()
{
return tldLocationsCache;
}
public void setTldLocationsCache(TldLocationsCache tldC)
{
tldLocationsCache = tldC;
}
public String getJavaEncoding()
{
return javaEncoding;
}
public boolean getFork()
{
return fork;
}
public JspConfig getJspConfig()
{
return jspConfig;
}
public TagPluginManager getTagPluginManager()
{
return tagPluginManager;
}
public JspServletOptions(ServletConfig config, ServletContext context)
{
Enumeration enumeration = config.getInitParameterNames();
while (enumeration.hasMoreElements())
{
String k = (String) enumeration.nextElement();
String v = config.getInitParameter(k);
setProperty(k, v);
}
String validating = config.getInitParameter("validating");
if ("false".equals(validating)) ParserUtils.validating = false;
String keepgen = config.getInitParameter("keepgenerated");
if (keepgen != null)
{
if (keepgen.equalsIgnoreCase("true"))
{
this.keepGenerated = true;
}
else if (keepgen.equalsIgnoreCase("false"))
{
this.keepGenerated = false;
}
else
{
log.warn(Localizer.getMessage("jsp.warning.keepgen"));
}
}
String trimsp = config.getInitParameter("trimSpaces");
if (trimsp != null)
{
if (trimsp.equalsIgnoreCase("true"))
{
trimSpaces = true;
}
else if (trimsp.equalsIgnoreCase("false"))
{
trimSpaces = false;
}
else
{
log.warn(Localizer.getMessage("jsp.warning.trimspaces"));
}
}
this.isPoolingEnabled = true;
String poolingEnabledParam
= config.getInitParameter("enablePooling");
if (poolingEnabledParam != null
&& !poolingEnabledParam.equalsIgnoreCase("true"))
{
if (poolingEnabledParam.equalsIgnoreCase("false"))
{
this.isPoolingEnabled = false;
}
else
{
log.warn(Localizer.getMessage("jsp.warning.enablePooling"));
}
}
String mapFile = config.getInitParameter("mappedfile");
if (mapFile != null)
{
if (mapFile.equalsIgnoreCase("true"))
{
this.mappedFile = true;
}
else if (mapFile.equalsIgnoreCase("false"))
{
this.mappedFile = false;
}
else
{
log.warn(Localizer.getMessage("jsp.warning.mappedFile"));
}
}
String senderr = config.getInitParameter("sendErrToClient");
if (senderr != null)
{
if (senderr.equalsIgnoreCase("true"))
{
this.sendErrorToClient = true;
}
else if (senderr.equalsIgnoreCase("false"))
{
this.sendErrorToClient = false;
}
else
{
log.warn(Localizer.getMessage("jsp.warning.sendErrToClient"));
}
}
String debugInfo = config.getInitParameter("classdebuginfo");
if (debugInfo != null)
{
if (debugInfo.equalsIgnoreCase("true"))
{
this.classDebugInfo = true;
}
else if (debugInfo.equalsIgnoreCase("false"))
{
this.classDebugInfo = false;
}
else
{
log.warn(Localizer.getMessage("jsp.warning.classDebugInfo"));
}
}
String checkInterval = config.getInitParameter("checkInterval");
if (checkInterval != null)
{
try
{
this.checkInterval = Integer.parseInt(checkInterval);
if (this.checkInterval == 0)
{
this.checkInterval = 300;
log.warn(Localizer.getMessage("jsp.warning.checkInterval"));
}
}
catch (NumberFormatException ex)
{
log.warn(Localizer.getMessage("jsp.warning.checkInterval"));
}
}
String modificationTestInterval = config.getInitParameter("modificationTestInterval");
if (modificationTestInterval != null)
{
try
{
this.modificationTestInterval = Integer.parseInt(modificationTestInterval);
}
catch (NumberFormatException ex)
{
log.warn(Localizer.getMessage("jsp.warning.modificationTestInterval"));
}
}
String development = config.getInitParameter("development");
if (development != null)
{
if (development.equalsIgnoreCase("true"))
{
this.development = true;
}
else if (development.equalsIgnoreCase("false"))
{
this.development = false;
}
else
{
log.warn(Localizer.getMessage("jsp.warning.development"));
}
}
String suppressSmap = config.getInitParameter("suppressSmap");
if (suppressSmap != null)
{
if (suppressSmap.equalsIgnoreCase("true"))
{
isSmapSuppressed = true;
}
else if (suppressSmap.equalsIgnoreCase("false"))
{
isSmapSuppressed = false;
}
else
{
log.warn(Localizer.getMessage("jsp.warning.suppressSmap"));
}
}
String dumpSmap = config.getInitParameter("dumpSmap");
if (dumpSmap != null)
{
if (dumpSmap.equalsIgnoreCase("true"))
{
isSmapDumped = true;
}
else if (dumpSmap.equalsIgnoreCase("false"))
{
isSmapDumped = false;
}
else
{
log.warn(Localizer.getMessage("jsp.warning.dumpSmap"));
}
}
String genCharArray = config.getInitParameter("genStrAsCharArray");
if (genCharArray != null)
{
if (genCharArray.equalsIgnoreCase("true"))
{
genStringAsCharArray = true;
}
else if (genCharArray.equalsIgnoreCase("false"))
{
genStringAsCharArray = false;
}
else
{
log.warn(Localizer.getMessage("jsp.warning.genchararray"));
}
}
String errBeanClass =
config.getInitParameter("errorOnUseBeanInvalidClassAttribute");
if (errBeanClass != null)
{
if (errBeanClass.equalsIgnoreCase("true"))
{
errorOnUseBeanInvalidClassAttribute = true;
}
else if (errBeanClass.equalsIgnoreCase("false"))
{
errorOnUseBeanInvalidClassAttribute = false;
}
else
{
log.warn(Localizer.getMessage("jsp.warning.errBean"));
}
}
String ieClassId = config.getInitParameter("ieClassId");
if (ieClassId != null)
this.ieClassId = ieClassId;
String classpath = config.getInitParameter("classpath");
if (classpath != null)
this.classpath = classpath;
String dir = config.getInitParameter("scratchdir");
if (dir != null)
{
scratchDir = new File(dir);
}
else
{
scratchDir = (File) context.getAttribute(Constants.TMP_DIR);
if (scratchDir == null)
{
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 fork = config.getInitParameter("fork");
if (fork != null)
{
if (fork.equalsIgnoreCase("true"))
{
this.fork = true;
}
else if (fork.equalsIgnoreCase("false"))
{
this.fork = false;
}
else
{
log.warn(Localizer.getMessage("jsp.warning.fork"));
}
}
String xpoweredBy = config.getInitParameter("xpoweredBy");
if (xpoweredBy != null)
{
if (xpoweredBy.equalsIgnoreCase("true"))
{
this.xpoweredBy = true;
}
else if (xpoweredBy.equalsIgnoreCase("false"))
{
this.xpoweredBy = false;
}
else
{
log.warn(Localizer.getMessage("jsp.warning.xpoweredBy"));
}
}
String base = "tagLibJar";
ArrayList tldJars = new ArrayList();
int count = 0;
String jarPath = null;
do
{
String name = base + count;
jarPath = config.getInitParameter(name);
if( jarPath != null )
tldJars.add(jarPath);
count ++;
} while( jarPath != null );
tldLocationsCache = new TagLibCache(context, tldJars);
jspConfig = new JspConfig(context);
tagPluginManager = new TagPluginManager(context);
}
}