You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by co...@apache.org on 2001/06/08 06:57:02 UTC
cvs commit: jakarta-tomcat-jasper/jasper34/generator/org/apache/jasper34/parser JspReader.java
costin 01/06/07 21:57:02
Modified: jasper34/generator/org/apache/jasper34/generator
GeneratorBase.java JspParseEventListener.java
ServletWriter.java
jasper34/generator/org/apache/jasper34/parser JspReader.java
Added: jasper34/generator/org/apache/jasper34/generator
DependGenerator.java
Log:
Added 2 more hooks in the generator.
The first one allows generators to declare dependencies. The liaison could
use those to implement reloading ( including the famous "include" bug ).
The second one allows static content generators to pre-declare the
chunks. It is not used right now, but will work in association with
the RuntimeLiaison to optimize the whole output system ( pre-conversion
to byte[], caching of static content on the server side, etc ).
Revision Changes Path
1.3 +23 -2 jakarta-tomcat-jasper/jasper34/generator/org/apache/jasper34/generator/GeneratorBase.java
Index: GeneratorBase.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-jasper/jasper34/generator/org/apache/jasper34/generator/GeneratorBase.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- GeneratorBase.java 2001/06/06 06:16:03 1.2
+++ GeneratorBase.java 2001/06/08 04:56:58 1.3
@@ -100,6 +100,8 @@
public static final int INIT_METHOD_HOOK = 3;
public static final int SERVICE_METHOD_HOOK = 4;
public static final int STATIC_INITIALIZER_HOOK = 5;
+ public static final int CHUNKS = 5;
+ public static final int DEPENDS = 5;
public static String hookNames[] = {
"generateClassDeclaration",
@@ -107,10 +109,12 @@
"generateFileDeclaration",
"generateInitMethod",
"generateServiceMethod",
- "generateStaticInitializer"
+ "generateStaticInitializer",
+ "generateChunks",
+ "generateDepends"
};
- static final int HOOK_COUNT=6;
+ static final int HOOK_COUNT=8;
public boolean hasHook( int hookId ) {
if( hooks==null ) initHooks();
@@ -118,6 +122,23 @@
}
// -------------------- New interface --------------------
+
+ /** Generate content chunks ( not used right now )
+ * Chunks will be used instead of out.println( String ), to
+ * enable a number of optimizations and for better support for
+ * large files.
+ */
+ public void generateChunks( ServletWriter out )
+ throws JasperException
+ {
+ }
+
+ /** Generate depend declarations.
+ */
+ public void generateDepends( ServletWriter out )
+ throws JasperException
+ {
+ }
public void generateClassDeclaration( ServletWriter out )
throws JasperException
1.5 +5 -0 jakarta-tomcat-jasper/jasper34/generator/org/apache/jasper34/generator/JspParseEventListener.java
Index: JspParseEventListener.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-jasper/jasper34/generator/org/apache/jasper34/generator/JspParseEventListener.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- JspParseEventListener.java 2001/06/07 06:59:00 1.4
+++ JspParseEventListener.java 2001/06/08 04:56:58 1.5
@@ -163,9 +163,14 @@
throw new CompileException(start,
Constants.getString("jsp.error.include.missing.file"));
+
// jsp.error.include.bad.file needs taking care of here??
try {
reader.pushFile(file);
+ // Add an IncludeGenerator - only for deps
+ DependGenerator dg=new DependGenerator( start,stop,
+ reader.getCurrentFile());
+ pageInfo.addGenerator( dg );
} catch (FileNotFoundException fnfe) {
throw new CompileException(start,
Constants.getString("jsp.error.include.bad.file"));
1.4 +51 -0 jakarta-tomcat-jasper/jasper34/generator/org/apache/jasper34/generator/ServletWriter.java
Index: ServletWriter.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-jasper/jasper34/generator/org/apache/jasper34/generator/ServletWriter.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ServletWriter.java 2001/06/07 06:59:02 1.3
+++ ServletWriter.java 2001/06/08 04:56:59 1.4
@@ -91,6 +91,10 @@
generateStaticInit(pageInfo );
+ generateDepends(pageInfo );
+
+ generateChunks(pageInfo );
+
generateConstructor(pageInfo );
generateJspxInit( pageInfo );
@@ -258,6 +262,53 @@
this.popIndent();
this.println("}");
this.println();
+ }
+
+
+ private void generateDepends(JspPageInfo pageInfo )
+ throws JasperException
+ {
+ this.println("private static final String _depends[] = { ");
+ this.pushIndent();
+
+ for(int i = 0; i < pageInfo.generators.size(); i++) {
+ GeneratorBase gen=(GeneratorBase)pageInfo.generators.elementAt(i);
+ gen.generateDepends(this);
+ }
+
+ this.println("null");
+
+ this.popIndent();
+ this.println("}; ");
+ this.println();
+ this.println("public final String[] _getDepends() " +
+ " { return _depends; }");
+ this.println();
+
+ }
+
+
+ private void generateChunks(JspPageInfo pageInfo )
+ throws JasperException
+ {
+ this.println("private static final String _chunks[] = { ");
+ this.pushIndent();
+
+ for(int i = 0; i < pageInfo.generators.size(); i++) {
+ GeneratorBase gen=(GeneratorBase)pageInfo.generators.elementAt(i);
+ gen.generateChunks(this);
+ }
+
+ this.println("null");
+
+ this.popIndent();
+ this.println("}; ");
+ this.println();
+
+ this.println("public final String[] _getChunks() " +
+ " { return _chunks; }");
+ this.println();
+
}
1.1 jakarta-tomcat-jasper/jasper34/generator/org/apache/jasper34/generator/DependGenerator.java
Index: DependGenerator.java
===================================================================
/*
* ====================================================================
*
* 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
* <http://www.apache.org/>.
*
*/
package org.apache.jasper34.generator;
import java.util.Hashtable;
import java.util.Enumeration;
import java.io.File;
import org.apache.jasper34.core.*;
import org.apache.jasper34.runtime.JasperException;
import org.apache.jasper34.parser.*;
import org.apache.jasper34.jsptree.*;
/**
* Generates a dependency, for reloading.
* Used for include directive, can also be used to register
* deps on TLDs, etc.
*
*
* @author Anil K. Vijendran
* @author Mandar Raje
*/
public class DependGenerator extends GeneratorBase
{
String file;
public DependGenerator(Mark start, Mark stop, String file )
throws JasperException
{
super( start, stop );
this.file=file;
}
public void generateDepends(ServletWriter writer) {
writer.println( "\"" + file + "\",");
}
}
1.2 +8 -0 jakarta-tomcat-jasper/jasper34/generator/org/apache/jasper34/parser/JspReader.java
Index: JspReader.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-jasper/jasper34/generator/org/apache/jasper34/parser/JspReader.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- JspReader.java 2001/06/06 05:40:14 1.1
+++ JspReader.java 2001/06/08 04:57:01 1.2
@@ -170,6 +170,14 @@
}
}
+ public String getCurrentFile() {
+ File file=new File( master );
+ String longName = (context == null)
+ ? file.getAbsolutePath()
+ : context.getRealPath(file.toString());
+ return longName;
+ }
+
/**
* Push a new file to be parsed onto the stack.
* @param inputFile The fully qualified path of the file.