/*
* $Header: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/JspC.java,v 1.12.2.6 2003/03/17 20:53:39 costin Exp $
* $Revision: 1.12.2.6 $
* $Date: 2003/03/17 20:53:39 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
*
<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
* @author Pierre Delisle
* @author Costin Manolache
*/
public class JspC implements Options {
public static final String DEFAULT_IE_CLASS_ID =
"clsid:8AD9C840-044E-11D1-B3E9-00805F499D93";
public static final String SWITCH_VERBOSE = "-v";
public static final String SWITCH_QUIET = "-q";
public static final String SWITCH_OUTPUT_DIR = "-d";
public static final String SWITCH_OUTPUT_SIMPLE_DIR = "-dd";
public static final String SWITCH_IE_CLASS_ID = "-ieplugin";
public static final String SWITCH_PACKAGE_NAME = "-p";
public static final String SWITCH_CLASS_NAME = "-c";
public static final String SWITCH_FULL_STOP = "--";
public static final String SWITCH_COMPILE = "-compile";
public static final String SWITCH_URI_BASE = "-uribase";
public static final String SWITCH_URI_ROOT = "-uriroot";
public static final String SWITCH_FILE_WEBAPP = "-webapp";
public static final String SWITCH_WEBAPP_INC = "-webinc";
public static final String SWITCH_WEBAPP_XML = "-webxml";
public static final String SWITCH_MAPPED = "-mapped";
public static final String SWITCH_DIE = "-die";
public static final String SHOW_SUCCESS ="-s";
public static final String LIST_ERRORS = "-l";
public static final int NO_WEBXML = 0;
public static final int INC_WEBXML = 10;
public static final int ALL_WEBXML = 20;
public static final int DEFAULT_DIE_LEVEL = 1;
public static final int NO_DIE_LEVEL = 0;
String classPath=null;
URLClassLoader loader=null;
// future direction
//public static final String SWITCH_XML_OUTPUT = "-xml";
boolean largeFile = false;
boolean mappedFile = false;
int jspVerbosityLevel = Logger.INFORMATION;
File scratchDir;
String ieClassId = DEFAULT_IE_CLASS_ID;
String targetPackage;
String targetClassName;
String uriBase;
String uriRoot;
String javaEncoding = "UTF-8"; // default = UTF-8, which was originally hardcoded
int dieLevel;
boolean dieOnExit = false;
static int die; // I realize it is duplication, but this is for
// the static main catch
boolean compile=false;
String compiler=null;
boolean dirset;
boolean classDebugInfo=true;
Vector extensions;
Vector pages = new Vector();
// Generation of web.xml fragments
String webxmlFile;
int webxmlLevel;
Writer mapout;
CharArrayWriter servletout;
CharArrayWriter mappingout;
static PrintStream log;
JspCServletContext context;
/**
* Cache for the TLD locations
*/
private TldLocationsCache tldLocationsCache = null;
private boolean listErrors = false;
private boolean showSuccess = false;
public boolean getKeepGenerated() {
// isn't this why we are running jspc?
return true;
}
public boolean getLargeFile() {
return largeFile;
}
public boolean isPoolingEnabled() {
return true;
}
/**
* Are we supporting HTML mapped servlets?
*/
public boolean getMappedFile() {
return mappedFile;
}
// Off-line compiler, no need for security manager
public Object getProtectionDomain() {
return null;
}
public boolean getSendErrorToClient() {
// implied send to System.err
return true;
}
public void setClassDebugInfo( boolean b ) {
classDebugInfo=b;
}
public boolean getClassDebugInfo() {
// compile with debug info
return classDebugInfo;
}
/**
* Background compilation check intervals in seconds
*/
public int getCheckInterval() {
return 300;
}
/**
* Is Jasper being used in development mode?
*/
public boolean getDevelopment() {
return false;
}
/**
* JSP reloading check ?
*/
public boolean getReloading() {
return true;
}
public String getIeClassId() {
return ieClassId;
}
public int getJspVerbosityLevel() {
return jspVerbosityLevel;
}
public File getScratchDir() {
return scratchDir;
}
public Class getJspCompilerPlugin() {
// we don't compile, so this is meanlingless
return null;
}
public String getJspCompilerPath() {
// we don't compile, so this is meanlingless
return null;
}
/**
* Compiler to use.
*/
public String getCompiler() {
return compiler;
}
public void setCompiler(String c) {
compiler=c;
}
public TldLocationsCache getTldLocationsCache() {
return tldLocationsCache;
}
public String getJavaEncoding() {
return javaEncoding;
}
public void setJavaEncoding(String newencoding) {
javaEncoding = newencoding;
}
public boolean getFork() {
return false;
}
public String getClassPath() {
if( classPath != null )
return classPath;
return System.getProperty("java.class.path");
}
public JspC() {
Constants.jasperLog = new JasperLogger();
}
// -------------------- Options --------------------
public void setClassPath(String s) {
classPath=s;
}
/** Base dir for the webapp. Used to generate class names and
* resolve includes
*/
public void setUriroot( String s ) {
if( s==null ) {
uriRoot=s;
return;
}
try {
uriRoot=new File( s ).getCanonicalPath();
} catch( Exception ex ) {
uriRoot=s;
}
}
public void setVerbose( int level ) {
Constants.jasperLog.setVerbosityLevel(level);
}
public void setCompile( boolean b ) {
compile=b;
}
public void setValidateXml( boolean b ) {
org.apache.jasper.xmlparser.ParserUtils.validating=b;
}
public void setOutputDir( String s ) {
if( s!= null ) {
scratchDir=new File(new File(s).getAbsolutePath());
dirset=true;
} else {
scratchDir=null;
}
}
public void setPackage( String p ) {
targetPackage=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 ?
*/
public void setClassName( String p ) {
targetClassName=p;
}
/** File where we generate a web.xml fragment with the class definitions.
*/
public void setWebXmlFragment( String s ) {
webxmlFile=s;
webxmlLevel=INC_WEBXML;
}
/**
* Resolve relative path, and create output directories.
*/
void setupContext(JspCompilationContext clctxt) {
String outputDir = scratchDir.getAbsolutePath();
if (dirset) {
int indexOfSlash = clctxt.getJspFile().lastIndexOf('/');
/* String pathName = "";
if (indexOfSlash != -1) {
pathName = clctxt.getJspFile().substring(0, indexOfSlash);
} */
String tmpDir = outputDir + File.separatorChar; // + pathName;
File f = new File(tmpDir);
if (!f.exists()) {
f.mkdirs();
}
}
clctxt.setOutputDir( outputDir );
}
void initClassLoader( JspCompilationContext clctxt ) throws IOException {
classPath = getClassPath();
ClassLoader parent=this.getClass().getClassLoader();
ArrayList urls = new ArrayList();
File webappBase=new File(uriRoot);
if( parent instanceof URLClassLoader ) {
URLClassLoader uL=(URLClassLoader) parent;
URL path[]=uL.getURLs();
for( int i=0; i