org.apache.jasper

Class JspC

public class JspC extends Object 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="jasper2" >
      <classpath>
          <pathelement location="${java.home}/../lib/tools.jar"/>
          <fileset dir="${ENV.CATALINA_HOME}/server/lib">
              <include name="*.jar"/>
          </fileset>
          <fileset dir="${ENV.CATALINA_HOME}/common/lib">
              <include name="*.jar"/>
          </fileset>
          <path refid="myjars"/>
       </classpath>
  </taskdef>

  <jasper2 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 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 Projectproject
protected JspRuntimeContextrctxt
The runtime context.
protected FilescratchDir
protected CharArrayWriterservletout
protected booleanshowSuccess
protected booleansmapDumped
protected booleansmapSuppressed
protected static StringSHOW_SUCCESS
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_VERBOSE
protected static StringSWITCH_WEBAPP_INC
protected static StringSWITCH_WEBAPP_XML
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 booleanverbose
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()
voidexecute()
Executes the compilation.
voidgenerateWebMapping(String file, JspCompilationContext clctxt)
booleangenStringAsCharArray()
Indicates whether text strings are to be generated as char arrays.
MapgetCache()
intgetCheckInterval()
Background compilation check intervals in seconds
booleangetClassDebugInfo()
StringgetClassPath()
StringgetCompiler()
Compiler to use.
StringgetCompilerClassName()
Compiler class name to use.
StringgetCompilerSourceVM()
StringgetCompilerTargetVM()
booleangetDevelopment()
Is Jasper being used in development mode?
booleangetDisplaySourceFragment()
booleangetErrorOnUseBeanInvalidClassAttribute()
ListgetExtensions()
Returns the list of file extensions that are treated as JSP files.
booleangetFailOnError()
booleangetFork()
StringgetIeClassId()
Gets the class-id value that is sent to Internet Explorer when using tags.
StringgetJavaEncoding()
Returns the encoding to use for java files.
StringgetJspCompilerPath()
ClassgetJspCompilerPlugin()
JspConfiggetJspConfig()
Obtain JSP configuration informantion specified in web.xml.
booleangetKeepGenerated()
booleangetMappedFile()
Are we supporting HTML mapped servlets?
intgetModificationTestInterval()
Modification test interval.
ProjectgetProject()
Returns the project: may be null if not running inside an Ant project.
ObjectgetProtectionDomain()
FilegetScratchDir()
TagPluginManagergetTagPluginManager()
intgetTagPoolSize()
TldLocationsCachegetTldLocationsCache()
booleangetTrimSpaces()
protected voidinitClassLoader(JspCompilationContext clctxt)
Initializes the classloader as/if needed for the given compilation context.
protected voidinitServletContext()
protected voidinitWebXml()
booleanisCaching()
booleanisPoolingEnabled()
booleanisSmapDumped()
Should SMAP info for JSR45 debugging be dumped to a file?
booleanisSmapSuppressed()
Is the generation of SMAP info for JSR45 debuggin suppressed?
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)
voidsetArgs(String[] arg)
voidsetCaching(boolean caching)
voidsetClassDebugInfo(boolean b)
voidsetClassName(String p)
Class name of the generated file ( without package ).
voidsetClassPath(String s)
voidsetCompile(boolean b)
Sets the compile flag.
voidsetCompiler(String c)
voidsetCompilerSourceVM(String vm)
voidsetCompilerTargetVM(String vm)
voidsetErrorOnUseBeanInvalidClassAttribute(boolean b)
voidsetFailOnError(boolean b)
Set 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 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)
voidsetPoolingEnabled(boolean poolingEnabled)
voidsetProject(Project theProject)
Sets the project.
voidsetSmapDumped(boolean smapDumped)
Set smapSuppressed flag.
voidsetSmapSuppressed(boolean smapSuppressed)
Set smapSuppressed flag.
voidsetTrimSpaces(boolean ts)
voidsetUriroot(String s)
Base dir for the webapp.
voidsetValidateXml(boolean b)
voidsetVerbose(int level)
Sets the verbosity level.
voidsetWebXml(String s)
File where we generate a complete web.xml with the class definitions.
voidsetWebXmlFragment(String s)
File where we generate a web.xml fragment with the class definitions.
voidsetXpoweredBy(boolean xpoweredBy)

Field Detail

ALL_WEBXML

protected static final int ALL_WEBXML

addWebXmlMappings

protected boolean addWebXmlMappings

argPos

protected int argPos

args

protected String[] args

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

project

protected Project project

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_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_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_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

verbose

protected boolean verbose

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()

execute

public void execute()
Executes the compilation.

Throws: JasperException If an error occurs

generateWebMapping

public void generateWebMapping(String file, JspCompilationContext clctxt)

genStringAsCharArray

public boolean genStringAsCharArray()
Indicates whether text strings are to be generated as char arrays.

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

getCache

public Map getCache()

See Also: getCache

getCheckInterval

public int getCheckInterval()
Background compilation check intervals in seconds

getClassDebugInfo

public boolean getClassDebugInfo()

getClassPath

public String getClassPath()

getCompiler

public String getCompiler()
Compiler to use.

getCompilerClassName

public String getCompilerClassName()
Compiler class name to use.

getCompilerSourceVM

public String getCompilerSourceVM()

See Also: getCompilerSourceVM

getCompilerTargetVM

public String getCompilerTargetVM()

See Also: Options

getDevelopment

public boolean getDevelopment()
Is Jasper being used in development mode?

getDisplaySourceFragment

public boolean getDisplaySourceFragment()

getErrorOnUseBeanInvalidClassAttribute

public boolean getErrorOnUseBeanInvalidClassAttribute()

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()

getFork

public boolean getFork()

getIeClassId

public String getIeClassId()
Gets the class-id value that is sent to Internet Explorer when using tags.

Returns: Class-id value

getJavaEncoding

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

Returns: String The encoding

getJspCompilerPath

public String getJspCompilerPath()

getJspCompilerPlugin

public Class getJspCompilerPlugin()

getJspConfig

public JspConfig getJspConfig()
Obtain JSP configuration informantion specified in web.xml.

getKeepGenerated

public boolean getKeepGenerated()

getMappedFile

public boolean getMappedFile()
Are we supporting HTML mapped servlets?

getModificationTestInterval

public int getModificationTestInterval()
Modification test interval.

getProject

public Project getProject()
Returns the project: may be null if not running inside an Ant project.

Returns: The project

getProtectionDomain

public Object getProtectionDomain()

getScratchDir

public File getScratchDir()

getTagPluginManager

public TagPluginManager getTagPluginManager()

getTagPoolSize

public int getTagPoolSize()

getTldLocationsCache

public TldLocationsCache getTldLocationsCache()

getTrimSpaces

public boolean getTrimSpaces()

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()

isCaching

public boolean isCaching()

See Also: isCaching

isPoolingEnabled

public boolean isPoolingEnabled()

isSmapDumped

public boolean isSmapDumped()
Should SMAP info for JSR45 debugging be dumped to a file?

isSmapSuppressed

public boolean isSmapSuppressed()
Is the generation of SMAP info for JSR45 debuggin suppressed?

isXpoweredBy

public boolean isXpoweredBy()

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)

setArgs

public void setArgs(String[] arg)

setCaching

public void setCaching(boolean caching)

See Also: isCaching

setClassDebugInfo

public void setClassDebugInfo(boolean b)

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)

setCompile

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

Parameters: b Flag value

setCompiler

public void setCompiler(String c)

setCompilerSourceVM

public void setCompilerSourceVM(String vm)

See Also: getCompilerSourceVM

setCompilerTargetVM

public void setCompilerTargetVM(String vm)

setErrorOnUseBeanInvalidClassAttribute

public void setErrorOnUseBeanInvalidClassAttribute(boolean b)

setFailOnError

public void setFailOnError(boolean b)
Set 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 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)

setPoolingEnabled

public void setPoolingEnabled(boolean poolingEnabled)

setProject

public void setProject(Project theProject)
Sets the project.

Parameters: theProject The project

setSmapDumped

public void setSmapDumped(boolean smapDumped)
Set smapSuppressed flag.

setSmapSuppressed

public void setSmapSuppressed(boolean smapSuppressed)
Set smapSuppressed flag.

setTrimSpaces

public void setTrimSpaces(boolean ts)

setUriroot

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

setValidateXml

public void setValidateXml(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.

setWebXmlFragment

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

setXpoweredBy

public void setXpoweredBy(boolean xpoweredBy)
Copyright © 2000-2011 Apache Software Foundation. All Rights Reserved.