You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by ho...@apache.org on 2006/04/21 15:54:25 UTC

svn commit: r395886 - /geronimo/trunk/plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/deployment/mavenplugin/MergeWebXML.java

Author: hogstrom
Date: Fri Apr 21 06:54:11 2006
New Revision: 395886

URL: http://svn.apache.org/viewcvs?rev=395886&view=rev
Log:
GERONIMO-1844 Precompile jsp pages in console - Added the MergeXML.java from the patch

Added:
    geronimo/trunk/plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/deployment/mavenplugin/MergeWebXML.java

Added: geronimo/trunk/plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/deployment/mavenplugin/MergeWebXML.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/deployment/mavenplugin/MergeWebXML.java?rev=395886&view=auto
==============================================================================
--- geronimo/trunk/plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/deployment/mavenplugin/MergeWebXML.java (added)
+++ geronimo/trunk/plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/deployment/mavenplugin/MergeWebXML.java Fri Apr 21 06:54:11 2006
@@ -0,0 +1,145 @@
+/**
+ *
+ * Copyright 2006 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.deployment.mavenplugin;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.PrintWriter;
+
+public class MergeWebXML {
+
+    private static final String[] insertBefore =
+    { "</web-app>", "<servlet-mapping>", "<session-config>",
+      "<mime-mapping>", "<welcome-file-list>", "<error-page>", "<taglib>",
+      "<resource-env-ref>", "<resource-ref>", "<security-constraint>",
+      "<login-config>", "<security-role>", "<env-entry>", "<ejb-ref>",
+      "<ejb-local-ref>" };
+
+    private String uriRoot;
+
+    public String getUriRoot() {
+        return uriRoot;
+    }
+
+    public void setUriRoot(String uriRoot) {
+        this.uriRoot = uriRoot;
+    }
+
+
+    public void execute() throws Exception {
+        File webappBase = new File(uriRoot);
+        File webXml = new File(webappBase, "WEB-INF/web.xml");
+        File webxmlFile = new File(webappBase, "WEB-INF/generated-web.xml");
+        File webXml2 = new File(webappBase, "WEB-INF/web2.xml");
+        String insertStartMarker = "<!-- start insert jspc generated web fragment -->";
+        String insertEndMarker = "<!-- end insert jspc generated web fragment -->";
+
+        BufferedReader reader = new BufferedReader(new FileReader(webXml));
+        BufferedReader fragmentReader =
+            new BufferedReader(new FileReader(webxmlFile));
+        PrintWriter writer = new PrintWriter(new FileWriter(webXml2));
+
+        // Insert the <servlet> and <servlet-mapping> declarations
+        int pos = -1;
+        String line = null;
+        while (true) {
+            line = reader.readLine();
+            if (line == null) {
+                break;
+            }
+            // Skip anything previously generated by JSPC
+            if (line.indexOf(insertStartMarker) >= 0) {
+                while (true) {
+                    line = reader.readLine();
+                    if (line == null) {
+                        return;
+                    }
+                    if (line.indexOf(insertEndMarker) >= 0) {
+                        line = reader.readLine();
+                        if (line == null) {
+                            return;
+                        }
+                        break;
+                    }
+                }
+            }
+            for (int i = 0; i < insertBefore.length; i++) {
+                pos = line.indexOf(insertBefore[i]);
+                if (pos >= 0)
+                    break;
+            }
+            if (pos >= 0) {
+                writer.println(line.substring(0, pos));
+                break;
+            } else {
+                writer.println(line);
+            }
+        }
+
+        writer.println(insertStartMarker);
+        while (true) {
+            String line2 = fragmentReader.readLine();
+            if (line2 == null) {
+                writer.println();
+                break;
+            }
+            writer.println(line2);
+        }
+        writer.println(insertEndMarker);
+        writer.println();
+
+        for (int i = 0; i < pos; i++) {
+            writer.print(" ");
+        }
+        writer.println(line.substring(pos));
+
+        while (true) {
+            line = reader.readLine();
+            if (line == null) {
+                break;
+            }
+            writer.println(line);
+        }
+        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();
+        webxmlFile.delete();
+    }
+}