/*
- * Copyright 1999,2004 The Apache Software Foundation.
+ * Copyright 1999,2004-2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* @author Mark Roth
*/
public class Constants {
+
/**
* The base class of the generated servlets.
*/
- public static final String JSP_SERVLET_BASE = "org.apache.jasper.runtime.HttpJspBase";
+ public static final String JSP_SERVLET_BASE =
+ System.getProperty("org.apache.jasper.Constants.JSP_SERVLET_BASE", "org.apache.jasper.runtime.HttpJspBase");
/**
* _jspService is the name of the method that is called by
* HttpJspBase.service(). This is where most of the code generated
* from JSPs go.
*/
- public static final String SERVICE_METHOD_NAME = "_jspService";
+ public static final String SERVICE_METHOD_NAME =
+ System.getProperty("org.apache.jasper.Constants.SERVICE_METHOD_NAME", "_jspService");
/**
* Default servlet content type.
};
/**
- * FIXME
* ServletContext attribute for classpath. This is tomcat specific.
* Other servlet engines may choose to support this attribute if they
* want to have this JSP engine running on them.
*/
- public static final String SERVLET_CLASSPATH = "org.apache.catalina.jsp_classpath";
+ public static final String SERVLET_CLASSPATH =
+ System.getProperty("org.apache.jasper.Constants.SERVLET_CLASSPATH", "org.apache.catalina.jsp_classpath");
/**
- * FIXME
* Request attribute for <code><jsp-file></code> element of a
* servlet definition. If present on a request, this overrides the
* value returned by <code>request.getServletPath()</code> to select
* the JSP page to be executed.
*/
- public static final String JSP_FILE = "org.apache.catalina.jsp_file";
+ public static final String JSP_FILE =
+ System.getProperty("org.apache.jasper.Constants.JSP_FILE", "org.apache.catalina.jsp_file");
/**
- * FIXME
- * ServletContext attribute for class loader. This is tomcat specific.
- * Other servlet engines can choose to have this attribute if they
- * want to have this JSP engine running on them.
- */
- //public static final String SERVLET_CLASS_LOADER = "org.apache.tomcat.classloader";
- public static final String SERVLET_CLASS_LOADER = "org.apache.catalina.classloader";
-
- /**
* Default size of the JSP buffer.
*/
- public static final int K = 1024;
- public static final int DEFAULT_BUFFER_SIZE = 8*K;
+ public static final int DEFAULT_BUFFER_SIZE = 8 * 1024;
/**
* Default size for the tag buffers.
* The query parameter that causes the JSP engine to just
* pregenerated the servlet but not invoke it.
*/
- public static final String PRECOMPILE = "jsp_precompile";
+ public static final String PRECOMPILE =
+ System.getProperty("org.apache.jasper.Constants.PRECOMPILE", "jsp_precompile");
/**
* The default package name for compiled jsp pages.
*/
- public static final String JSP_PACKAGE_NAME = "org.apache.jsp";
+ public static final String JSP_PACKAGE_NAME =
+ System.getProperty("org.apache.jasper.Constants.JSP_PACKAGE_NAME", "org.apache.jsp");
/**
* The default package name for tag handlers generated from tag files
*/
- public static final String TAG_FILE_PACKAGE_NAME = "org.apache.jsp.tag";
+ public static final String TAG_FILE_PACKAGE_NAME =
+ System.getProperty("org.apache.jasper.Constants.TAG_FILE_PACKAGE_NAME", "org.apache.jsp.tag");
/**
* Servlet context and request attributes that the JSP engine
* uses.
*/
- public static final String INC_REQUEST_URI = "javax.servlet.include.request_uri";
public static final String INC_SERVLET_PATH = "javax.servlet.include.servlet_path";
public static final String TMP_DIR = "javax.servlet.context.tempdir";
- public static final String FORWARD_SEEN = "javax.servlet.forward.seen";
// Must be kept in sync with org/apache/catalina/Globals.java
- public static final String ALT_DD_ATTR = "org.apache.catalina.deploy.alt_dd";
+ public static final String ALT_DD_ATTR =
+ System.getProperty("org.apache.jasper.Constants.ALT_DD_ATTR", "org.apache.catalina.deploy.alt_dd");
/**
* Public Id and the Resource path (of the cached copy)
* Prefix to use for generated temporary variable names
*/
public static final String TEMP_VARIABLE_NAME_PREFIX =
- "_jspx_temp";
+ System.getProperty("org.apache.jasper.Constants.TEMP_VARIABLE_NAME_PREFIX", "_jspx_temp");
/**
* A replacement char for "\$".
* XXX This is a hack to avoid changing EL interpreter to recognize "\$"
*/
- public static final char ESC='\u001b';
- public static final String ESCStr="'\\u001b'";
-}
+ public static final char ESC = '\u001b';
+ public static final String ESCStr = "'\\u001b'";
+}
/*
- * Copyright 1999,2004-2005 The Apache Software Foundation.
+ * Copyright 1999,2004-2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
"clsid:8AD9C840-044E-11D1-B3E9-00805F499D93";
// Logger
- private static Log log = LogFactory.getLog(JspC.class);
-
- private static final String SWITCH_VERBOSE = "-v";
- private static final String SWITCH_HELP = "-help";
- private static final String SWITCH_QUIET = "-q";
- private static final String SWITCH_OUTPUT_DIR = "-d";
- private static final String SWITCH_IE_CLASS_ID = "-ieplugin";
- private static final String SWITCH_PACKAGE_NAME = "-p";
- private static final String SWITCH_CACHE = "-cache";
- private static final String SWITCH_CLASS_NAME = "-c";
- private static final String SWITCH_FULL_STOP = "--";
- private static final String SWITCH_COMPILE = "-compile";
- private static final String SWITCH_SOURCE = "-source";
- private static final String SWITCH_TARGET = "-target";
- private static final String SWITCH_URI_BASE = "-uribase";
- private static final String SWITCH_URI_ROOT = "-uriroot";
- private static final String SWITCH_FILE_WEBAPP = "-webapp";
- private static final String SWITCH_WEBAPP_INC = "-webinc";
- private static final String SWITCH_WEBAPP_XML = "-webxml";
- private static final String SWITCH_MAPPED = "-mapped";
- private static final String SWITCH_XPOWERED_BY = "-xpoweredBy";
- private static final String SWITCH_TRIM_SPACES = "-trimSpaces";
- private static final String SWITCH_CLASSPATH = "-classpath";
- private static final String SWITCH_DIE = "-die";
- private static final String SWITCH_POOLING = "-poolingEnabled";
- private static final String SWITCH_ENCODING = "-javaEncoding";
- private static final String SWITCH_SMAP = "-smap";
- private static final String SWITCH_DUMP_SMAP = "-dumpsmap";
-
- private static final String SHOW_SUCCESS ="-s";
- private static final String LIST_ERRORS = "-l";
- private static final int NO_WEBXML = 0;
- private static final int INC_WEBXML = 10;
- private static final int ALL_WEBXML = 20;
- private static final int DEFAULT_DIE_LEVEL = 1;
- private static final int NO_DIE_LEVEL = 0;
-
- private static final String[] insertBefore =
+ protected static Log log = LogFactory.getLog(JspC.class);
+
+ protected static final String SWITCH_VERBOSE = "-v";
+ protected static final String SWITCH_HELP = "-help";
+ protected static final String SWITCH_OUTPUT_DIR = "-d";
+ protected static final String SWITCH_PACKAGE_NAME = "-p";
+ protected static final String SWITCH_CACHE = "-cache";
+ protected static final String SWITCH_CLASS_NAME = "-c";
+ protected static final String SWITCH_FULL_STOP = "--";
+ protected static final String SWITCH_COMPILE = "-compile";
+ protected static final String SWITCH_SOURCE = "-source";
+ protected static final String SWITCH_TARGET = "-target";
+ protected static final String SWITCH_URI_BASE = "-uribase";
+ protected static final String SWITCH_URI_ROOT = "-uriroot";
+ protected static final String SWITCH_FILE_WEBAPP = "-webapp";
+ protected static final String SWITCH_WEBAPP_INC = "-webinc";
+ protected static final String SWITCH_WEBAPP_XML = "-webxml";
+ protected static final String SWITCH_MAPPED = "-mapped";
+ protected static final String SWITCH_XPOWERED_BY = "-xpoweredBy";
+ protected static final String SWITCH_TRIM_SPACES = "-trimSpaces";
+ protected static final String SWITCH_CLASSPATH = "-classpath";
+ protected static final String SWITCH_DIE = "-die";
+ protected static final String SWITCH_POOLING = "-poolingEnabled";
+ protected static final String SWITCH_ENCODING = "-javaEncoding";
+ protected static final String SWITCH_SMAP = "-smap";
+ protected static final String SWITCH_DUMP_SMAP = "-dumpsmap";
+
+ protected static final String SHOW_SUCCESS ="-s";
+ protected static final String LIST_ERRORS = "-l";
+ protected static final int INC_WEBXML = 10;
+ protected static final int ALL_WEBXML = 20;
+ protected static final int DEFAULT_DIE_LEVEL = 1;
+ protected static final int NO_DIE_LEVEL = 0;
+
+ protected static final String[] insertBefore =
{ "</web-app>", "<servlet-mapping>", "<session-config>",
"<mime-mapping>", "<welcome-file-list>", "<error-page>", "<taglib>",
"<resource-env-ref>", "<resource-ref>", "<security-constraint>",
"<login-config>", "<security-role>", "<env-entry>", "<ejb-ref>",
"<ejb-local-ref>" };
- private static int die;
- private String classPath = null;
- private URLClassLoader loader = null;
- private boolean trimSpaces = false;
- private boolean genStringAsCharArray = false;
- private boolean xpoweredBy;
- private boolean mappedFile = false;
- private boolean poolingEnabled = true;
- private File scratchDir;
- private String ieClassId = DEFAULT_IE_CLASS_ID;
- private String targetPackage;
- private String targetClassName;
- private String uriBase;
- private String uriRoot;
- private Project project;
- private int dieLevel;
- private boolean helpNeeded = false;
- private boolean compile = false;
- private boolean smapSuppressed = true;
- private boolean smapDumped = false;
- private boolean caching = true;
- private Map cache = new HashMap();
-
- private String compiler = null;
-
- private String compilerTargetVM = "1.4";
- private String compilerSourceVM = "1.4";
-
- private boolean classDebugInfo = true;
+ protected static int die;
+ protected String classPath = null;
+ protected URLClassLoader loader = null;
+ protected boolean trimSpaces = false;
+ protected boolean genStringAsCharArray = false;
+ protected boolean xpoweredBy;
+ protected boolean mappedFile = false;
+ protected boolean poolingEnabled = true;
+ protected File scratchDir;
+ protected String ieClassId = DEFAULT_IE_CLASS_ID;
+ protected String targetPackage;
+ protected String targetClassName;
+ protected String uriBase;
+ protected String uriRoot;
+ protected Project project;
+ protected int dieLevel;
+ protected boolean helpNeeded = false;
+ protected boolean compile = false;
+ protected boolean smapSuppressed = true;
+ protected boolean smapDumped = false;
+ protected boolean caching = true;
+ protected Map cache = new HashMap();
+
+ protected String compiler = null;
+
+ protected String compilerTargetVM = "1.4";
+ protected String compilerSourceVM = "1.4";
+
+ protected boolean classDebugInfo = true;
/**
* Throw an exception if there's a compilation error, or swallow it.
* Default is true to preserve old behavior.
*/
- private boolean failOnError = true;
+ protected boolean failOnError = true;
/**
* The file extensions to be handled as JSP files.
* Default list is .jsp and .jspx.
*/
- private List extensions;
+ protected List extensions;
/**
* The pages.
*/
- private List pages = new Vector();
+ protected List pages = new Vector();
/**
* Needs better documentation, this data member does.
* True by default.
*/
- private boolean errorOnUseBeanInvalidClassAttribute = true;
+ protected boolean errorOnUseBeanInvalidClassAttribute = true;
/**
* The java file encoding. Default
* is UTF-8. Added per bugzilla 19622.
*/
- private String javaEncoding = "UTF-8";
+ protected String javaEncoding = "UTF-8";
// Generation of web.xml fragments
- private String webxmlFile;
- private int webxmlLevel;
- private boolean addWebXmlMappings = false;
+ protected String webxmlFile;
+ protected int webxmlLevel;
+ protected boolean addWebXmlMappings = false;
- private Writer mapout;
- private CharArrayWriter servletout;
- private CharArrayWriter mappingout;
+ protected Writer mapout;
+ protected CharArrayWriter servletout;
+ protected CharArrayWriter mappingout;
/**
* The servlet context.
*/
- private JspCServletContext context;
+ protected JspCServletContext context;
/**
* The runtime context.
* Maintain a dummy JspRuntimeContext for compiling tag files.
*/
- private JspRuntimeContext rctxt;
+ protected JspRuntimeContext rctxt;
/**
* Cache for the TLD locations
*/
- private TldLocationsCache tldLocationsCache = null;
+ protected TldLocationsCache tldLocationsCache = null;
- private JspConfig jspConfig = null;
- private TagPluginManager tagPluginManager = null;
+ protected JspConfig jspConfig = null;
+ protected TagPluginManager tagPluginManager = null;
- private boolean verbose = false;
- private boolean listErrors = false;
- private boolean showSuccess = false;
- private int argPos;
- private boolean fullstop = false;
- private String args[];
+ protected boolean verbose = false;
+ protected boolean listErrors = false;
+ protected boolean showSuccess = false;
+ protected int argPos;
+ protected boolean fullstop = false;
+ protected String args[];
public static void main(String arg[]) {
if (arg.length == 0) {
}
} catch (JasperException je) {
System.err.println(je);
- //System.err.println(je.getMessage());
if (die != NO_DIE_LEVEL) {
System.exit(die);
}
}
/**
+ * Compiler class name to use.
+ */
+ public String getCompilerClassName() {
+ return null;
+ }
+
+ /**
* @see Options#getCompilerTargetVM
*/
public String getCompilerTargetVM() {
}
- private void processFile(String file)
+ protected void processFile(String file)
throws JasperException
{
ClassLoader originalClassLoader = null;
* jsps are specified.
*/
public void scanFiles( File base ) throws JasperException {
- Stack dirs = new Stack();
- dirs.push(base);
+ Stack<String> dirs = new Stack<String>();
+ dirs.push(base.toString());
// Make sure default extensions are always included
if ((getExtensions() == null) || (getExtensions().size() < 2)) {
}
while (!dirs.isEmpty()) {
- String s = dirs.pop().toString();
+ String s = dirs.pop();
File f = new File(s);
if (f.exists() && f.isDirectory()) {
String[] files = f.list();
}
}
- // ==================== Private utility methods ====================
+ // ==================== protected utility methods ====================
- private String nextArg() {
+ protected String nextArg() {
if ((argPos >= args.length)
|| (fullstop = SWITCH_FULL_STOP.equals(args[argPos]))) {
return null;
}
}
- private String nextFile() {
+ protected String nextFile() {
if (fullstop) argPos++;
if (argPos >= args.length) {
return null;
}
}
- private void initWebXml() {
+ protected void initWebXml() {
try {
if (webxmlLevel >= INC_WEBXML) {
File fmapings = new File(webxmlFile);
}
}
- private void completeWebXml() {
+ protected void completeWebXml() {
if (mapout != null) {
try {
servletout.writeTo(mapout);
}
}
- private void initServletContext() {
+ protected void initServletContext() {
try {
context =new JspCServletContext
(new PrintWriter(System.out),
* @param clctxt The compilation context
* @throws IOException If an error occurs
*/
- private void initClassLoader(JspCompilationContext clctxt)
+ protected void initClassLoader(JspCompilationContext clctxt)
throws IOException {
classPath = getClassPath();
}
// Turn the classPath into URLs
- ArrayList urls = new ArrayList();
+ ArrayList<URL> urls = new ArrayList<URL>();
StringTokenizer tokenizer = new StringTokenizer(classPath,
File.pathSeparator);
while (tokenizer.hasMoreTokens()) {
* This is used if no explicit docbase is set, but only files.
* XXX Maybe we should require the docbase.
*/
- private void locateUriRoot( File f ) {
+ protected void locateUriRoot( File f ) {
String tUriBase = uriBase;
if (tUriBase == null) {
tUriBase = "/";
return jspCompiler;
}
jspCompiler = null;
- if (options.getCompiler() == null) {
- jspCompiler = createCompiler("org.apache.jasper.compiler.JDTCompiler");
- if (jspCompiler == null) {
- jspCompiler = createCompiler("org.apache.jasper.compiler.AntCompiler");
- }
+ if (options.getCompilerClassName() != null) {
+ jspCompiler = createCompiler(options.getCompilerClassName());
} else {
- jspCompiler = createCompiler("org.apache.jasper.compiler.AntCompiler");
- if (jspCompiler == null) {
+ if (options.getCompiler() == null) {
jspCompiler = createCompiler("org.apache.jasper.compiler.JDTCompiler");
+ if (jspCompiler == null) {
+ jspCompiler = createCompiler("org.apache.jasper.compiler.AntCompiler");
+ }
+ } else {
+ jspCompiler = createCompiler("org.apache.jasper.compiler.AntCompiler");
+ if (jspCompiler == null) {
+ jspCompiler = createCompiler("org.apache.jasper.compiler.JDTCompiler");
+ }
}
}
if (jspCompiler == null) {
Compiler compiler = null;
try {
compiler = (Compiler) Class.forName(className).newInstance();
- } catch (Throwable t) {
+ } catch (InstantiationException e) {
+ log.warn(Localizer.getMessage("jsp.error.compiler"), e);
+ } catch (IllegalAccessException e) {
+ log.warn(Localizer.getMessage("jsp.error.compiler"), e);
+ } catch (ClassNotFoundException e) {
if (log.isDebugEnabled()) {
- log.debug(Localizer.getMessage("jsp.error.compiler"), t);
+ log.debug(Localizer.getMessage("jsp.error.compiler"), e);
}
}
return compiler;
* generated.
*/
public String getServletJavaFileName() {
-
if (servletJavaFileName == null) {
- servletJavaFileName =
- getOutputDir() + getServletClassName() + ".java";
- } else {
- // Make sure output dir exists
- makeOutputDir();
+ servletJavaFileName = getOutputDir() + getServletClassName() + ".java";
}
return servletJavaFileName;
}
- public void setServletJavaFileName(String servletJavaFileName) {
- this.servletJavaFileName = servletJavaFileName;
- }
-
/**
* Get hold of the Options object for this context.
*/
}
public String getClassFileName() {
-
if (classFileName == null) {
classFileName = getOutputDir() + getServletClassName() + ".class";
- } else {
- // Make sure output dir exists
- makeOutputDir();
}
return classFileName;
}
static Object outputDirLock = new Object();
- private void makeOutputDir() {
+ private boolean makeOutputDir() {
synchronized(outputDirLock) {
File outDirFile = new File(outputDir);
- outDirFile.mkdirs();
+ return outDirFile.mkdirs();
}
}
path = getServletPackageName().replace('.', '/');
}
- try {
// Append servlet or tag handler path to scratch dir
- baseUrl = options.getScratchDir().toURL();
- String outUrlString = baseUrl.toString() + '/' + path;
- URL outUrl = new URL(outUrlString);
- outputDir = outUrl.getFile() + File.separator;
- makeOutputDir();
- } catch (Exception e) {
- throw new IllegalStateException("No output directory: " +
- e.getMessage());
- }
+ try {
+ baseUrl = options.getScratchDir().toURL();
+ String outUrlString = baseUrl.toString() + '/' + path;
+ URL outUrl = new URL(outUrlString);
+ outputDir = outUrl.getFile() + File.separator;
+ if (!makeOutputDir()) {
+ throw new IllegalStateException(Localizer.getMessage("jsp.error.outputfolder"));
+ }
+ } catch (MalformedURLException e) {
+ throw new IllegalStateException(Localizer.getMessage("jsp.error.outputfolder"), e);
+ }
}
private static final boolean isPathSeparator(char c) {