Class JspCompilationContext
java.lang.Object
org.apache.jasper.JspCompilationContext
A placeholder for various things that are used throughout the JSP engine. This is a per-request/per-context data
structure. Some of the instance variables are set at different points. Most of the path-related stuff is here -
mangling names, versions, dirs, loading resources and dealing with uris.
-
Constructor Summary
ConstructorsConstructorDescriptionJspCompilationContext(String tagfile, TagInfo tagInfo, Options options, ServletContext context, JspServletWrapper jsw, JspRuntimeContext rctxt, Jar tagJar) Creates a compilation context for a tag file.JspCompilationContext(String jspUri, Options options, ServletContext context, JspServletWrapper jsw, JspRuntimeContext rctxt) Creates a compilation context for a JSP page. -
Method Summary
Modifier and TypeMethodDescriptionprotected static StringCanonicalizes a URI string by resolving relative path components like '.' and '..' and collapsing multiple separators.voidChecks and creates the output directory if it does not exist.voidClears the JSP class loader so it will be recreated on next access.voidcompile()Compiles the JSP if it is out of date with respect to the generated class file.Create a "Compiler" object based on some init param data.protected CompilercreateCompiler(String className) Creates a compiler instance by class name using reflection.protected voidCreates the output directory path based on the package name and scratch directory.Returns the base package name into which all servlet and associated code is generated.Returns the full path name of the compiled class file.What class loader to use for loading classes while compiling this JSP?Returns the classpath used by the Java compiler for this JSP.Returns the compiler instance for this compilation context.protected StringReturns the derived package name based on the JSP URI path hierarchy.getFQCN()Returns the fully qualified class name of the generated servlet or tag handler.Returns the path of the Java file relative to the work directory.Path of the JSP URI.Returns the JSP-specific class loader, creating it if necessary.getLastModified(String resource) Returns the last modified time of the given resource using the default tag JAR.getLastModified(String resource, Jar tagJar) Returns the last modified time of the given resource.Returns the options object for this compilation context.The output directory to generate code into.getRealPath(String path) Gets the actual path of a URI relative to the context of the compilation.getResource(String res) Gets a resource as a URL, relative to the context of this compilation.Gets a resource as a stream, relative to the meanings of this context's implementation.getResourcePaths(String path) Gets the resource paths beneath the given path, relative to the context.Returns the JSP runtime context for this compilation context.Just the class name (does not include package name) of the generated class.Returns the servlet context for this compilation context.Returns the full path name of the Java file into which the servlet is being generated.Package name for the generated class is made up of the base package name, which is user settable, and the derived package name.Returns the JAR file in which the tag file for which this JspCompilationContext was created is packaged, or null if this JspCompilationContext does not correspond to a tag file, or if the corresponding tag file is not packaged in a JAR.Returns the tag information for this compilation context.getTldResourcePath(String uri) Gets the 'location' of the TLD associated with the given taglib 'uri'.Returns the writer used to write the generated Servlet source code.voidIncrements the removed counter and removes the wrapper from the runtime context.protected static booleanisPathSeparator(char c) Checks whether the given character is a path separator.booleanReturns whether we are compiling a tag file in prototype mode, i.e., generating code with class for the tag handler with empty method bodies.booleanReturns whether this JSP has been removed.booleanReturns whether this compilation context corresponds to a tag file.booleanReturns whether the generated code is kept after compilation.Class<?> load()Loads the compiled servlet class using the JSP class loader.protected booleanCreates the output directory for generated files.resolveRelativeUri(String uri) Get the full value of a URI relative to this compilations context uses current file as the base.voidsetBasePackageName(String basePackageName) The package name into which the servlet class is generated.voidsetClassLoader(ClassLoader loader) Sets the class loader to use for loading classes while compiling this JSP.voidsetClassPath(String classPath) The classpath that is passed off to the Java compiler.voidsetPrototypeMode(boolean pm) Sets the prototype mode for tag file compilation.voidsetServletClassName(String className) Sets the class name for the generated servlet.voidsetTagFileJar(Jar tagJar) Sets the JAR file in which the tag file is packaged.voidsetTagInfo(TagInfo tagi) Sets the tag information for this compilation context.voidsetWriter(ServletWriter writer) Sets the writer used to write the generated Servlet source code.
-
Constructor Details
-
JspCompilationContext
public JspCompilationContext(String jspUri, Options options, ServletContext context, JspServletWrapper jsw, JspRuntimeContext rctxt) Creates a compilation context for a JSP page.- Parameters:
jspUri- The URI of the JSP page relative to the contextoptions- The compilation optionscontext- The servlet contextjsw- The JSP servlet wrapperrctxt- The JSP runtime context
-
JspCompilationContext
public JspCompilationContext(String tagfile, TagInfo tagInfo, Options options, ServletContext context, JspServletWrapper jsw, JspRuntimeContext rctxt, Jar tagJar) Creates a compilation context for a tag file.- Parameters:
tagfile- The URI of the tag filetagInfo- The tag informationoptions- The compilation optionscontext- The servlet contextjsw- The JSP servlet wrapperrctxt- The JSP runtime contexttagJar- The JAR containing the tag file
-
-
Method Details
-
getClassPath
Returns the classpath used by the Java compiler for this JSP.- Returns:
- the classpath that is passed off to the Java compiler
-
setClassPath
The classpath that is passed off to the Java compiler.- Parameters:
classPath- The class path to use
-
getClassLoader
What class loader to use for loading classes while compiling this JSP?- Returns:
- the class loader used to load all compiled classes
-
setClassLoader
Sets the class loader to use for loading classes while compiling this JSP.- Parameters:
loader- The class loader
-
getJspLoader
Returns the JSP-specific class loader, creating it if necessary.- Returns:
- the JSP class loader
-
clearJspLoader
public void clearJspLoader()Clears the JSP class loader so it will be recreated on next access. -
getOutputDir
The output directory to generate code into. The output directory is make up of the scratch directory, which is provided in Options, plus the directory derived from the package name.- Returns:
- the output directory in which the generated sources are placed
-
createCompiler
Create a "Compiler" object based on some init param data. This is not done yet. Right now we're just hardcoding the actual compilers that are created.- Returns:
- the Java compiler wrapper
-
createCompiler
-
getCompiler
Returns the compiler instance for this compilation context.- Returns:
- the compiler instance
-
resolveRelativeUri
-
getResourceAsStream
Gets a resource as a stream, relative to the meanings of this context's implementation.- Parameters:
res- the resource to look for- Returns:
- a null if the resource cannot be found or represented as an InputStream.
-
getResource
Gets a resource as a URL, relative to the context of this compilation.- Parameters:
res- The resource path- Returns:
- the resource URL
- Throws:
MalformedURLException- If the resource URL is malformed
-
getResourcePaths
-
getRealPath
-
getTagFileJar
Returns the JAR file in which the tag file for which this JspCompilationContext was created is packaged, or null if this JspCompilationContext does not correspond to a tag file, or if the corresponding tag file is not packaged in a JAR.- Returns:
- a JAR file
-
setTagFileJar
Sets the JAR file in which the tag file is packaged.- Parameters:
tagJar- The JAR file
-
getServletClassName
Just the class name (does not include package name) of the generated class.- Returns:
- the class name
-
setServletClassName
Sets the class name for the generated servlet.- Parameters:
className- The class name
-
getJspFile
Path of the JSP URI. Note that this is not a file name. This is the context rooted URI of the JSP file.- Returns:
- the path to the JSP
-
getLastModified
-
getLastModified
-
isTagFile
public boolean isTagFile()Returns whether this compilation context corresponds to a tag file.- Returns:
trueif this is a tag file
-
getTagInfo
Returns the tag information for this compilation context.- Returns:
- the tag info, or
nullif not a tag file
-
setTagInfo
Sets the tag information for this compilation context.- Parameters:
tagi- The tag info
-
isPrototypeMode
public boolean isPrototypeMode()Returns whether we are compiling a tag file in prototype mode, i.e., generating code with class for the tag handler with empty method bodies.- Returns:
trueif we are compiling a tag file in prototype mode
-
setPrototypeMode
public void setPrototypeMode(boolean pm) Sets the prototype mode for tag file compilation.- Parameters:
pm- The prototype mode flag
-
getServletPackageName
Package name for the generated class is made up of the base package name, which is user settable, and the derived package name. The derived package name directly mirrors the file hierarchy of the JSP page.- Returns:
- the package name
-
getDerivedPackageName
Returns the derived package name based on the JSP URI path hierarchy.- Returns:
- the derived package name
-
getBasePackageName
Returns the base package name into which all servlet and associated code is generated.- Returns:
- the base package name
-
setBasePackageName
The package name into which the servlet class is generated.- Parameters:
basePackageName- The package name to use
-
getServletJavaFileName
Returns the full path name of the Java file into which the servlet is being generated.- Returns:
- the full path of the generated Java file
-
getOptions
Returns the options object for this compilation context.- Returns:
- the options object
-
getServletContext
Returns the servlet context for this compilation context.- Returns:
- the servlet context
-
getRuntimeContext
Returns the JSP runtime context for this compilation context.- Returns:
- the runtime context
-
getJavaPath
Returns the path of the Java file relative to the work directory.- Returns:
- the relative path of the Java file
-
getClassFileName
Returns the full path name of the compiled class file.- Returns:
- the class file path
-
getWriter
Returns the writer used to write the generated Servlet source code.- Returns:
- the servlet writer
-
setWriter
Sets the writer used to write the generated Servlet source code.- Parameters:
writer- The servlet writer
-
getTldResourcePath
Gets the 'location' of the TLD associated with the given taglib 'uri'.- Parameters:
uri- The taglib URI- Returns:
- An array of two Strings: The first element denotes the real path to the TLD. If the path to the TLD points to a jar file, then the second element denotes the name of the TLD entry in the jar file. Returns null if the given uri is not associated with any tag library 'exposed' in the web application.
-
keepGenerated
public boolean keepGenerated()Returns whether the generated code is kept after compilation.- Returns:
trueif generated code is kept
-
incrementRemoved
public void incrementRemoved()Increments the removed counter and removes the wrapper from the runtime context. -
isRemoved
public boolean isRemoved()Returns whether this JSP has been removed.- Returns:
trueif this JSP has been removed
-
compile
Compiles the JSP if it is out of date with respect to the generated class file.- Throws:
JasperException- If a compilation error occursFileNotFoundException- If the JSP file has been removed
-
load
Loads the compiled servlet class using the JSP class loader.- Returns:
- the loaded servlet class
- Throws:
JasperException- If the class cannot be loaded
-
getFQCN
Returns the fully qualified class name of the generated servlet or tag handler.- Returns:
- the fully qualified class name
-
checkOutputDir
public void checkOutputDir()Checks and creates the output directory if it does not exist. -
makeOutputDir
protected boolean makeOutputDir()Creates the output directory for generated files.- Returns:
trueif the directory was created or already exists
-
createOutputDir
protected void createOutputDir()Creates the output directory path based on the package name and scratch directory. -
isPathSeparator
protected static boolean isPathSeparator(char c) Checks whether the given character is a path separator.- Parameters:
c- The character to check- Returns:
trueif the character is '/' or '\\'
-
canonicalURI
-