tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kin-Man Chung <Kin-Man.Ch...@Eng.Sun.COM>
Subject Re: cvs commit: jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper JspC.java
Date Thu, 17 Apr 2003 20:55:37 GMT
The last part of the the method mergeIntoWebXml copies webXml2 to webXml,
and then deletes webXml2, it is simpler to just do

	webXml.delete();
	webXml2.renameTo(webXml);
	
-Kin-man

> Date: Thu, 17 Apr 2003 20:19:07 +0000
> From: remm@apache.org
> Subject: cvs commit: jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper 
JspC.java
> To: jakarta-tomcat-jasper-cvs@apache.org
> 
> remm        2003/04/17 13:19:07
> 
>   Modified:    jasper2/src/share/org/apache/jasper JspC.java
>   Log:
>   - Implement hack to merge the generated deployment descriptor with
>     the webapp deployment descriptor.
>   
>   Revision  Changes    Path
>   1.41      +95 -3     
jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/JspC.java
>   
>   Index: JspC.java
>   ===================================================================
>   RCS file: 
/home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/JspC.java,v
>   retrieving revision 1.40
>   retrieving revision 1.41
>   diff -u -r1.40 -r1.41
>   --- JspC.java	17 Apr 2003 00:32:02 -0000	1.40
>   +++ JspC.java	17 Apr 2003 20:19:07 -0000	1.41
>   @@ -65,6 +65,15 @@
>    import java.net.*;
>    import java.util.*;
>    
>   +import javax.xml.parsers.DocumentBuilder;
>   +import javax.xml.parsers.DocumentBuilderFactory;
>   +
>   +import org.w3c.dom.Node;
>   +import org.w3c.dom.NodeList;
>   +import org.w3c.dom.Element;
>   +import org.w3c.dom.Document;
>   +import org.xml.sax.InputSource;
>   +
>    import org.apache.jasper.compiler.ServletWriter;
>    import org.apache.jasper.compiler.Compiler;
>    import org.apache.jasper.compiler.TldLocationsCache;
>   @@ -165,6 +174,7 @@
>        // Generation of web.xml fragments
>        private String webxmlFile;
>        private int webxmlLevel;
>   +    private boolean addWebXmlMappings = false;
>    
>        private Writer mapout;
>        private CharArrayWriter servletout;
>   @@ -465,6 +475,18 @@
>        }
>    
>        /**
>   +     * File where we generate a complete web.xml with the class 
definitions.
>   +     */
>   +    public void setWebXml( String s ) {
>   +        webxmlFile=s;
>   +        webxmlLevel=ALL_WEBXML;
>   +    }
>   +
>   +    public void setAddWebXmlMappings(boolean b) {
>   +        addWebXmlMappings = b;
>   +    }
>   +
>   +    /**
>         * Obtain JSP configuration informantion specified in web.xml.
>         */
>        public JspConfig getJspConfig() {
>   @@ -505,6 +527,72 @@
>            }
>        }
>    
>   +    /**
>   +     * Include the generated web.xml inside the webapp's web.xml.
>   +     */
>   +    protected void mergeIntoWebXml()
>   +        throws Exception {
>   +
>   +        File webappBase = new File(uriRoot);
>   +        File webXml = new File(webappBase, "WEB-INF/web.xml");
>   +        File webXml2 = new File(webappBase, "WEB-INF/web2.xml");
>   +
>   +        BufferedReader reader = new BufferedReader(new FileReader(webXml));
>   +        BufferedReader fragmentReader = 
>   +            new BufferedReader(new FileReader(webxmlFile));
>   +        PrintWriter writer = new PrintWriter(new FileWriter(webXml2));
>   +
>   +        // TODO: This is a hack
>   +        while (true) {
>   +            String line = reader.readLine();
>   +            if (line == null) {
>   +                break;
>   +            }
>   +            int pos = line.indexOf("</web-app>");
>   +            if (pos >= 0) {
>   +                writer.println(line.substring(0, pos));
>   +                break;
>   +            } else {
>   +                writer.write(line);
>   +                writer.write("\n");
>   +            }
>   +        }
>   +
>   +        while (true) {
>   +            String line = fragmentReader.readLine();
>   +            if (line == null) {
>   +                break;
>   +            }
>   +            writer.write(line);
>   +            writer.write("\n");
>   +        }
>   +
>   +        writer.write("</web-app>");
>   +        writer.write("\n");
>   +        writer.close();
>   +
>   +        reader.close();
>   +        fragmentReader.close();
>   +
>   +        FileInputStream fis = new FileInputStream(webXml2);
>   +        FileOutputStream fos = new FileOutputStream(webXml);
>   +
>   +        byte buf[] = new byte[512];
>   +        while (true) {
>   +            int n = fis.read(buf);
>   +            if (n < 0) {
>   +                break;
>   +            }
>   +            fos.write(buf, 0, n);
>   +        }
>   +
>   +        fis.close();
>   +        fos.close();
>   +
>   +        webXml2.delete();
>   +
>   +    }
>   +
>        public boolean processFile(String file)
>            throws JasperException
>        {
>   @@ -670,6 +758,10 @@
>    
>    	    completeWebXml();
>    	    
>   +            if (addWebXmlMappings) {
>   +                mergeIntoWebXml();
>   +            }
>   +
>            } catch (Throwable t) {
>                t.printStackTrace();
>            }
>   
>   
>   
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org


Mime
View raw message