costin      01/06/16 14:09:47

  Modified:    jasper34/liaison/org/apache/jasper34/cli
                        CommandLineContext.java JspC.java
  Log:
  Fixes to make it compile - I haven't tested it so far.
  
  One big change - I split the very long methods in simpler ones, and tried to
  simplify a bit the code to make it easier to understand ( so it can be fixed later ).
  
  Important: both cli and servlet are ( temporarily ) using URLClassLoader ( i.e
   do not work with JDK1.1 ). This can be fixed without too much effort, but it's not
   a big priority ( since we still have JspInterceptor supporting JDK1.1 ).
  
  Revision  Changes    Path
  1.5       +69 -94    
jakarta-tomcat-jasper/jasper34/liaison/org/apache/jasper34/cli/CommandLineContext.java
  
  Index: CommandLineContext.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-jasper/jasper34/liaison/org/apache/jasper34/cli/CommandLineContext.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- CommandLineContext.java   2001/06/12 15:30:57     1.4
  +++ CommandLineContext.java   2001/06/16 21:09:47     1.5
  @@ -58,6 +58,8 @@
   package org.apache.jasper34.cli;
   
   import java.io.*;
  +import java.net.*;
  +import java.util.*;
   
   import org.apache.jasper34.generator.*;
   import org.apache.jasper34.core.*;
  @@ -88,26 +90,22 @@
       ClassLoader loader;
       boolean errPage;
       String jspFile;
  -    String servletClassName;
  -    String servletPackageName;
  -    String servletJavaFileName;
       String contentType;
       Options options;
   
       String uriBase;
       File uriRoot;
   
  -    boolean packageNameLocked;
  -    boolean classNameLocked;
  +    //    boolean packageNameLocked;
  +    //    boolean classNameLocked;
       boolean outputInDirs;
   
  -    public CommandLineContext(ClassLoader newLoader, String newClassPath,
  +    public CommandLineContext(String newClassPath,
                                 String newJspFile, String newUriBase,
                                 String newUriRoot, boolean newErrPage,
                                 Options newOptions)
       throws JasperException
       {
  -        loader = newLoader;
           classPath = newClassPath;
           uriBase = newUriBase;
           String tUriRoot = newUriRoot;
  @@ -164,13 +162,57 @@
        * this JSP? I don't think this is used right now -- akv. 
        */
       public ClassLoader getClassLoader() {
  -        return loader;
  +     // Construct a loader
  +     if( loader != null ) return loader;
  +     File uriDir = new File(this.getRealPath("/"));
  +
  +     ClassLoader parentLoader=getClass().getClassLoader();
  +
  +     try {
  +         URL urls[]=getWebAppClassPath(uriDir);
  +         // XXX compat XXX
  +         loader= new URLClassLoader( urls,
  +                                     parentLoader );
  +     } catch( IOException ex ) {
  +         ex.printStackTrace();
  +     }
  +     return loader;
  +    }
  +
  +    // XXX compat XXX 
  +    private URL[] getWebAppClassPath( File uriDir )
  +     throws IOException
  +    {
  +     String uriRoot=uriDir.toString();
  +     if(debug>0) log( "URIRoot " + uriRoot );
  +     Vector urls=new Vector();
  +     
  +     urls.add( options.getScratchDir().toURL());
  +     if(debug>0) log("CP: " + options.getScratchDir().toURL());
  +     
  +     File classes = new File(uriRoot + "/WEB-INF/classes");
  +     if (classes.exists()) {
  +         if(debug>0) log("CP: " + classes.toURL());
  +         urls.add(classes.toURL());
  +     }
  +
  +     File lib = new File( uriRoot + "/WEB-INF/lib");
  +     if (lib.exists() && lib.isDirectory()) {
  +         String[] libs = lib.list();
  +         for (int i = 0; i < libs.length; i++) {
  +             File libFile = new File(lib.toString()
  +                                     + File.separator
  +                                     + libs[i]);
  +             urls.add(libFile.toURL());
  +             if(debug>0) log("CP: " + libFile.toURL());
  +         }
  +     }
  +     
  +     URL urlA[]=new URL[ urls.size() ];
  +     urls.toArray( urlA );
  +     return urlA;
       }
   
  -//     public void addJar( String jar ) throws IOException  {
  -//   loader.addJar( jar );
  -//     }
  -    
       /**
        * Are we processing something that has been declared as an
        * errorpage? 
  @@ -189,56 +231,6 @@
       }
       
       /**
  -     * 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() {
  -        return jspFile;
  -    }
  -    
  -    /**
  -     * Just the class name (does not include package name) of the
  -     * generated class. 
  -     */
  -    public String getServletClassName() {
  -        return servletClassName;
  -    }
  -    
  -    /**
  -     * The package name into which the servlet class is generated. 
  -     */
  -    public String getServletPackageName() {
  -        return servletPackageName;
  -    }
  -
  -    /**
  -     * Utility method to get the full class name from the package and
  -     * class name. 
  -     */
  -    public String getFullClassName() {
  -        String pkg = getServletPackageName();
  -        if (pkg != null) {
  -            pkg += ".";
  -        } else {
  -            pkg = "";
  -        }
  -        return pkg + getServletClassName();
  -   }
  -
  -    /**
  -     * Full path name of the Java file into which the servlet is being
  -     * generated. 
  -     */
  -    public String getServletJavaFileName() {
  -        if (outputInDirs) {
  -            return getServletPackageName().replace('.', File.separatorChar)
  -                   + servletJavaFileName;
  -        } else {
  -            return servletJavaFileName;
  -        }
  -    }
  -
  -    /**
        * Are we keeping generated code around?
        */
       public boolean keepGenerated() {
  @@ -272,37 +264,18 @@
           this.writer = writer;
       }
       
  -    public void setServletClassName(String servletClassName) {
  -        if (classNameLocked) {
  -            //System.out.println("Did not change clazz to " + servletClassName);
  -        } else {
  -            this.servletClassName = servletClassName;
  -        }
  -    }
  -    
  -    public void setServletPackageName(String servletPackageName) {
  -        if (packageNameLocked) {
  -            //System.out.println("Did not change pkg to " + servletPackageName);
  -        } else {
  -            this.servletPackageName = servletPackageName;
  -        }
  -    }
  -    
  -    public void setServletJavaFileName(String servletJavaFileName) {
  -        this.servletJavaFileName = servletJavaFileName;
  -    }
  -    
       public void setErrorPage(boolean isErrPage) {
           errPage = isErrPage;
       }
  -
  -    public void lockPackageName() {
  -        packageNameLocked = true;
  -    }
   
  -    public void lockClassName() {
  -        classNameLocked = true;
  -    }
  +    // What is this ?
  +    //     public void lockPackageName() {
  +    //         packageNameLocked = true;
  +    //     }
  +    
  +    //     public void lockClassName() {
  +    //         classNameLocked = true;
  +    //     }
   
       public void setOutputInDirs(boolean newValue) {
           outputInDirs = true;
  @@ -317,7 +290,7 @@
        * Get the full value of a URI relative to this compilations context
        * uses current file as the base.
        */
  -    public String resolveRelativeUri(String uri) {
  +    public String resolveRelativeUri(String uri, String uriBase ) {
           if (uri.startsWith("/")) {
               return uri;
           } else {
  @@ -348,7 +321,7 @@
           }
           // that dind't work, last chance is to try the classloaders
           if (in == null) {
  -            in = loader.getResourceAsStream(res);
  +            in = getClassLoader().getResourceAsStream(res);
           }
           return in;
       }
  @@ -359,7 +332,7 @@
        * the compilation.
        */
       public String getRealPath(String path) {
  -        path = resolveRelativeUri(path);
  +        path = resolveRelativeUri(path, uriBase);
           if (path.startsWith("/")) {
               path = path.substring(1);
           }
  @@ -379,12 +352,14 @@
        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 );
       }
   
  +    private static int debug=1;
   }
   
  
  
  
  1.5       +245 -224  
jakarta-tomcat-jasper/jasper34/liaison/org/apache/jasper34/cli/JspC.java
  
  Index: JspC.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-jasper/jasper34/liaison/org/apache/jasper34/cli/JspC.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- JspC.java 2001/06/12 15:30:58     1.4
  +++ JspC.java 2001/06/16 21:09:47     1.5
  @@ -68,9 +68,6 @@
   import org.apache.jasper34.javacompiler.*;
   import org.apache.jasper34.liaison.*;
   
  -// XXX Will be replaced with URLClassLoader ( via JDKCompat )
  -import org.apache.jasper34.servlet.JasperLoader;
  -
   import org.apache.tomcat.util.log.*;
   
   /**
  @@ -145,6 +142,7 @@
           return jspVerbosityLevel;
       }
   
  +    // -------------------- Argument processing --------------------
       int argPos;
       // value set by beutifully obsfucscated java
       boolean fullstop = false;
  @@ -252,54 +250,21 @@
               }
           }
        }
  +
  +    // -------------------- Process a file --------------------
       
       public boolean parseFile(PrintStream log, String file,
                             Writer servletout, Writer mappingout)
       {
           try {
  -            JasperLoader loader =
  -                    new JasperLoader();
  -         loader.setParentClassLoader(getClass().getClassLoader());
  -         //loader.setOptions( optionsP );
  -         loader.setScratchDir( optionsP.getScratchDir().toString() );
  -            CommandLineContext clctxt = new CommandLineContext(
  -                    loader, optionsP.getClassPath(), file, uriBase,
  -                 uriRoot, false,
  -                    optionsP );
  -            if ((targetClassName != null) && (targetClassName.length() > 0)) {
  -                clctxt.setServletClassName(targetClassName);
  -                clctxt.lockClassName();
  -            }
  -            if (targetPackage != null) {
  -                clctxt.setServletPackageName(targetPackage);
  -                clctxt.lockPackageName();
  -            }
  +            CommandLineContext clctxt =
  +             new CommandLineContext(optionsP.getClassPath(), file, uriBase,
  +                                    uriRoot, false,  optionsP );
               if (dirset) {
                   clctxt.setOutputInDirs(true);
               }
  -            File uriDir = new File(clctxt.getRealPath("/"));
  -            if (uriDir.exists()) {
  -                if ((new File(uriDir, "WEB-INF/classes")).exists()) {
  -                    loader.addJar(clctxt.getRealPath("/WEB-INF/classes"));
  -                }
  -                File lib = new File(clctxt.getRealPath("WEB-INF/lib"));
  -                if (lib.exists() && lib.isDirectory()) {
  -                    String[] libs = lib.list();
  -                    for (int i = 0; i < libs.length; i++) {
  -                        try {
  -                            loader.addJar(lib.getCanonicalPath()
  -                                    + File.separator
  -                                    + libs[i]);
  -                        } catch (IOException ioe) {
  -                            // failing a toCanonicalPath on a file that
  -                            // exists() should be a JVM regression test,
  -                            // therefore we have permission to freak out
  -                            throw new RuntimeException(ioe.toString());
  -                        }
  -                    }
  -                }
  -            }
  -            Compiler clc = new Compiler(clctxt);
  +
  +            Compiler compiler = new Compiler(clctxt);
            ManglerCli mangler=new ManglerCli();
            
            mangler.init(file,
  @@ -307,8 +272,25 @@
                         clctxt.isOutputInDirs());
   
            JspPageInfo pageInfo=new JspPageInfo( clctxt,optionsP, mangler);
  +         
  +         compiler.jsp2java( pageInfo );
  +
  +         String javaFile=
  +             pageInfo.getMangler().getJavaFileName();
  +         
  +         JavaCompiler javaC=
  +             compiler.createJavaCompiler( pageInfo );
  +         compiler.prepareCompiler( javaC, pageInfo );
  +         boolean status = javaC.compile( javaFile );
  +
  +         if (status == false) {
  +             String msg = javaC.getCompilerMessage();
  +             throw new JasperException("Unable to compile "
  +                                       + msg);
  +         }
            
  -            clc.compile(pageInfo, JavaCompiler.getDefaultCompiler());
  +         // remove java file if !keepgenerated, etc
  +         compiler.postCompile(pageInfo);
   
               targetClassName = null;
               String thisServletName;
  @@ -352,13 +334,9 @@
           }
           return false;
       }
  -
   
  -    public void parseFiles(PrintStream log)  throws JasperException {
  -
  -        boolean scratchDirSet = (optionsP.getScratchDir() != null);
  -        boolean urirootSet = (uriRoot != null);
  -
  +    // -------------------- Process all files --------------------
  +    private void prepareScratchDir( ) {
           // set up a scratch/output dir if none is provided
           if (optionsP.getScratchDir() == null) {
               String temp = System.getProperty("java.io.tempdir");
  @@ -368,8 +346,64 @@
               options.put( Options.SCRATCH_DIR,  
                         new File(new File(temp).getAbsolutePath()));
           }
  +    }
  +
  +    /** Search for uriRoot
  +     */
  +    private void findUriRoot( File f ) {
  +     String tUriBase = uriBase;
  +     if (tUriBase == null) {
  +         tUriBase = "/";
  +     }
  +     try {
  +         if (f.exists()) {
  +             f = new File(f.getCanonicalPath());
  +             while (f != null) {
  +                 File g = new File(f, "WEB-INF");
  +                 if (g.exists() && g.isDirectory()) {
  +                     uriRoot = f.getCanonicalPath();
  +                     uriBase = tUriBase;
  +                     ContainerLiaison.message("jspc.implicit.uriRoot",
  +                                              new Object[] { uriRoot },
  +                                              Log.INFORMATION);
  +                     break;
  +                 }
  +                 if (f.exists() && f.isDirectory()) {
  +                     tUriBase = "/" + f.getName() + "/" + tUriBase;
  +                 }
  +                 
  +                 String fParent = f.getParent();
  +                 if (fParent == null) {
  +                     f = new File(args[argPos]);
  +                     fParent = f.getParent();
  +                     if (fParent == null) {
  +                         fParent = File.separator;
  +                     }
  +                     uriRoot = new File(fParent).getCanonicalPath();
  +                     uriBase = "/";
  +                     break;
  +                        } else {
  +                            f = new File(fParent);
  +                        }
  +                 
  +                 // If there is no acceptible candidate, uriRoot will
  +                 // remain null to indicate to the CompilerContext to
  +                 // use the current working/user dir.
  +             }
  +         }
  +     } catch (IOException ioe) {
  +         // since this is an optional default and a null value
  +         // for uriRoot has a non-error meaning, we can just
  +         // pass straight through
  +     }
  +    }
  +    File froot=null;
  +    
  +    public void parseFiles(PrintStream log)
  +     throws JasperException, IOException
  +    {
  +     prepareScratchDir();
   
  - 
           File f = new File(args[argPos]);
           while (!f.exists()) {
               boolean webApp = false;
  @@ -399,7 +433,8 @@
                   }
               }
           }
  -        if (uriRoot == null) {
  +
  +     if (uriRoot == null) {
               if (SWITCH_FILE_WEBAPP.equals(args[argPos])) {
                   if (args.length > argPos + 1) {
                       f = new File(args[argPos + 1]);
  @@ -409,56 +444,12 @@
                   }
               }
               // set up the uri root if none is explicitly set
  -            String tUriBase = uriBase;
  -            if (tUriBase == null) {
  -                tUriBase = "/";
  -            }
  -            try {
  -                if (f.exists()) {
  -                    f = new File(f.getCanonicalPath());
  -                    while (f != null) {
  -                        File g = new File(f, "WEB-INF");
  -                        if (g.exists() && g.isDirectory()) {
  -                            uriRoot = f.getCanonicalPath();
  -                            uriBase = tUriBase;
  -                            ContainerLiaison.message("jspc.implicit.uriRoot",
  -                                              new Object[] { uriRoot },
  -                                              Log.INFORMATION);
  -                            break;
  -                        }
  -                        if (f.exists() && f.isDirectory()) {
  -                            tUriBase = "/" + f.getName() + "/" + tUriBase;
  -                        }
  -                        
  -                        String fParent = f.getParent();
  -                        if (fParent == null) {
  -                            f = new File(args[argPos]);
  -                            fParent = f.getParent();
  -                            if (fParent == null) {
  -                                fParent = File.separator;
  -                            }
  -                            uriRoot = new File(fParent).getCanonicalPath();
  -                            uriBase = "/";
  -                            break;
  -                        } else {
  -                            f = new File(fParent);
  -                        }
  -
  -                        // If there is no acceptible candidate, uriRoot will
  -                        // remain null to indicate to the CompilerContext to
  -                        // use the current working/user dir.
  -                    }
  -                }
  -            } catch (IOException ioe) {
  -                // since this is an optional default and a null value
  -                // for uriRoot has a non-error meaning, we can just
  -                // pass straight through
  -            }
  +         findUriRoot(f);
           }
   
   
           String file = nextFile();
  -        File froot = new File(uriRoot);
  +     froot = new File(uriRoot);
           String ubase = null;
           try {
               ubase = froot.getCanonicalPath();
  @@ -469,131 +460,7 @@
           while (file != null) {
               if (SWITCH_FILE_WEBAPP.equals(file)) {
                   String base = nextFile();
  -                if (base == null) {
  -                    ContainerLiaison.message("jspc.error.emptyWebApp", 
  -                            Log.ERROR);
  -                    return;
  -                }// else if (".".equals(base)) {
  -                //    base = "";
  -                //}
  -                String oldRoot = uriRoot;
  -                if (!urirootSet) {
  -                    uriRoot = base;
  -                }
  -                Vector pages = new Vector();
  -
  -                Stack dirs = new Stack();
  -                dirs.push(base);
  -                if (extensions == null) {
  -                    extensions = new Vector();
  -                    extensions.addElement("jsp");
  -                }
  -                while (!dirs.isEmpty()) {
  -                    String s = dirs.pop().toString();
  -                    //System.out.println("--" + s);
  -                    f = new File(s);
  -                    if (f.exists() && f.isDirectory()) {
  -                        String[] files = f.list();
  -                        String ext;
  -                        for (int i = 0; i < files.length; i++) {
  -                            File f2 = new File(s, files[i]);
  -                            //System.out.println(":" + f2.getPath());
  -                            if (f2.isDirectory()) {
  -                                dirs.push(f2.getPath());
  -                                //System.out.println("++" + f2.getPath());
  -                            } else {
  -                                ext = files[i].substring(
  -                                        files[i].lastIndexOf('.') + 1);
  -                                if (extensions.contains(ext)) {
  -                                    //System.out.println(s + "?" + files[i]);
  -                                    pages.addElement(
  -                                        s + File.separatorChar + files[i]);
  -                                } else {
  -                                    //System.out.println("not done:" + ext);
  -                                }
  -                            }
  -                        }
  -                    }
  -                }
  -
  -                String ubaseOld = ubase;
  -                File frootOld = froot;
  -                froot = new File(uriRoot);
  -
  -                try {
  -                    ubase = froot.getCanonicalPath();
  -                } catch (IOException ioe) {
  -                    // if we cannot get the base, leave it null
  -                }
  -
  -                //System.out.println("==" + ubase);
  -
  -
  -                Writer mapout;
  -                CharArrayWriter servletout, mappingout;
  -                try {
  -                    if (webxmlLevel >= INC_WEBXML) {
  -                        File fmapings = new File(webxmlFile);
  -                        mapout = new FileWriter(fmapings);
  -                        servletout = new CharArrayWriter();
  -                        mappingout = new CharArrayWriter();
  -                    } else {
  -                        mapout = null;
  -                        servletout = null;
  -                        mappingout = null;
  -                    }
  -                    if (webxmlLevel >= ALL_WEBXML) {
  -                        
mapout.write(ContainerLiaison.getString("jspc.webxml.header"));
  -                    } else if (webxmlLevel>= INC_WEBXML) {
  -                        
mapout.write(ContainerLiaison.getString("jspc.webinc.header"));
  -                    }
  -                } catch (IOException ioe) {
  -                    mapout = null;
  -                    servletout = null;
  -                    mappingout = null;
  -                }
  -
  -                Enumeration e = pages.elements();
  -                while (e.hasMoreElements())
  -                {
  -                    String nextjsp = e.nextElement().toString();
  -                    try {
  -                        if (ubase != null) {
  -                            File fjsp = new File(nextjsp);
  -                            String s = fjsp.getCanonicalPath();
  -                            //System.out.println("**" + s);
  -                            if (s.startsWith(ubase)) {
  -                                nextjsp = s.substring(ubase.length());
  -                            }
  -                        }
  -                    } catch (IOException ioe) {
  -                        // if we got problems dont change the file name
  -                    }
  -
  -                    if (nextjsp.startsWith("." + File.separatorChar)) {
  -                        nextjsp = nextjsp.substring(2);
  -                    }
  -
  -                    parseFile(log, nextjsp, servletout, mappingout);
  -                }
  -                uriRoot = oldRoot;
  -                ubase = ubaseOld;
  -                froot = frootOld;
  -
  -                if (mapout != null) {
  -                    try {
  -                        servletout.writeTo(mapout);
  -                        mappingout.writeTo(mapout);
  -                        if (webxmlLevel >= ALL_WEBXML) {
  -                            
mapout.write(ContainerLiaison.getString("jspc.webxml.footer"));
  -                        } else if (webxmlLevel >= INC_WEBXML) {
  -                            
mapout.write(ContainerLiaison.getString("jspc.webinc.footer"));
  -                        }
  -                        mapout.close();
  -                    } catch (IOException ioe) {
  -                        // noting to do if it fails since we are done with it
  -                    }
  -                }
  +             processWebApp( base, uriRoot, ubase, log );
               } else {
                   try {
                       if (ubase != null) {
  @@ -616,6 +483,113 @@
           }
       }
   
  +    private void processJspFiles( Vector pages, String ubase,
  +                               PrintStream log,
  +                               Writer servletout, Writer mappingout)
  +     throws IOException
  +    {
  +     Enumeration e = pages.elements();
  +     while (e.hasMoreElements()) {
  +         String nextjsp = e.nextElement().toString();
  +         try {
  +             if (ubase != null) {
  +                 File fjsp = new File(nextjsp);
  +                 String s = fjsp.getCanonicalPath();
  +                 //System.out.println("**" + s);
  +                 if (s.startsWith(ubase)) {
  +                     nextjsp = s.substring(ubase.length());
  +                 }
  +             }
  +         } catch (IOException ioe) {
  +             // if we got problems dont change the file name
  +         }
  +
  +         if (nextjsp.startsWith("." + File.separatorChar)) {
  +             nextjsp = nextjsp.substring(2);
  +         }
  +
  +         parseFile(log, nextjsp, servletout, mappingout);
  +     }
  +    }
  +    
  +    public void processWebApp( String base, String uriRoot, String ubase,
  +                            PrintStream log)
  +     throws IOException
  +    {
  +     if (base == null) {
  +         ContainerLiaison.message("jspc.error.emptyWebApp", 
  +                                  Log.ERROR);
  +         return;
  +     }
  +
  +     String oldRoot = uriRoot;
  +        boolean urirootSet = (uriRoot != null);
  +     if (!urirootSet) {
  +         uriRoot = base;
  +     }
  +     if (extensions == null) {
  +         extensions = new Vector();
  +         extensions.addElement("jsp");
  +     }
  +     
  +     Vector pages=findByExtension( base, extensions );
  +     
  +     String ubaseOld = ubase;
  +     File frootOld = froot;
  +     froot = new File(uriRoot);
  +
  +     try {
  +         ubase = froot.getCanonicalPath();
  +     } catch (IOException ioe) {
  +         // if we cannot get the base, leave it null
  +     }
  +
  +     Writer mapout;
  +     CharArrayWriter servletout, mappingout;
  +     try {
  +         if (webxmlLevel >= INC_WEBXML) {
  +             File fmapings = new File(webxmlFile);
  +             mapout = new FileWriter(fmapings);
  +             servletout = new CharArrayWriter();
  +             mappingout = new CharArrayWriter();
  +         } else {
  +             mapout = null;
  +             servletout = null;
  +             mappingout = null;
  +         }
  +         if (webxmlLevel >= ALL_WEBXML) {
  +             mapout.write(ContainerLiaison.getString("jspc.webxml.header"));
  +         } else if (webxmlLevel>= INC_WEBXML) {
  +             mapout.write(ContainerLiaison.getString("jspc.webinc.header"));
  +         }
  +     } catch (IOException ioe) {
  +         mapout = null;
  +         servletout = null;
  +         mappingout = null;
  +     }
  +     
  +     processJspFiles( pages, ubase, log, servletout, mappingout );
  +     
  +     uriRoot = oldRoot;
  +     ubase = ubaseOld;
  +     froot = frootOld;
  +     
  +     if (mapout != null) {
  +         try {
  +             servletout.writeTo(mapout);
  +             mappingout.writeTo(mapout);
  +             if (webxmlLevel >= ALL_WEBXML) {
  +                 mapout.write(ContainerLiaison.getString("jspc.webxml.footer"));
  +             } else if (webxmlLevel >= INC_WEBXML) {
  +                 mapout.write(ContainerLiaison.getString("jspc.webinc.footer"));
  +             }
  +             mapout.close();
  +         } catch (IOException ioe) {
  +             // noting to do if it fails since we are done with it
  +         }
  +     }
  +    }
  +    
       public static void main(String arg[]) {
           if (arg.length == 0) {
              System.out.println(ContainerLiaison.getString("jspc.usage"));
  @@ -623,7 +597,7 @@
               try {
                   JspC jspc = new JspC(arg, System.out);
                   jspc.parseFiles(System.out);
  -            } catch (JasperException je) {
  +            } catch (Exception je) {
                   System.err.print("error:");
                   System.err.println(je.getMessage());
                   if (die != NO_DIE_LEVEL) {
  @@ -632,6 +606,53 @@
               }
           }
       }
  +
  +    private static final int debug=1;
  +    private void log( String s ) {
  +     System.out.println("JspC: " + s );
  +    }
  +
  +    // -------------------- utils --------------------
  +
  +
  +    public Vector findByExtension(String base, Vector extensions )
  +     throws IOException
  +    {
  +     Vector pages = new Vector();
  +
  +     Stack dirs = new Stack();
  +
  +     dirs.push(base);
  +     while (!dirs.isEmpty()) {
  +         String s = dirs.pop().toString();
  +         //System.out.println("--" + s);
  +         File f = new File(s);
  +         if (f.exists() && f.isDirectory()) {
  +             String[] files = f.list();
  +             String ext;
  +             for (int i = 0; i < files.length; i++) {
  +                 File f2 = new File(s, files[i]);
  +                 //System.out.println(":" + f2.getPath());
  +                 if (f2.isDirectory()) {
  +                     dirs.push(f2.getPath());
  +                     //System.out.println("++" + f2.getPath());
  +                 } else {
  +                     ext = files[i].substring(
  +                                              files[i].lastIndexOf('.') + 1);
  +                     if (extensions.contains(ext)) {
  +                         //System.out.println(s + "?" + files[i]);
  +                         pages.addElement(
  +                                          s + File.separatorChar + files[i]);
  +                     } else {
  +                         //System.out.println("not done:" + ext);
  +                     }
  +                 }
  +             }
  +         }
  +     }
  +     return pages;
  +    }
  +
   
   }
   
  
  
  

Reply via email to