You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by sh...@locus.apache.org on 2000/07/11 02:15:05 UTC
cvs commit: jakarta-tomcat/src/share/org/apache/jasper/compiler JspReader.java
shemnon 00/07/10 17:15:04
Modified: src/share/org/apache/jasper JspC.java
CommandLineContext.java JspEngineContext.java
src/share/org/apache/jasper/compiler JspReader.java
Log:
Generalized maintinence
* A bug with -webapp and no -uriroot and -uribase fixed
(found by Stephen Zhou <szhou on an email server named entricom.com>)
* removed some "};" sequences breaking forte (a habit I picked up in
my pascal days
* unified some error messages to use the logger and the resource bundle
Revision Changes Path
1.16 +131 -73 jakarta-tomcat/src/share/org/apache/jasper/JspC.java
Index: JspC.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/jasper/JspC.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- JspC.java 2000/06/27 20:59:39 1.15
+++ JspC.java 2000/07/11 00:15:03 1.16
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/jasper/JspC.java,v 1.15 2000/06/27 20:59:39 costin Exp $
- * $Revision: 1.15 $
- * $Date: 2000/06/27 20:59:39 $
+ * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/jasper/JspC.java,v 1.16 2000/07/11 00:15:03 shemnon Exp $
+ * $Revision: 1.16 $
+ * $Date: 2000/07/11 00:15:03 $
*
* ====================================================================
*
@@ -138,6 +138,7 @@
int webxmlLevel;
int dieLevel;
+ boolean dieOnExit = false;
static int die; // I realize it is duplication, but this is for
// the static main catch
@@ -211,8 +212,8 @@
private void pushBackArg() {
if (!fullstop) {
argPos--;
- };
- };
+ }
+ }
private String nextArg() {
if ((argPos >= args.length)
@@ -221,7 +222,7 @@
} else {
return args[argPos++];
}
- };
+ }
private String nextFile() {
if (fullstop) argPos++;
@@ -230,7 +231,7 @@
} else {
return args[argPos++];
}
- };
+ }
public JspC(String[] arg, PrintStream log) {
args = arg;
@@ -290,12 +291,12 @@
webxmlFile = nextArg();
if (webxmlFile != null) {
webxmlLevel = INC_WEBXML;
- };
+ }
} else if (tok.equals(SWITCH_WEBAPP_XML)) {
webxmlFile = nextArg();
if (webxmlFile != null) {
webxmlLevel = ALL_WEBXML;
- };
+ }
} else if (tok.equals(SWITCH_MAPPED)) {
mappedFile = true;
} else if (tok.startsWith(SWITCH_DIE)) {
@@ -304,7 +305,7 @@
tok.substring(SWITCH_DIE.length()));
} catch (NumberFormatException nfe) {
dieLevel = DEFAULT_DIE_LEVEL;
- };
+ }
die = dieLevel;
} else {
pushBackArg();
@@ -316,9 +317,9 @@
Constants.jasperLog = new TomcatLogger();
Constants.jasperLog.setVerbosityLevel(verbosityLevel);
- };
+ }
- public boolean parseFile(PrintStream log, String file, Writer mapout)
+ public boolean parseFile(PrintStream log, String file, Writer servletout, Writer mappingout)
{
try {
JasperLoader loader =
@@ -338,7 +339,7 @@
}
if (dirset) {
clctxt.setOutputInDirs(true);
- };
+ }
File uriDir = new File(clctxt.getRealPath("/"));
if (uriDir.exists()) {
if ((new File(uriDir, "WEB-INF/classes")).exists()) {
@@ -360,46 +361,51 @@
}
}
}
- };
+ }
CommandLineCompiler clc = new CommandLineCompiler(clctxt);
clc.compile();
targetClassName = null;
- if (mapout != null) {
- String thisServletName;
- if (clc.getPackageName() == null) {
- thisServletName = clc.getClassName();
- } else {
- thisServletName = clc.getPackageName()
- + '.' + clc.getClassName();
- };
- mapout.write("\n\t<servlet>\n\t\t<servlet-name>");
- mapout.write(thisServletName);
- mapout.write("</servlet-name>\n\t\t<servlet-class>");
- mapout.write(thisServletName);
- mapout.write("</servlet-class>\n\t</servlet>\n\t<servlet-mapping>\n\t\t<url-pattern>");
- mapout.write(file);
- mapout.write("</url-pattern>\n\t\t<servlet-name>");
- mapout.write(thisServletName);
- mapout.write("</servlet-name>\n\t</servlet-mapping>\n");
- };
+ String thisServletName;
+ if (clc.getPackageName() == null) {
+ thisServletName = clc.getClassName();
+ } else {
+ thisServletName = clc.getPackageName()
+ + '.' + clc.getClassName();
+ }
+ if (servletout != null) {
+ servletout.write("\n\t<servlet>\n\t\t<servlet-name>");
+ servletout.write(thisServletName);
+ servletout.write("</servlet-name>\n\t\t<servlet-class>");
+ servletout.write(thisServletName);
+ servletout.write("</servlet-class>\n\t</servlet>\n");
+ }
+ if (mappingout != null) {
+ mappingout.write("\n\t<servlet-mapping>\n\t\t<url-pattern>");
+ mappingout.write(file);
+ mappingout.write("</url-pattern>\n\t\t<servlet-name>");
+ mappingout.write(thisServletName);
+ mappingout.write("</servlet-name>\n\t</servlet-mapping>\n");
+ }
return true;
} catch (JasperException je) {
- je.printStackTrace(log);
- log.print("error:");
- log.println(je.getMessage());
+ //je.printStackTrace(log);
+ Constants.message("jspc.error.jasperException",
+ new Object[] {file, je}, Logger.ERROR);
if (dieLevel != NO_DIE_LEVEL) {
- System.exit(dieLevel);
+ dieOnExit = true;
}
+ } catch (FileNotFoundException fne) {
+ Constants.message("jspc.error.fileDoesNotExist",
+ new Object[] {fne.getMessage()}, Logger.WARNING);
} catch (Exception e) {
- e.printStackTrace(log);
- log.print("ERROR:");
- log.println(e.toString());
+ Constants.message("jspc.error.generalException",
+ new Object[] {file, e}, Logger.ERROR);
if (dieLevel != NO_DIE_LEVEL) {
- System.exit(dieLevel);
+ dieOnExit = true;
}
- };
+ }
return false;
}
@@ -418,10 +424,45 @@
scratchDir = new File(new File(temp).getAbsolutePath());
}
+
File f = new File(args[argPos]);
- if (!f.exists() && f.isDirectory() && (args.length - argPos == 1)) {
- // do web-app conversion
- } else if (uriRoot == null) {
+ while (!f.exists()) {
+ boolean webApp = false;
+ if (SWITCH_FILE_WEBAPP.equals(args[argPos])) {
+ webApp = true;
+ if (args.length > argPos + 1) {
+ f = new File(args[argPos + 1]);
+ } else {
+ // end of arguments, nothing left to parse
+ Constants.message("jspc.error.emptyWebApp",
+ Logger.ERROR);
+ return;
+ }
+ }
+ if (!f.exists()) {
+ Constants.message("jspc.error.fileDoesNotExist",
+ new Object[] {f}, Logger.WARNING);
+ argPos++;
+ if (webApp) {
+ argPos++;
+ }
+ if (argPos >= args.length) {
+ // end of arguments, nothing left to parse
+ return;
+ } else {
+ f = new File(args[argPos]);
+ }
+ }
+ }
+ if (uriRoot == null) {
+ if (SWITCH_FILE_WEBAPP.equals(args[argPos])) {
+ if (args.length > argPos + 1) {
+ f = new File(args[argPos + 1]);
+ } else {
+ // end of arguments, nothing left to parse
+ return;
+ }
+ }
// set up the uri root if none is explicitly set
String tUriBase = uriBase;
if (tUriBase == null) {
@@ -442,7 +483,7 @@
}
if (f.exists() && f.isDirectory()) {
tUriBase = "/" + f.getName() + "/" + tUriBase;
- };
+ }
String fParent = f.getParent();
if (fParent == null) {
@@ -478,21 +519,22 @@
ubase = froot.getCanonicalPath();
} catch (IOException ioe) {
// if we cannot get the base, leave it null
- };
+ }
while (file != null) {
if (SWITCH_FILE_WEBAPP.equals(file)) {
String base = nextFile();
if (base == null) {
- // friendly but quiet failure
- break;
+ Constants.message("jspc.error.emptyWebApp",
+ Logger.ERROR);
+ return;
}// else if (".".equals(base)) {
// base = "";
- //};
+ //}
String oldRoot = uriRoot;
if (!urirootSet) {
uriRoot = base;
- };
+ }
Vector pages = new Vector();
Stack dirs = new Stack();
@@ -500,7 +542,7 @@
if (extensions == null) {
extensions = new Vector();
extensions.addElement("jsp");
- };
+ }
while (!dirs.isEmpty()) {
String s = dirs.pop().toString();
//System.out.println("--" + s);
@@ -523,11 +565,11 @@
s + File.separatorChar + files[i]);
} else {
//System.out.println("not done:" + ext);
- };
- };
- };
- };
- };
+ }
+ }
+ }
+ }
+ }
String ubaseOld = ubase;
File frootOld = froot;
@@ -537,25 +579,34 @@
ubase = froot.getCanonicalPath();
} catch (IOException ioe) {
// if we cannot get the base, leave it null
- };
+ }
//System.out.println("==" + ubase);
Writer mapout;
+ CharArrayWriter servletout, mappingout;
try {
if (webxmlLevel >= INC_WEBXML) {
File fmapings = new File(webxmlFile);
mapout = new FileWriter(fmapings);
+ servletout = new CharArrayWriter();
+ mappingout = new CharArrayWriter();
} else {
mapout = null;
- };
+ servletout = null;
+ mappingout = null;
+ }
if (webxmlLevel >= ALL_WEBXML) {
mapout.write(Constants.getString("jspc.webxml.header"));
- };
+ } else if (webxmlLevel>= INC_WEBXML) {
+ mapout.write(Constants.getString("jspc.webinc.header"));
+ }
} catch (IOException ioe) {
mapout = null;
- };
+ servletout = null;
+ mappingout = null;
+ }
Enumeration e = pages.elements();
while (e.hasMoreElements())
@@ -568,27 +619,31 @@
//System.out.println("**" + s);
if (s.startsWith(ubase)) {
nextjsp = s.substring(ubase.length());
- };
- };
+ }
+ }
} catch (IOException ioe) {
// if we got problems dont change the file name
- };
+ }
if (nextjsp.startsWith("." + File.separatorChar)) {
nextjsp = nextjsp.substring(2);
- };
+ }
- parseFile(log, nextjsp, mapout);
- };
+ parseFile(log, nextjsp, servletout, mappingout);
+ }
uriRoot = oldRoot;
ubase = ubaseOld;
froot = frootOld;
if (mapout != null) {
try {
+ servletout.writeTo(mapout);
+ mappingout.writeTo(mapout);
if (webxmlLevel >= ALL_WEBXML) {
mapout.write(Constants.getString("jspc.webxml.footer"));
- };
+ } else if (webxmlLevel >= INC_WEBXML) {
+ mapout.write(Constants.getString("jspc.webinc.footer"));
+ }
mapout.close();
} catch (IOException ioe) {
// noting to do if it fails since we are done with it
@@ -601,17 +656,20 @@
String s = fjsp.getCanonicalPath();
if (s.startsWith(ubase)) {
file = s.substring(ubase.length());
- };
+ }
}
} catch (IOException ioe) {
// if we got problems dont change the file name
- };
+ }
- parseFile(log, file, null);
- };
+ parseFile(log, file, null, null);
+ }
file = nextFile();
}
- };
+ if (dieOnExit) {
+ System.exit(die);
+ }
+ }
public static void main(String arg[]) {
if (arg.length == 0) {
@@ -628,7 +686,7 @@
}
}
}
- };
+ }
}
1.6 +44 -44 jakarta-tomcat/src/share/org/apache/jasper/CommandLineContext.java
Index: CommandLineContext.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/jasper/CommandLineContext.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- CommandLineContext.java 2000/06/27 20:59:39 1.5
+++ CommandLineContext.java 2000/07/11 00:15:04 1.6
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/jasper/CommandLineContext.java,v 1.5 2000/06/27 20:59:39 costin Exp $
- * $Revision: 1.5 $
- * $Date: 2000/06/27 20:59:39 $
+ * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/jasper/CommandLineContext.java,v 1.6 2000/07/11 00:15:04 shemnon Exp $
+ * $Revision: 1.6 $
+ * $Date: 2000/07/11 00:15:04 $
*
* ====================================================================
*
@@ -125,11 +125,11 @@
// strip the basde slash since it will be combined with the
// uriBase to generate a file
uriBase = "/" + uriBase;
- };
+ }
if (uriBase.charAt(uriBase.length() - 1) != '/') {
uriBase += '/';
- };
+ }
if (tUriRoot == null) {
uriRoot = new File("");
@@ -138,30 +138,30 @@
if (!uriRoot.exists() || !uriRoot.isDirectory()) {
throw new JasperException(
Constants.getString("jsp.error.jspc.uriroot_not_dir"));
- };
- };
- };
+ }
+ }
+ }
/**
* The classpath that is passed off to the Java compiler.
*/
public String getClassPath() {
return 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
@@ -169,7 +169,7 @@
*/
public ClassLoader getClassLoader() {
return loader;
- };
+ }
public void addJar( String jar ) throws IOException {
loader.addJar( jar );
@@ -181,7 +181,7 @@
*/
public boolean isErrorPage() {
return errPage;
- };
+ }
/**
* What is the scratch directory we are generating code into?
@@ -190,7 +190,7 @@
*/
public String getOutputDir() {
return options.getScratchDir().toString();
- };
+ }
/**
* Path of the JSP URI. Note that this is not a file name. This is
@@ -198,7 +198,7 @@
*/
public String getJspFile() {
return jspFile;
- };
+ }
/**
* Just the class name (does not include package name) of the
@@ -206,14 +206,14 @@
*/
public String getServletClassName() {
return servletClassName;
- };
+ }
/**
* The package name into which the servlet class is generated.
*/
public String getServletPackageName() {
return servletPackageName;
- };
+ }
/**
* Utility method to get the full class name from the package and
@@ -225,9 +225,9 @@
pkg += ".";
} else {
pkg = "";
- };
+ }
return pkg + getServletClassName();
- };
+ }
/**
* Full path name of the Java file into which the servlet is being
@@ -240,14 +240,14 @@
} else {
return servletJavaFileName;
}
- };
+ }
/**
* Are we keeping generated code around?
*/
public boolean keepGenerated() {
return options.getKeepGenerated();
- };
+ }
/**
* What's the content type of this JSP? Content type includes
@@ -255,66 +255,66 @@
*/
public String getContentType() {
return contentType;
- };
+ }
/**
* Get hold of the Options object for this context.
*/
public Options getOptions() {
return options;
- };
+ }
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) {
if (classNameLocked) {
//System.out.println("Did not change clazz to " + servletClassName);
} else {
this.servletClassName = servletClassName;
- };
- };
+ }
+ }
public void setServletPackageName(String servletPackageName) {
if (packageNameLocked) {
//System.out.println("Did not change pkg to " + servletPackageName);
} else {
this.servletPackageName = servletPackageName;
- };
- };
+ }
+ }
public void setServletJavaFileName(String servletJavaFileName) {
this.servletJavaFileName = servletJavaFileName;
- };
+ }
public void setErrorPage(boolean isErrPage) {
errPage = isErrPage;
- };
+ }
public void lockPackageName() {
packageNameLocked = true;
- };
+ }
public void lockClassName() {
classNameLocked = true;
- };
+ }
public void setOutputInDirs(boolean newValue) {
outputInDirs = true;
- };
+ }
public boolean isOutputInDirs() {
return outputInDirs;
- };
+ }
/**
* Create a "Compiler" object based on some init param data. This
@@ -323,7 +323,7 @@
*/
public Compiler createCompiler() throws JasperException {
return new CommandLineCompiler(this);
- };
+ }
/**
@@ -336,7 +336,7 @@
} else {
return uriBase + uri;
}
- };
+ }
/**
@@ -352,19 +352,19 @@
in = new FileInputStream(getRealPath(res));
} catch (IOException ioe) {
in = null;
- };
+ }
// next, try it as an absolute name
if (in == null) try {
in = new FileInputStream(res);
} catch (IOException ioe) {
in = null;
- };
+ }
// that dind't work, last chance is to try the classloaders
if (in == null) {
in = loader.getResourceAsStream(res);
- };
+ }
return in;
- };
+ }
/**
@@ -375,10 +375,10 @@
path = resolveRelativeUri(path);
if (path.startsWith("/")) {
path = path.substring(1);
- };
+ }
File f = new File(uriRoot, path.replace('/', File.separatorChar));
return f.getAbsolutePath();
- };
+ }
}
1.9 +6 -6 jakarta-tomcat/src/share/org/apache/jasper/JspEngineContext.java
Index: JspEngineContext.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/jasper/JspEngineContext.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- JspEngineContext.java 2000/06/27 20:59:39 1.8
+++ JspEngineContext.java 2000/07/11 00:15:04 1.9
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/jasper/JspEngineContext.java,v 1.8 2000/06/27 20:59:39 costin Exp $
- * $Revision: 1.8 $
- * $Date: 2000/06/27 20:59:39 $
+ * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/jasper/JspEngineContext.java,v 1.9 2000/07/11 00:15:04 shemnon Exp $
+ * $Revision: 1.9 $
+ * $Date: 2000/07/11 00:15:04 $
*
* ====================================================================
*
@@ -335,7 +335,7 @@
String baseURI = actURI.substring(0, actURI.lastIndexOf('/'));
return baseURI + '/' + uri;
}
- };
+ }
/**
* Gets a resource as a stream, relative to the meanings of this
@@ -346,7 +346,7 @@
public java.io.InputStream getResourceAsStream(String res)
{
return context.getResourceAsStream(res);
- };
+ }
/**
* Gets the actual path of a URI relative to the context of
@@ -362,7 +362,7 @@
{
return path;
}
- };
+ }
}
1.17 +1 -1 jakarta-tomcat/src/share/org/apache/jasper/compiler/JspReader.java
Index: JspReader.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/jasper/compiler/JspReader.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- JspReader.java 2000/06/11 20:48:50 1.16
+++ JspReader.java 2000/07/11 00:15:04 1.17
@@ -310,7 +310,7 @@
}
return new String(current.stream, cur_cursor, current.cursor-cur_cursor);
- };
+ }
char[] getChars(Mark start, Mark stop) throws ParseException {
Mark oldstart = mark();
Re: cvs commit: jakarta-tomcat/src/share/org/apache/jasper/compiler JspReader.java
Posted by Alex Chaffee <al...@edamame.stinky.com>.
On Tue, Jul 11, 2000 at 12:15:05AM -0000, shemnon@locus.apache.org wrote:
> Constants.jasperLog = new TomcatLogger();
> Constants.jasperLog.setVerbosityLevel(verbosityLevel);
Are you sure this is what you want?
> - };
> - };
> - };
> - };
> - };
> + }
> + }
> + }
> + }
> + }
:-) :-)
--
Alex Chaffee mailto:alex@jguru.com
jGuru - Java News and FAQs http://www.jguru.com/alex/
Creator of Gamelan http://www.gamelan.com/
Founder of Purple Technology http://www.purpletech.com/
Curator of Stinky Art Collective http://www.stinky.com/