📄 jspinterceptor.java
字号:
// System.out.println("uri=" + uri +
// //" outputDir=" + outputDir +
// //" jspSource=" + jspSource +
// " pkgDir=" + pkgDir +
// " baseClassN=" + baseClassN +
// " ext=" + ext +
// " mapPath=" + mapPath +
// " version=" + version);
}
/** After startup we try to find if the file was precompiled
before
*/
void readVersion() {
File mapFile=new File(mapPath);
version=0;
compileTime=0;
try {
FileInputStream fis=new FileInputStream( mapFile );
version=(int)fis.read();
// System.out.println("Version=" + version );
fis.close();
} catch( Exception ex ) {
ex.printStackTrace();
}
}
/** After we compile a page, we save the version in a
file with known name, so we can restore the state when we
restart. Note that this should move to a general-purpose
persist repository ( on my plans for next version of tomcat )
*/
void writeVersion() {
File mapFile=new File(mapPath);
try {
FileOutputStream fis=new FileOutputStream( mapFile );
fis.write(version);
// System.out.println("WVersion=" + version );
fis.close();
} catch( Exception ex ) {
ex.printStackTrace();
}
}
/** After a startup we read the compile time from the class
file lastModified. No further access to that file is done.
*/
void updateCompileTime() {
File f=new File( realClassPath );
compileTime=0;
if( ! f.exists() ) return;
compileTime=f.lastModified();
}
}
// XXX add code to set the options
class TomcatOptions implements Options {
public boolean keepGenerated = true;
public boolean largeFile = false;
public boolean mappedFile = false;
public boolean sendErrorToClient = false;
public boolean classDebugInfo = false;
public String ieClassId = "clsid:8AD9C840-044E-11D1-B3E9-00805F499D93";
public Class jspCompilerPlugin = null;
public String jspCompilerPath = null;
public File scratchDir;
private Object protectionDomain;
public String classpath = null;
public boolean getKeepGenerated() {
return keepGenerated;
}
public boolean getLargeFile() {
return largeFile;
}
public boolean getMappedFile() {
return mappedFile;
}
public boolean getSendErrorToClient() {
return sendErrorToClient;
}
public boolean getClassDebugInfo() {
return classDebugInfo;
}
public String getIeClassId() {
return ieClassId;
}
public void setScratchDir( File f ) {
scratchDir=f;
}
public File getScratchDir() {
System.out.println("Options: getScratchDir " + scratchDir);
return scratchDir;
}
public final Object getProtectionDomain() {
System.out.println("Options: GetPD" );
return protectionDomain;
}
public String getClassPath() {
System.out.println("Options: GetCP " + classpath );
return classpath;
}
public Class getJspCompilerPlugin() {
return jspCompilerPlugin;
}
public String getJspCompilerPath() {
return jspCompilerPath;
}
/**
* FIXME: see how compiler.Compiler handles javaEncoding
* and implement that behavior in this class when it
* is 'enabled' (pierred). This has been added only so the
* code compiles.
*/
public String getJavaEncoding() {
return "FIXME: NOT IMPLEMENTED";
}
}
class JspEngineContext1 implements JspCompilationContext {
JspReader reader;
ServletWriter writer;
ServletContext context;
JspLoader loader;
String classpath; // for compiling JSPs.
boolean isErrPage;
String jspFile;
String servletClassName;
String servletPackageName;
String servletJavaFileName;
String contentType;
Options options;
Request req;
Mangler m;
public JspEngineContext1(Request req, Mangler m)
{
this.req=req;
this.m=m;
}
public HttpServletRequest getRequest() {
System.out.println("JspEngineContext1: getRequest " + req );
return req.getFacade();
}
/**
* Get the http response we are using now...
*/
public HttpServletResponse getResponse() {
System.out.println("JspEngineContext1: getResponse " );
return req.getResponse().getFacade();
}
/**
* The classpath that is passed off to the Java compiler.
*/
public String getClassPath() {
System.out.println("JspEngineContext1: getClassPath " +
req.getContext().getServletLoader().getClassPath());
return req.getContext().getServletLoader().getClassPath();
}
/**
* Get the input reader for the JSP text.
*/
public JspReader getReader() {
System.out.println("JspEngineContext1: getReader " + reader );
return reader;
}
/**
* Where is the servlet being generated?
*/
public ServletWriter getWriter() {
System.out.println("JspEngineContext1: getWriter " + writer );
return writer;
}
/**
* Get the ServletContext for the JSP we're processing now.
*/
public ServletContext getServletContext() {
System.out.println("JspEngineContext1: getCtx " +
req.getContext().getFacade());
return req.getContext().getFacade();
}
/**
* What class loader to use for loading classes while compiling
* this JSP? I don't think this is used right now -- akv.
*/
public ClassLoader getClassLoader() {
System.out.println("JspEngineContext1: getLoader " + loader );
return req.getContext().getServletLoader().getClassLoader();
}
public void addJar( String jar ) throws IOException {
System.out.println("Add jar " + jar);
//loader.addJar( jar );
}
/**
* Are we processing something that has been declared as an
* errorpage?
*/
public boolean isErrorPage() {
System.out.println("JspEngineContext1: isErrorPage " + isErrPage );
return isErrPage;
}
/**
* What is the scratch directory we are generating code into?
* FIXME: In some places this is called scratchDir and in some
* other places it is called outputDir.
*/
public String getOutputDir() {
System.out.println("JspEngineContext1: getOutputDir " +
req.getContext().getWorkDir().getAbsolutePath());
return req.getContext().getWorkDir().getAbsolutePath();
}
/**
* Path of the JSP URI. Note that this is not a file name. This is
* the context rooted URI of the JSP file.
*/
public String getJspFile() {
String sP=req.getServletPath();
Context ctx=req.getContext();
System.out.println("JspEngineContext1: getJspFile " +
sP);// ctx.getRealPath( sP ) );
// return ctx.getRealPath( sP );
return sP;
}
/**
* Just the class name (does not include package name) of the
* generated class.
*/
public String getServletClassName() {
System.out.println("JspEngineContext1: getServletClassName " +
m.getClassName());
return m.getClassName();
}
/**
* The package name into which the servlet class is generated.
*/
public String getServletPackageName() {
System.out.println("JspEngineContext1: getServletPackageName " +
servletPackageName );
return servletPackageName;
}
/**
* Utility method to get the full class name from the package and
* class name.
*/
public final String getFullClassName() {
System.out.println("JspEngineContext1: getServletPackageName " +
servletPackageName + "." + servletClassName);
if (servletPackageName == null)
return servletClassName;
return servletPackageName + "." + servletClassName;
}
/**
* Full path name of the Java file into which the servlet is being
* generated.
*/
public String getServletJavaFileName() {
System.out.println("JspEngineContext1: getServletPackageName " +
servletPackageName + "." + servletClassName);
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
* content type and encoding.
*/
public String getContentType() {
return contentType;
}
/**
* Get hold of the Options object for this context.
*/
public Options getOptions() {
return options;
}
public void setOptions(Options options) {
this.options=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) {
this.servletClassName = servletClassName;
}
public void setServletPackageName(String servletPackageName) {
this.servletPackageName = servletPackageName;
}
public void setServletJavaFileName(String servletJavaFileName) {
this.servletJavaFileName = servletJavaFileName;
}
public void setErrorPage(boolean isErrPage) {
this.isErrPage = isErrPage;
}
public Compiler createCompiler() throws JasperException {
System.out.println("JspEngineContext1: createCompiler ");
return null;
}
public String resolveRelativeUri(String uri)
{
System.out.println("JspEngineContext1: resolveRelativeUri " + uri);
return null;
};
public java.io.InputStream getResourceAsStream(String res)
{
System.out.println("JspEngineContext1: getRAS " + res);
return req.getContext().getFacade().getResourceAsStream(res);
};
/**
* Gets the actual path of a URI relative to the context of
* the compilation.
*/
public String getRealPath(String path)
{
System.out.println("GetRP " + path + " " +
req.getContext().getRealPath(path));
return req.getContext().getRealPath(path);
};
}
class JspMangler implements Mangler{
JspInfo jspInfo;
public JspMangler(JspInfo info) {
this.jspInfo=info;
}
public final String getClassName() {
return jspInfo.classN;
}
public final String getJavaFileName() {
return jspInfo.javaFilePath;
}
public final String getPackageName() {
return jspInfo.pkg;
// It's not used, and shouldn't be used by compiler.
// ( well, it's used to rename the file after compile
// in JspServlet scheme - that must be out of compiler )
}
// Full path to the class file - without version.
public final String getClassFileName() {
return null; // see getPackageName comment
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -