costin      01/06/16 13:54:15

  Modified:    jasper34/liaison/org/apache/jasper34/tomcat33
                        JasperEngineContext.java JspInterceptor.java
  Log:
  Eliminate unused code ( duplicate that was consolidated, etc ).
  
  Move code from JspInterceptor to liaison ( to simplify interceptor and to
  allow the move to a "toolkit" pattern )
  
  Fix the method signatures.
  
  Fix in JspInterceptor to allow the use of a JspServlet without any setting changes
  in the module ( for example if a webapp is using a foreign jsp impl )
  XXX this might need to be ported back to 33.
  
  In JspInterceptor, eliminate JasperLiaison ( it's not needed, many of the ideas are
  migrated into Compiler )
  
  Revision  Changes    Path
  1.5       +63 -204   
jakarta-tomcat-jasper/jasper34/liaison/org/apache/jasper34/tomcat33/JasperEngineContext.java
  
  Index: JasperEngineContext.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-jasper/jasper34/liaison/org/apache/jasper34/tomcat33/JasperEngineContext.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- JasperEngineContext.java  2001/06/12 15:45:27     1.4
  +++ JasperEngineContext.java  2001/06/16 20:54:15     1.5
  @@ -61,6 +61,7 @@
   import org.apache.jasper34.core.*;
   import org.apache.jasper34.runtime.*;
   import org.apache.jasper34.parser.*;
  +import org.apache.jasper34.javacompiler.*;
   import org.apache.jasper34.jsptree.*;
   import org.apache.jasper34.liaison.*;
   
  @@ -68,233 +69,76 @@
   import java.io.*;
   import java.net.*;
   
  -//import org.apache.jasper.JspCompilationContext;
  +import org.apache.tomcat.core.*;
  +import org.apache.tomcat.util.compat.*;
  +    
   
  -/** Alternative implementation of JspCompilationContext ( in addition
  -    to the servlet and standalone ). Used by JspInterceptor - but
  -    it's in no way specific to tomcat.
  -*/
  +/** Container liaison for tomcat33
  + *
  + * @author Costin Manolache
  + */
   public class JasperEngineContext extends ContainerLiaison
   {
  -    JspReader reader;
  -    ServletWriter writer;
  -    ServletContext context;
  -    ClassLoader loader;
  -    boolean isErrPage;
  -    String jspFile;
  -    String servletClassName;
  -    String servletPackageName;
  -    String servletJavaFileName;
  -    String contentType;
  -    Options options;
  -
  -    String cpath;    // for compiling JSPs.
  -    ServletContext sctx;
  -    String outputDir;
  +    String cpath;  // cache
   
  -    public JasperEngineContext()
  +    Context ctx;
  +    
  +    public JasperEngineContext(Context ctx)
       {
  +     this.ctx=ctx;
  +     debug=ctx.getDebug();
       }
   
  -    public void setClassPath( String s ) {
  -     cpath=s;
  -    }
  -    
       /**
  -     * The classpath that is passed off to the Java compiler. 
  +     * Extract the class path from the Context
        */
       public String getClassPath() {
  +     if( cpath != null )
  +         return cpath;
  +     String separator = System.getProperty("path.separator", ":");
  +     URL classP[]=ctx.getClassPath();
  +        cpath= JavaCompiler.extractClassPath(classP);
  +
  +     Jdk11Compat jdkProxy=Jdk11Compat.getJdkCompat();
  +        URL appsCP[];
  +        URL commonCP[];
  +        ClassLoader parentLoader=ctx.getContextManager().getParentLoader();
  +        appsCP=jdkProxy.getParentURLs(parentLoader);
  +        commonCP=jdkProxy.getURLs(parentLoader);
  +     if( appsCP!=null ) 
  +         cpath+=separator+  JavaCompiler.extractClassPath(appsCP);
  +     if( commonCP!=null ) 
  +         cpath+=separator+ JavaCompiler.extractClassPath(commonCP);
        return cpath;
       }
       
       /**
  -     * Get the input reader for the JSP text. 
  -     */
  -    public JspReader getReader() {
  -     if( debug>0 ) log("getReader " + reader );
  -        return reader;
  -    }
  -    
  -    /**
  -     * Where is the servlet being generated?
  -     */
  -    public ServletWriter getWriter() {
  -     if( debug>0 ) log("getWriter " + writer );
  -        return writer;
  -    }
  -
  -    public void setServletContext( Object o ) {
  -     sctx=(ServletContext)o;
  -    }
  -    
  -    /**
  -     * Get the ServletContext for the JSP we're processing now. 
  -     */
  -    public ServletContext getServletContext() {
  -     if( debug>0 ) log("getCtx " + sctx );
  -        return sctx;
  -    }
  -    
  -    /**
        * What class loader to use for loading classes while compiling
        * this JSP? I don't think this is used right now -- akv. 
        */
       public ClassLoader getClassLoader() {
  -     if( debug>0 ) log("getLoader " + loader );
  -        return loader;
  -    }
  -
  -    public void setClassLoader( ClassLoader cl ) {
  -     loader=cl;
  -    }
  -
  -    public void addJar( String jar ) throws IOException {
  -     if( debug>0 ) log("Add jar " + jar);
  -     //loader.addJar( jar );
  +     if( debug>0 ) log("getLoader " + ctx.getClassLoader() );
  +        return ctx.getClassLoader();
       }
   
       /**
  -     * Are we processing something that has been declared as an
  -     * errorpage? 
  -     */
  -    public boolean isErrorPage() {
  -     if( debug>0 ) log("isErrorPage " + isErrPage );
  -        return isErrPage;
  -    }
  -    
  -    /**
        * What is the scratch directory we are generating code into?
        * FIXME: In some places this is called scratchDir and in some
        * other places it is called outputDir.
        */
       public String getOutputDir() {
  -     if( debug>0 ) log("getOutputDir " + outputDir  );
  -        return outputDir;
  -    }
  -
  -    public void setOutputDir(String s ) {
  -     outputDir=s;
  -    }
  -    
  -    /**
  -     * Path of the JSP URI. Note that this is not a file name. This is
  -     * the context rooted URI of the JSP file. 
  -     */
  -    public String getJspFile() {
  -     if( debug>0 ) log("getJspFile " +  jspFile);
  -     return jspFile;
  -    }
  -
  -    public void setJspFile( String s ) {
  -     jspFile=s;
  -    }
  -    
  -    /**
  -     * Just the class name (does not include package name) of the
  -     * generated class. 
  -     */
  -    public String getServletClassName() {
  -     if( debug>0 ) log("getServletClassName " +  servletClassName);
  -        return servletClassName;
  -    }
  -
  -    public void setServletClassName( String s ) {
  -     servletClassName=s;
  -    }
  -    
  -    /**
  -     * The package name into which the servlet class is generated. 
  -     */
  -    public String getServletPackageName() {
  -     if( debug>0 ) log("getServletPackageName " +
  -                        servletPackageName );
  -        return servletPackageName;
  -    }
  -
  -    /**
  -     * Utility method to get the full class name from the package and
  -     * class name. 
  -     */
  -    public final String getFullClassName() {
  -     if( debug>0 ) log("getServletPackageName " +
  -                        servletPackageName + "." + servletClassName);
  -        if (servletPackageName == null)
  -            return servletClassName;
  -        return servletPackageName + "." + servletClassName;
  -    }
  -
  -    /**
  -     * Full path name of the Java file into which the servlet is being
  -     * generated. 
  -     */
  -    public String getServletJavaFileName() {
  -     if( debug>0 ) log("getServletPackageName " +
  -                        servletPackageName + "." + servletClassName);
  -        return servletJavaFileName;
  -    }
  -
  -    /**
  -     * Are we keeping generated code around?
  -     */
  -    public boolean keepGenerated() {
  -        return options.getKeepGenerated();
  -    }
  -
  -    /**
  -     * What's the content type of this JSP? Content type includes
  -     * content type and encoding. 
  -     */
  -//     public String getContentType() {
  -//         return contentType;
  -//     }
  -
  -    /**
  -     * Get hold of the Options object for this context. 
  -     */
  -    public Options getOptions() {
  -        return options;
  +     if( debug>0 )
  +         log("getOutputDir " +  ctx.getWorkDir().getAbsolutePath() );
  +     return ctx.getWorkDir().getAbsolutePath();
       }
   
  -    public void setOptions(Options options) {
  -     this.options=options;
  -    }
  -    
  -//     public void setContentType(String contentType) {
  -//         this.contentType = contentType;
  -//     }
  -
  -    public void setReader(JspReader reader) {
  -        this.reader = reader;
  -    }
  -    
  -    public void setWriter(ServletWriter writer) {
  -        this.writer = writer;
  -    }
  -    
  -    public void setServletPackageName(String servletPackageName) {
  -        this.servletPackageName = servletPackageName;
  -    }
  -    
  -    public void setServletJavaFileName(String servletJavaFileName) {
  -        this.servletJavaFileName = servletJavaFileName;
  -    }
  -    
  -    public void setErrorPage(boolean isErrPage) {
  -        this.isErrPage = isErrPage;
  -    }
  -
  -    public Compiler createCompiler() throws JasperException {
  -     if( debug>0 ) log("createCompiler ");
  -     return null;
  -    }
  -    
  -    public String resolveRelativeUri(String uri)
  +    public String resolveRelativeUri(String uri, String baseURI)
       {
        if( debug>0 ) log("resolveRelativeUri " + uri);
        if (uri.charAt(0) == '/') {
            return uri;
           } else {
  -            String baseURI = jspFile.substring(0, jspFile.lastIndexOf('/'));
  +         //String baseURI = jspFile.substring(0, jspFile.lastIndexOf('/'));
               return baseURI + '/' + uri;
           }
       }
  @@ -302,7 +146,7 @@
       public java.io.InputStream getResourceAsStream(String res)
       {
        if( debug>0 ) log("getResourceAsStream " + res);
  -     return sctx.getResourceAsStream(res);
  +     return ((ServletContext)ctx.getFacade()).getResourceAsStream(res);
       }
   
       /** 
  @@ -311,9 +155,9 @@
        */
       public String getRealPath(String path)
       {
  -     if( debug>0 ) log("getRealPath " + path + " = " +
  -                       sctx.getRealPath( path ));
  -     return sctx.getRealPath( path );
  +     String rpath=((ServletContext)ctx.getFacade()).getRealPath( path );
  +     if( debug>0 ) log("getRealPath " + path + " = " + rpath );
  +     return rpath;
       }
   
       public void readWebXml( TagLibraries tli )
  @@ -327,16 +171,31 @@
        implementation ( TagLibReader ).
       */
       public void readTLD( TagLibraries libs,
  -                      TagLibraryInfoImpl tl, String prefix, String uri )
  +                      TagLibraryInfoImpl tl, String prefix, String uri,
  +                      String uriBase )
        throws IOException, JasperException
       {
        TagLibReader reader=new TagLibReader( this, libs );
  -     reader.readTagLib( tl, prefix, uri );
  +     reader.readTLD( tl, prefix, uri, uriBase );
  +    }
  +
  +    /** Hook called after a JSP page has been detected and processed.
  +     *  The container may register the page as if it would be a web.xml
  +     *  servlet and avoid the future overhead of going through the
  +     *  jsp module.
  +     */
  +    public boolean addJspServlet( String uri, String servletName ) {
  +     return false;
       }
  +
  +    public boolean addDependency( String servletName, String file ) {
  +     return false;
  +    }
  +    
       
  -    // development tracing 
  -    private static int debug=0;
  -    private void log( String s ) {
  -     System.out.println("JasperEngineContext: "+ s);
  +    // -------------------- development tracing --------------------
  +    private int debug=0;
  +    public void log( String s ) {
  +     ctx.log("JasperEngineContext: "+ s);
       }
   }
  
  
  
  1.8       +117 -205  
jakarta-tomcat-jasper/jasper34/liaison/org/apache/jasper34/tomcat33/JspInterceptor.java
  
  Index: JspInterceptor.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-jasper/jasper34/liaison/org/apache/jasper34/tomcat33/JspInterceptor.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- JspInterceptor.java       2001/06/13 01:11:37     1.7
  +++ JspInterceptor.java       2001/06/16 20:54:15     1.8
  @@ -217,10 +217,10 @@
            type=JIKES;
        if( "javac".equals( type ) )
            type="org.apache.jasper34.javacompiler.SunJavaCompiler";
  -             
  +     
        args.put( "jspCompilerPlugin", type );
       }
  -
  +    
       int pageContextPoolSize=JspFactoryImpl.DEFAULT_POOL_SIZE;
       /** Set the PageContext pool size for jasper factory.
        0 will disable pooling of PageContexts.
  @@ -300,15 +300,6 @@
                jspServlet.getServletInfo().addInitParam(s, v );
            }
   
  -         // XXX redo - when containerL becomes one per/context 
  -//       if( debug > 0 ) {
  -//           //enable jasperServlet logging
  -//           log( "Seetting debug on jsp servlet");
  -//           containerL.setLog(loghelper);
  -//           //              org.apache.jasper.containerL.jasperLog.
  -//           //                  setVerbosityLevel("debug");
  -//       }
  -
            jspServlet.setServletClassName(jspServletCN);
        } else {
            ctx.addServlet( new JspPrecompileH());
  @@ -331,7 +322,7 @@
                    log( "PreServletInit: HttpJspBase.setParentClassLoader" +
                         sw );
                HttpJspBase h = (HttpJspBase) theServlet;
  -             h.setClassLoader(ctx.getClassLoader());
  +             //h.setClassLoader(ctx.getClassLoader());
            }
        } catch(Exception ex ) {
            throw new TomcatException( ex );
  @@ -371,12 +362,24 @@
        if( wrapper==null )
            return 0;
   
  +     if(debug> 0 )
  +         log( wrapper.getName() );
  +     
        // It's not a jsp if it's not "*.jsp" mapped or a servlet
        if( (! "jsp".equals( wrapper.getName())) &&
            (! (wrapper instanceof ServletHandler)) ) {
            return 0;
        }
   
  +     String wrapperCN=((ServletHandler)wrapper).getServletClassName();
  +     if( null != wrapperCN && ! "jsp".equals( wrapperCN )) {
  +         //it's a real servlet mapped to a .jsp
  +         if( debug > 0 )
  +             log( "Class: " +
  +                  ((ServletHandler)wrapper).getServletClassName());
  +         return 0;
  +     }
  +
        ServletHandler handler=null;
        String jspFile=null;
   
  @@ -439,8 +442,7 @@
        }
   
        // we need to compile... ( or find previous .class )
  -     JasperLiaison liasion=new JasperLiaison(getLog(), debug);
  -     liasion.processJspFile( req, jspFile, handler, args);
  +     processJspFile( req, jspFile, handler, args);
   
        dep= handler.getServletInfo().getDependManager();
        dep.reset();
  @@ -507,49 +509,7 @@
        return wrapper;
       }
   
  -}
  -
  -// -------------------- Jsp_precompile handler --------------------
  -
  -/** What to do for jsp precompile
  - */
  -class JspPrecompileH extends Handler {
  -    static StringManager sm=StringManager.
  -     getManager("org.apache.tomcat.resources");
  -    
  -    JspPrecompileH() {
  -     name="tomcat.jspPrecompileHandler";
  -    }
  -
  -    public void doService(Request req, Response res)
  -     throws Exception
  -    {
  -     res.setContentType("text/html");        
  -
  -     String msg="<h1>Jsp Precompile Done</h1>";
  -
  -     res.setContentLength(msg.length());
  -
  -     res.getBuffer().write( msg );
  -    }
  -}
  -
  -
  -
   
  -// -------------------- The main Jasper Liaison --------------------
  -
  -final class JasperLiaison {
  -    Log log;
  -    final int debug;
  -    //    ContainerLiaison containerL;
  -    
  -    JasperLiaison(  Log log, int debug ) {
  -     this.log=log;
  -     this.debug=debug;
  -     //      this.containerL=containerL;
  -    }
  -    
       /** Generate mangled names, check for previous versions,
        *  generate the .java file, compile it - all the expensive
        *  operations. This happens only once ( or when the jsp file
  @@ -564,7 +524,7 @@
        // to either compile it or find the previous compiled version
        // If dep.isExpired() we need to recompile.
   
  -     if( debug > 10 ) log.log( "Before compile sync  " + jspFile );
  +     if( debug > 10 ) log( "Before compile sync  " + jspFile );
        synchronized( handler ) {
            
            // double check - maybe another thread did that for us
  @@ -575,9 +535,9 @@
            }
            if( debug > 0 ) 
                if( depM == null )
  -                 log.log( "DepM==null ");
  +                 log( "DepM==null ");
                else
  -                 log.log( "DepM.shouldReload()" + depM.shouldReload());
  +                 log( "DepM.shouldReload()" + depM.shouldReload());
            Context ctx=req.getContext();
            
            // Mangle the names - expensive operation, but nothing
  @@ -588,20 +548,17 @@
                              jspFile );
   
            Options options=new OptionsProperties(args); 
  -         
  -         JasperEngineContext ctxt = new JasperEngineContext();
  -         ctxt.setClassPath( computeClassPath( req.getContext()) );
  -         ctxt.setServletContext( req.getContext().getFacade());
  -         ctxt.setOptions( options );
  -         ctxt.setClassLoader( req.getContext().getClassLoader());
  -         ctxt.setOutputDir(req.getContext().getWorkDir().getAbsolutePath());
            
  -         JspPageInfo pageInfo=new JspPageInfo( ctxt, options, mangler );
  +         JasperEngineContext containerL =
  +             new JasperEngineContext(req.getContext());
  +         containerL.setOptions( options );
  +
  +         JspPageInfo pageInfo=new JspPageInfo( containerL, options, mangler );
            
            //pageInfo.setServletClassName( mangler.getClassName());
            pageInfo.setJspFile( jspFile );
            
  -         Compiler compiler=new Compiler(ctxt);
  +         Compiler compiler=new Compiler(containerL);
            
            // register the handler as dependend of the jspfile 
            if( depM==null ) {
  @@ -614,7 +571,7 @@
                if( ! depM.shouldReload() ) {
                    addExtraDeps( depM, handler );                  
                    if( debug > 0 )
  -                     log.log( "Loaded dependency, shouldReload = " +
  +                     log( "Loaded dependency, shouldReload = " +
                                 depM.shouldReload() );
                    return 0;
                }
  @@ -641,17 +598,19 @@
   
            // Update the class name in wrapper
            if( debug> 1 )
  -             log.log( "Update class Name " + mangler.getServletClassName());
  +             log( "Update class Name " + mangler.getServletClassName());
            handler.setServletClassName( mangler.getServletClassName() );
   
            
            try {
  -
  -             jsp2java( compiler, mangler, ctxt, pageInfo );
  +             synchronized ( mangler ) {
  +                 compiler.jsp2java(pageInfo);
  +             }
   
  -             javac( compiler, pageInfo, options, ctxt, mangler );
  +             boolean result=
  +                 javac( compiler, pageInfo, options, containerL, mangler );
            
  -             if(debug>0)log.log( "Generated " +
  +             if(debug>0)log( "Generated " +
                                    mangler.getClassFileName() );
   
                addExtraDeps( depM, handler );
  @@ -659,7 +618,7 @@
                if( ctx!=null )
                    ctx.log("compile error: req="+req, ex);
                else
  -                 log.log("compile error: req="+req, ex);
  +                 log("compile error: req="+req, ex);
                handler.setErrorException(ex);
                handler.setState(Handler.STATE_DISABLED);
                // until the jsp cahnges, when it'll be enabled again
  @@ -676,30 +635,9 @@
       /** Convert the .jsp file to a java file, then compile it to class
        */
       void jsp2java(Compiler compiler, Mangler mangler,
  -               JasperEngineContext ctxt, JspPageInfo pageInfo )
  +               JasperEngineContext containerL, JspPageInfo pageInfo )
        throws Exception
       {
  -     if( debug > 0 ) log.log( "Generating " + mangler.getJavaFileName());
  -     // make sure we have the directories
  -     String javaFileName=mangler.getJavaFileName();
  -     
  -     File javaFile=new File(javaFileName);
  -     
  -     // make sure the directory is created
  -     new File( javaFile.getParent()).mkdirs();
  -     
  -     // we will compile ourself
  -     // compiler.setJavaCompiler( null );
  -     
  -     
  -     synchronized ( mangler ) {
  -         compiler.jsp2java(pageInfo);
  -     }
  -     if( debug > 0 ) {
  -         File f = new File( mangler.getJavaFileName());
  -         log.log( "Created file : " + f +  " " + f.lastModified());
  -         
  -     }
       }
       
       String javaEncoding = "UTF8";           // perhaps debatable?
  @@ -713,7 +651,7 @@
        with JavaCompiler - it's a general purpose code, no need to
        keep it part of jasper
       */
  -    void javac(Compiler compiler,
  +    boolean javac(Compiler compiler,
               JspPageInfo pageInfo,
               Options options,
               ContainerLiaison containerL,
  @@ -721,119 +659,54 @@
        throws JasperException
       {
        String javaFileName = mangler.getJavaFileName();
  -     if( debug>0 ) log.log( "Compiling java file " + javaFileName);
   
  +     if( debug>0 ) log( "Compiling java file " + javaFileName);
  +
        boolean status=true;
  -     if( jspCompilerPluginS == null ) {
  -         jspCompilerPluginS=options.getJspCompilerPlugin();
  -     }
  +     String javaFile=pageInfo.getMangler().getJavaFileName();
  +     JavaCompiler javaC=null;
        
        // If no explicit compiler, and we never tried before
        if( jspCompilerPlugin==null && tryJikes ) {
  -
  -         ByteArrayOutputStream out = new ByteArrayOutputStream (256);
            try {
  -             jspCompilerPlugin=Class.forName(JspInterceptor.JIKES);
  -             JavaCompiler javaC=
  -                 JavaCompiler.createJavaCompiler( containerL,
  -                                                  jspCompilerPlugin );
  +             javaC=compiler.createJavaCompiler(pageInfo,
  +                                               JspInterceptor.JIKES);
  +             compiler.prepareCompiler( javaC, pageInfo );
  +             status = javaC.compile( javaFile );
  +
  +             // remove java file if !keepgenerated, etc
  +             compiler.postCompile(pageInfo);
                
  -             compiler.prepareCompiler( javaC, options, pageInfo );
  -             javaC.setMsgOutput(out);
  -             status = compiler.javac(pageInfo, javaC );
            } catch( Exception ex ) {   
  -             log.log("Guess java compiler: no jikes " + ex.toString());
  +             log("Guess java compiler: no jikes " + ex.toString());
                status=false;
            }
            if( status==false ) {
  -             log.log("Guess java compiler: no jikes ");
  -             log.log("Guess java compiler: OUT " + out.toString());
  +             log("Guess java compiler: no jikes ");
  +             log("Guess java compiler: OUT " +
  +                 ((javaC==null)?"":javaC.getCompilerMessage()));
                jspCompilerPlugin=null;
                tryJikes=false;
            } else {
  -             log.log("Guess java compiler: using jikes ");
  +             log("Guess java compiler: using jikes ");
            }
        }
   
  -     JavaCompiler javaC=
  -         JavaCompiler.createJavaCompiler( containerL, jspCompilerPlugin );
  -     compiler.prepareCompiler( javaC, options, pageInfo );
  -     ByteArrayOutputStream out = new ByteArrayOutputStream (256);
  -     javaC.setMsgOutput(out);
  -     
  -     status = javaC.compile(javaFileName);
  +     javaC=compiler.createJavaCompiler( pageInfo );
  +     compiler.prepareCompiler( javaC, pageInfo );
  +     status = javaC.compile( javaFile );
   
  -        if (!containerL.getOptions().getKeepGenerated()) {
  -            File javaFile = new File(javaFileName);
  -            javaFile.delete();
  -        }
  -    
           if (status == false) {
  -            String msg = out.toString ();
  +            String msg = javaC.getCompilerMessage();
               throw new JasperException("Unable to compile "
                                         + msg);
           }
  -     if( debug > 0 ) log.log("Compiled ok");
  -    }
  -
  -    private String computeClassPath(Context ctx) {
  -     String separator = System.getProperty("path.separator", ":");
  -     URL classP[]=ctx.getClassPath();
  -        String cpath = "";
  -        cpath+=extractClassPath(classP);
  -        Jdk11Compat jdkProxy=Jdk11Compat.getJdkCompat();
  -        URL appsCP[];
  -        URL commonCP[];
  -        ClassLoader parentLoader=ctx.getContextManager().getParentLoader();
  -        appsCP=jdkProxy.getParentURLs(parentLoader);
  -        commonCP=jdkProxy.getURLs(parentLoader);
  -     if( appsCP!=null ) 
  -         cpath+=separator+extractClassPath(appsCP);
  -     if( commonCP!=null ) 
  -         cpath+=separator+extractClassPath(commonCP);
  -     return cpath;
  -    }
  -    String extractClassPath(URL urls[]){
  -     String separator = System.getProperty("path.separator", ":");
  -        String cpath="";
  -        for(int i=0; i< urls.length; i++ ) {
  -            URL cp = urls[i];
  -         if( cp == null ) {
  -             continue;
  -         }
  -            File f = new File( cp.getFile());
  -            if (cpath.length()>0) cpath += separator;
  -            cpath += f;
  -        }
  -        return cpath;
  -    }
   
  -    private void addExtraDeps( DependManager depM, ServletHandler handler )
  -    {
  -     try {
  -         Servlet theServlet = handler.getServlet();
  -         if (theServlet instanceof HttpJspBase)  {
  -             HttpJspBase httpJsp = (HttpJspBase) theServlet;
  -             String deps[]=httpJsp._getDepends();
  -             if( deps==null ) return;
  -             
  -             for( int i=0; i < deps.length ; i++ ) {
  -                 if( deps[i]==null ) continue;
  -                 Dependency d=new Dependency();
  -                 File f=new File( deps[i] );
  -                 d.setOrigin( f );
  -                 d.setTarget( handler );
  -                 d.setLastModified( f.lastModified() );
  -                 d.checkExpiry();
  -                 depM.addDependency( d );
  -                 log.log( "Adding dependency " + d  +
  -                          " " + depM.shouldReload() );
  -             }
  -         }
  -     } catch( Exception ex ) {
  -         ex.printStackTrace();
  -     }
  -
  +     // remove java file if !keepgenerated, etc
  +     compiler.postCompile(pageInfo);
  +         
  +     if( debug > 0 ) log("Compiled ok");
  +     return status;
       }
   
       private String getJspFilePath( String docBase, JspPageInfo pageInfo )
  @@ -841,7 +714,6 @@
        return FileUtil.safePath( docBase,
                                  pageInfo.getJspFile());
       }
  -
       
       // Add an "expire check" to the generated servlet.
       private DependManager setDependency( Context ctx, Mangler mangler,
  @@ -850,7 +722,7 @@
       {
        ServletInfo info=handler.getServletInfo();
        // create a lastModified checker.
  -     if( debug>0) log.log("Registering dependency for " + handler );
  +     if( debug>0) log("Registering dependency for " + handler );
        DependManager depM=new DependManager(4); // jsps have fewer deps
        depM.setDebug( debug );
        Dependency dep=new Dependency();
  @@ -860,7 +732,7 @@
        System.out.println("XXX " + depFile + " " + depFile.lastModified());
        dep.setTarget( handler );
        //dep.setLocal( true );
  -     File f=new File( mangler.getClassFileName() );
  +     File f=new File( pageInfo.getMangler().getClassFileName() );
        if( mangler.getVersion() > 0 ) {
            // it has a previous version
            dep.setLastModified(f.lastModified());
  @@ -874,28 +746,68 @@
        depM.addDependency( dep );
        
        if( debug>0 )
  -         log.log( "file = " + mangler.getClassFileName() + " " +
  +         log( "file = " + pageInfo.getMangler().getClassFileName() + " " +
                     f.lastModified() );
        if( debug>0 )
  -         log.log("origin = " + dep.getOrigin() + " " +
  +         log("origin = " + dep.getOrigin() + " " +
                    dep.getOrigin().lastModified());
  -     /* This would add a dependency on the whole application,
  -        causing a reload of the context when a jsp changes.
  -     */
  -     /*
  +
  +     info.setDependManager( depM );
  +     return depM;
  +    }
  +
  +    private void addExtraDeps( DependManager depM, ServletHandler handler )
  +    {
        try {
  -         DependManager dm=(DependManager)ctx.getContainer().
  -             getNote("DependManager");
  -         if( dm!=null ) {
  -             dm.addDependency( dep );
  +         Servlet theServlet = handler.getServlet();
  +         if (theServlet instanceof HttpJspBase)  {
  +             HttpJspBase httpJsp = (HttpJspBase) theServlet;
  +             String deps[]=httpJsp._getDepends();
  +             if( deps==null ) return;
  +             
  +             for( int i=0; i < deps.length ; i++ ) {
  +                 if( deps[i]==null ) continue;
  +                 Dependency d=new Dependency();
  +                 File f=new File( deps[i] );
  +                 d.setOrigin( f );
  +                 d.setTarget( handler );
  +                 d.setLastModified( f.lastModified() );
  +                 d.checkExpiry();
  +                 depM.addDependency( d );
  +                 log( "Adding dependency " + d  +
  +                          " " + depM.shouldReload() );
  +             }
            }
  -     } catch( TomcatException ex ) {
  +     } catch( Exception ex ) {
            ex.printStackTrace();
        }
  -     */
  -     info.setDependManager( depM );
  -     return depM;
  +
  +    }
  +
  +
  +    }
  +
  +// -------------------- Jsp_precompile handler --------------------
  +
  +/** What to do for jsp precompile
  + */
  +class JspPrecompileH extends Handler {
  +    static StringManager sm=StringManager.
  +     getManager("org.apache.tomcat.resources");
  +    
  +    JspPrecompileH() {
  +     name="tomcat.jspPrecompileHandler";
       }
   
  +    public void doService(Request req, Response res)
  +     throws Exception
  +    {
  +     res.setContentType("text/html");        
  +
  +     String msg="<h1>Jsp Precompile Done</h1>";
   
  +     res.setContentLength(msg.length());
  +
  +     res.getBuffer().write( msg );
  +    }
   }
  
  
  

Reply via email to