Return-Path: Delivered-To: apmail-jakarta-tomcat-dev-archive@apache.org Received: (qmail 6472 invoked from network); 2 Apr 2002 23:50:48 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 2 Apr 2002 23:50:48 -0000 Received: (qmail 3099 invoked by uid 97); 2 Apr 2002 23:50:44 -0000 Delivered-To: qmlist-jakarta-archive-tomcat-dev@jakarta.apache.org Received: (qmail 3082 invoked by uid 97); 2 Apr 2002 23:50:44 -0000 Mailing-List: contact tomcat-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Tomcat Developers List" Reply-To: "Tomcat Developers List" Delivered-To: mailing list tomcat-dev@jakarta.apache.org Received: (qmail 3063 invoked by uid 97); 2 Apr 2002 23:50:44 -0000 Date: 2 Apr 2002 23:50:36 -0000 Message-ID: <20020402235036.5028.qmail@icarus.apache.org> From: kinman@apache.org To: jakarta-tomcat-4.0-cvs@apache.org Subject: cvs commit: jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler CommandLineCompiler.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N kinman 02/04/02 15:50:36 Modified: jasper/src/share/org/apache/jasper Tag: tomcat_40_branch CommandLineContext.java jasper/src/share/org/apache/jasper/compiler Tag: tomcat_40_branch CommandLineCompiler.java Log: - Applied fixes from the head branch that fixed 5471 and 7488 Revision Changes Path No revision No revision 1.6.2.3 +17 -18 jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/CommandLineContext.java Index: CommandLineContext.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/CommandLineContext.java,v retrieving revision 1.6.2.2 retrieving revision 1.6.2.3 diff -u -r1.6.2.2 -r1.6.2.3 --- CommandLineContext.java 2 Apr 2002 16:11:12 -0000 1.6.2.2 +++ CommandLineContext.java 2 Apr 2002 23:50:36 -0000 1.6.2.3 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/CommandLineContext.java,v 1.6.2.2 2002/04/02 16:11:12 glenn Exp $ - * $Revision: 1.6.2.2 $ - * $Date: 2002/04/02 16:11:12 $ + * $Header: /home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/CommandLineContext.java,v 1.6.2.3 2002/04/02 23:50:36 kinman Exp $ + * $Revision: 1.6.2.3 $ + * $Date: 2002/04/02 23:50:36 $ * * ==================================================================== * @@ -216,33 +216,32 @@ /** * 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 - int indexOfSlash = getJspFile().lastIndexOf('/'); + //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 speced on + + //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("")) { + if (servletPackageName != null) { packageName = servletPackageName; } - if (packageName.equals("")) { - packageName = pathName.replace('/', '.'); - } else { - packageName += pathName.replace('/', '.'); - } - //strip off any leading '.' in the package name - if (!packageName.equals("") && packageName.charAt(0) == '.') { - packageName = packageName.substring(1); - } - return packageName; + packageName += pathName.replace('/', '.'); + + return CommandLineCompiler.manglePackage(packageName); } /** @@ -344,7 +343,7 @@ /** * Gets a resource as a stream, relative to the meanings of this * context's implementation. - *@returns a null if the resource cannot be found or represented + * @return a null if the resource cannot be found or represented * as an InputStream. */ public java.io.InputStream getResourceAsStream(String res) { No revision No revision 1.2.2.3 +43 -16 jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/CommandLineCompiler.java Index: CommandLineCompiler.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/CommandLineCompiler.java,v retrieving revision 1.2.2.2 retrieving revision 1.2.2.3 diff -u -r1.2.2.2 -r1.2.2.3 --- CommandLineCompiler.java 2 Apr 2002 16:11:12 -0000 1.2.2.2 +++ CommandLineCompiler.java 2 Apr 2002 23:50:36 -0000 1.2.2.3 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/CommandLineCompiler.java,v 1.2.2.2 2002/04/02 16:11:12 glenn Exp $ - * $Revision: 1.2.2.2 $ - * $Date: 2002/04/02 16:11:12 $ + * $Header: /home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/CommandLineCompiler.java,v 1.2.2.3 2002/04/02 23:50:36 kinman Exp $ + * $Revision: 1.2.2.3 $ + * $Date: 2002/04/02 23:50:36 $ * * The Apache Software License, Version 1.1 * @@ -61,6 +61,7 @@ import java.io.File; import java.io.IOException; +import java.util.StringTokenizer; import org.apache.jasper.Constants; import org.apache.jasper.JspCompilationContext; @@ -86,8 +87,6 @@ jsp = new File(ctxt.getJspFile()); outputDir = ctxt.getOptions().getScratchDir().getAbsolutePath(); packageName = ctxt.getServletPackageName(); - if( packageName == null ) - packageName = ""; pkgName = packageName; setMangler(this); @@ -163,30 +162,36 @@ className = jsp.getName().substring(0, jsp.getName().length() - 4); else className = jsp.getName(); + } + return mangleName(className); + } + 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 (className.equals(keywords[i])) { - className += "%"; + if (name.equals(keywords[i])) { + name += "%"; + break; }; }; // Fix for invalid characters. If you think of more add to the list. - StringBuffer modifiedClassName = new StringBuffer(); - if (Character.isJavaIdentifierStart(className.charAt(0))) - modifiedClassName.append(className.charAt(0)); + StringBuffer modifiedName = new StringBuffer(); + if (Character.isJavaIdentifierStart(name.charAt(0))) + modifiedName.append(name.charAt(0)); else - modifiedClassName.append(mangleChar(className.charAt(0))); - for (int i = 1; i < className.length(); i++) { - if (Character.isJavaIdentifierPart(className.charAt(i))) - modifiedClassName.append(className.charAt(i)); + 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 - modifiedClassName.append(mangleChar(className.charAt(i))); + modifiedName.append(mangleChar(name.charAt(i))); } - return modifiedClassName.toString(); + return modifiedName.toString(); } private static final String mangleChar(char ch) { @@ -205,6 +210,28 @@ return new String(result); } + /** + * 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(); + } public final String getClassName() { return className; -- To unsubscribe, e-mail: For additional commands, e-mail: