-- Update --
This is a known problem with Tomcat 4.0.3 and was fixed in 4.0.4. Since I
don't have the option of upgrading, I hacked out a solution by modifying
the org.apache.jasper.CommandLineContext class to correctly handle this
situation.
The bug is #7488 submitted by Alain Coetmeur who also posted a hackpatch
with the bug.
For anyone who has to deal with this in the future, I've included my hack
below. It simply folds changes from the 4.0.4 source to the 4.0.3 version
of the file (replace getServletPackageName() method with the following):
// ==== BEGIN ================================================
/**
* The package name for the generated class.
* The final package is assembled from the one specified in -p, and
* the one derived from the path to jsp file.
*/
public String getServletPackageName() {
//Get the path to the jsp file. Note that the jspFile, by the
//time it gets here, would have been normalized to use '/'
//as file separator.
int indexOfSlash = getJspFile().lastIndexOf('/');
String pathName;
if (indexOfSlash != -1) {
pathName = getJspFile().substring(0, indexOfSlash);
} else {
pathName = "/";
}
//Assemble the package name from the base package name specified on
//the command line and the package name derived from the path to
//the jsp file
String packageName = "";
if (servletPackageName != null) {
packageName = servletPackageName;
}
indexOfSlash = pathName.lastIndexOf('/');
pathName = pathName.substring(0, indexOfSlash);
packageName += pathName.replace('/', '.');
return CommandLineContext.manglePackage(packageName);
}
public static String [] keywords = {
"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", "super",
"switch", "synchronized", "this",
"throw", "throws", "transient",
"try", "void", "volatile", "while"
};
/**
* Make sure that the package name is a legal Java name
*
* @param name The input string, containing arbitary chars separated by
* '.'s, with possible leading, trailing, or double '.'s
* @return legal Java package name.
*/
public static String manglePackage(String name) {
boolean first = true;
StringBuffer b = new StringBuffer();
StringTokenizer t = new StringTokenizer(name, ".");
while (t.hasMoreTokens()) {
String nt = t.nextToken();
if (nt.length() > 0) {
if (b.length() > 0)
b.append('.');
b.append(mangleName(nt));
}
}
return b.toString();
}
private static final String mangleName(String name) {
// since we don't mangle extensions like the servlet does,
// we need to check for keywords as class names
for (int i = 0; i < keywords.length; i++) {
if (name.equals(keywords[i])) {
name += "%";
break;
};
};
// Fix for invalid characters. If you think of more add to the list.
StringBuffer modifiedName = new StringBuffer();
if (Character.isJavaIdentifierStart(name.charAt(0)))
modifiedName.append(name.charAt(0));
else
modifiedName.append(mangleChar(name.charAt(0)));
for (int i = 1; i < name.length(); i++) {
if (Character.isJavaIdentifierPart(name.charAt(i)))
modifiedName.append(name.charAt(i));
else
modifiedName.append(mangleChar(name.charAt(i)));
}
return modifiedName.toString();
}
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];
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);
}
// ==== END =========================================================
At 12:43 PM 8/16/2002, you wrote:
>All --
>
>Searched through the bug database and discussions and couldn't find
>anything about this ... would be surprised if I was the first person to
>see it. Anyways, I'm seeing a problem with Tomcat 4.0.3 when
>pre-compiling jsps using the -p option. For a command such as:
>
>jspc -v -d . -p basepackage._util -c __dbconvert dbconvert.jsp
>
>I get a generated java file (in the correctly generated directory
>structure) with a package declaration:
>
>package basepackage._util.;
>
>This generated source will not compile because of the extra "." at the end
>of the package. Is this a known issue? Any hints on where I can go in
>the source to fix it? Again, my apologies if this is known/addressed and
>I missed it.
>
>Much appreciated,
>justin
>
>_________________________
>Justin Ruthenbeck
>Software Engineer
>NextEngine Inc.
>401 Wilshire Blvd, 9th Floor
>Santa Monica CA 90401
>[EMAIL PROTECTED]
>
>This email is intended only for the use of the individual or entity to which
>it is addressed and contains information that is privileged and
>confidential. If the reader of this message is not the intended recipient
>or the employee or agent responsible for delivering the message to the
>intended recipient, you are hereby notified that any review, use, disclosure
>or distribution of this communication is strictly prohibited. If you have
>received this communication in error, please notify the sender immediately
>by reply email and destroy all copies of the original message. Thank you.
>_________________________
>
>
>--
>To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
>For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>