remm 2002/06/02 23:58:39 Modified: jasper2/src/share/org/apache/jasper CommandLineContext.java JspEngineContext.java Log: - Formatting. - Remove some dead code. Revision Changes Path 1.4 +127 -96 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/CommandLineContext.java Index: CommandLineContext.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/CommandLineContext.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- CommandLineContext.java 2 Jun 2002 21:40:22 -0000 1.3 +++ CommandLineContext.java 3 Jun 2002 06:58:38 -0000 1.4 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/CommandLineContext.java,v 1.3 2002/06/02 21:40:22 remm Exp $ - * $Revision: 1.3 $ - * $Date: 2002/06/02 21:40:22 $ + * $Header: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/CommandLineContext.java,v 1.4 2002/06/03 06:58:38 remm Exp $ + * $Revision: 1.4 $ + * $Date: 2002/06/03 06:58:38 $ * * ==================================================================== * @@ -111,6 +111,10 @@ boolean outputInDirs; + + // ------------------------------------------------------------ Constructor + + public CommandLineContext(String newJspFile, String newUriBase, String newUriRoot, boolean newErrPage, Options newOptions) @@ -148,6 +152,9 @@ } + // --------------------------------------------------------- Public Methods + + /** * Resolve relative path, and create output directories. */ @@ -171,13 +178,17 @@ } + // ------------------------------------------ JspCompilationContext Methods + + /** * The classpath that is passed off to the Java compiler. */ public String getClassPath() { return classPath; } - + + /** * The classpath that is passed off to the Java compiler. */ @@ -185,20 +196,23 @@ this.classPath = classPath; } + /** * Get the input reader for the JSP text. */ public JspReader getReader() { return reader; } - + + /** * Where is the servlet being generated? */ public ServletWriter getWriter() { return writer; } - + + /** * What class loader to use for loading classes while compiling * this JSP? @@ -207,6 +221,7 @@ return loader; } + /** * Are we processing something that has been declared as an * errorpage? @@ -214,15 +229,16 @@ public boolean isErrorPage() { return errPage; } - + + /** * The scratch directory to generate code into. */ public String getOutputDir() { return outputDir; - //return options.getScratchDir().toString(); } - + + /** * Path of the JSP URI. Note that this is not a file name. This is * the context rooted URI of the JSP file. @@ -230,7 +246,30 @@ public String getJspFile() { return jspFile; } - + + + /** + * Path of the JSP relative to the work directory. + */ + public String getJspPath() { + if (jspPath != null) { + return jspPath; + } + String dirName = getJspFile(); + int pos = dirName.lastIndexOf('/'); + if (pos > 0) { + dirName = dirName.substring(0, pos + 1); + } else { + dirName = ""; + } + jspPath = dirName + getServletClassName() + ".java"; + if (jspPath.startsWith("/")) { + jspPath = jspPath.substring(1); + } + return jspPath; + } + + /** * Just the class name (does not include package name) of the * generated class. @@ -261,7 +300,8 @@ servletClassName = modifiedClassName.toString(); return servletClassName; } - + + /** * The package name for the generated class. * The final package is assembled from the one specified in -p, and @@ -292,37 +332,23 @@ } - public String getJspPath() { - if (jspPath != null) { - return jspPath; - } - String dirName = getJspFile(); - int pos = dirName.lastIndexOf('/'); - if (pos > 0) { - dirName = dirName.substring(0, pos + 1); - } else { - dirName = ""; - } - jspPath = dirName + getServletClassName() + ".java"; - if (jspPath.startsWith("/")) { - jspPath = jspPath.substring(1); - } - return jspPath; - } public String getClassFileName() { + if (classFileName != null) { return classFileName; } String outputDir = getOutputDir(); classFileName = getServletClassName() + ".class"; - if (outputDir != null && !outputDir.equals("")) { - classFileName = outputDir + File.separatorChar + classFileName; + if (outputDir != null && !outputDir.equals("")) { + classFileName = outputDir + File.separatorChar + classFileName; } - return classFileName; + return classFileName; + } + /** * Are we keeping generated code around? */ @@ -330,6 +356,7 @@ return options.getKeepGenerated(); } + /** * The content type of this JSP. * @@ -339,6 +366,7 @@ return contentType; } + /** * Get hold of the Options object for this context. */ @@ -346,46 +374,57 @@ return options; } + public void setClassLoader(URLClassLoader loader) { this.loader = loader; } + public void setContentType(String contentType) { this.contentType = contentType; } + public void setReader(JspReader reader) { this.reader = reader; } - + + public void setWriter(ServletWriter writer) { this.writer = writer; } - + + public void setServletClassName(String servletClassName) { this.servletClassName = servletClassName; } + public void setServletPackageName(String servletPackageName) { this.servletPackageName = servletPackageName; } - + + public void setServletJavaFileName(String servletJavaFileName) { this.servletJavaFileName = servletJavaFileName; } - + + public void setErrorPage(boolean isErrPage) { errPage = isErrPage; } + public void setOutputInDirs(boolean newValue) { outputInDirs = true; } + public boolean isOutputInDirs() { return outputInDirs; } + /** * Create a "Compiler" object based on some init param data. This * is not done yet. Right now we're just hardcoding the actual @@ -441,12 +480,13 @@ return in; } + public URL getResource(String res) - throws MalformedURLException - { + throws MalformedURLException { return loader.getResource(res); } + /** * Gets the actual path of a URI relative to the context of * the compilation. @@ -460,12 +500,14 @@ return f.getAbsolutePath(); } + public String[] getTldLocation(String uri) throws JasperException { String[] location = options.getTldLocationsCache().getLocation(uri); return location; } + public String getClassName() { String outputDir = getOutputDir(); String classFileName = getBaseClassName() + ".class"; @@ -474,7 +516,11 @@ return classFileName; } - public static String [] keywords = { + + // -------------------------------------------------------- Private Methods + + + private static final String [] keywords = { "abstract", "boolean", "break", "byte", "case", "catch", "char", "class", "const", "continue", "default", "do", @@ -490,6 +536,7 @@ "try", "void", "volatile", "while" }; + private final String getBaseClassName() { String className = getServletClassName(); String prefix = null; @@ -512,71 +559,55 @@ 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 (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(); + // 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); - } - /** - * 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)); - } + if (ch == File.separatorChar) { + ch = '/'; } - return b.toString(); + 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); + } 1.12 +10 -8 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/JspEngineContext.java Index: JspEngineContext.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/JspEngineContext.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- JspEngineContext.java 1 Jun 2002 00:43:01 -0000 1.11 +++ JspEngineContext.java 3 Jun 2002 06:58:38 -0000 1.12 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/JspEngineContext.java,v 1.11 2002/06/01 00:43:01 remm Exp $ - * $Revision: 1.11 $ - * $Date: 2002/06/01 00:43:01 $ + * $Header: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/JspEngineContext.java,v 1.12 2002/06/03 06:58:38 remm Exp $ + * $Revision: 1.12 $ + * $Date: 2002/06/03 06:58:38 $ * * ==================================================================== * @@ -312,6 +312,7 @@ return options.getKeepGenerated(); } + /** * Get the content type of this JSP. * @@ -516,12 +517,12 @@ try { URL outURL = options.getScratchDir().toURL(); String outURI = outURL.toString(); - if( outURI.endsWith("/") ) { - outURI = outURI + - jspUri.substring(1,jspUri.lastIndexOf("/")+1); + if (outURI.endsWith("/")) { + outURI = outURI + + jspUri.substring(1,jspUri.lastIndexOf("/")+1); } else { - outURI = outURI + - jspUri.substring(0,jspUri.lastIndexOf("/")+1);; + outURI = outURI + + jspUri.substring(0,jspUri.lastIndexOf("/")+1); } outURL = new URL(outURI); outDir = new File(outURL.getFile()); @@ -535,6 +536,7 @@ e.getMessage()); } } + /** * Mangle the specified character to create a legal Java class name.
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>