craigmcc 01/09/07 15:51:26
Modified: jasper/src/share/org/apache/jasper/compiler JspCompiler.java
Log:
Because JSP source and class files are now stored in a directory tree that
mirrors the context-relative path, there is no need to include the
directory path in the generated filenames as well.
This is based on the patch submitted by Kin-Man Chung
<[EMAIL PROTECTED]> but modified to fix an additional bug -- the
previous algorithm would only work when JSP pages were mapped to "*.jsp",
but would fail when a different servlet mapping was mapped to the JSP
servlet. In addition, name mangling is still necessary to convert
characters that are not legal Java identifiers.
PR: Bugzilla #2917
Submitted by: [EMAIL PROTECTED]
Revision Changes Path
1.7 +25 -21
jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/JspCompiler.java
Index: JspCompiler.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/JspCompiler.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- JspCompiler.java 2001/05/16 06:02:48 1.6
+++ JspCompiler.java 2001/09/07 22:51:26 1.7
@@ -122,32 +122,35 @@
return classFileName;
}
+
+ /**
+ * Convert the final path component to a valid base class name, maintaining
+ * uniqueness as required.
+ */
private final String getBaseClassName() {
- String className;
-
- if (jsp.endsWith(".jsp"))
- className = jsp.substring(0, jsp.length() - 4);
- else
- className = jsp;
-
-
- // Fix for invalid characters. If you think of more add to the list.
- StringBuffer modifiedClassName = new StringBuffer();
- for (int i = 0; i < className.length(); i++) {
- if (Character.isLetterOrDigit(className.charAt(i)) == true)
- modifiedClassName.append(className.substring(i,i+1));
- else
- modifiedClassName.append(mangleChar(className.charAt(i)));
- }
- modifiedClassName.append("_jsp");
- return modifiedClassName.toString();
+
+ int iSep = jsp.lastIndexOf('/') + 1;
+ int iEnd = jsp.length();
+ StringBuffer modifiedClassName = new StringBuffer(jsp.length() - iSep);
+ for (int i = iSep; i < iEnd; i++) {
+ char ch = jsp.charAt(i);
+ if (Character.isLetterOrDigit(ch))
+ modifiedClassName.append(ch);
+ else if (ch == '.')
+ modifiedClassName.append('$');
+ else
+ modifiedClassName.append(mangleChar(ch));
+ }
+ return (modifiedClassName.toString());
+
}
+
+ /**
+ * Mangle the specified character to create a legal Java class name.
+ */
private static final String mangleChar(char ch) {
- if(ch == File.separatorChar) {
- ch = '/';
- }
String s = Integer.toHexString(ch);
int nzeros = 5 - s.length();
char[] result = new char[6];
@@ -158,6 +161,7 @@
result[i] = s.charAt(j);
return new String(result);
}
+
/**
* Determines whether the current JSP class is older than the JSP file