remm 2003/02/10 03:03:07 Modified: jasper2/src/share/org/apache/jasper Tag: tomcat_4_branch JspC.java Log: - Port all the JSPC fixes from Tomcat 5. Revision Changes Path No revision No revision 1.12.2.4 +74 -15 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.12.2.3 retrieving revision 1.12.2.4 diff -u -r1.12.2.3 -r1.12.2.4 --- JspC.java 31 Dec 2002 14:00:36 -0000 1.12.2.3 +++ JspC.java 10 Feb 2003 11:03:06 -0000 1.12.2.4 @@ -381,15 +381,6 @@ * Resolve relative path, and create output directories. */ void setupContext(JspCompilationContext clctxt) { - // set up a scratch/output dir if none is provided - if (scratchDir == null) { - String temp = System.getProperty("java.io.tempdir"); - if (temp == null) { - temp = ""; - } - scratchDir = new File(new File(temp).getAbsolutePath()); - } - String outputDir = scratchDir.getAbsolutePath(); if (dirset) { @@ -527,6 +518,15 @@ throws JasperException { try { + // set up a scratch/output dir if none is provided + if (scratchDir == null) { + String temp = System.getProperty("java.io.tmpdir"); + if (temp == null) { + temp = ""; + } + scratchDir = new File(new File(temp).getAbsolutePath()); + } + String jspUri=file.replace('\\','/'); String baseDir = scratchDir.getCanonicalPath(); this.setOutputDir( baseDir + jspUri.substring( 0, jspUri.lastIndexOf( '/' ) ) ); @@ -539,7 +539,15 @@ targetClassName = null; } if (targetPackage != null) { - clctxt.setServletPackageName(targetPackage); + String jspPackage = toPackageName(jspUri); + if (jspPackage.equals("")) { + clctxt.setServletPackageName(targetPackage); + } else { + clctxt.setServletPackageName(targetPackage + "." + + jspPackage); + } + } else { + clctxt.setServletPackageName( toPackageName(jspUri)); } setupContext(clctxt); @@ -585,7 +593,7 @@ } else if (dieLevel != NO_DIE_LEVEL) { dieOnExit = true; } - throw new JasperException( e ); + throw new JasperException( "Error compiling " + file, e ); } } @@ -814,7 +822,7 @@ jspc.execute(); } catch (JasperException je) { System.err.print("error:"); - System.err.println(je.getMessage()); + je.printStackTrace(); if (die != NO_DIE_LEVEL) { System.exit(die); } @@ -942,5 +950,56 @@ JspC.log = log; } + + /** + * 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), + * an empty package name is returned. + * + * @param jspUri the context-relative path for the JSP file, starting + * with a slash + */ + private String toPackageName(String jspUri) { + StringBuffer modifiedPackageName = new StringBuffer(); + int iSep = jspUri.lastIndexOf('/'); + // Start after the first slash + for (int i = 1; i < iSep; i++) { + char ch = jspUri.charAt(i); + if (Character.isJavaIdentifierPart(ch)) { + modifiedPackageName.append(ch); + } + else if (ch == '/') { + modifiedPackageName.append('.'); + } else { + modifiedPackageName.append(mangleChar(ch)); + } + } + return modifiedPackageName.toString(); + } + + + /** + * Mangle the specified character to create a legal Java class name. + * FIX: This is a copy of the method from JspCompilationContext. It + * would be better to make that method public, or put it in a utility + * class. + */ + private String mangleChar(char ch) { + + String s = Integer.toHexString(ch); + int nzeros = 5 - s.length(); + char[] result = new char[6]; + result[0] = '_'; + for (int i = 1; i <= nzeros; i++) { + result[i] = '0'; + } + for (int i = nzeros+1, j = 0; i < 6; i++, j++) { + result[i] = s.charAt(j); + } + return new String(result); + } + + }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]