org.apache.jasper

Class JspC

public class JspC extends Task implements Options

Shell for the jspc compiler. Handles all options associated with the command line and creates compilation contexts which it then compiles according to the specified options. This version can process files from a _single_ webapp at once, i.e. a single docbase can be specified. It can be used as an Ant task using:
   <taskdef classname="org.apache.jasper.JspC" name="jasper" >
      <classpath>
          <pathelement location="${java.home}/../lib/tools.jar"/>
          <fileset dir="${ENV.CATALINA_HOME}/lib">
              <include name="*.jar"/>
          </fileset>
          <path refid="myjars"/>
       </classpath>
  </taskdef>

  <jasper verbose="0"
           package="my.package"
           uriroot="${webapps.dir}/${webapp.name}"
           webXmlFragment="${build.dir}/generated_web.xml"
           outputDir="${webapp.dir}/${webapp.name}/WEB-INF/src/my/package" />
 

Author: Danno Ferrin Pierre Delisle Costin Manolache Yoav Shapira

Field Summary
protected static intALL_WEBXML
protected booleanaddWebXmlMappings
protected intargPos
protected String[]args
protected booleanblockExternal
protected Mapcache
protected booleancaching
protected booleanclassDebugInfo
protected StringclassPath
protected booleancompile
protected Stringcompiler
protected StringcompilerSourceVM
protected StringcompilerTargetVM
protected JspCServletContextcontext
The servlet context.
protected static intdie
protected intdieLevel
protected static intDEFAULT_DIE_LEVEL
static StringDEFAULT_IE_CLASS_ID
protected booleanerrorOnUseBeanInvalidClassAttribute
Needs better documentation, this data member does.
protected Listextensions
The file extensions to be handled as JSP files.
protected booleanfailOnError
Throw an exception if there's a compilation error, or swallow it.
protected booleanfullstop
protected booleangenStringAsCharArray
protected booleanhelpNeeded
protected StringieClassId
protected static String[]insertBefore
protected static intINC_WEBXML
protected StringjavaEncoding
The java file encoding.
protected JspConfigjspConfig
protected booleanlistErrors
protected URLClassLoaderloader
protected static Loglog
protected static StringLIST_ERRORS
protected Writermapout
protected booleanmappedFile
protected CharArrayWritermappingout
protected static intNO_DIE_LEVEL
protected Listpages
The pages.
protected booleanpoolingEnabled
protected JspRuntimeContextrctxt
The runtime context.
protected FilescratchDir
protected CharArrayWriterservletout
protected booleanshowSuccess
protected booleansmapDumped
protected booleansmapSuppressed
protected static StringSHOW_SUCCESS
protected static StringSWITCH_ADD_WEBAPP_XML_MAPPINGS
protected static StringSWITCH_BLOCK_EXTERNAL
protected static StringSWITCH_CACHE
protected static StringSWITCH_CLASSPATH
protected static StringSWITCH_CLASS_NAME
protected static StringSWITCH_COMPILE
protected static StringSWITCH_DIE
protected static StringSWITCH_DUMP_SMAP
protected static StringSWITCH_ENCODING
protected static StringSWITCH_FILE_WEBAPP
protected static StringSWITCH_FULL_STOP
protected static StringSWITCH_HELP
protected static StringSWITCH_MAPPED
protected static StringSWITCH_OUTPUT_DIR
protected static StringSWITCH_PACKAGE_NAME
protected static StringSWITCH_POOLING
protected static StringSWITCH_SMAP
protected static StringSWITCH_SOURCE
protected static StringSWITCH_TARGET
protected static StringSWITCH_TRIM_SPACES
protected static StringSWITCH_URI_BASE
protected static StringSWITCH_URI_ROOT
protected static StringSWITCH_VALIDATE_TLD
protected static StringSWITCH_VERBOSE
protected static StringSWITCH_WEBAPP_INC
protected static StringSWITCH_WEBAPP_XML
protected static StringSWITCH_WEBAPP_XML_ENCODING
protected static StringSWITCH_XPOWERED_BY
protected TagPluginManagertagPluginManager
protected StringtargetClassName
protected StringtargetPackage
protected TldLocationsCachetldLocationsCache
Cache for the TLD locations
protected booleantrimSpaces
protected StringuriBase
protected StringuriRoot
protected booleanvalidateTld
protected booleanverbose
protected StringwebxmlEncoding
protected StringwebxmlFile
protected intwebxmlLevel
protected booleanxpoweredBy
Method Summary
protected voidaddExtension(String extension)
Adds the given file extension to the list of extensions handled as JSP files.
protected voidcompleteWebXml()
voidgenerateWebMapping(String file, JspCompilationContext clctxt)
Adds servlet declaration and mapping for the JSP page servlet to the generated web.xml fragment.
booleangenStringAsCharArray()
MapgetCache()
intgetCheckInterval()
In JspC this always returns 0.
booleangetClassDebugInfo()
StringgetClassPath()
StringgetCompiler()
StringgetCompilerClassName()
StringgetCompilerSourceVM()
StringgetCompilerTargetVM()
booleangetDevelopment()
In JspC this always returns false.
booleangetDisplaySourceFragment()
In JspC this always returns true.
booleangetErrorOnUseBeanInvalidClassAttribute()
ListgetExtensions()
Returns the list of file extensions that are treated as JSP files.
booleangetFailOnError()
Returns true if an exception will be thrown in case of a compilation error.
booleangetFork()
StringgetIeClassId()
StringgetJavaEncoding()
Returns the encoding to use for java files.
JspConfiggetJspConfig()
booleangetKeepGenerated()
In JspC this always returns true.
booleangetMappedFile()
intgetModificationTestInterval()
In JspC this always returns 0.
booleangetRecompileOnFail()
In JspC this always returns false.
FilegetScratchDir()
TagPluginManagergetTagPluginManager()
TldLocationsCachegetTldLocationsCache()
booleangetTrimSpaces()
protected voidinitClassLoader(JspCompilationContext clctxt)
Initializes the classloader as/if needed for the given compilation context.
protected voidinitServletContext()
protected voidinitWebXml()
booleanisBlockExternal()
booleanisCaching()
booleanisPoolingEnabled()
booleanisSmapDumped()
booleanisSmapSuppressed()
booleanisValidateTld()
booleanisXpoweredBy()
protected voidlocateUriRoot(File f)
Find the WEB-INF dir by looking up in the directory tree.
static voidmain(String[] arg)
protected voidmergeIntoWebXml()
Include the generated web.xml inside the webapp's web.xml.
protected StringnextArg()
protected StringnextFile()
protected voidprocessFile(String file)
protected FileresolveFile(String s)
Resolves the relative or absolute pathname correctly in both Ant and command-line situations.
voidscanFiles(File base)
Locate all jsp files in the webapp.
voidsetAddWebXmlMappings(boolean b)
Sets the option to merge generated web.xml fragment into the WEB-INF/web.xml file of the web application that we were processing.
voidsetArgs(String[] arg)
Apply command-line arguments.
voidsetBlockExternal(boolean b)
voidsetCaching(boolean caching)
Sets the option to enable caching.
voidsetClassDebugInfo(boolean b)
Sets the option to include debug information in compiled class.
voidsetClassName(String p)
Class name of the generated file ( without package ).
voidsetClassPath(String s)
Sets the classpath used while compiling the servlets generated from JSP files
voidsetCompile(boolean b)
Sets the compile flag.
voidsetCompiler(String c)
Sets the option to determine what compiler to use.
voidsetCompilerSourceVM(String vm)
Sets the compiler source VM.
voidsetCompilerTargetVM(String vm)
Sets the compiler target VM.
voidsetErrorOnUseBeanInvalidClassAttribute(boolean b)
Sets the option to issue a compilation error if the class attribute specified in useBean action is invalid.
voidsetFailOnError(boolean b)
Sets the option that throws an exception in case of a compilation error.
voidsetGenStringAsCharArray(boolean genStringAsCharArray)
Determines whether text strings are to be generated as char arrays, which improves performance in some cases.
voidsetIeClassId(String ieClassId)
Sets the class-id value to be sent to Internet Explorer when using <jsp:plugin> tags.
voidsetJavaEncoding(String encodingName)
Sets the encoding to use for java files.
voidsetJspFiles(String jspFiles)
Parses comma-separated list of JSP files to be processed.
voidsetListErrors(boolean b)
voidsetOutputDir(String s)
voidsetPackage(String p)
Sets the package name to be used for the generated servlet classes.
voidsetPoolingEnabled(boolean poolingEnabled)
Sets the option to enable the tag handler pooling.
voidsetSmapDumped(boolean smapDumped)
Sets smapDumped flag.
voidsetSmapSuppressed(boolean smapSuppressed)
Sets smapSuppressed flag.
voidsetTrimSpaces(boolean ts)
Sets the option to trim white spaces between directives or actions.
voidsetUriroot(String s)
Base dir for the webapp.
voidsetValidateTld(boolean b)
voidsetVerbose(int level)
Sets the verbosity level.
voidsetWebXml(String s)
File where we generate a complete web.xml with the class definitions.
voidsetWebXmlEncoding(String encoding)
Sets the encoding to be used to read and write web.xml files.
voidsetWebXmlFragment(String s)
File where we generate a web.xml fragment with the class definitions.
voidsetXpoweredBy(boolean xpoweredBy)
Sets the option to enable generation of X-Powered-By response header.

Field Detail

ALL_WEBXML

protected static final int ALL_WEBXML

addWebXmlMappings

protected boolean addWebXmlMappings

argPos

protected int argPos

args

protected String[] args

blockExternal

protected boolean blockExternal

cache

protected Map cache

caching

protected boolean caching

classDebugInfo

protected boolean classDebugInfo

classPath

protected String classPath

compile

protected boolean compile

compiler

protected String compiler

compilerSourceVM

protected String compilerSourceVM

compilerTargetVM

protected String compilerTargetVM

context

protected JspCServletContext context
The servlet context.

die

protected static int die

dieLevel

protected int dieLevel

DEFAULT_DIE_LEVEL

protected static final int DEFAULT_DIE_LEVEL

DEFAULT_IE_CLASS_ID

public static final String DEFAULT_IE_CLASS_ID

errorOnUseBeanInvalidClassAttribute

protected boolean errorOnUseBeanInvalidClassAttribute
Needs better documentation, this data member does. True by default.

extensions

protected List extensions
The file extensions to be handled as JSP files. Default list is .jsp and .jspx.

failOnError

protected boolean failOnError
Throw an exception if there's a compilation error, or swallow it. Default is true to preserve old behavior.

fullstop

protected boolean fullstop

genStringAsCharArray

protected boolean genStringAsCharArray

helpNeeded

protected boolean helpNeeded

ieClassId

protected String ieClassId

insertBefore

protected static final String[] insertBefore

INC_WEBXML

protected static final int INC_WEBXML

javaEncoding

protected String javaEncoding
The java file encoding. Default is UTF-8. Added per bugzilla 19622.

jspConfig

protected JspConfig jspConfig

listErrors

protected boolean listErrors

loader

protected URLClassLoader loader

log

protected static Log log

LIST_ERRORS

protected static final String LIST_ERRORS

mapout

protected Writer mapout

mappedFile

protected boolean mappedFile

mappingout

protected CharArrayWriter mappingout

NO_DIE_LEVEL

protected static final int NO_DIE_LEVEL

pages

protected List pages
The pages.

poolingEnabled

protected boolean poolingEnabled

rctxt

protected JspRuntimeContext rctxt
The runtime context. Maintain a dummy JspRuntimeContext for compiling tag files.

scratchDir

protected File scratchDir

servletout

protected CharArrayWriter servletout

showSuccess

protected boolean showSuccess

smapDumped

protected boolean smapDumped

smapSuppressed

protected boolean smapSuppressed

SHOW_SUCCESS

protected static final String SHOW_SUCCESS

SWITCH_ADD_WEBAPP_XML_MAPPINGS

protected static final String SWITCH_ADD_WEBAPP_XML_MAPPINGS

SWITCH_BLOCK_EXTERNAL

protected static final String SWITCH_BLOCK_EXTERNAL

SWITCH_CACHE

protected static final String SWITCH_CACHE

SWITCH_CLASSPATH

protected static final String SWITCH_CLASSPATH

SWITCH_CLASS_NAME

protected static final String SWITCH_CLASS_NAME

SWITCH_COMPILE

protected static final String SWITCH_COMPILE

SWITCH_DIE

protected static final String SWITCH_DIE

SWITCH_DUMP_SMAP

protected static final String SWITCH_DUMP_SMAP

SWITCH_ENCODING

protected static final String SWITCH_ENCODING

SWITCH_FILE_WEBAPP

protected static final String SWITCH_FILE_WEBAPP

SWITCH_FULL_STOP

protected static final String SWITCH_FULL_STOP

SWITCH_HELP

protected static final String SWITCH_HELP

SWITCH_MAPPED

protected static final String SWITCH_MAPPED

SWITCH_OUTPUT_DIR

protected static final String SWITCH_OUTPUT_DIR

SWITCH_PACKAGE_NAME

protected static final String SWITCH_PACKAGE_NAME

SWITCH_POOLING

protected static final String SWITCH_POOLING

SWITCH_SMAP

protected static final String SWITCH_SMAP

SWITCH_SOURCE

protected static final String SWITCH_SOURCE

SWITCH_TARGET

protected static final String SWITCH_TARGET

SWITCH_TRIM_SPACES

protected static final String SWITCH_TRIM_SPACES

SWITCH_URI_BASE

protected static final String SWITCH_URI_BASE

SWITCH_URI_ROOT

protected static final String SWITCH_URI_ROOT

SWITCH_VALIDATE_TLD

protected static final String SWITCH_VALIDATE_TLD

SWITCH_VERBOSE

protected static final String SWITCH_VERBOSE

SWITCH_WEBAPP_INC

protected static final String SWITCH_WEBAPP_INC

SWITCH_WEBAPP_XML

protected static final String SWITCH_WEBAPP_XML

SWITCH_WEBAPP_XML_ENCODING

protected static final String SWITCH_WEBAPP_XML_ENCODING

SWITCH_XPOWERED_BY

protected static final String SWITCH_XPOWERED_BY

tagPluginManager

protected TagPluginManager tagPluginManager

targetClassName

protected String targetClassName

targetPackage

protected String targetPackage

tldLocationsCache

protected TldLocationsCache tldLocationsCache
Cache for the TLD locations

trimSpaces

protected boolean trimSpaces

uriBase

protected String uriBase

uriRoot

protected String uriRoot

validateTld

protected boolean validateTld

verbose

protected boolean verbose

webxmlEncoding

protected String webxmlEncoding

webxmlFile

protected String webxmlFile

webxmlLevel

protected int webxmlLevel

xpoweredBy

protected boolean xpoweredBy

Method Detail

addExtension

protected void addExtension(String extension)
Adds the given file extension to the list of extensions handled as JSP files.

Parameters: extension The extension to add, e.g. "myjsp"

completeWebXml

protected void completeWebXml()

generateWebMapping

public void generateWebMapping(String file, JspCompilationContext clctxt)
Adds servlet declaration and mapping for the JSP page servlet to the generated web.xml fragment.

Parameters: file Context-relative path to the JSP file, e.g. /index.jsp clctxt Compilation context of the servlet

genStringAsCharArray

public boolean genStringAsCharArray()
{@inheritDoc }

getCache

public Map getCache()
{@inheritDoc }

getCheckInterval

public int getCheckInterval()
In JspC this always returns 0. {@inheritDoc }

getClassDebugInfo

public boolean getClassDebugInfo()
{@inheritDoc }

getClassPath

public String getClassPath()
{@inheritDoc }

getCompiler

public String getCompiler()
{@inheritDoc }

getCompilerClassName

public String getCompilerClassName()
{@inheritDoc }

getCompilerSourceVM

public String getCompilerSourceVM()
{@inheritDoc }

getCompilerTargetVM

public String getCompilerTargetVM()
{@inheritDoc }

getDevelopment

public boolean getDevelopment()
In JspC this always returns false. {@inheritDoc }

getDisplaySourceFragment

public boolean getDisplaySourceFragment()
In JspC this always returns true. {@inheritDoc }

getErrorOnUseBeanInvalidClassAttribute

public boolean getErrorOnUseBeanInvalidClassAttribute()
{@inheritDoc }

getExtensions

public List getExtensions()
Returns the list of file extensions that are treated as JSP files.

Returns: The list of extensions

getFailOnError

public boolean getFailOnError()
Returns true if an exception will be thrown in case of a compilation error.

getFork

public boolean getFork()
{@inheritDoc }

getIeClassId

public String getIeClassId()
{@inheritDoc }

getJavaEncoding

public String getJavaEncoding()
Returns the encoding to use for java files. The default is UTF-8.

Returns: String The encoding

getJspConfig

public JspConfig getJspConfig()
{@inheritDoc }

getKeepGenerated

public boolean getKeepGenerated()
In JspC this always returns true. {@inheritDoc }

getMappedFile

public boolean getMappedFile()
{@inheritDoc }

getModificationTestInterval

public int getModificationTestInterval()
In JspC this always returns 0. {@inheritDoc }

getRecompileOnFail

public boolean getRecompileOnFail()
In JspC this always returns false. {@inheritDoc }

getScratchDir

public File getScratchDir()
{@inheritDoc }

getTagPluginManager

public TagPluginManager getTagPluginManager()
{@inheritDoc }

getTldLocationsCache

public TldLocationsCache getTldLocationsCache()
{@inheritDoc }

getTrimSpaces

public boolean getTrimSpaces()
{@inheritDoc }

initClassLoader

protected void initClassLoader(JspCompilationContext clctxt)
Initializes the classloader as/if needed for the given compilation context.

Parameters: clctxt The compilation context

Throws: IOException If an error occurs

initServletContext

protected void initServletContext()

initWebXml

protected void initWebXml()

isBlockExternal

public boolean isBlockExternal()

isCaching

public boolean isCaching()
{@inheritDoc }

isPoolingEnabled

public boolean isPoolingEnabled()
{@inheritDoc }

isSmapDumped

public boolean isSmapDumped()
{@inheritDoc }

isSmapSuppressed

public boolean isSmapSuppressed()
{@inheritDoc }

isValidateTld

public boolean isValidateTld()

isXpoweredBy

public boolean isXpoweredBy()
{@inheritDoc }

locateUriRoot

protected void locateUriRoot(File f)
Find the WEB-INF dir by looking up in the directory tree. This is used if no explicit docbase is set, but only files. XXX Maybe we should require the docbase.

main

public static void main(String[] arg)

mergeIntoWebXml

protected void mergeIntoWebXml()
Include the generated web.xml inside the webapp's web.xml.

nextArg

protected String nextArg()

nextFile

protected String nextFile()

processFile

protected void processFile(String file)

resolveFile

protected File resolveFile(String s)
Resolves the relative or absolute pathname correctly in both Ant and command-line situations. If Ant launched us, we should use the basedir of the current project to resolve relative paths. See Bugzilla 35571.

Parameters: s The file

Returns: The file resolved

scanFiles

public void scanFiles(File base)
Locate all jsp files in the webapp. Used if no explicit jsps are specified.

setAddWebXmlMappings

public void setAddWebXmlMappings(boolean b)
Sets the option to merge generated web.xml fragment into the WEB-INF/web.xml file of the web application that we were processing.

Parameters: b true to merge the fragment into the existing web.xml file of the processed web application ({uriroot}/WEB-INF/web.xml), false to keep the generated web.xml fragment

setArgs

public void setArgs(String[] arg)
Apply command-line arguments.

Parameters: arg The arguments

setBlockExternal

public void setBlockExternal(boolean b)

setCaching

public void setCaching(boolean caching)
Sets the option to enable caching.

See Also: isCaching

setClassDebugInfo

public void setClassDebugInfo(boolean b)
Sets the option to include debug information in compiled class.

setClassName

public void setClassName(String p)
Class name of the generated file ( without package ). Can only be used if a single file is converted. XXX Do we need this feature ?

setClassPath

public void setClassPath(String s)
Sets the classpath used while compiling the servlets generated from JSP files

setCompile

public void setCompile(boolean b)
Sets the compile flag.

Parameters: b Flag value

setCompiler

public void setCompiler(String c)
Sets the option to determine what compiler to use.

See Also: getCompiler

setCompilerSourceVM

public void setCompilerSourceVM(String vm)
Sets the compiler source VM.

See Also: getCompilerSourceVM

setCompilerTargetVM

public void setCompilerTargetVM(String vm)
Sets the compiler target VM.

See Also: getCompilerTargetVM

setErrorOnUseBeanInvalidClassAttribute

public void setErrorOnUseBeanInvalidClassAttribute(boolean b)
Sets the option to issue a compilation error if the class attribute specified in useBean action is invalid.

setFailOnError

public void setFailOnError(boolean b)
Sets the option that throws an exception in case of a compilation error.

setGenStringAsCharArray

public void setGenStringAsCharArray(boolean genStringAsCharArray)
Determines whether text strings are to be generated as char arrays, which improves performance in some cases.

Parameters: genStringAsCharArray true if text strings are to be generated as char arrays, false otherwise

setIeClassId

public void setIeClassId(String ieClassId)
Sets the class-id value to be sent to Internet Explorer when using <jsp:plugin> tags.

Parameters: ieClassId Class-id value

setJavaEncoding

public void setJavaEncoding(String encodingName)
Sets the encoding to use for java files.

Parameters: encodingName The name, e.g. "UTF-8"

setJspFiles

public void setJspFiles(String jspFiles)
Parses comma-separated list of JSP files to be processed. If the argument is null, nothing is done.

Each file is interpreted relative to uriroot, unless it is absolute, in which case it must start with uriroot.

Parameters: jspFiles Comma-separated list of JSP files to be processed

setListErrors

public void setListErrors(boolean b)

setOutputDir

public void setOutputDir(String s)

setPackage

public void setPackage(String p)
Sets the package name to be used for the generated servlet classes.

setPoolingEnabled

public void setPoolingEnabled(boolean poolingEnabled)
Sets the option to enable the tag handler pooling.

setSmapDumped

public void setSmapDumped(boolean smapDumped)
Sets smapDumped flag.

See Also: isSmapDumped

setSmapSuppressed

public void setSmapSuppressed(boolean smapSuppressed)
Sets smapSuppressed flag.

setTrimSpaces

public void setTrimSpaces(boolean ts)
Sets the option to trim white spaces between directives or actions.

setUriroot

public void setUriroot(String s)
Base dir for the webapp. Used to generate class names and resolve includes.

setValidateTld

public void setValidateTld(boolean b)

setVerbose

public void setVerbose(int level)
Sets the verbosity level. The actual number doesn't matter: if it's greater than zero, the verbose flag will be true.

Parameters: level Positive means verbose

setWebXml

public void setWebXml(String s)
File where we generate a complete web.xml with the class definitions.

setWebXmlEncoding

public void setWebXmlEncoding(String encoding)
Sets the encoding to be used to read and write web.xml files.

If not specified, defaults to the platform default encoding.

Parameters: encoding Encoding, e.g. "UTF-8".

setWebXmlFragment

public void setWebXmlFragment(String s)
File where we generate a web.xml fragment with the class definitions.

setXpoweredBy

public void setXpoweredBy(boolean xpoweredBy)
Sets the option to enable generation of X-Powered-By response header.
Copyright © 2000-2014 Apache Software Foundation. All Rights Reserved.