Author: taylor
Date: Wed Jan  3 22:31:48 2007
New Revision: 492423

URL: http://svn.apache.org/viewvc?view=rev&rev=492423
Log:
https://issues.apache.org/jira/browse/JS2-461
Population scripts are now converted to run with Serializer component
All seed data is sourced from XML
integrated into all builds (maven-1, maven-2, custom-maven-1, custom-maven-2)
this commit does not include the DDL UTILS replacement of the Torque/SQL DDL 
scripts
The original contribution had too many errors with DDL UTILs
I've included the all-or-none patches in build-with-DDLUTILS.xml, 
pom-with-DDLUTILS.xml, and plugin-with-DDLUTILS.jelly
contribution from Hajo Birthelmer

Added:
    portals/jetspeed-2/trunk/etc/build-with-DDLUTILS.xml
    portals/jetspeed-2/trunk/etc/pom-with-DDLUTILS.xml
    portals/jetspeed-2/trunk/etc/schema/merge.xslt
    portals/jetspeed-2/trunk/maven-plugin/plugin-with-DDLUTILS.jelly
Modified:
    portals/jetspeed-2/trunk/components/pom.xml
    portals/jetspeed-2/trunk/components/portal/pom.xml
    portals/jetspeed-2/trunk/components/portal/project.xml
    
portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/aggregator/TestWorkerMonitor.java
    portals/jetspeed-2/trunk/components/registry/pom.xml
    
portals/jetspeed-2/trunk/components/security/src/java/org/apache/jetspeed/security/impl/RdbmsPolicy.java
    
portals/jetspeed-2/trunk/components/serializer/src/java/org/apache/jetspeed/serializer/JetspeedDDLApplication.java
    
portals/jetspeed-2/trunk/components/serializer/src/java/org/apache/jetspeed/serializer/JetspeedDDLUtil.java
    
portals/jetspeed-2/trunk/components/serializer/src/java/org/apache/jetspeed/serializer/JetspeedSerializerApplication.java
    
portals/jetspeed-2/trunk/components/serializer/src/java/org/apache/jetspeed/serializer/JetspeedSerializerImpl.java
    portals/jetspeed-2/trunk/etc/build.xml
    portals/jetspeed-2/trunk/etc/pom.xml
    portals/jetspeed-2/trunk/etc/schema/security-schema.xml
    
portals/jetspeed-2/trunk/maven-archetypes/portal/src/archetype/archetype-resources/etc/build.xml
    
portals/jetspeed-2/trunk/maven-archetypes/portal/src/archetype/archetype-resources/etc/pom.xml
    portals/jetspeed-2/trunk/maven-plugin/plugin.jelly

Modified: portals/jetspeed-2/trunk/components/pom.xml
URL: 
http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/components/pom.xml?view=diff&rev=492423&r1=492422&r2=492423
==============================================================================
--- portals/jetspeed-2/trunk/components/pom.xml (original)
+++ portals/jetspeed-2/trunk/components/pom.xml Wed Jan  3 22:31:48 2007
@@ -145,7 +145,7 @@
                 <directory>../../etc/db-ojb</directory>
             </testResource>
             <testResource>
-                <directory>../../src/webapp/WEB-INF/assembly</directory>
+                <directory>../../src/webapp/WEB-INF/assembly/boot</directory>
             </testResource>
         </testResources>
 

Modified: portals/jetspeed-2/trunk/components/portal/pom.xml
URL: 
http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/components/portal/pom.xml?view=diff&rev=492423&r1=492422&r2=492423
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/pom.xml (original)
+++ portals/jetspeed-2/trunk/components/portal/pom.xml Wed Jan  3 22:31:48 2007
@@ -229,6 +229,16 @@
         </testResources>
 
         <plugins>
+           <plugin>
+              <groupId>org.apache.maven.plugins</groupId>
+              <artifactId>maven-surefire-plugin</artifactId>
+              <configuration>
+                  <skip>true</skip>
+                <excludes>
+                  <exclude>**/*TestAggregator.java</exclude>
+                </excludes>
+              </configuration>
+            </plugin>            
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-antrun-plugin</artifactId>

Modified: portals/jetspeed-2/trunk/components/portal/project.xml
URL: 
http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/components/portal/project.xml?view=diff&rev=492423&r1=492422&r2=492423
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/project.xml (original)
+++ portals/jetspeed-2/trunk/components/portal/project.xml Wed Jan  3 22:31:48 
2007
@@ -50,6 +50,9 @@
             <includes>
                 <include>**/Test*</include>
             </includes>
+            <excludes>
+                <exclude>**/TestAggregator.java</exclude>
+            </excludes>
             <resources>
                 <resource>
                     <directory>${basedir}/src/java</directory>

Modified: 
portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/aggregator/TestWorkerMonitor.java
URL: 
http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/aggregator/TestWorkerMonitor.java?view=diff&rev=492423&r1=492422&r2=492423
==============================================================================
--- 
portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/aggregator/TestWorkerMonitor.java
 (original)
+++ 
portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/aggregator/TestWorkerMonitor.java
 Wed Jan  3 22:31:48 2007
@@ -30,7 +30,7 @@
  * <P>Test the aggregation service</P>
  *
  * @author <a href="mailto:[EMAIL PROTECTED]">David Sean Taylor</a>
- * @version $Id: TestAggregator.java 279463 2005-09-07 23:45:24Z taylor $
+ * @version $Id: $
  * 
  */
 public class TestWorkerMonitor extends TestCase

Modified: portals/jetspeed-2/trunk/components/registry/pom.xml
URL: 
http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/components/registry/pom.xml?view=diff&rev=492423&r1=492422&r2=492423
==============================================================================
--- portals/jetspeed-2/trunk/components/registry/pom.xml (original)
+++ portals/jetspeed-2/trunk/components/registry/pom.xml Wed Jan  3 22:31:48 
2007
@@ -88,6 +88,34 @@
     <!-- Build Configuration -->
 
     <build>
+        <testResources>
+            <testResource>
+                <directory>etc/assembly</directory>                
+             </testResource>
+            <testResource>
+                <directory>src/java</directory>
+                <excludes>
+                    <exclude>**/*.java</exclude>
+                    <exclude>**/JETSPEED-INF/**</exclude>
+                </excludes>
+            </testResource>
+            <testResource>
+                <directory>src/test</directory>
+                <excludes>
+                    <exclude>**/*.java</exclude>
+                </excludes>
+            </testResource>
+            <testResource>
+                <directory>../../etc/log4j</directory>
+            </testResource>
+            <testResource>
+                <directory>../../etc/db-ojb</directory>
+            </testResource>
+            <testResource>
+                <directory>../../src/webapp/WEB-INF/assembly</directory>
+            </testResource>            
+        </testResources>
+        
         <plugins>
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
@@ -146,11 +174,6 @@
             </plugin>
         </plugins>
 
-        <testResources>
-            <testResource>
-                <directory>etc/assembly</directory>                
-             </testResource>
-        </testResources>
     </build>
 
     <!-- Project Information -->

Modified: 
portals/jetspeed-2/trunk/components/security/src/java/org/apache/jetspeed/security/impl/RdbmsPolicy.java
URL: 
http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/components/security/src/java/org/apache/jetspeed/security/impl/RdbmsPolicy.java?view=diff&rev=492423&r1=492422&r2=492423
==============================================================================
--- 
portals/jetspeed-2/trunk/components/security/src/java/org/apache/jetspeed/security/impl/RdbmsPolicy.java
 (original)
+++ 
portals/jetspeed-2/trunk/components/security/src/java/org/apache/jetspeed/security/impl/RdbmsPolicy.java
 Wed Jan  3 22:31:48 2007
@@ -77,10 +77,10 @@
      */
     public void refresh()
     {
-        if (log.isDebugEnabled())
-        {
-            log.debug("RdbmsPolicy refresh called.");
-        }
+//        if (log.isDebugEnabled())
+//        {
+//            log.debug("RdbmsPolicy refresh called.");
+//        }
     }
 
     /**

Modified: 
portals/jetspeed-2/trunk/components/serializer/src/java/org/apache/jetspeed/serializer/JetspeedDDLApplication.java
URL: 
http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/components/serializer/src/java/org/apache/jetspeed/serializer/JetspeedDDLApplication.java?view=diff&rev=492423&r1=492422&r2=492423
==============================================================================
--- 
portals/jetspeed-2/trunk/components/serializer/src/java/org/apache/jetspeed/serializer/JetspeedDDLApplication.java
 (original)
+++ 
portals/jetspeed-2/trunk/components/serializer/src/java/org/apache/jetspeed/serializer/JetspeedDDLApplication.java
 Wed Jan  3 22:31:48 2007
@@ -15,15 +15,25 @@
  */
 package org.apache.jetspeed.serializer;
 
+import java.io.BufferedWriter;
 import java.io.File;
 import java.io.FileInputStream;
+import java.io.FileWriter;
 import java.io.FilenameFilter;
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.StringTokenizer;
 
+import javax.xml.transform.Result;
+import javax.xml.transform.Source;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+
 import javolution.xml.XMLBinding;
 import javolution.xml.XMLObjectReader;
 
@@ -54,6 +64,11 @@
  * </p>
  * 
  * <p>
+ * -m if directory list provided this is the merge file to use. If not set here
+ * or in the properties file, a hardcoded version is used
+ * </p>
+ * 
+ * <p>
  * note that - if -I and -O are specified, the output file will contain the
  * UPDATED database
  * </p>
@@ -66,6 +81,9 @@
  * </p>
  * 
  * <p>
+ * -dn databaseName, for example MYSQL or ORACLE10
+ * </p>
+ * <p>
  * -dc driverClass, for example com.mysql.jdbc.Driver
  * </p>
  * <p>
@@ -79,7 +97,7 @@
  * -dp password
  * </p>
  * <p>
- * -l log4j-level, ERROR (default), WARN, INFO 
+ * -l log4j-level, ERROR (default), WARN, INFO
  * </p>
  * 
  * @author <a href="mailto:[EMAIL PROTECTED]">Hajo Birthelmer</a>
@@ -93,48 +111,49 @@
        String exludeFileName = null;
        String orderFileName = null;
 
-    String logLevel = null;
+       String logLevel = null;
 
        PropertiesConfiguration configuration = null;
 
        boolean doImport = false;
        boolean doExport = false;
        String schemaDirectory = null; // if specified all xml files in that
-                                                                       // 
directory will be processed
+       // directory will be processed
        String outputFile = null; // if specified the database schema will be
-                                                               // exported to 
that file
+       // exported to that file
        boolean overwrite = false; // default, do not overwrite the database
-                                                               // (ignored if 
only output)
+       // (ignored if only output)
        String driverClass = null; // jdbc driver
        String url = null; // jdbc url to database
        String user = null; // user
        String password = null; // password
-
+       String databaseName = null;
+       
        String[] filesToProcess = null;
 
+       String mergeFile = null; //name of XSLT merge file
        String[] args = null;
 
-
-       
-       
        public static void main(String[] args) throws Exception
        {
                JetspeedDDLApplication app = new JetspeedDDLApplication();
                app.processArguments(args);
        }
 
-       
-       
        public JetspeedDDLApplication()
        {
        }
-       
+
        /**
         * ensure that we have valid database settings
-        *
+        * 
         */
        private void checkDBSettings()
        {
+               if (databaseName == null)
+                       databaseName = System.getProperty(
+                                       
"org.apache.jetspeed.database.databaseName",
+                                       "mysql");
                if (driverClass == null)
                        driverClass = System.getProperty(
                                        
"org.apache.jetspeed.database.driverClass",
@@ -160,11 +179,11 @@
                                        "Can't proceed without a valid database 
user");
                return;
        }
-       
+
        /**
-        * parse arguments for process instructions, order and exclude files as 
well as 
-        * optional database arguments 
-        *
+        * parse arguments for process instructions, order and exclude files as 
well
+        * as optional database arguments
+        * 
         */
        private void parseArguments()
        {
@@ -182,28 +201,55 @@
                        } else if (args[n].equals("-s"))
                        {
                                orderFileName = args[++n];
-                       } else if (args[n].equals("-x"))
+                       }
+                       else if (args[n].equals("-x"))
                        {
                                exludeFileName = args[++n];
-                       } else if (args[n].equals("-R"))
+                       } 
+                       else if (args[n].equals("-m"))
+                       {
+                               mergeFile = args[++n];
+                       } 
+                       else if (args[n].equals("-R"))
                                overwrite = true;
+                       else if (args[n].equals("-dn"))
+            {
+                               databaseName = args[++n];
+            }
                        else if (args[n].equals("-dc"))
                                driverClass = args[++n];
                        else if (args[n].equals("-ds"))
                                url = args[++n];
                        else if (args[n].equals("-du"))
-                               user = args[++n];
+            {
+                if (((n + 1) >= args.length) || args[n + 1].startsWith("-d"))
+                {
+                    user = "";
+                } else
+                {
+                    user = args[++n];
+                }
+            } 
                        else if (args[n].equals("-dp"))
-                               password = args[++n];
+            {
+                if (((n + 1) >= args.length) || args[n + 1].startsWith("-d"))
+                {
+                    password = "";
+                } else
+                {
+                    password = args[++n];
+                }
+            } 
                        else if (args[n].equals("-P"))
                                propertyFileName = args[++n];
-           else if (args[n].equals("-l")) logLevel = args[++n];
+                       else if (args[n].equals("-l"))
+                               logLevel = args[++n];
 
                        else
                                throw new IllegalArgumentException("Unknown 
argument: "
                                                + args[n]);
                }
-                       
+
        }
 
        /**
@@ -217,7 +263,7 @@
                try
                {
                        File dir = new File(schemaDirectory);
-                       if (!(dir.exists())) 
+                       if (!(dir.exists()))
                                return fileList;
                        if (!(dir.isDirectory()))
                        {
@@ -225,8 +271,9 @@
                                fileList[0] = schemaDirectory;
                                return fileList;
                        }
-                       //      Handling a directory
-                       LocalFilenameFilter filter = new 
LocalFilenameFilter(exludeFileName,orderFileName);
+                       // Handling a directory
+                       LocalFilenameFilter filter = new LocalFilenameFilter(
+                                       exludeFileName, orderFileName);
                        File[] files = dir.listFiles(filter);
                        if (files == null)
                                return fileList;
@@ -259,9 +306,10 @@
                                        String filename = null;
                                        try
                                        {
-                                               filename= 
((JSGroup)_it.next()).getName();
+                                               filename = ((JSGroup) 
_it.next()).getName();
+                                       } catch (Exception eeee)
+                                       {
                                        }
-                                       catch (Exception eeee) {}
                                        if (filename != null)
                                        {
                                                for (int i = 0; i < 
files.length; i++)
@@ -271,7 +319,7 @@
                                                                fileList[j++] = 
files[i].getAbsolutePath();
                                                                tempList[i] = 
null;
                                                        }
-                                               }       
+                                               }
                                        }
                                }
                                for (int i = 0; i < files.length; i++)
@@ -280,8 +328,7 @@
                                                fileList[j++] = 
files[i].getAbsolutePath();
                                }
                                return fileList;
-                       }
-                       catch (Exception eee)
+                       } catch (Exception eee)
                        {
                                eee.printStackTrace();
                                return null;
@@ -289,19 +336,18 @@
 
                } catch (Exception e)
                {
-                       e.printStackTrace(); 
+                       e.printStackTrace();
                        throw new IllegalArgumentException(
                                        "Processing the schema-directory " + 
schemaDirectory
-                                                       + " caused exception "
-                                                       + 
e.getLocalizedMessage());
+                                                       + " caused exception " 
+ e.getLocalizedMessage());
                }
 
-               
        }
-       
+
        /**
-        * setup environment by processing all arguments and call 
-        * requested process routine
+        * setup environment by processing all arguments and call requested 
process
+        * routine
+        * 
         * @param arguments
         * @throws Exception
         */
@@ -317,7 +363,6 @@
                processPropertyFile();
 
                checkDBSettings();
-               
 
                /**
                 * The only required argument is the filename for either export 
or
@@ -338,25 +383,23 @@
                JetspeedDDLUtil ddlUtil = null;
 
                HashMap context = new HashMap();
-
+               context.put(JetspeedDDLUtil.DATASOURCE_DATABASENAME, 
databaseName);
                context.put(JetspeedDDLUtil.DATASOURCE_DRIVER, driverClass);
                context.put(JetspeedDDLUtil.DATASOURCE_URL, url);
                context.put(JetspeedDDLUtil.DATASOURCE_USERNAME, user);
                context.put(JetspeedDDLUtil.DATASOURCE_PASSWORD, password);
 
-               Logger  logger = Logger.getLogger("org.apache.ddlutils");
+               Logger logger = Logger.getLogger("org.apache.ddlutils");
                Level level = logger.getLevel();
                if (logLevel == null)
                        logger.setLevel(Level.ERROR);
+               else if (logLevel.equalsIgnoreCase("INFO"))
+                       logger.setLevel(Level.INFO);
+               else if (logLevel.equalsIgnoreCase("WARN"))
+                       logger.setLevel(Level.WARN);
                else
-                       if (logLevel.equalsIgnoreCase("INFO"))
-                               logger.setLevel(Level.INFO);
-                       else
-                               if (logLevel.equalsIgnoreCase("WARN"))
-                                       logger.setLevel(Level.WARN);
-                               else
-                                       logger.setLevel(Level.ERROR);
-               
+                       logger.setLevel(Level.ERROR);
+
                try
                {
                        ddlUtil = new JetspeedDDLUtil();
@@ -370,8 +413,10 @@
                }
                try
                {
-                       if (doImport) processImport(ddlUtil);
-                       if (doExport) processExport(ddlUtil);
+                       if (doImport)
+                               processImport(ddlUtil);
+                       if (doExport)
+                               processExport(ddlUtil);
                } catch (Exception e)
                {
                        System.err.println("Failed to process XML "
@@ -394,49 +439,204 @@
                        }
                }
 
-               
        }
 
        /**
-        * create/alter database 
+        * create/alter database
         * 
         * @param ddlUtil
         */
        private void processImport(JetspeedDDLUtil ddlUtil)
        {
-               for (int i = 0; i < filesToProcess.length; i++)
+               String file = null;
+               if ((filesToProcess == null) || (filesToProcess.length == 0))
+                       return;
+               if (filesToProcess.length > 1)
+                       file = mergeFiles(filesToProcess);
+
+               System.out.println("Importing " + file);
+               Database db = ddlUtil.createDatabaseSchemaFromXML(file);
+               try
                {
-                       String file = filesToProcess[i];
-                       System.out.println("Importing " + file);
-                       Database db = ddlUtil.createDatabaseSchemaFromXML(file);
-                       try
-                       {
-                               if ((i == 0) && (overwrite))
-                                       ddlUtil.createDatabase(db); // 
overwrite existing
-                                                                               
                // database
-                               else
-                                       ddlUtil.alterDatabase(db);
-                               System.out.println("Importing " + file + " 
completed");
-                       }
-                       catch (Exception ePr)
-                       {
-                               ePr.printStackTrace();
-                               //continue with the process despite that one of 
the files was bad...
+                       if (overwrite)
+                               ddlUtil.createDatabase(db); // overwrite 
existing
+                       // database
+                       else
+                               ddlUtil.alterDatabase(db);
+                       System.out.println("Importing " + file + " completed");
+               } catch (Exception ePr)
+               {
+                       ePr.printStackTrace();
+                       // continue with the process despite that one of the 
files was
+                       // bad...
+               }
+
+       }
+
+       /**
+        * Helper routine to create a temporary file
+        * 
+        * @param suffix
+        * @return
+        */
+       private File createTemp(String suffix)
+       {
+               try
+               {
+                       // Create temp file.
+                       File temp = File.createTempFile("tmp", suffix);
+
+                       // Delete temp file when program exits.
+                       temp.deleteOnExit();
+                       return temp;
+               } catch (IOException e)
+               {
+                       System.out.println("Failed to create temproary file 
with "
+                                       + e.getLocalizedMessage());
+                       e.printStackTrace();
+                       return null;
+               }
+
+       }
+       /**
+        * Open the merge file from disk
+        * 
+        * @param fileName
+        * @return
+        */
+       private File createXSLTFromFile(String fileName)
+       {
+               if (fileName == null)
+                       return null;
+               try
+               {
+                       File f = new File(fileName);
+                       if (f.exists())
+                               return f;
+                       return null;
+               }
+               catch (Exception e)
+               {
+                       System.out.println("Failed to open merge template " + 
e.getLocalizedMessage());
+                       e.printStackTrace();
+                       return null;
+               }
+       }
+       /**
+        * If everything else fails, use a hardcoded XSLT here
+        * 
+        * @return
+        */
+       private File createXSLTFromMemory()
+       {
+               StringBuffer buffer = new StringBuffer();
+
+               buffer.append("<?xml version=\"1.0\"?>");
+               buffer
+                               .append("<xslt:transform version=\"1.0\" 
xmlns:xslt=\"http://www.w3.org/1999/XSL/Transform\";>");
+               buffer
+                               .append("<!-- Simple template to merge two 
database schemas into one  -->");
+               buffer.append("<xslt:param name=\"fileTwo\" />");
+               buffer.append("<xslt:template match=\"/\">");
+
+               buffer.append("<xslt:message>");
+               buffer
+                               .append("<xslt:text /> Merging input with 
'<xslt:value-of select=\"$fileTwo\"/>");
+               buffer.append("<xslt:text>'</xslt:text>");
+               buffer.append("</xslt:message>");
+               buffer.append("<xslt:if test=\"string($fileTwo)=''\">");
+               buffer.append("<xslt:message terminate=\"yes\">");
+               buffer
+                               .append("<xslt:text>No input file specified 
(parameter 'fileTwo')</xslt:text>");
+               buffer.append("</xslt:message>");
+               buffer.append("</xslt:if>");
+               buffer.append("<database name=\"generic\">");
+               buffer.append("<xslt:apply-templates />");
+               buffer.append("</database>");
+               buffer.append("</xslt:template>");
+               buffer.append("<xslt:template match=\"database\">");
+               buffer.append("<xslt:apply-templates />");
+               buffer.append("<xslt:apply-templates 
select=\"document($fileTwo)/database/table\"/>");
+               buffer.append("</xslt:template>");
+
+               buffer.append("<xslt:template match=\"@*|node()\">");
+               buffer.append("<xslt:copy>");
+               buffer.append("<xslt:apply-templates select=\"@*|node()\"/>");
+               buffer.append("</xslt:copy>");
+               buffer.append("</xslt:template>");
+               buffer.append("</xslt:transform>");
+
+               File xslt = createTemp(".xslt");
+               try
+               {
+                       // Write to temp file
+
+                       BufferedWriter out = new BufferedWriter(new 
FileWriter(xslt));
+                       out.write(buffer.toString());
+                       out.close();
+                       return xslt;
+               } catch (Exception e)
+               {
+                       e.printStackTrace();
+                       return null;
+               }
+       }
+       /**
+        * process of merging two or more schema files into one schema file.
+        *  
+        * @param fileList The filelist contains a (potentially) ordered list 
of schemas
+        * @return The name of the created temporary schema file
+        */
+       private String mergeFiles(String[] fileList)
+       {
+               try
+               {
+                       File xsltFile = createXSLTFromFile(mergeFile);
+                       if (xsltFile == null)
+                               xsltFile = createXSLTFromMemory();
+                       Source xslt = new StreamSource(xsltFile);
+                       Transformer transformer = 
TransformerFactory.newInstance()
+                                       .newTransformer(xslt);
+
+                       String sourceName = fileList[0];
+                       File target = null;
+                       for (int i = 1; i < fileList.length; i++)
+                       {
+                               File soureFile = new File(sourceName);
+                               Source source = new StreamSource(soureFile);
+                               // JAXP reads data using the Source interface
+                               target = createTemp(".xml");
+
+                               Result targetResult = new StreamResult(target);
+                               File f = new File(fileList[i]);
+                               String other = "file:///" + 
f.getCanonicalPath();  // required on Win-platforms
+                               other = other.replace('\\', '/');
+
+                               transformer.setParameter("fileTwo", other);
+                               transformer.transform(source, targetResult);
+                               sourceName = target.getAbsolutePath();
                        }
+                       return sourceName;
+
+               } catch (Exception e)
+               {
+                       e.printStackTrace();
+                       return null;
                }
+
        }
-       
+
        /**
         * read database schema to file
         * 
         */
        private void processExport(JetspeedDDLUtil ddlUtil)
        {
-               //TODO: implement
+               // TODO: implement
                ddlUtil.writeDatabaseSchematoFile(this.outputFile);
 
        }
-       
+
        /**
         * read the property file and read what has not yet been defined
         */
@@ -469,6 +669,8 @@
                                user = configuration.getString("user");
                        if (password == null)
                                password = configuration.getString("password");
+                       if (mergeFile == null)
+                               mergeFile = 
configuration.getString("mergeFile");
                        if (!(doImport))
                        {
                                schemaDirectory = 
configuration.getString("schema");
@@ -485,12 +687,9 @@
                                logLevel = configuration.getString("loglevel");
 
                }
-               
+
        }
-       
-       
-       
-       
+
        private static String[] getTokens(String _line)
        {
                if ((_line == null) || (_line.length() == 0))
@@ -539,72 +738,64 @@
                return query.toString();
        }
 
-       
-       
-       
-       
-       
        /**
         * read an xml file describing the basic order of the files to be 
processed
+        * 
         * @param importFileName
         * @return
         * @throws SerializerException
         */
-       
-    private ArrayList readOrderFile(String importFileName)
+
+       private ArrayList readOrderFile(String importFileName)
        {
                XMLObjectReader reader = null;
-               
-        XMLBinding binding = new XMLBinding();
-        binding.setAlias(ArrayList.class, "ProcessOrder");
-        binding.setAlias(JSGroup.class, "File");
 
-               
-        ArrayList snap = null;
+               XMLBinding binding = new XMLBinding();
+               binding.setAlias(ArrayList.class, "ProcessOrder");
+               binding.setAlias(JSGroup.class, "File");
+
+               ArrayList snap = null;
                try
                {
-                   reader = XMLObjectReader.newInstance(new FileInputStream(
-                           importFileName));
+                       reader = XMLObjectReader.newInstance(new 
FileInputStream(
+                                       importFileName));
                } catch (Exception e)
                {
-                   e.printStackTrace();
-                   return null;
+                       e.printStackTrace();
+                       return null;
                }
                try
                {
-                   reader.setBinding(binding);
-                   snap = (ArrayList) reader.read("ProcessOrder",
-                               ArrayList.class);
-               
+                       reader.setBinding(binding);
+                       snap = (ArrayList) reader.read("ProcessOrder", 
ArrayList.class);
+
                } catch (Exception e)
                {
-                   e.printStackTrace();
+                       e.printStackTrace();
                } finally
                {
-                   /** ensure the reader is closed */
-                   try
-                   {
-                       reader.close();
-                   } catch (Exception e1)
-                   {
-                       /**
-                        * don't do anything with this exception - never let 
the bubble
-                        * out of the finally block
-                        */
-                   }
+                       /** ensure the reader is closed */
+                       try
+                       {
+                               reader.close();
+                       } catch (Exception e1)
+                       {
+                               /**
+                                * don't do anything with this exception - 
never let the bubble
+                                * out of the finally block
+                                */
+                       }
                }
-       return snap;
+               return snap;
        }
-       
 
-    
        class LocalFilenameFilter implements FilenameFilter
        {
 
                String exclude = null;
                String sortFile = null;
                String sort = null;
-               
+
                String getSortFile()
                {
                        return sortFile;
@@ -613,7 +804,7 @@
                {
                        this.exclude = exclude;
                        this.sort = sort;
-                       
+
                }
                public boolean accept(File dir, String name)
                {
@@ -626,11 +817,10 @@
                                        sortFile = dir.getAbsolutePath() + "/" 
+ sort;
                                        return false;
                                }
-                       
+
                        return name.endsWith(".xml");
                }
 
        }
 
-       
 }

Modified: 
portals/jetspeed-2/trunk/components/serializer/src/java/org/apache/jetspeed/serializer/JetspeedDDLUtil.java
URL: 
http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/components/serializer/src/java/org/apache/jetspeed/serializer/JetspeedDDLUtil.java?view=diff&rev=492423&r1=492422&r2=492423
==============================================================================
--- 
portals/jetspeed-2/trunk/components/serializer/src/java/org/apache/jetspeed/serializer/JetspeedDDLUtil.java
 (original)
+++ 
portals/jetspeed-2/trunk/components/serializer/src/java/org/apache/jetspeed/serializer/JetspeedDDLUtil.java
 Wed Jan  3 22:31:48 2007
@@ -36,11 +36,10 @@
 import org.apache.ddlutils.io.DataReader;
 import org.apache.ddlutils.io.DataToDatabaseSink;
 import org.apache.ddlutils.io.DatabaseIO;
+import org.apache.ddlutils.model.Column;
 import org.apache.ddlutils.model.Database;
 import org.apache.ddlutils.model.JdbcTypeCategoryEnum;
 import org.apache.ddlutils.model.Table;
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
 
 /**
  * Jetspeed DDLUtil
@@ -53,6 +52,7 @@
  */
 public class JetspeedDDLUtil
 {
+       public static final String DATASOURCE_DATABASENAME = 
"DATABASENAME".intern();
        public static final String DATASOURCE_CLASS = 
"DATASOURCE_CLASS".intern();
        public static final String DATASOURCE_DRIVER = 
"driverClassName".intern();
        public static final String DATASOURCE_URL = "url".intern();
@@ -145,7 +145,9 @@
         */
        protected Database createDatabaseSchemaFromXML(String fileName)
        {
-               return new DatabaseIO().read(fileName);
+               DatabaseIO io = new DatabaseIO();
+               io.setValidateXml(false);
+               return io.read(fileName);
        }
 
        /**
@@ -223,6 +225,8 @@
                                }
                                catch (Exception aEX)
                                {
+                                       System.out.println("Error in ALTER 
DATABASE");
+                                       aEX.printStackTrace();
                                        log.error(aEX);
                                }
                        } else
@@ -235,10 +239,11 @@
 //                                             String s = 
platform.getDropTablesSql(model, true);
 //                                             log.debug(s);
 //                                     }
-                               platform.dropTables(model, true);
-                               
-                               
-                               
+                    if (model == null)
+                    {
+                        model = targetModel;
+                    }
+                    platform.dropTables(model, true);                          
                                }
                                catch (Exception aEX)
                                {
@@ -246,14 +251,30 @@
                                }
                                try
                                {
-                               platform.createTables(targetModel, false, true);
+                                   platform.createTables(model, false, true);
+                    if (this._databaseName.startsWith("oracle"))
+                    {
+                        model = this.readModelFromDatabase(null);
+                        modifyVarBinaryColumn(model, "PA_METADATA_FIELDS", 
"COLUMN_VALUE");
+                        modifyVarBinaryColumn(model, "PD_METADATA_FIELDS", 
"COLUMN_VALUE");
+                        modifyVarBinaryColumn(model, "LANGUAGE", "KEYWORDS");
+                        modifyVarBinaryColumn(model, "PORTLET_CONTENT_TYPE", 
"MODES");
+                        modifyVarBinaryColumn(model, "PARAMETER", 
"PARAMETER_VALUE");
+                        modifyVarBinaryColumn(model, "LOCALIZED_DESCRIPTION", 
"DESCRIPTION");
+                        modifyVarBinaryColumn(model, "LOCALIZED_DISPLAY_NAME", 
"DISPLAY_NAME");
+                        modifyVarBinaryColumn(model, "CUSTOM_PORTLET_MODE", 
"DESCRIPTION");
+                        modifyVarBinaryColumn(model, "CUSTOM_WINDOW_STATE", 
"DESCRIPTION");
+                        modifyVarBinaryColumn(model, "MEDIA_TYPE", 
"DESCRIPTION");
+                        platform.alterTables(model, true);                     
   
+                    }
                                }
                                catch (Exception aEX)
                                {
+                    aEX.printStackTrace();
                                        log.error(aEX);
                                }
                        }
-                       model = this.readModelFromDatabase(null);
+                       // TODO: DST: REMOVE, AINT WORKING IN ORACLE model = 
this.readModelFromDatabase(null);
                } catch (Exception ex)
                {
                        ex.printStackTrace();
@@ -263,6 +284,14 @@
                }
        }
 
+    private void modifyVarBinaryColumn(Database targetModel, String tableName, 
String columnName)
+    {
+        Table table = targetModel.findTable(tableName);
+        Column c = table.findColumn(columnName);
+        c.setType("VARCHAR");        
+        c.setSize("2000");
+        System.out.println("updating column " + c.getName() + " for table " + 
table.getName());
+    }
        /**
         * Alter an existing database from the given model. Data is preserved as
         * much as possible
@@ -386,24 +415,45 @@
                {
                        throw new DatabaseOperationException(ex);
                }
-
-               _databaseName = new 
PlatformUtils().determineDatabaseType(dataSource);
+               String databaseName = null;
+               _databaseName = null;        
+               try
+               {
+                       databaseName = (String) 
parameters.get(DATASOURCE_DATABASENAME);
+                       if (databaseName != null)
+                       {
+                               platform = 
PlatformFactory.createNewPlatformInstance(databaseName);
+                               if (platform != null)
+                                       _databaseName = databaseName;
+                       }
+               } catch (Exception ex)
+               {
+                       log.warn("Exception in trying to establish connection 
to " + databaseName + " : " + ex.getLocalizedMessage());
+                       log.warn(ex);
+               }
                if (_databaseName == null)
                {
-                       throw new DatabaseOperationException(
+                       _databaseName = new 
PlatformUtils().determineDatabaseType(dataSource);
+                       if (_databaseName == null)
+                       {
+                               throw new DatabaseOperationException(
                                        "Could not determine platform from 
datasource, please specify it in the jdbc.properties via the ddlutils.platform 
property");
+                       }
+                       else
+                       {
+                               try
+                               {
+                                       platform = 
PlatformFactory.createNewPlatformInstance(_databaseName);
+                               } catch (Exception ex)
+                               {
+                                       throw new DatabaseOperationException(
+                                       "Could not establish connection to " + 
_databaseName + " : " + ex.getLocalizedMessage(),ex);
+                               }
+                       }
                }
-
 //             com.mysql.jdbc.Driver
                
                writer = new StringWriter();
-               try
-               {
-                       platform = 
PlatformFactory.createNewPlatformInstance(_databaseName);
-               } catch (Exception ex)
-               {
-                       throw new DatabaseOperationException(ex);
-               }
                platform.getSqlBuilder().setWriter(writer);
 //             if 
(platform.getPlatformInfo().isDelimitedIdentifiersSupported())
 //             {
@@ -412,8 +462,9 @@
 
        
                platform.setDataSource(dataSource);
-
+        System.out.println("reading model...");
                model = this.readModelFromDatabase(null);
+        System.out.println("done reading model...");
 /**            
                JdbcModelReader reader = platform.getModelReader();             
                try

Modified: 
portals/jetspeed-2/trunk/components/serializer/src/java/org/apache/jetspeed/serializer/JetspeedSerializerApplication.java
URL: 
http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/components/serializer/src/java/org/apache/jetspeed/serializer/JetspeedSerializerApplication.java?view=diff&rev=492423&r1=492422&r2=492423
==============================================================================
--- 
portals/jetspeed-2/trunk/components/serializer/src/java/org/apache/jetspeed/serializer/JetspeedSerializerApplication.java
 (original)
+++ 
portals/jetspeed-2/trunk/components/serializer/src/java/org/apache/jetspeed/serializer/JetspeedSerializerApplication.java
 Wed Jan  3 22:31:48 2007
@@ -15,6 +15,8 @@
  */
 package org.apache.jetspeed.serializer;
 
+import java.io.File;
+import java.io.FilenameFilter;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Map;
@@ -28,15 +30,16 @@
  * Jetspeed Serializer Application
  * 
  * invoke with mandatory 
- * <p>-E filename or -I filename to denote the export or the import file
- *   
+ * <p>-E filename or -I filename to denote the export or the import file</p>
+ * <p>-I filename | directory, if a directory will process all XML files of 
pattern "*seed.xml"</p>
+ * 
  * invoke with (optional) parameters as
- * <p>-p propertyFilename : overwrite the default filename defined in 
System.getProperty JetSpeed.Serializer.Configuration 
- * <p>-a ApplicationPath : overwrite the default ./ or ApplicationPath 
property in properties file)
- * <p>-b bootPath : directory to Spring boot files,   overwrite the default 
assembly/boot/ or bootPath  property in properties file)  
- * <p>-c configPath : directory to Spring config files,   overwrite the 
default assembly/ or configPath property in properties file)
+ * <p>-p propertyFilename : overwrite the default filename defined in 
System.getProperty JetSpeed.Serializer.Configuration</p> 
+ * <p>-a ApplicationPath : overwrite the default ./ or ApplicationPath 
property in properties file)</p>
+ * <p>-b bootPath : directory to Spring boot files,   overwrite the default 
assembly/boot/ or bootPath  property in properties file)</p>  
+ * <p>-c configPath : directory to Spring config files,   overwrite the 
default assembly/ or configPath property in properties file)</p>
  * 
- * <p>-o optionstring : overwrite defrault "ALL,REPLACE"
+ * <p>-o optionstring : overwrite defrault "ALL,REPLACE"</p>
  * <p>optionstring: 
  *      ALL - extract/import all 
  *      USER - extract/import users
@@ -45,7 +48,7 @@
  *      PROFILE = extract/import profile settings (for export requires USER) 
  *      NOOVERWRITE = don't overwrite existing file (for export)
  *      BACKUP = backup before process
-
+ * </p>
  * <p>
  * -dc driverClass, for example com.mysql.jdbc.Driver
  * </p>
@@ -75,8 +78,7 @@
     {
         String propertyFileName = null;
         
-        String fileName = null; // XML filename - mandatory on command line
-        
+        String fileName = null; // XML filename - mandatory on command line    
    
         String applicationPath = null; // 
configuration.getProperties("applicationPath");
         String bootConfigFiles = null; // 
configuration.getProperties("bootConfigFiles");
         String configFiles = null; // 
configuration.getProperties("configFiles");
@@ -104,28 +106,64 @@
 
         
         // Parse all the command-line arguments
-        for(int n = 0; n < args.length; n++) 
+        for (int n = 0; n < args.length; n++)
         {
-          if (args[n].equals("-p")) propertyFileName = args[++n];
-          else if (args[n].equals("-a")) applicationPath = args[++n];
-          else if (args[n].equals("-b")) bootConfigFiles = args[++n];
-          else if (args[n].equals("-c")) configFiles = args[++n];
-          else if (args[n].equals("-E")) { doExport = true; fileName = 
args[++n];}
-          else if (args[n].equals("-I")) { doImport = true; fileName = 
args[++n];}
-          else if (args[n].equals("-N")) name = args[++n];
-          else if (args[n].equals("-l")) logLevel = args[++n];
-            else if (args[n].equals("-O")) options = args[++n];
-               else if (args[n].equals("-dc"))
-                       driverClass = args[++n];
-               else if (args[n].equals("-ds"))
-                       url = args[++n];
-               else if (args[n].equals("-du"))
-                       user = args[++n];
-               else if (args[n].equals("-dp"))
-                       password = args[++n];
-          else throw new IllegalArgumentException("Unknown argument: " + 
args[n]);
+            if (args[n].equals("-p"))
+                propertyFileName = args[++n];
+            else if (args[n].equals("-a"))
+                applicationPath = args[++n];
+            else if (args[n].equals("-b"))
+                bootConfigFiles = args[++n];
+            else if (args[n].equals("-c"))
+                configFiles = args[++n];
+            else if (args[n].equals("-E"))
+            {
+                doExport = true;
+                fileName = args[++n];
+            } 
+            else if (args[n].equals("-I"))
+            {
+                doImport = true;
+                fileName = args[++n];
+            } 
+            else if (args[n].equals("-N"))
+            {
+                name = args[++n];
+            }
+            else if (args[n].equals("-l"))
+                logLevel = args[++n];
+            else if (args[n].equals("-O"))
+                options = args[++n];
+            else if (args[n].equals("-dc"))
+                driverClass = args[++n];
+            else if (args[n].equals("-ds"))
+                url = args[++n];
+            else if (args[n].equals("-du"))
+            {
+                if (((n + 1) >= args.length) || args[n + 1].startsWith("-d"))
+                {
+                    user = "";
+                } else
+                {
+                    user = args[++n];
+                }
+            } 
+            else if (args[n].equals("-dp"))
+            {
+                if (((n + 1) >= args.length) || args[n + 1].startsWith("-d"))
+                {
+                    password = "";
+                } else
+                {
+                    password = args[++n];
+                }
+            } 
+            else
+            {
+                throw new IllegalArgumentException("Unknown argument: "
+                        + args[n]);
+            }
         }
-
         
         /** The only required argument is the filename for either export or 
import*/
         if ((!doImport) && (!doExport))
@@ -158,11 +196,16 @@
             {
                 /** only read what was not defined on the command line */
             
-                if (applicationPath == null) applicationPath = 
configuration.getString("applicationPath");
-                if (bootConfigFiles == null) applicationPath = 
configuration.getString("bootConfigFiles");
-                if (configFiles == null) applicationPath = 
configuration.getString("configFiles");
-                if (options == null) applicationPath = 
configuration.getString("options");
-                if (defaultIndent == null) applicationPath = 
configuration.getString("defaultIndent");
+                if (applicationPath == null) 
+                    applicationPath = 
configuration.getString("applicationPath");
+                if (bootConfigFiles == null)  
+                    bootConfigFiles = 
configuration.getString("bootConfigFiles");
+                if (configFiles == null) 
+                    configFiles = configuration.getString("configFiles");
+                if (options == null) 
+                    options = configuration.getString("options");
+                if (defaultIndent == null) 
+                    defaultIndent = configuration.getString("defaultIndent");
 
                        if (driverClass == null)
                                driverClass = 
configuration.getString("driverClass");
@@ -180,10 +223,14 @@
         }
 
         // if we still miss some settings, use hardoced defaults
-        if (applicationPath == null) applicationPath = "./";
-        if (bootConfigFiles == null) bootConfigFiles = "assembly/boot/";
-        if (configFiles == null) configFiles = "assembly/";
-               if (logLevel == null) logLevel = "ERROR";
+        if (applicationPath == null) 
+            applicationPath = "./";
+        if (bootConfigFiles == null) 
+            bootConfigFiles = "assembly/boot/";
+        if (configFiles == null) 
+            configFiles = "assembly/";
+               if (logLevel == null) 
+            logLevel = "ERROR";
       
 
         bootConfigFiles = bootConfigFiles + "*.xml";
@@ -297,44 +344,123 @@
             e.printStackTrace();
             System.exit(1);
         }
-            
         System.out.println("starter framework established " + starter);
-               
-        try
+        String[] importList = null;
+
+        if (doImport)
+               importList = parseFiles(fileName);
+       
+        if ((doImport) && (importList != null) && (importList.length > 0))
         {
-            serializer = new 
JetspeedSerializerImpl(starter.getComponentManager());     
-            if (doExport)
-                serializer.exportData(name, fileName, settings);
-            else
-                serializer.importData(fileName, settings);
-            
-        } 
-        catch (Exception e)
+                       for (int i = 0; i < importList.length; i++)
+                       {
+                               try
+                           {
+                               System.out.println("processing import  " + 
importList[i]);
+                               serializer = new 
JetspeedSerializerImpl(starter.getComponentManager());
+                               serializer.importData(importList[i], settings);
+                               System.out.println("processing import  " + 
importList[i] + " done");
+                               
+                           } 
+                           catch (Exception e)
+                           {
+                               System.err.println("Failed to process XML 
import for " + importList[i] + ":" + e);
+                               e.printStackTrace();
+                           }
+                           finally
+                           {
+                               if (serializer != null)
+                                   serializer.closeUp();
+                           }
+                        }
+        }
+        if (doExport)
         {
-            System.err.println("Failed to process XML " + 
(doExport?"export":"import")+ ":" + e);
-            e.printStackTrace();
+               try
+               {
+                   serializer = new 
JetspeedSerializerImpl(starter.getComponentManager());
+                       serializer.exportData(name, fileName, settings);
+               } 
+               catch (Exception e)
+               {
+                   System.err.println("Failed to process XML export of " + 
fileName + ": " + e);
+                   e.printStackTrace();
+               }
+               finally
+               {
+                   if (serializer != null)
+                       serializer.closeUp();
+               }
+
         }
-        finally
+        try
         {
-            if (serializer != null)
-                serializer.closeUp();
-            try
-            {
-               starter.tearDown();
-               logger.setLevel(level);;
-            }
-            catch (Exception e1)
-            {
-                System.out.println("starter framework teardown caused 
exception "  + e1.getLocalizedMessage());
-                e1.printStackTrace();
-                
-            }            
-            System.out.println("DONE performing " + 
(doExport?"export":"import")+ " with " + fileName);
+           starter.tearDown();
+           logger.setLevel(level);;
         }
-
+        catch (Exception e1)
+        {
+            System.out.println("starter framework teardown caused exception "  
+ e1.getLocalizedMessage());
+            e1.printStackTrace();
+            
+        }            
+        System.out.println("DONE performing " + (doExport?"export":"import")+ 
" with " + fileName);
     }
+    
         
        
+       /**
+        * process provided filename or directory name
+        * 
+        * @return one or more files to be processed
+        */
+       static private String[] parseFiles(String schemaDirectory)
+       {
+               String[] fileList = null;
+               try
+               {
+                       File dir = new File(schemaDirectory);
+                       if (!(dir.exists()))
+            {
+                               return fileList;
+            }
+                       if (!(dir.isDirectory()))
+                       {
+                               fileList = new String[1];
+                               fileList[0] = schemaDirectory;
+                               return fileList;
+                       }
+                       //      Handling a directory
+                       File[] files = dir.listFiles(
+                                   new FilenameFilter() {
+                                       public boolean accept(File dir, String 
name) 
+                                                               {String n = 
name.toLowerCase();
+                                                                       return 
n.endsWith("seed.xml");
+                                       }
+                                   });
+                       if (files == null)
+                               return fileList;
+
+                       fileList = new String[files.length];
+                       for (int i = 0; i < files.length; i++)
+            {
+                               fileList[i] = files[i].getAbsolutePath();
+            }
+                       return fileList;
+               } 
+        catch (Exception e)
+               {
+                       e.printStackTrace(); 
+                       throw new IllegalArgumentException(
+                                       "Processing the schema-directory " + 
schemaDirectory
+                                                       + " caused exception "
+                                                       + 
e.getLocalizedMessage());
+               }
+
+               
+       }
+
+    
         private static  String[] getTokens(String _line)
         {
             if ((_line == null) || (_line.length() == 0))
@@ -351,4 +477,5 @@
             return s;
         }
 
+        
 }

Modified: 
portals/jetspeed-2/trunk/components/serializer/src/java/org/apache/jetspeed/serializer/JetspeedSerializerImpl.java
URL: 
http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/components/serializer/src/java/org/apache/jetspeed/serializer/JetspeedSerializerImpl.java?view=diff&rev=492423&r1=492422&r2=492423
==============================================================================
--- 
portals/jetspeed-2/trunk/components/serializer/src/java/org/apache/jetspeed/serializer/JetspeedSerializerImpl.java
 (original)
+++ 
portals/jetspeed-2/trunk/components/serializer/src/java/org/apache/jetspeed/serializer/JetspeedSerializerImpl.java
 Wed Jan  3 22:31:48 2007
@@ -2241,7 +2241,8 @@
      */
     private void logMe(String text)
     {
-        if (log.isDebugEnabled()) log.debug(text);
+        if (log.isDebugEnabled()) 
+            log.debug(text);
     }
 
     /**



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to