luehe 2003/03/06 12:11:18
Modified: jasper2/src/share/org/apache/jasper JspC.java
Log:
Rearranged public and private methods, so code becomes more readable.
Changed visibility of instance variables from "public" to "private".
Revision Changes Path
1.37 +426 -445
jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/JspC.java
Index: JspC.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/JspC.java,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -r1.36 -r1.37
--- JspC.java 6 Mar 2003 19:42:54 -0000 1.36
+++ JspC.java 6 Mar 2003 20:11:16 -0000 1.37
@@ -85,27 +85,27 @@
* This version can process files from a _single_ webapp at once, i.e.
* a single docbase can be specified.
*
- * It can be used as a Ant task using:
- <pre>
- <taskdef classname="org.apache.jasper.JspC" name="jasper2" >
- <classpath>
- <pathelement location="${java.home}/../lib/tools.jar"/>
- <fileset dir="${ENV.CATALINA_HOME}/server/lib">
- <include name="*.jar"/>
- </fileset>
- <fileset dir="${ENV.CATALINA_HOME}/common/lib">
- <include name="*.jar"/>
- </fileset>
- <path refid="myjars"/>
- </classpath>
- </taskdef>
-
- <jasper2 verbose="0"
- package="my.package"
- uriroot="${webapps.dir}/${webapp.name}"
- webXmlFragment="${build.dir}/generated_web.xml"
- outputDir="${webapp.dir}/${webapp.name}/WEB-INF/src/my/package" />
- </pre>
+ * It can be used as an Ant task using:
+ * <pre>
+ * <taskdef classname="org.apache.jasper.JspC" name="jasper2" >
+ * <classpath>
+ * <pathelement location="${java.home}/../lib/tools.jar"/>
+ * <fileset dir="${ENV.CATALINA_HOME}/server/lib">
+ * <include name="*.jar"/>
+ * </fileset>
+ * <fileset dir="${ENV.CATALINA_HOME}/common/lib">
+ * <include name="*.jar"/>
+ * </fileset>
+ * <path refid="myjars"/>
+ * </classpath>
+ * </taskdef>
+ *
+ * <jasper2 verbose="0"
+ * package="my.package"
+ * uriroot="${webapps.dir}/${webapp.name}"
+ * webXmlFragment="${build.dir}/generated_web.xml"
+ * outputDir="${webapp.dir}/${webapp.name}/WEB-INF/src/my/package" />
+ * </pre>
*
* @author Danno Ferrin
* @author Pierre Delisle
@@ -119,83 +119,76 @@
// Logger
private static Log log = LogFactory.getLog(JspC.class);
- public static final String SWITCH_VERBOSE = "-v";
- public static final String SWITCH_QUIET = "-q";
- public static final String SWITCH_OUTPUT_DIR = "-d";
- public static final String SWITCH_OUTPUT_SIMPLE_DIR = "-dd";
- public static final String SWITCH_IE_CLASS_ID = "-ieplugin";
- public static final String SWITCH_PACKAGE_NAME = "-p";
- public static final String SWITCH_CLASS_NAME = "-c";
- public static final String SWITCH_FULL_STOP = "--";
- public static final String SWITCH_COMPILE = "-compile";
- public static final String SWITCH_URI_BASE = "-uribase";
- public static final String SWITCH_URI_ROOT = "-uriroot";
- public static final String SWITCH_FILE_WEBAPP = "-webapp";
- public static final String SWITCH_WEBAPP_INC = "-webinc";
- public static final String SWITCH_WEBAPP_XML = "-webxml";
- public static final String SWITCH_MAPPED = "-mapped";
- public static final String SWITCH_DIE = "-die";
- public static final String SHOW_SUCCESS ="-s";
- public static final String LIST_ERRORS = "-l";
-
- public static final int NO_WEBXML = 0;
- public static final int INC_WEBXML = 10;
- public static final int ALL_WEBXML = 20;
-
- public static final int DEFAULT_DIE_LEVEL = 1;
- public static final int NO_DIE_LEVEL = 0;
-
-
- String classPath=null;
- URLClassLoader loader=null;
-
- // future direction
- //public static final String SWITCH_XML_OUTPUT = "-xml";
-
-
- boolean largeFile = false;
- boolean mappedFile = false;
+ private static final String SWITCH_VERBOSE = "-v";
+ private static final String SWITCH_QUIET = "-q";
+ private static final String SWITCH_OUTPUT_DIR = "-d";
+ private static final String SWITCH_OUTPUT_SIMPLE_DIR = "-dd";
+ private static final String SWITCH_IE_CLASS_ID = "-ieplugin";
+ private static final String SWITCH_PACKAGE_NAME = "-p";
+ 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_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_DIE = "-die";
+ 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;
- File scratchDir;
-
- String ieClassId = DEFAULT_IE_CLASS_ID;
-
- String targetPackage;
-
- String targetClassName;
-
- String uriBase;
-
- String uriRoot;
-
- int dieLevel;
- boolean dieOnExit = false;
- static int die; // I realize it is duplication, but this is for
- // the static main catch
+ private static final String javaKeywords[] = {
+ "abstract", "boolean", "break", "byte", "case",
+ "catch", "char", "class", "const", "continue",
+ "default", "do", "double", "else", "extends",
+ "final", "finally", "float", "for", "goto",
+ "if", "implements", "import", "instanceof", "int",
+ "interface", "long", "native", "new", "package",
+ "private", "protected", "public", "return", "short",
+ "static", "strictfp", "super", "switch", "synchronized",
+ "this", "throws", "transient", "try", "void",
+ "volatile", "while" };
- boolean compile=false;
- String compiler=null;
+ private static int die;
- boolean dirset;
+ private String classPath = null;
+ private URLClassLoader loader = null;
+ private boolean largeFile = false;
+ private boolean mappedFile = false;
+ private File scratchDir;
+ private String ieClassId = DEFAULT_IE_CLASS_ID;
+ private String targetPackage;
+ private String targetClassName;
+ private String uriBase;
+ private String uriRoot;
+ private int dieLevel;
+ private boolean dieOnExit = false;
+
+ private boolean compile = false;
+ private String compiler = null;
+ private boolean dirset;
+ private boolean classDebugInfo = true;
+ private Vector extensions;
+ private Vector pages = new Vector();
- boolean classDebugInfo=true;
+ // Generation of web.xml fragments
+ private String webxmlFile;
+ private int webxmlLevel;
- Vector extensions;
+ private Writer mapout;
+ private CharArrayWriter servletout;
+ private CharArrayWriter mappingout;
- Vector pages = new Vector();
+ private JspCServletContext context;
- // Generation of web.xml fragments
- String webxmlFile;
- int webxmlLevel;
- Writer mapout;
- CharArrayWriter servletout;
- CharArrayWriter mappingout;
-
- JspCServletContext context;
- /*
- * Maintain a dummy JspRuntimeContext for compiling tag files
- */
- JspRuntimeContext rctxt;
+ // Maintain a dummy JspRuntimeContext for compiling tag files
+ private JspRuntimeContext rctxt;
/**
* Cache for the TLD locations
@@ -208,6 +201,28 @@
private boolean verbose = false;
private boolean listErrors = false;
private boolean showSuccess = false;
+ private int argPos;
+ private boolean fullstop = false;
+ private String args[];
+
+ public static void main(String arg[]) {
+ if (arg.length == 0) {
+ System.out.println(Localizer.getMessage("jspc.usage"));
+ } else {
+ try {
+ JspC jspc = new JspC();
+ jspc.setArgs(arg);
+ jspc.execute();
+ } catch (JasperException je) {
+ System.err.print("error:");
+ je.printStackTrace();
+ //System.err.println(je.getMessage());
+ if (die != NO_DIE_LEVEL) {
+ System.exit(die);
+ }
+ }
+ }
+ }
public void setArgs(String[] arg) {
args = arg;
@@ -311,7 +326,7 @@
* Are we supporting HTML mapped servlets?
*/
public boolean getMappedFile() {
- return mappedFile;
+ return mappedFile;
}
// Off-line compiler, no need for security manager
@@ -390,7 +405,6 @@
compiler=c;
}
-
public TldLocationsCache getTldLocationsCache() {
return tldLocationsCache;
}
@@ -409,13 +423,13 @@
return System.getProperty("java.class.path");
}
- // -------------------- Options --------------------
public void setClassPath(String s) {
classPath=s;
}
- /** Base dir for the webapp. Used to generate class names and
- * resolve includes
+ /**
+ * Base dir for the webapp. Used to generate class names and resolve
+ * includes
*/
public void setUriroot( String s ) {
if( s==null ) {
@@ -454,15 +468,17 @@
targetPackage=p;
}
- /** Class name of the generated file ( without package ).
- * Can only be used if a single file is converted.
- * XXX Do we need this feature ?
+ /**
+ * Class name of the generated file ( without package ).
+ * Can only be used if a single file is converted.
+ * XXX Do we need this feature ?
*/
public void setClassName( String p ) {
targetClassName=p;
}
- /** File where we generate a web.xml fragment with the class definitions.
+ /**
+ * File where we generate a web.xml fragment with the class definitions.
*/
public void setWebXmlFragment( String s ) {
webxmlFile=s;
@@ -470,110 +486,14 @@
}
/**
- * Resolve relative path, and create output directories.
+ * Obtain JSP configuration informantion specified in web.xml.
*/
- void setupContext(JspCompilationContext clctxt) {
- String outputDir = scratchDir.getAbsolutePath();
-
- if (dirset) {
- int indexOfSlash = clctxt.getJspFile().lastIndexOf('/');
-
- /* String pathName = "";
- if (indexOfSlash != -1) {
- pathName = clctxt.getJspFile().substring(0, indexOfSlash);
- } */
- String tmpDir = outputDir + File.separatorChar; // + pathName;
- File f = new File(tmpDir);
- if (!f.exists()) {
- f.mkdirs();
- }
- }
- clctxt.setOutputDir( outputDir );
+ public JspConfig getJspConfig() {
+ return jspConfig;
}
- void initClassLoader( JspCompilationContext clctxt ) throws IOException {
- classPath = getClassPath();
-
- ClassLoader parent=this.getClass().getClassLoader();
-
- ArrayList urls = new ArrayList();
- File webappBase=new File(uriRoot);
-
- if( parent instanceof URLClassLoader ) {
- URLClassLoader uL=(URLClassLoader) parent;
- URL path[]=uL.getURLs();
- for( int i=0; i<path.length; i++ ) {
- urls.add( path[i] );
- classPath = classPath + File.pathSeparator +
- path[i].getFile();
- }
- }
-
- if( parent instanceof org.apache.tools.ant.AntClassLoader ) {
- classPath= classPath + File.pathSeparator +
- ((org.apache.tools.ant.AntClassLoader)parent).getClasspath();
- }
-
- // Turn the classPath in URLs
- StringTokenizer tokenizer = new StringTokenizer(classPath,
File.pathSeparator);
- while (tokenizer.hasMoreTokens()) {
- String path = tokenizer.nextToken();
- try {
- File libFile = new File(path);
- urls.add(libFile.toURL());
- } catch (IOException ioe) {
- // Failing a toCanonicalPath on a file that
- // exists() should be a JVM regression test,
- // therefore we have permission to freak uot
- throw new RuntimeException(ioe.toString());
- }
- }
-
- if (webappBase.exists()) {
- File classes = new File(webappBase, "/WEB-INF/classes");
- try {
- if (classes.exists()) {
- classPath = classPath + File.pathSeparator
- + classes.getCanonicalPath();
- urls.add(classes.getCanonicalFile().toURL());
- }
- } catch (IOException ioe) {
- // failing a toCanonicalPath on a file that
- // exists() should be a JVM regression test,
- // therefore we have permission to freak out
- throw new RuntimeException(ioe.toString());
- }
- File lib = new File(webappBase, "/WEB-INF/lib");
- if (lib.exists() && lib.isDirectory()) {
- String[] libs = lib.list();
- for (int i = 0; i < libs.length; i++) {
- if( libs[i].length() <5 ) continue;
- String ext=libs[i].substring( libs[i].length() - 4 );
- if( ! ".jar".equalsIgnoreCase( ext )) {
- System.out.println("XXX bad jar " + libs[i]);
- continue;
- }
- try {
- File libFile = new File(lib, libs[i]);
- classPath = classPath + File.pathSeparator
- + libFile.getCanonicalPath();
- urls.add(libFile.getCanonicalFile().toURL());
- } catch (IOException ioe) {
- // failing a toCanonicalPath on a file that
- // exists() should be a JVM regression test,
- // therefore we have permission to freak out
- throw new RuntimeException(ioe.toString());
- }
- }
- }
- }
-
- // What is this ??
- urls.add(new File(clctxt.getRealPath("/")).getCanonicalFile().toURL());
-
- URL urlsA[]=new URL[urls.size()];
- urls.toArray(urlsA);
- loader = new URLClassLoader(urlsA, this.getClass().getClassLoader());
+ public TagPluginManager getTagPluginManager() {
+ return tagPluginManager;
}
public void generateWebMapping( String file, JspCompilationContext clctxt )
@@ -606,7 +526,6 @@
}
}
-
public boolean processFile(String file)
throws JasperException
{
@@ -622,7 +541,8 @@
String jspUri=file.replace('\\','/');
String baseDir = scratchDir.getCanonicalPath();
- this.setOutputDir( baseDir + jspUri.substring( 0, jspUri.lastIndexOf(
'/' ) ) );
+ this.setOutputDir(baseDir
+ + jspUri.substring(0, jspUri.lastIndexOf('/')));
JspCompilationContext clctxt = new JspCompilationContext
( jspUri, false, this, context, null, rctxt );
@@ -688,68 +608,9 @@
}
}
- /** Find the WEB-INF dir by looking up in the directory tree.
- * This is used if no explicit docbase is set, but only files.
- * XXX Maybe we should require the docbase.
- */
- private void locateUriRoot( File f ) {
- String tUriBase = uriBase;
- if (tUriBase == null) {
- tUriBase = "/";
- }
- try {
- if (f.exists()) {
- f = new File(f.getCanonicalPath());
- while (f != null) {
- File g = new File(f, "WEB-INF");
- if (g.exists() && g.isDirectory()) {
- uriRoot = f.getCanonicalPath();
- uriBase = tUriBase;
- if (log.isInfoEnabled()) {
- log.info(Localizer.getMessage("jspc.implicit.uriRoot",
- uriRoot));
- }
- break;
- }
- if (f.exists() && f.isDirectory()) {
- tUriBase = "/" + f.getName() + "/" + tUriBase;
- }
-
- String fParent = f.getParent();
- if (fParent == null) {
- f = new File(args[argPos]);
- fParent = f.getParent();
- if (fParent == null) {
- fParent = File.separator;
- }
- uriRoot = new File(fParent).getCanonicalPath();
- uriBase = "/";
- break;
- } else {
- f = new File(fParent);
- }
-
- // If there is no acceptible candidate, uriRoot will
- // remain null to indicate to the CompilerContext to
- // use the current working/user dir.
- }
-
- try {
- File froot = new File(uriRoot);
- uriRoot = froot.getCanonicalPath();
- } catch (IOException ioe) {
- // if we cannot get the base, leave it null
- }
- }
- } catch (IOException ioe) {
- // since this is an optional default and a null value
- // for uriRoot has a non-error meaning, we can just
- // pass straight through
- }
- }
-
- /** Locate all jsp files in the webapp. Used if no explicit
- * jsps are specified.
+ /**
+ * Locate all jsp files in the webapp. Used if no explicit
+ * jsps are specified.
*/
public void scanFiles( File base ) {
Stack dirs = new Stack();
@@ -772,14 +633,14 @@
dirs.push(f2.getPath());
//System.out.println("++" + f2.getPath());
} else {
- ext = files[i].substring(
- files[i].lastIndexOf('.') + 1);
+ ext = files[i].substring(files[i].lastIndexOf('.')
+ + 1);
if (extensions.contains(ext)) {
//System.out.println(s + "?" + files[i]);
- pages.addElement(
- s + File.separatorChar + files[i]);
+ pages.addElement(s + File.separatorChar
+ + files[i]);
} else {
- //System.out.println("not done:" + ext);
+ //System.out.println("not done:" + ext);
}
}
}
@@ -787,154 +648,69 @@
}
}
- private void initWebXml() {
+ public void execute() throws JasperException {
+
try {
- if (webxmlLevel >= INC_WEBXML) {
- File fmapings = new File(webxmlFile);
- mapout = new FileWriter(fmapings);
- servletout = new CharArrayWriter();
- mappingout = new CharArrayWriter();
- } else {
- mapout = null;
- servletout = null;
- mappingout = null;
- }
- if (webxmlLevel >= ALL_WEBXML) {
- mapout.write(Localizer.getMessage("jspc.webxml.header"));
- } else if (webxmlLevel>= INC_WEBXML) {
- mapout.write(Localizer.getMessage("jspc.webinc.header"));
- }
- mapout.flush();
- } catch (IOException ioe) {
- mapout = null;
- servletout = null;
- mappingout = null;
+ if (uriRoot == null) {
+ if( pages.size() == 0 ) {
+ throw new JasperException("No uriRoot or files");
+ }
+ String firstJsp=(String)pages.elementAt( 0 );
+ locateUriRoot( new File( firstJsp ) );
+ }
+
+ // No explicit page, we'll process all .jsp in the webapp
+ if (pages.size() == 0) {
+ scanFiles( new File( uriRoot ));
+ }
+
+ File uriRootF = new File(uriRoot);
+ if (!uriRootF.exists() || !uriRootF.isDirectory()) {
+ throw new JasperException(
+ Localizer.getMessage("jsp.error.jspc.uriroot_not_dir"));
+ }
+
+ if( context==null )
+ initServletContext();
+
+ initWebXml();
+
+ Enumeration e = pages.elements();
+ while (e.hasMoreElements()) {
+ String nextjsp = e.nextElement().toString();
+ try {
+ File fjsp = new File(nextjsp);
+ if (!fjsp.exists()) {
+ if (log.isWarnEnabled()) {
+
log.warn(Localizer.getMessage("jspc.error.fileDoesNotExist",
+ fjsp.toString()));
+ }
+ continue;
+ }
+ String s = fjsp.getCanonicalPath();
+ //System.out.println("**" + s);
+ if (s.startsWith(uriRoot)) {
+ nextjsp = s.substring(uriRoot.length());
+ }
+ } catch (IOException ioe) {
+ // if we got problems dont change the file name
+ }
+
+ if (nextjsp.startsWith("." + File.separatorChar)) {
+ nextjsp = nextjsp.substring(2);
+ }
+
+ processFile(nextjsp);
+ }
+
+ completeWebXml();
+
+ } catch (Throwable t) {
+ t.printStackTrace();
}
}
- private void completeWebXml() {
- if (mapout != null) {
- try {
- servletout.writeTo(mapout);
- mappingout.writeTo(mapout);
- if (webxmlLevel >= ALL_WEBXML) {
- mapout.write(Localizer.getMessage("jspc.webxml.footer"));
- } else if (webxmlLevel >= INC_WEBXML) {
- mapout.write(Localizer.getMessage("jspc.webinc.footer"));
- }
- mapout.close();
- } catch (IOException ioe) {
- // noting to do if it fails since we are done with it
- }
- }
- }
-
- private void initServletContext() {
- try {
- context =new JspCServletContext
- (new PrintWriter(System.out),
- new URL("file:" + uriRoot.replace('\\','/') + '/'));
- tldLocationsCache = new
- TldLocationsCache(context, true);
- } catch (MalformedURLException me) {
- System.out.println("**" + me);
- }
- rctxt = new JspRuntimeContext(context, this);
- jspConfig = new JspConfig(context);
- tagPluginManager = new TagPluginManager(context);
- }
-
-
- public void execute() throws JasperException {
-
- try {
-
- if( uriRoot==null ) {
- if( pages.size() == 0 ) {
- throw new JasperException( "No uriRoot or files");
- }
- String firstJsp=(String)pages.elementAt( 0 );
- locateUriRoot( new File( firstJsp ) );
- }
-
- // No explicit page, we'll process all .jsp in the webapp
- if( pages.size() == 0 ) {
- scanFiles( new File( uriRoot ));
- }
-
- File uriRootF = new File(uriRoot);
- if (!uriRootF.exists() || !uriRootF.isDirectory()) {
- throw new JasperException(
- Localizer.getMessage("jsp.error.jspc.uriroot_not_dir"));
- }
-
- if( context==null )
- initServletContext();
-
- initWebXml();
-
- Enumeration e = pages.elements();
- while (e.hasMoreElements()) {
- String nextjsp = e.nextElement().toString();
- try {
- File fjsp = new File(nextjsp);
- if (!fjsp.exists()) {
- if (log.isWarnEnabled()) {
- log.warn(Localizer.getMessage("jspc.error.fileDoesNotExist",
- fjsp.toString()));
- }
- continue;
- }
- String s = fjsp.getCanonicalPath();
- //System.out.println("**" + s);
- if (s.startsWith(uriRoot)) {
- nextjsp = s.substring(uriRoot.length());
- }
- } catch (IOException ioe) {
- // if we got problems dont change the file name
- }
-
- if (nextjsp.startsWith("." + File.separatorChar)) {
- nextjsp = nextjsp.substring(2);
- }
-
- processFile(nextjsp);
- }
-
- completeWebXml();
-
- } catch (Throwable t) {
- t.printStackTrace();
- }
-
- }
-
-
- // ==================== CLI support ====================
-
- int argPos;
- // value set by beutifully obsfucscated java
- boolean fullstop = false;
- String args[];
-
- public static void main(String arg[]) {
- if (arg.length == 0) {
- System.out.println(Localizer.getMessage("jspc.usage"));
- } else {
- try {
- JspC jspc = new JspC();
- jspc.setArgs(arg);
- jspc.execute();
- } catch (JasperException je) {
- System.err.print("error:");
- je.printStackTrace();
- //System.err.println(je.getMessage());
- if (die != NO_DIE_LEVEL) {
- System.exit(die);
- }
- }
- }
- }
+ // ==================== Private utility methods ====================
private String nextArg() {
if ((argPos >= args.length)
@@ -955,17 +731,6 @@
}
/**
- * Obtain JSP configuration informantion specified in web.xml.
- */
- public JspConfig getJspConfig() {
- return jspConfig;
- }
-
- public TagPluginManager getTagPluginManager() {
- return tagPluginManager;
- }
-
- /**
* Converts the JSP file path into a valid package name with a
* structure that mirrors the directory structure. If the JSP file
* path doesn't contain a directory structure (top-level file),
@@ -994,12 +759,70 @@
modifiedPackageName.append(mangleChar(ch));
}
}
- if (nameStart < iSep && isJavaKeyword(jspUri.substring(nameStart, iSep))) {
+ if (nameStart < iSep
+ && isJavaKeyword(jspUri.substring(nameStart, iSep))) {
modifiedPackageName.append('_');
}
return modifiedPackageName.toString();
}
+ private void initWebXml() {
+ try {
+ if (webxmlLevel >= INC_WEBXML) {
+ File fmapings = new File(webxmlFile);
+ mapout = new FileWriter(fmapings);
+ servletout = new CharArrayWriter();
+ mappingout = new CharArrayWriter();
+ } else {
+ mapout = null;
+ servletout = null;
+ mappingout = null;
+ }
+ if (webxmlLevel >= ALL_WEBXML) {
+ mapout.write(Localizer.getMessage("jspc.webxml.header"));
+ } else if (webxmlLevel>= INC_WEBXML) {
+ mapout.write(Localizer.getMessage("jspc.webinc.header"));
+ }
+ mapout.flush();
+ } catch (IOException ioe) {
+ mapout = null;
+ servletout = null;
+ mappingout = null;
+ }
+ }
+
+ private void completeWebXml() {
+ if (mapout != null) {
+ try {
+ servletout.writeTo(mapout);
+ mappingout.writeTo(mapout);
+ if (webxmlLevel >= ALL_WEBXML) {
+ mapout.write(Localizer.getMessage("jspc.webxml.footer"));
+ } else if (webxmlLevel >= INC_WEBXML) {
+ mapout.write(Localizer.getMessage("jspc.webinc.footer"));
+ }
+ mapout.close();
+ } catch (IOException ioe) {
+ // noting to do if it fails since we are done with it
+ }
+ }
+ }
+
+ private void initServletContext() {
+ try {
+ context =new JspCServletContext
+ (new PrintWriter(System.out),
+ new URL("file:" + uriRoot.replace('\\','/') + '/'));
+ tldLocationsCache = new
+ TldLocationsCache(context, true);
+ } catch (MalformedURLException me) {
+ System.out.println("**" + me);
+ }
+ rctxt = new JspRuntimeContext(context, this);
+ jspConfig = new JspConfig(context);
+ tagPluginManager = new TagPluginManager(context);
+ }
+
/**
* Mangle the specified character to create a legal Java class name.
* FIX: This is a copy of the method from JspCompilationContext. It
@@ -1021,19 +844,177 @@
return new String(result);
}
- static final String javaKeywords[] = {
- "abstract", "boolean", "break", "byte", "case",
- "catch", "char", "class", "const", "continue",
- "default", "do", "double", "else", "extends",
- "final", "finally", "float", "for", "goto",
- "if", "implements", "import", "instanceof", "int",
- "interface", "long", "native", "new", "package",
- "private", "protected", "public", "return", "short",
- "static", "strictfp", "super", "switch", "synchronized",
- "this", "throws", "transient", "try", "void",
- "volatile", "while" };
+ /**
+ * Resolve relative path, and create output directories.
+ */
+ private void setupContext(JspCompilationContext clctxt) {
+ String outputDir = scratchDir.getAbsolutePath();
+
+ if (dirset) {
+ int indexOfSlash = clctxt.getJspFile().lastIndexOf('/');
+
+ /* String pathName = "";
+ if (indexOfSlash != -1) {
+ pathName = clctxt.getJspFile().substring(0, indexOfSlash);
+ } */
+ String tmpDir = outputDir + File.separatorChar; // + pathName;
+ File f = new File(tmpDir);
+ if (!f.exists()) {
+ f.mkdirs();
+ }
+ }
+ clctxt.setOutputDir( outputDir );
+ }
+
+ private void initClassLoader(JspCompilationContext clctxt)
+ throws IOException {
+
+ classPath = getClassPath();
+
+ ClassLoader parent=this.getClass().getClassLoader();
+
+ ArrayList urls = new ArrayList();
+ File webappBase=new File(uriRoot);
+
+ if( parent instanceof URLClassLoader ) {
+ URLClassLoader uL=(URLClassLoader) parent;
+ URL path[]=uL.getURLs();
+ for( int i=0; i<path.length; i++ ) {
+ urls.add( path[i] );
+ classPath = classPath + File.pathSeparator +
+ path[i].getFile();
+ }
+ }
+
+ if( parent instanceof org.apache.tools.ant.AntClassLoader ) {
+ classPath= classPath + File.pathSeparator +
+ ((org.apache.tools.ant.AntClassLoader)parent).getClasspath();
+ }
+
+ // Turn the classPath in URLs
+ StringTokenizer tokenizer = new StringTokenizer(classPath,
File.pathSeparator);
+ while (tokenizer.hasMoreTokens()) {
+ String path = tokenizer.nextToken();
+ try {
+ File libFile = new File(path);
+ urls.add(libFile.toURL());
+ } catch (IOException ioe) {
+ // Failing a toCanonicalPath on a file that
+ // exists() should be a JVM regression test,
+ // therefore we have permission to freak uot
+ throw new RuntimeException(ioe.toString());
+ }
+ }
+
+ if (webappBase.exists()) {
+ File classes = new File(webappBase, "/WEB-INF/classes");
+ try {
+ if (classes.exists()) {
+ classPath = classPath + File.pathSeparator
+ + classes.getCanonicalPath();
+ urls.add(classes.getCanonicalFile().toURL());
+ }
+ } catch (IOException ioe) {
+ // failing a toCanonicalPath on a file that
+ // exists() should be a JVM regression test,
+ // therefore we have permission to freak out
+ throw new RuntimeException(ioe.toString());
+ }
+ File lib = new File(webappBase, "/WEB-INF/lib");
+ if (lib.exists() && lib.isDirectory()) {
+ String[] libs = lib.list();
+ for (int i = 0; i < libs.length; i++) {
+ if( libs[i].length() <5 ) continue;
+ String ext=libs[i].substring( libs[i].length() - 4 );
+ if( ! ".jar".equalsIgnoreCase( ext )) {
+ System.out.println("XXX bad jar " + libs[i]);
+ continue;
+ }
+ try {
+ File libFile = new File(lib, libs[i]);
+ classPath = classPath + File.pathSeparator
+ + libFile.getCanonicalPath();
+ urls.add(libFile.getCanonicalFile().toURL());
+ } catch (IOException ioe) {
+ // failing a toCanonicalPath on a file that
+ // exists() should be a JVM regression test,
+ // therefore we have permission to freak out
+ throw new RuntimeException(ioe.toString());
+ }
+ }
+ }
+ }
+
+ // What is this ??
+ urls.add(new File(clctxt.getRealPath("/")).getCanonicalFile().toURL());
+
+ URL urlsA[]=new URL[urls.size()];
+ urls.toArray(urlsA);
+ loader = new URLClassLoader(urlsA, this.getClass().getClassLoader());
+ }
+
+ /**
+ * Find the WEB-INF dir by looking up in the directory tree.
+ * This is used if no explicit docbase is set, but only files.
+ * XXX Maybe we should require the docbase.
+ */
+ private void locateUriRoot( File f ) {
+ String tUriBase = uriBase;
+ if (tUriBase == null) {
+ tUriBase = "/";
+ }
+ try {
+ if (f.exists()) {
+ f = new File(f.getCanonicalPath());
+ while (f != null) {
+ File g = new File(f, "WEB-INF");
+ if (g.exists() && g.isDirectory()) {
+ uriRoot = f.getCanonicalPath();
+ uriBase = tUriBase;
+ if (log.isInfoEnabled()) {
+ log.info(Localizer.getMessage("jspc.implicit.uriRoot",
+ uriRoot));
+ }
+ break;
+ }
+ if (f.exists() && f.isDirectory()) {
+ tUriBase = "/" + f.getName() + "/" + tUriBase;
+ }
+
+ String fParent = f.getParent();
+ if (fParent == null) {
+ f = new File(args[argPos]);
+ fParent = f.getParent();
+ if (fParent == null) {
+ fParent = File.separator;
+ }
+ uriRoot = new File(fParent).getCanonicalPath();
+ uriBase = "/";
+ break;
+ } else {
+ f = new File(fParent);
+ }
+
+ // If there is no acceptible candidate, uriRoot will
+ // remain null to indicate to the CompilerContext to
+ // use the current working/user dir.
+ }
+
+ try {
+ File froot = new File(uriRoot);
+ uriRoot = froot.getCanonicalPath();
+ } catch (IOException ioe) {
+ // if we cannot get the base, leave it null
+ }
+ }
+ } catch (IOException ioe) {
+ // since this is an optional default and a null value
+ // for uriRoot has a non-error meaning, we can just
+ // pass straight through
+ }
+ }
- static private boolean isJavaKeyword(String key) {
+ private static boolean isJavaKeyword(String key) {
int i = 0;
int j = javaKeywords.length;
while (i < j) {
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]