org.apache.sling.scripting.jsp.jasper
Class JspCompilationContext

java.lang.Object
  extended by org.apache.sling.scripting.jsp.jasper.JspCompilationContext

public class JspCompilationContext
extends java.lang.Object

A place holder for various things that are used through out 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.

Author:
Anil K. Vijendran, Harish Prabandham, Pierre Delisle, Costin Manolache, Kin-man Chung

Constructor Summary
JspCompilationContext(java.lang.String jspUri, boolean isErrPage, Options options, javax.servlet.ServletContext context, JspRuntimeContext rctxt)
           
JspCompilationContext(java.lang.String tagfile, javax.servlet.jsp.tagext.TagInfo tagInfo, Options options, javax.servlet.ServletContext context, JspRuntimeContext rctxt, java.net.URL tagFileJarUrl)
           
 
Method Summary
 void checkOutputDir()
           
 JasperException compile()
           
 boolean delete(java.lang.String fileName)
          Removes a (generated) file.
 java.lang.String getClassFileName()
           
 java.lang.ClassLoader getClassLoader()
          What class loader to use for loading classes while compiling this JSP?
 Compiler getCompiler()
           
 java.lang.String getContentType()
          Get the content type of this JSP.
protected  java.lang.String getDerivedPackageName()
           
 java.io.InputStream getInputStream(java.lang.String fileName)
          Creates an input stream from the given file
 java.lang.String getJavaPath()
          Path of the Java file relative to the work directory.
 java.lang.String getJspFile()
          Path of the JSP URI.
 Options getOptions()
          Get hold of the Options object for this context.
 java.lang.String getOutputDir()
          The output directory to generate code into.
 java.io.OutputStream getOutputStream(java.lang.String fileName)
          Creates an output stream to the given file
 java.lang.String getRealPath(java.lang.String path)
          Gets the actual path of a URI relative to the context of the compilation.
 java.net.URL getResource(java.lang.String res)
           
 java.io.InputStream getResourceAsStream(java.lang.String res)
          Gets a resource as a stream, relative to the meanings of this context's implementation.
 java.util.Set<java.lang.String> getResourcePaths(java.lang.String path)
           
 JspRuntimeContext getRuntimeContext()
           
 java.lang.String getServletClassName()
          Just the class name (does not include package name) of the generated class.
 javax.servlet.ServletContext getServletContext()
           
 java.lang.String getServletJavaFileName()
          Full path name of the Java file into which the servlet is being generated.
 java.lang.String getServletPackageName()
          Package name for the generated class is make up of the base package name, which is user settable, and the derived package name.
 java.net.URL getTagFileJarUrl()
          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.
 java.net.URL getTagFileJarUrl(java.lang.String tagFile)
          Returns the tag-file-name-to-JAR-file map of this compilation unit, which maps tag file names to the JAR files in which the tag files are packaged.
 javax.servlet.jsp.tagext.TagInfo getTagInfo()
           
 java.lang.String[] getTldLocation(java.lang.String uri)
          Gets the 'location' of the TLD associated with the given taglib 'uri'.
 ServletWriter getWriter()
          Where is the servlet being generated?
 boolean isErrorPage()
          Are we processing something that has been declared as an errorpage?
 boolean isPrototypeMode()
          True if we are compiling a tag file in prototype mode.
 boolean isTagFile()
           
 boolean keepGenerated()
          Are we keeping generated code around?
 java.lang.Class<?> load()
           
 boolean rename(java.lang.String oldFileName, java.lang.String newFileName)
          Renams then old file to the new file
 java.lang.String resolveRelativeUri(java.lang.String uri)
          Get the full value of a URI relative to this compilations context uses current file as the base.
 void setContentType(java.lang.String contentType)
           
 void setErrorPage(boolean isErrPage)
           
 void setPrototypeMode(boolean pm)
           
 void setServletClassName(java.lang.String className)
           
 void setServletPackageName(java.lang.String servletPackageName)
          The package name into which the servlet class is generated.
 void setTagFileJarUrl(java.lang.String tagFile, java.net.URL tagFileURL)
           
 void setTagInfo(javax.servlet.jsp.tagext.TagInfo tagi)
           
 void setWriter(ServletWriter writer)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JspCompilationContext

public JspCompilationContext(java.lang.String jspUri,
                             boolean isErrPage,
                             Options options,
                             javax.servlet.ServletContext context,
                             JspRuntimeContext rctxt)

JspCompilationContext

public JspCompilationContext(java.lang.String tagfile,
                             javax.servlet.jsp.tagext.TagInfo tagInfo,
                             Options options,
                             javax.servlet.ServletContext context,
                             JspRuntimeContext rctxt,
                             java.net.URL tagFileJarUrl)
Method Detail

getClassLoader

public java.lang.ClassLoader getClassLoader()
What class loader to use for loading classes while compiling this JSP?


getOutputStream

public java.io.OutputStream getOutputStream(java.lang.String fileName)
                                     throws java.io.IOException
Creates an output stream to the given file

Parameters:
fileName - The path to the file to write to
Returns:
The OutputStream to the file
Throws:
java.io.IOException - If an error occurrs creating the output stream.

getInputStream

public java.io.InputStream getInputStream(java.lang.String fileName)
                                   throws java.io.FileNotFoundException,
                                          java.io.IOException
Creates an input stream from the given file

Parameters:
fileName - The path to the file to read from
Returns:
The InputStream from the file
Throws:
java.io.FileNotFoundException - If the file cannot be found
java.io.IOException - If an error occurrs creating the intput stream.

delete

public boolean delete(java.lang.String fileName)
Removes a (generated) file.

Parameters:
fileName - The path to the file to remove.
Returns:
true if the file has been removed.

rename

public boolean rename(java.lang.String oldFileName,
                      java.lang.String newFileName)
Renams then old file to the new file

Returns:
true if the file has been renamed

getOutputDir

public java.lang.String getOutputDir()
The output directory to generate code into. The output directory is make up of the scratch directory, which is provide in Options, plus the directory derived from the package name.


getCompiler

public Compiler getCompiler()

resolveRelativeUri

public java.lang.String resolveRelativeUri(java.lang.String uri)
Get the full value of a URI relative to this compilations context uses current file as the base.


getResourceAsStream

public java.io.InputStream getResourceAsStream(java.lang.String res)
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 as an InputStream.

getResource

public java.net.URL getResource(java.lang.String res)
                         throws java.net.MalformedURLException
Throws:
java.net.MalformedURLException

getResourcePaths

public java.util.Set<java.lang.String> getResourcePaths(java.lang.String path)

getRealPath

public java.lang.String getRealPath(java.lang.String path)
Gets the actual path of a URI relative to the context of the compilation.


getTagFileJarUrl

public java.net.URL getTagFileJarUrl(java.lang.String tagFile)
Returns the tag-file-name-to-JAR-file map of this compilation unit, which maps tag file names to the JAR files in which the tag files are packaged. The map is populated when parsing the tag-file elements of the TLDs of any imported taglibs.


setTagFileJarUrl

public void setTagFileJarUrl(java.lang.String tagFile,
                             java.net.URL tagFileURL)

getTagFileJarUrl

public java.net.URL getTagFileJarUrl()
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.


getServletClassName

public java.lang.String getServletClassName()
Just the class name (does not include package name) of the generated class.


setServletClassName

public void setServletClassName(java.lang.String className)

getJspFile

public java.lang.String getJspFile()
Path of the JSP URI. Note that this is not a file name. This is the context rooted URI of the JSP file.


isErrorPage

public boolean isErrorPage()
Are we processing something that has been declared as an errorpage?


setErrorPage

public void setErrorPage(boolean isErrPage)

isTagFile

public boolean isTagFile()

getTagInfo

public javax.servlet.jsp.tagext.TagInfo getTagInfo()

setTagInfo

public void setTagInfo(javax.servlet.jsp.tagext.TagInfo tagi)

isPrototypeMode

public boolean isPrototypeMode()
True if we are compiling a tag file in prototype mode. ie we only generate codes with class for the tag handler with empty method bodies.


setPrototypeMode

public void setPrototypeMode(boolean pm)

getServletPackageName

public java.lang.String getServletPackageName()
Package name for the generated class is make up of the base package name, which is user settable, and the derived package name. The derived package name directly mirrors the file heirachy of the JSP page.


getDerivedPackageName

protected java.lang.String getDerivedPackageName()

setServletPackageName

public void setServletPackageName(java.lang.String servletPackageName)
The package name into which the servlet class is generated.


getServletJavaFileName

public java.lang.String getServletJavaFileName()
Full path name of the Java file into which the servlet is being generated.


getOptions

public Options getOptions()
Get hold of the Options object for this context.


getServletContext

public javax.servlet.ServletContext getServletContext()

getRuntimeContext

public JspRuntimeContext getRuntimeContext()

getJavaPath

public java.lang.String getJavaPath()
Path of the Java file relative to the work directory.


getClassFileName

public java.lang.String getClassFileName()

getContentType

public java.lang.String getContentType()
Get the content type of this JSP. Content type includes content type and encoding.


setContentType

public void setContentType(java.lang.String contentType)

getWriter

public ServletWriter getWriter()
Where is the servlet being generated?


setWriter

public void setWriter(ServletWriter writer)

getTldLocation

public java.lang.String[] getTldLocation(java.lang.String uri)
                                  throws JasperException
Gets the 'location' of the TLD associated with the given 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.
Throws:
JasperException

keepGenerated

public boolean keepGenerated()
Are we keeping generated code around?


compile

public JasperException compile()

load

public java.lang.Class<?> load()
                        throws JasperException
Throws:
JasperException

checkOutputDir

public void checkOutputDir()


Copyright © 2007-2012 The Apache Software Foundation. All Rights Reserved.