Author: rich
Date: Fri Oct 29 16:21:19 2004
New Revision: 56004

Modified:
   
incubator/beehive/branches/v1/alpha/netui/src/compiler/org/apache/beehive/netui/compiler/genmodel/GenStrutsApp.java
   
incubator/beehive/branches/v1/alpha/netui/src/compiler/org/apache/beehive/netui/compiler/genmodel/GenValidationModel.java
Log:
This is a temporary workaround for 
http://issues.apache.org/jira/browse/XMLBEANS-72, which has been entered as a 
blocker for us (http://nagoya.apache.org/jira/browse/BEEHIVE-30).  It should 
NOT, I repeat NOT be merged into the main line.

DRT: netui (WinXP)
BB: self (linux)



Modified: 
incubator/beehive/branches/v1/alpha/netui/src/compiler/org/apache/beehive/netui/compiler/genmodel/GenStrutsApp.java
==============================================================================
--- 
incubator/beehive/branches/v1/alpha/netui/src/compiler/org/apache/beehive/netui/compiler/genmodel/GenStrutsApp.java
 (original)
+++ 
incubator/beehive/branches/v1/alpha/netui/src/compiler/org/apache/beehive/netui/compiler/genmodel/GenStrutsApp.java
 Fri Oct 29 16:21:19 2004
@@ -29,11 +29,7 @@
 import org.apache.xmlbeans.XmlCursor;
 import org.apache.xmlbeans.XmlObject;
 
-import java.io.File;
-import java.io.IOException;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.PrintStream;
+import java.io.*;
 import java.util.Date;
 import java.util.Collection;
 import java.util.List;
@@ -410,10 +406,50 @@
         throws FileNotFoundException, IOException, XmlException, 
NoWebInfDirectoryException
     {
         _strutsConfigFile.getParentFile().mkdirs();
-        PrintStream out = new PrintStream( new FileOutputStream( 
_strutsConfigFile ) );
-        writeXml( out, strutsMergeFile, _webappRoot );
-        out.close();
+        File tempFile = new File( _strutsConfigFile + ".fixdoctype" );
+        PrintStream out = new PrintStream( new FileOutputStream( tempFile ) );
+        try
+        {
+            writeXml( out, strutsMergeFile, _webappRoot );
+        }
+        finally
+        {
+            out.close();
+        }
+        
+        fixDocType( tempFile, _strutsConfigFile, "<!DOCTYPE struts-config 
PUBLIC \"-//Apache Software Foundation//DTD Struts Configuration 1.1//EN\" 
\"http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd\";>" );
+        tempFile.deleteOnExit();
     }    
+    
+    /**
+     * This is a TEMPORARY workaround for 
http://issues.apache.org/jira/browse/XMLBEANS-72.
+     * It must NOT be merged into the main line.
+     */
+    static void fixDocType( File inFile, File outFile, String doctype )
+        throws IOException
+    {
+        BufferedReader in = new BufferedReader( new FileReader( inFile ) );
+        PrintWriter out = new PrintWriter( new FileWriter( outFile ) );
+        
+        try
+        {
+            String line = in.readLine();
+            assert line.startsWith( "<?xml" );
+            out.println( line );
+            line = in.readLine();
+            if ( ! line.startsWith( "<!DOCTYPE" ) ) out.println( doctype );
+            out.println( line );
+            while ( ( line = in.readLine() ) != null )
+            {
+                out.println( line );
+            }
+        }
+        finally
+        {
+            in.close();
+            out.close();
+        }
+    }
     
     public File getStrutsConfigFile()
     {

Modified: 
incubator/beehive/branches/v1/alpha/netui/src/compiler/org/apache/beehive/netui/compiler/genmodel/GenValidationModel.java
==============================================================================
--- 
incubator/beehive/branches/v1/alpha/netui/src/compiler/org/apache/beehive/netui/compiler/genmodel/GenValidationModel.java
   (original)
+++ 
incubator/beehive/branches/v1/alpha/netui/src/compiler/org/apache/beehive/netui/compiler/genmodel/GenValidationModel.java
   Fri Oct 29 16:21:19 2004
@@ -377,10 +377,13 @@
     public void writeToFile()
         throws FileNotFoundException, XmlException, IOException
     {
-        String outputFile = _strutsApp.getWebappRoot() + 
_strutsApp.getOutputFileURI( STRUTS_VALIDATION_PREFIX );
-        PrintStream printStream = new PrintStream( new FileOutputStream( 
outputFile ) );
+        File outputFile = new File( _strutsApp.getWebappRoot() + 
_strutsApp.getOutputFileURI( STRUTS_VALIDATION_PREFIX ) );
+        File tempFile = new File( outputFile.getPath() + ".fixdoctype" );
+        PrintStream printStream = new PrintStream( new FileOutputStream( 
tempFile ) );
         writeXml( printStream, _mergeFile );
         printStream.close();
+        GenStrutsApp.fixDocType( tempFile, outputFile, "<!DOCTYPE 
form-validation PUBLIC \"-//Apache Software Foundation//DTD Commons Validator 
Rules Configuration 1.0//EN\" 
\"http://jakarta.apache.org/commons/dtds/validator_1_0.dtd\";>" );
+        tempFile.deleteOnExit();
     }
 
     public String getOutputFileURI()

Reply via email to