DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT <http://nagoya.apache.org/bugzilla/show_bug.cgi?id=7488>. ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND INSERTED IN THE BUG DATABASE.
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=7488 JspC generates wrong package with -webapp on PC/DOS/NT/Win2k Summary: JspC generates wrong package with -webapp on PC/DOS/NT/Win2k Product: Tomcat 4 Version: 4.0.3 Final Platform: PC OS/Version: Windows NT/2K Status: NEW Severity: Normal Priority: Other Component: Jasper AssignedTo: [EMAIL PROTECTED] ReportedBy: [EMAIL PROTECTED] (bug with patch!) When I tried to generate JSP-Servlets with JspC -webapp dir the generated code could not be compiled because the package was "org.apache.jsp." with a surious dot at the end. the reason is in CommandLineContext.getServletPackageName() which produce this wrong package name, because of the DOS filename in the jspfilename, and the double "\" used... this code is first not adapted to NT/DOS filename because it uses "/" and not File.separatorChar (which is \ on NT). moreover I've found that invalid package name could be generated if a subdirectory is named as a java reserved keyword like 'if' or 'int', contains "-" or similar character invalid in java identifiers... I've patched the whole function so it resolve these problems. I've tested on NT, but not on Unix, however it should work the same. note that I use a pair of "$" character as escape characters in package name (eg a=b\if\earn_much_$_quickly\foo.jsp -> package a$3d$b.$if$.earn_much_$$_quickly;) this may conflict with CVS keys, and you may prefer to use '_' as escape character. however, underscore is a frequent separator in file name which users may like to be kept the same as a package name... anyway this is not essential, since - JSP servlets are seldom put into CVS - JSP servlets package name are seldom used by humans here is the modified function /* * $Header: /home/cvs/jakarta-tomcat- 4.0/jasper/src/share/org/apache/jasper/CommandLineContext.java,v 1.6.2.1 2002/02/01 22:20:37 kinman Exp $ * $Revision: 1.6.2.1 $ * $Date: 2002/02/01 22:20:37 $ ... */ package org.apache.jasper; ... /** * Holds data used on a per-page compilation context that would otherwise spill * over to other pages being compiled. Things like the taglib classloaders * and directives. * * @author Danno Ferrin * @author Pierre Delisle */ public class CommandLineContext implements JspCompilationContext { /** * The package name for the generated class. * mangle the package name so there is no conflit with keywords * or special character, or with spurious dots * also works on DOS/Windows names * NB: usage of '/' is not good... rather use File.separatorChar... * check in the rest of the code! * @author modified by Alain Coetmeur */ public String getServletPackageName() { //get the path to the jsp file //System.out.println(getClass().getName()+".getServletPackageName(): file="+getJspFile()); //System.out.println(getClass().getName()+".getServletPackageName(): uriBase="+uriBase); //System.out.println(getClass().getName()+".getServletPackageName(): uriRoot="+uriRoot); //int indexOfSlash = getJspFile().lastIndexOf(File.separatorChar); String pathName=(new File(getJspFile())).getParent(); if(pathName==null) { pathName = File.separator; } //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 && !servletPackageName.equals("")) { packageName = servletPackageName; } packageName += pathName.replace(File.separatorChar, '.');/* unix/nt */ // escapes characted illegal in java identifiers as $hexvalue$, // and non ascii (problem sometime, often between iso8859/utf8) // escapes $ as $$ to ensure unicity (paranoid!) // escapes reserved keyword as $keyword$ // remove double dots (if file path contains double slash by error) // remove leading dots (if absolute path on unix) // remove trailing dots (if double slash at end) //System.out.println(getClass().getName()+".getServletPackageName(): pack0="+packageName); for(int pos=0;pos<packageName.length();pos++) { char cur=packageName.charAt(pos); if(cur=='.') { if( pos==0 /* remove leading dots */ || pos>=packageName.length()-1 /* remove trailing dots */ || packageName.charAt(pos+1)=='.' /* remove double dots */ ) { packageName=packageName.substring(0,pos)+packageName.substring (pos+1,packageName.length()); pos--; } continue; } boolean atStart=(pos==0 || packageName.charAt(pos-1)=='.'); boolean foundKeyword=false; if(atStart) { for(int i=0;i<CommandLineCompiler.keywords.length;i++) { String kw=CommandLineCompiler.keywords[i]; if( packageName.startsWith(kw, pos) && ( (kw.length()==packageName.length()-pos) || (kw.length()<packageName.length()-pos && packageName.charAt (pos+kw.length())=='.') ) ) { packageName=packageName.substring(0,pos) +"$"+kw+"$"+packageName.substring(pos+kw.length(),packageName.length()); pos+=kw.length()+1; foundKeyword=true; break; } } if(foundKeyword) {continue;} } if(cur!='$' && (int)cur >32 && (int)cur<128 && ( ( atStart && Character.isJavaIdentifierStart(cur) ) || ( !atStart && Character.isJavaIdentifierPart(cur) ) ) ) { continue; } String escaped=(cur=='$')?"$$":("$"+Integer.toHexString((int)cur) +"$"); packageName=packageName.substring(0,pos)+escaped+packageName.substring (pos+1,packageName.length()); pos+=escaped.length()-1; } //System.out.println(getClass().getName()+".getServletPackageName(): pack="+packageName); return packageName; } -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>