portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tay...@apache.org
Subject svn commit: r484723 - in /portals/jetspeed-2/trunk/components/serializer: ./ src/java/org/apache/jetspeed/serializer/ src/java/org/apache/jetspeed/serializer/objects/
Date Fri, 08 Dec 2006 20:02:59 GMT
Author: taylor
Date: Fri Dec  8 12:02:58 2006
New Revision: 484723

URL: http://svn.apache.org/viewvc?view=rev&rev=484723
Log:
https://issues.apache.org/jira/browse/JS2-461
Serializer component
This commit covers all security and admin tables, both XML import and export
Remaining tables to serialize: prefs, registry
Contribution from Hajo Birthelmer (hajo@bluesunrise.com)

Added:
    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/objects/JSPWAttributes.java
    portals/jetspeed-2/trunk/components/serializer/src/java/org/apache/jetspeed/serializer/objects/JSProcessOrder.java
Modified:
    portals/jetspeed-2/trunk/components/serializer/maven.xml
    portals/jetspeed-2/trunk/components/serializer/pom.xml
    portals/jetspeed-2/trunk/components/serializer/project.xml
    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/components/serializer/src/java/org/apache/jetspeed/serializer/objects/JSUser.java

Modified: portals/jetspeed-2/trunk/components/serializer/maven.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/components/serializer/maven.xml?view=diff&rev=484723&r1=484722&r2=484723
==============================================================================
--- portals/jetspeed-2/trunk/components/serializer/maven.xml (original)
+++ portals/jetspeed-2/trunk/components/serializer/maven.xml Fri Dec  8 12:02:58 2006
@@ -49,7 +49,7 @@
             <pathelement path="${maven.build.dest}"/>
             <pathelement path="${org.apache.jetspeed.production.jdbc.drivers.path}"/>                          
           </classpath>
-            <arg line="-E export.xml -b target/assembly/boot/ -c target/assembly/"/>  
+            <arg line="-E c:/temp/export100.xml -b target/assembly/boot/ -c target/assembly/"/>  
             <sysproperty key="org.apache.jetspeed.database.url" value="${org.apache.jetspeed.production.database.url}"/>
             <sysproperty key="org.apache.jetspeed.database.driver" value="${org.apache.jetspeed.production.database.driver}"/>
             <sysproperty key="org.apache.jetspeed.database.user" value="${org.apache.jetspeed.production.database.user}"/>
@@ -59,7 +59,57 @@
 	<preGoal name='export'>
         <attainGoal name="java:compile" />		
 	</preGoal>				
-    <goal name='test2'>
+    <goal name='import'>
+        <copy todir='${maven.build.dir}/classes'
+          file="../../etc/log4j/log4j.properties"/>
+        <copy todir='${maven.build.dir}/classes'>
+          <fileset dir="../../etc/db-ojb/"/>
+        </copy>                      
+        <attainGoal name='copyAssemblies'/>
+        <java classname="org.apache.jetspeed.serializer.JetspeedSerializerApplication" fork="yes">
+          <classpath>
+            <path refid="maven.dependency.classpath"/>
+            <pathelement path="${maven.build.dest}"/>
+            <pathelement path="${org.apache.jetspeed.production.jdbc.drivers.path}"/>                          
+          </classpath>
+            <arg line="-I c:/temp/export100.xml -b target/assembly/boot/ -c target/assembly/"/>  
+            <sysproperty key="org.apache.jetspeed.database.url" value="${org.apache.jetspeed.production.database.url}"/>
+            <sysproperty key="org.apache.jetspeed.database.driver" value="${org.apache.jetspeed.production.database.driver}"/>
+            <sysproperty key="org.apache.jetspeed.database.user" value="${org.apache.jetspeed.production.database.user}"/>
+            <sysproperty key="org.apache.jetspeed.database.password" value="${org.apache.jetspeed.production.database.password}"/>            
+        </java>
+    </goal>
+	<preGoal name='import'>
+        <attainGoal name="java:compile" />		
+	</preGoal>		   <goal name='test2'>
         <echo message="${org.apache.jetspeed.production.jdbc.drivers.path}"/>
     </goal>
+	
+	<goal name='createDB'>
+	        <copy todir='${maven.build.dir}/classes'
+	          file="../../etc/log4j/log4j.properties"/>
+	        <copy todir='${maven.build.dir}/schema'>
+	          <fileset dir="../../etc/schema/"/>
+	        </copy>                      
+	        <java classname="org.apache.jetspeed.serializer.JetspeedDDLApplication" fork="yes">
+	          <classpath>
+	            <path refid="maven.dependency.classpath"/>
+	            <pathelement path="${maven.build.dest}"/>
+	            <pathelement path="${org.apache.jetspeed.production.jdbc.drivers.path}"/>                          
+	          </classpath> 
+	            <arg line="-I target/schema -R"/>  
+	            <sysproperty key="org.apache.jetspeed.database.url" value="${org.apache.jetspeed.production.database.url}"/>
+	            <sysproperty key="org.apache.jetspeed.database.driver" value="${org.apache.jetspeed.production.database.driver}"/>
+	            <sysproperty key="org.apache.jetspeed.database.user" value="${org.apache.jetspeed.production.database.user}"/>
+	            <sysproperty key="org.apache.jetspeed.database.password" value="${org.apache.jetspeed.production.database.password}"/>            
+	        </java>
+	    </goal>
+		<preGoal name='export'>
+	        <attainGoal name="java:compile" />		
+		</preGoal>				
+	    <goal name='test2'>
+	        <echo message="${org.apache.jetspeed.production.jdbc.drivers.path}"/>
+	    </goal>
+		
+	
 </project>

Modified: portals/jetspeed-2/trunk/components/serializer/pom.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/components/serializer/pom.xml?view=diff&rev=484723&r1=484722&r2=484723
==============================================================================
--- portals/jetspeed-2/trunk/components/serializer/pom.xml (original)
+++ portals/jetspeed-2/trunk/components/serializer/pom.xml Fri Dec  8 12:02:58 2006
@@ -63,6 +63,11 @@
             <version>4.0.2</version>
         </dependency>
         <dependency>
+            <groupId>DdlUtils</groupId>
+            <artifactId>DdlUtils</artifactId>
+            <version>1.0-RC1-PATCHED</version>
+        </dependency>
+        <dependency>
             <groupId>${pom.groupId}</groupId>
             <artifactId>jetspeed-rdbms</artifactId>
         </dependency>

Modified: portals/jetspeed-2/trunk/components/serializer/project.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/components/serializer/project.xml?view=diff&rev=484723&r1=484722&r2=484723
==============================================================================
--- portals/jetspeed-2/trunk/components/serializer/project.xml (original)
+++ portals/jetspeed-2/trunk/components/serializer/project.xml Fri Dec  8 12:02:58 2006
@@ -17,7 +17,7 @@
     $Id: project.xml 355198 2005-12-08 20:44:03Z rogerrut $
 -->
 <project>
-<extend>${basedir}/../../jetspeed-components.xml</extend>
+<extend>${basedir}/../../core-build.xml</extend>
   <pomVersion>3</pomVersion>
   <id>jetspeed-serializer</id>
   <name>Jetspeed-2 Serializer</name>
@@ -35,16 +35,10 @@
         </developerConnection>
     <url>http://svn.apache.org/viewcvs.cgi/portals/jetspeed-2/trunk/components/serializer/</url>
   </repository>
-
+  
+  
   <dependencies>
   	<dependency>
-      <id>javolution</id>
-      <version>4.0.2</version>
-      <properties>
-         <war.bundle>true</war.bundle>
-      </properties>          
-    </dependency>	  
-  	<dependency>
       <id>org.apache.portals.jetspeed-2:jetspeed-commons</id>
       <version>${jetspeed.version}</version>
       <properties>
@@ -52,13 +46,6 @@
       </properties>                    
     </dependency>
   	<dependency>
-      <id>org.apache.portals.jetspeed-2:jetspeed-portal</id>
-      <version>${jetspeed.version}</version>
-      <properties>
-         <war.bundle>true</war.bundle>
-      </properties>                    
-    </dependency>            
-  	<dependency>
       <id>org.apache.portals.jetspeed-2:jetspeed-cm</id>
       <version>${jetspeed.version}</version>
       <properties>
@@ -87,5 +74,6 @@
       </properties>                            
     </dependency>            
   </dependencies>
+  
   
 </project>

Added: 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=auto&rev=484723
==============================================================================
--- portals/jetspeed-2/trunk/components/serializer/src/java/org/apache/jetspeed/serializer/JetspeedDDLApplication.java (added)
+++ portals/jetspeed-2/trunk/components/serializer/src/java/org/apache/jetspeed/serializer/JetspeedDDLApplication.java Fri Dec  8 12:02:58 2006
@@ -0,0 +1,636 @@
+/*
+ * Copyright 2000-2004 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.jetspeed.serializer;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FilenameFilter;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.StringTokenizer;
+
+import javolution.xml.XMLBinding;
+import javolution.xml.XMLObjectReader;
+
+import org.apache.commons.configuration.PropertiesConfiguration;
+import org.apache.ddlutils.model.Database;
+import org.apache.ddlutils.model.Table;
+import org.apache.jetspeed.serializer.objects.JSGroup;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+/**
+ * Jetspeed Serializer DDL- Application
+ * 
+ * invoke with mandatory either
+ * <p>
+ * -I directory or filename of schema files for input, if directory all xml
+ * files will be processed
+ * </p>
+ * and/or
+ * <p>
+ * -O schema file for output log of current database
+ * </p>
+ * and (if -I denotes a directory:)
+ * <p>
+ * -x if directory list provided for input schemas this pattern is excluded
+ * </p>
+ * <p>
+ * -s name of the order file (if schema directory)
+ * </p>
+ * 
+ * <p>
+ * note that - if -I and -O are specified, the output file will contain the
+ * UPDATED database
+ * </p>
+ * invoke with (optional) parameters
+ * <p>
+ * -P propertyFileName, for settings
+ * <p>
+ * -R (flag) replace : overwrites default "UPDATE" and clears out the database
+ * before processing (ignored with -O option above)
+ * </p>
+ * 
+ * <p>
+ * -dc driverClass, for example com.mysql.jdbc.Driver
+ * </p>
+ * <p>
+ * -ds url, ruls according to the driver used, URL needs to point to the correct
+ * database
+ * </p>
+ * <p>
+ * -du user, user with create/drop etc. rights on the database
+ * </p>
+ * <p>
+ * -dp password
+ * </p>
+ * <p>
+ * -l log4j-level, ERROR (default), WARN, INFO 
+ * </p>
+ * 
+ * @author <a href="mailto:hajo@bluesunrise.com">Hajo Birthelmer</a>
+ * @version $Id: $
+ */
+public class JetspeedDDLApplication
+{
+	public static final String JNDI_DS_NAME = "jetspeed";
+
+	String propertyFileName = null;
+	String exludeFileName = null;
+	String orderFileName = 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
+	String outputFile = null; // if specified the database schema will be
+								// exported to that file
+	boolean overwrite = false; // default, do not overwrite the database
+								// (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[] filesToProcess = null;
+
+	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 (driverClass == null)
+			driverClass = System.getProperty(
+					"org.apache.jetspeed.database.driverClass",
+					"com.mysql.jdbc.Driver");
+		if (url == null)
+			url = System.getProperty("org.apache.jetspeed.database.url",
+					"jdbc:mysql://localhost/j2test");
+		if (user == null)
+			user = System.getProperty("org.apache.jetspeed.database.user",
+					"user");
+		if (password == null)
+			password = System.getProperty(
+					"org.apache.jetspeed.database.password", "password");
+
+		if (driverClass == null)
+			throw new IllegalArgumentException(
+					"Can't proceed without a valid driver");
+		if (url == null)
+			throw new IllegalArgumentException(
+					"Can't proceed without a valid url to the target database");
+		if (user == null)
+			throw new IllegalArgumentException(
+					"Can't proceed without a valid database user");
+		return;
+	}
+	
+	/**
+	 * parse arguments for process instructions, order and exclude files as well as 
+	 * optional database arguments 
+	 *
+	 */
+	private void parseArguments()
+	{
+		// Parse all the command-Oine arguments
+		for (int n = 0; n < args.length; n++)
+		{
+			if (args[n].equals("-I"))
+			{
+				doImport = true;
+				schemaDirectory = args[++n];
+			} else if (args[n].equals("-O"))
+			{
+				doExport = true;
+				outputFile = args[++n];
+			} else if (args[n].equals("-s"))
+			{
+				orderFileName = args[++n];
+			} else if (args[n].equals("-x"))
+			{
+				exludeFileName = args[++n];
+			} else if (args[n].equals("-R"))
+				overwrite = true;
+			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 if (args[n].equals("-P"))
+				propertyFileName = args[++n];
+           else if (args[n].equals("-l")) logLevel = args[++n];
+
+			else
+				throw new IllegalArgumentException("Unknown argument: "
+						+ args[n]);
+		}
+			
+	}
+
+	/**
+	 * process provided filename or directory name
+	 * 
+	 * @return one or more files to be processed
+	 */
+	private String[] parseFiles()
+	{
+		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
+			LocalFilenameFilter filter = new LocalFilenameFilter(exludeFileName,orderFileName);
+			File[] files = dir.listFiles(filter);
+			if (files == null)
+				return fileList;
+
+			fileList = new String[files.length];
+			String sortorderFile = filter.getSortFile();
+			if (sortorderFile == null)
+			{
+				for (int i = 0; i < files.length; i++)
+					fileList[i] = files[i].getAbsolutePath();
+				return fileList;
+			}
+			try
+			{
+				ArrayList list = readOrderFile(sortorderFile);
+				fileList = new String[files.length];
+				if ((list == null) || (list.size() == 0))
+				{
+					for (int i = 0; i < files.length; i++)
+						fileList[i] = files[i].getAbsolutePath();
+					return fileList;
+				}
+				String[] tempList = new String[files.length];
+				for (int i = 0; i < files.length; i++)
+					tempList[i] = files[i].getName();
+				Iterator _it = list.iterator();
+				int j = 0;
+				while (_it.hasNext())
+				{
+					String filename = null;
+					try
+					{
+						filename= ((JSGroup)_it.next()).getName();
+					}
+					catch (Exception eeee) {}
+					if (filename != null)
+					{
+						for (int i = 0; i < files.length; i++)
+						{
+							if (filename.equalsIgnoreCase(tempList[i]))
+							{
+								fileList[j++] = files[i].getAbsolutePath();
+								tempList[i] = null;
+							}
+						}	
+					}
+				}
+				for (int i = 0; i < files.length; i++)
+				{
+					if (tempList[i] != null)
+						fileList[j++] = files[i].getAbsolutePath();
+				}
+				return fileList;
+			}
+			catch (Exception eee)
+			{
+				eee.printStackTrace();
+				return null;
+			}
+
+		} catch (Exception e)
+		{
+			e.printStackTrace(); 
+			throw new IllegalArgumentException(
+					"Processing the schema-directory " + schemaDirectory
+							+ " caused exception "
+							+ e.getLocalizedMessage());
+		}
+
+		
+	}
+	
+	/**
+	 * setup environment by processing all arguments and call 
+	 * requested process routine
+	 * @param arguments
+	 * @throws Exception
+	 */
+	private void processArguments(String[] arguments) throws Exception
+	{
+		this.args = arguments;
+		if (args == null)
+			throw new IllegalArgumentException(
+					"Either a schema directory, a schema file or an output filename have to be defined (-D followed by a driectory, -I or -O  followed by the filename");
+
+		parseArguments();
+
+		processPropertyFile();
+
+		checkDBSettings();
+		
+
+		/**
+		 * The only required argument is the filename for either export or
+		 * import
+		 */
+		if ((!doImport) && (!doExport))
+			throw new IllegalArgumentException(
+					"Either a schema directory, a schema file or an output filename have to be defined (-I or -O  followed by the directory-/filename");
+
+		if (doImport)
+		{
+			filesToProcess = parseFiles();
+			if (filesToProcess == null)
+				return;
+		}
+
+		/** create the instruction map */
+		JetspeedDDLUtil ddlUtil = null;
+
+		HashMap context = new HashMap();
+
+		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");
+		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
+					logger.setLevel(Level.ERROR);
+		
+		try
+		{
+			ddlUtil = new JetspeedDDLUtil();
+			ddlUtil.startUp();
+			ddlUtil.init(context);
+		} catch (Exception e)
+		{
+			System.err.println("Failed to initialize Utility!!!!!");
+			e.printStackTrace();
+			System.exit(-1);
+		}
+		try
+		{
+			if (doImport) processImport(ddlUtil);
+			if (doExport) processExport(ddlUtil);
+		} catch (Exception e)
+		{
+			System.err.println("Failed to process XML "
+					+ (doExport ? "export" : "import") + ":" + e);
+			e.printStackTrace();
+		} finally
+		{
+			try
+			{
+				logger.setLevel(level);
+				if (ddlUtil != null)
+					ddlUtil.tearDown();
+			} catch (Exception e1)
+			{
+				System.out
+						.println("starter framework teardown caused exception "
+								+ e1.getLocalizedMessage());
+				e1.printStackTrace();
+
+			}
+		}
+
+		
+	}
+
+	/**
+	 * create/alter database 
+	 * 
+	 * @param ddlUtil
+	 */
+	private void processImport(JetspeedDDLUtil ddlUtil)
+	{
+		for (int i = 0; i < filesToProcess.length; i++)
+		{
+			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...
+			}
+		}
+	}
+	
+	/**
+	 * read database schema to file
+	 * 
+	 */
+	private void processExport(JetspeedDDLUtil ddlUtil)
+	{
+		//TODO: implement
+		ddlUtil.writeDatabaseSchematoFile(this.outputFile);
+
+	}
+	
+	/**
+	 * read the property file and read what has not yet been defined
+	 */
+	private void processPropertyFile()
+	{
+		/** get system property definition */
+		if (propertyFileName == null)
+			propertyFileName = System.getProperty(
+					"org.apache.jetspeed.xml.ddlUtil.configuration", null);
+
+		if (propertyFileName == null)
+			return;
+		try
+		{
+			configuration = new PropertiesConfiguration(propertyFileName);
+		} catch (Exception e)
+		{
+			e.printStackTrace();
+			return;
+		}
+		if (configuration != null)
+		{
+			/** only read what was not defined on the command line */
+
+			if (driverClass == null)
+				driverClass = configuration.getString("driverClass");
+			if (url == null)
+				url = configuration.getString("url");
+			if (user == null)
+				user = configuration.getString("user");
+			if (password == null)
+				password = configuration.getString("password");
+			if (!(doImport))
+			{
+				schemaDirectory = configuration.getString("schema");
+				if (schemaDirectory != null)
+					doImport = true;
+			}
+			if (!(doExport))
+			{
+				outputFile = configuration.getString("outputFile");
+				if (outputFile != null)
+					doExport = true;
+			}
+			if (logLevel == null)
+				logLevel = configuration.getString("loglevel");
+
+		}
+		
+	}
+	
+	
+	
+	
+	private static String[] getTokens(String _line)
+	{
+		if ((_line == null) || (_line.length() == 0))
+			return null;
+
+		StringTokenizer st = new StringTokenizer(_line, ",");
+		ArrayList list = new ArrayList();
+
+		while (st.hasMoreTokens())
+			list.add(st.nextToken());
+		String[] s = new String[list.size()];
+		for (int i = 0; i < list.size(); i++)
+			s[i] = (String) list.get(i);
+		return s;
+	}
+
+	public List getRows(JetspeedDDLUtil ddlUtil, String tableName)
+	{
+		Table table = ddlUtil.getModel().findTable(tableName,
+				ddlUtil.getPlatform().isDelimitedIdentifierModeOn());
+
+		return ddlUtil.getPlatform().fetch(ddlUtil.getModel(),
+				getSelectQueryForAllString(ddlUtil, table), new Table[]
+				{table});
+	}
+
+	public String getSelectQueryForAllString(JetspeedDDLUtil ddlUtil,
+			Table table)
+	{
+
+		StringBuffer query = new StringBuffer();
+
+		query.append("SELECT * FROM ");
+		if (ddlUtil.getPlatform().isDelimitedIdentifierModeOn())
+		{
+			query.append(ddlUtil.getPlatform().getPlatformInfo()
+					.getDelimiterToken());
+		}
+		query.append(table.getName());
+		if (ddlUtil.getPlatform().isDelimitedIdentifierModeOn())
+		{
+			query.append(ddlUtil.getPlatform().getPlatformInfo()
+					.getDelimiterToken());
+		}
+		System.out.println(query.toString());
+		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)
+	{
+		XMLObjectReader reader = 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));
+		} catch (Exception e)
+		{
+		    e.printStackTrace();
+		    return null;
+		}
+		try
+		{
+		    reader.setBinding(binding);
+		    snap = (ArrayList) reader.read("ProcessOrder",
+		    		ArrayList.class);
+		
+		} catch (Exception e)
+		{
+		    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
+		         */
+		    }
+		}
+	return snap;
+	}
+	
+
+    
+	class LocalFilenameFilter implements FilenameFilter
+	{
+
+		String exclude = null;
+		String sortFile = null;
+		String sort = null;
+		
+		String getSortFile()
+		{
+			return sortFile;
+		}
+		LocalFilenameFilter(String exclude, String sort)
+		{
+			this.exclude = exclude;
+			this.sort = sort;
+			
+		}
+		public boolean accept(File dir, String name)
+		{
+			if (exclude != null)
+				if (name.equalsIgnoreCase(exclude))
+					return false;
+			if (sort != null)
+				if (name.equalsIgnoreCase(sort))
+				{
+					sortFile = dir.getAbsolutePath() + "/" + sort;
+					return false;
+				}
+			
+			return name.endsWith(".xml");
+		}
+
+	}
+
+	
+}

Added: 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=auto&rev=484723
==============================================================================
--- portals/jetspeed-2/trunk/components/serializer/src/java/org/apache/jetspeed/serializer/JetspeedDDLUtil.java (added)
+++ portals/jetspeed-2/trunk/components/serializer/src/java/org/apache/jetspeed/serializer/JetspeedDDLUtil.java Fri Dec  8 12:02:58 2006
@@ -0,0 +1,546 @@
+/*
+ * Copyright 2000-2004 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.jetspeed.serializer;
+
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.sql.DataSource;
+
+import org.apache.commons.beanutils.BeanUtils;
+import org.apache.commons.beanutils.DynaBean;
+import org.apache.commons.beanutils.DynaProperty;
+import org.apache.commons.dbcp.BasicDataSource;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.ddlutils.DatabaseOperationException;
+import org.apache.ddlutils.Platform;
+import org.apache.ddlutils.PlatformFactory;
+import org.apache.ddlutils.PlatformUtils;
+import org.apache.ddlutils.io.DataReader;
+import org.apache.ddlutils.io.DataToDatabaseSink;
+import org.apache.ddlutils.io.DatabaseIO;
+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
+ * <p>
+ * The Jetspeed DDL Utility is capabale of extracting existing schema
+ * information as well as recreating databases.
+ * 
+ * @author <a href="mailto:hajo@bluesunrise.com">Hajo Birthelmer</a>
+ * @version $Id: $
+ */
+public class JetspeedDDLUtil
+{
+	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();
+	public static final String DATASOURCE_USERNAME = "username".intern();
+	public static final String DATASOURCE_PASSWORD = "password".intern();
+
+	
+    /** Logger */
+    private static final Log log = LogFactory.getLog(JetspeedDDLUtil.class);
+
+	JdbcTypeCategoryEnum temEnum = null;
+	
+	Map parameters;
+
+	PlatformUtils utils;
+
+	StringWriter writer;
+
+	private Platform platform;
+
+	/** The data source to test against. */
+	private DataSource dataSource;
+	/** The database name. */
+	private String _databaseName;
+	/** The database model. */
+	private Database model;
+
+	private boolean connected = false;
+
+	public JetspeedDDLUtil()
+	{
+
+	}
+
+	public void startUp()
+	{
+
+	}
+
+	public void tearDown()
+	{
+		if (connected)
+		{
+			platform = null;
+			// todo: closeup
+		}
+	}
+
+	/**
+	 * Tries to determine whether a the jdbc driver and connection url re
+	 * supported.
+	 * 
+	 * @param driverName
+	 *            The fully qualified name of the JDBC driver
+	 * @param jdbcConnectionUrl
+	 *            The connection url
+	 * @return True if this driver/url is supported
+	 */
+	public boolean isDatabaseSupported(String driverName,
+			String jdbcConnectionUrl)
+	{
+		if (utils.determineDatabaseType(driverName, jdbcConnectionUrl) != null)
+			return true;
+		else
+			return false;
+
+	}
+
+	
+
+	/**
+	 * Parses the database defined in the given XML file and creates a database
+	 * schema (model) object
+	 * 
+	 * @param fileName 
+	 */
+	public void writeDatabaseSchematoFile(String fileName)
+	{
+		new DatabaseIO().write(model, fileName);
+	}
+
+	
+	/**
+	 * Parses the database defined in the given XML file and creates a database
+	 * schema (model) object
+	 * 
+	 * @param dbDef
+	 *            The database XML definition
+	 * @return The database model
+	 */
+	protected Database createDatabaseSchemaFromXML(String fileName)
+	{
+		return new DatabaseIO().read(fileName);
+	}
+
+	/**
+	 * Parses the database defined in the given XML definition String and
+	 * creates a database schema (model) object
+	 * 
+	 * @param dbDef
+	 *            The database XML definition
+	 * @return The database model
+	 */
+	protected Database createDatabaseSchemaFromString(String dbDef)
+	{
+		DatabaseIO dbIO = new DatabaseIO();
+
+		dbIO.setUseInternalDtd(true);
+		dbIO.setValidateXml(false);
+		return dbIO.read(new StringReader(dbDef));
+	}
+
+	/**
+	 * <p>
+	 * Create a database connection (platform instance) from a data source
+	 * </p>
+	 * 
+	 * @param dataSource
+	 */
+	protected Platform connectToDatabase(DataSource dataSource)
+	{
+		return PlatformFactory.createNewPlatformInstance(dataSource);
+	}
+
+	/**
+	 * <p>
+	 * Create a database connection (platform instance) from a (case
+	 * insensitive) database type (like MySQL)
+	 * </p>
+	 * 
+	 * @param dataSource
+	 */
+	protected Platform connectToDatabase(String databaseType)
+	{
+		return PlatformFactory.createNewPlatformInstance(databaseType);
+	}
+	/**
+	 * <p>
+	 * Update a given database schema to match the schema of targetModel If
+	 * alterDB is true, the routine attempts to modify the existing database
+	 * shcema while preserving the data (as much as possible). If not, the
+	 * existing tables are dropped prior to recreate
+	 * 
+	 * @param targetModel
+	 *            The new database model
+	 * @param alterDb
+	 *            if true, try to use alter database and preserve data
+	 */
+	protected void updateDatabaseSchema(Database targetModel, boolean alterDb)
+			throws SerializerException
+	{
+		try
+		{
+			platform.setSqlCommentsOn(false);
+			try
+			{
+				targetModel.resetDynaClassCache();
+			} catch (Exception internalEx)
+			{
+				internalEx.printStackTrace();
+			}
+			if (alterDb)
+			{
+				model.mergeWith(targetModel);
+				try
+				{
+					platform.alterTables(model, true);
+				}
+				catch (Exception aEX)
+				{
+					log.error(aEX);
+				}
+			} else
+			{
+				try
+				{
+				
+//					if (log.isDebugEnabled())
+//					{
+//						String s = platform.getDropTablesSql(model, true);
+//						log.debug(s);
+//					}
+				platform.dropTables(model, true);
+				
+				
+				
+				}
+				catch (Exception aEX)
+				{
+					log.error(aEX);
+				}
+				try
+				{
+				platform.createTables(targetModel, false, true);
+				}
+				catch (Exception aEX)
+				{
+					log.error(aEX);
+				}
+			}
+			model = this.readModelFromDatabase(null);
+		} catch (Exception ex)
+		{
+			ex.printStackTrace();
+			throw new SerializerException(
+			// TODO: HJB create exception
+					SerializerException.CREATE_OBJECT_FAILED.create(ex.getLocalizedMessage()));
+		}
+	}
+
+	/**
+	 * Alter an existing database from the given model. Data is preserved as
+	 * much as possible
+	 * 
+	 * @param model
+	 *            The new database model
+	 */
+	public void alterDatabase(Database model) throws SerializerException
+	{
+		updateDatabaseSchema(model, true);
+	}
+
+	/**
+	 * Creates a new database from the given model. Note that all data is LOST
+	 * 
+	 * @param model
+	 *            The new database model
+	 */
+	public void createDatabase(Database model) throws SerializerException
+	{
+		updateDatabaseSchema(model, false);
+	}
+
+	/**
+	 * <p>
+	 * Inserts data into the database. Data is expected to be in the format
+	 * </p>
+	 * <p>
+	 * <?xml version='1.0' encoding='ISO-8859-1'?> <data> <TABLENAME
+	 * FIELD1='TEXTVALUE' FIELD2=INTVALUE .... /> <TABLENAME FIELD1='TEXTVALUE'
+	 * FIELD2=INTVALUE .... /> </data>
+	 * </p>
+	 * 
+	 * @param model
+	 *            The database model
+	 * @param dataXml
+	 *            The data xml
+	 * @return The database
+	 */
+	protected Database insertData(Database model, String dataXml)
+			throws DatabaseOperationException
+	{
+		try
+		{
+			DataReader dataReader = new DataReader();
+
+			dataReader.setModel(model);
+			dataReader.setSink(new DataToDatabaseSink(platform, model));
+			dataReader.parse(new StringReader(dataXml));
+			return model;
+		} catch (Exception ex)
+		{
+			throw new DatabaseOperationException(ex);
+		}
+	}
+
+	/**
+	 * Drops the tables defined in the database model on this connection.
+	 * 
+	 * @param model
+	 *            The database model
+	 * 
+	 */
+	protected void dropDatabaseTables(Database model)
+			throws DatabaseOperationException
+	{
+		platform.dropTables(model, true);
+	}
+
+	/**
+	 * Reads the database model from a live database.
+	 * 
+	 * @param platform
+	 *            The physical database connection
+	 * @param databaseName
+	 *            The name of the resulting database
+	 * @return The model
+	 */
+	public Database readModelFromDatabase(String databaseName)
+	{
+		return platform.readModelFromDatabase(databaseName);
+	}
+
+	/**
+	 * datasource.class=org.apache.commons.dbcp.BasicDataSource
+	 * datasource.driverClassName=com.mysql.jdbc.Driver
+	 * datasource.url=jdbc:mysql://localhost/ddlutils datasource.username=root
+	 * datasource.password=root123
+	 * 
+	 */
+
+	/**
+	 * Initializes the datasource and the connection (platform)
+	 */
+	public void init(Map parameters)
+	{
+		if (connected)
+			tearDown();
+
+		try
+		{
+			String dataSourceClass = (String) parameters.get(DATASOURCE_CLASS);
+			if (dataSourceClass == null)
+				dataSourceClass = BasicDataSource.class.getName();
+
+			dataSource = (DataSource) Class.forName(dataSourceClass)
+					.newInstance();
+
+			for (Iterator it = parameters.entrySet().iterator(); it.hasNext();)
+			{
+				Map.Entry entry = (Map.Entry) it.next();
+				String propName = (String) entry.getKey();
+
+				if (!(propName.equals(DATASOURCE_CLASS)))
+				{
+					BeanUtils.setProperty(dataSource, propName, entry
+							.getValue());
+				}
+			}
+		} catch (Exception ex)
+		{
+			throw new DatabaseOperationException(ex);
+		}
+
+		_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");
+		}
+
+//		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())
+//		{
+//			platform.setDelimitedIdentifierModeOn(true);
+//		}
+
+	
+		platform.setDataSource(dataSource);
+
+		model = this.readModelFromDatabase(null);
+/**		
+		JdbcModelReader reader = platform.getModelReader();		
+		try
+		{
+		model = reader.getDatabase(platform.borrowConnection(), null);
+		} catch (Exception ex)
+		{
+			throw new DatabaseOperationException(ex);
+		}
+*/
+		
+		connected = true;
+	}
+
+	/**
+	 * Returns the database model.
+	 * 
+	 * @return The model
+	 */
+	protected Database getModel()
+	{
+		return model;
+	}
+
+	/**
+	 * Inserts data into the database.
+	 * 
+	 * @param dataXml
+	 *            The data xml
+	 * @return The database
+	 */
+	protected Database insertData(String dataXml)
+			throws DatabaseOperationException
+	{
+		try
+		{
+			DataReader dataReader = new DataReader();
+
+			dataReader.setModel(model);
+			dataReader.setSink(new DataToDatabaseSink(platform, model));
+			dataReader.parse(new StringReader(dataXml));
+			return model;
+		} catch (Exception ex)
+		{
+			throw new DatabaseOperationException(ex);
+		}
+	}
+
+	/**
+	 * Drops the tables defined in the database model.
+	 */
+	protected void dropDatabase() throws DatabaseOperationException
+	{
+		platform.dropTables(model, true);
+	}
+
+	/**
+	 * Determines the value of the bean's property that has the given name.
+	 * Depending on the case-setting of the current builder, the case of teh
+	 * name is considered or not.
+	 * 
+	 * @param bean
+	 *            The bean
+	 * @param propName
+	 *            The name of the property
+	 * @return The value
+	 */
+	protected Object getPropertyValue(DynaBean bean, String propName)
+	{
+		if (platform.isDelimitedIdentifierModeOn())
+		{
+			return bean.get(propName);
+		} else
+		{
+			DynaProperty[] props = bean.getDynaClass().getDynaProperties();
+
+			for (int idx = 0; idx < props.length; idx++)
+			{
+				if (propName.equalsIgnoreCase(props[idx].getName()))
+				{
+					return bean.get(props[idx].getName());
+				}
+			}
+			throw new IllegalArgumentException(
+					"The bean has no property with the name " + propName);
+		}
+	}
+
+	public DataSource getDataSource()
+	{
+		return dataSource;
+	}
+
+	public Platform getPlatform()
+	{
+		return platform;
+	}
+	
+		 
+	
+    public  List getRows(String tableName)
+    {
+        Table table = getModel().findTable(tableName, getPlatform().isDelimitedIdentifierModeOn());
+        
+        return getPlatform().fetch(getModel(), getSelectQueryForAllString( table), new Table[] { table });
+    }
+
+    
+    public  String getSelectQueryForAllString( Table table)
+    {
+    
+	    StringBuffer query = new StringBuffer();
+	
+	    query.append("SELECT * FROM ");
+	    if (getPlatform().isDelimitedIdentifierModeOn())
+	    {
+	        query.append(getPlatform().getPlatformInfo().getDelimiterToken());
+	    }
+	    query.append(table.getName());
+	    if (getPlatform().isDelimitedIdentifierModeOn())
+	    {
+	        query.append(getPlatform().getPlatformInfo().getDelimiterToken());
+	    }
+	    return query.toString();
+    }
+	
+    
+  
+    
+}

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=484723&r1=484722&r2=484723
==============================================================================
--- 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 Fri Dec  8 12:02:58 2006
@@ -22,6 +22,8 @@
 
 import org.apache.commons.configuration.PropertiesConfiguration;
 import org.apache.jetspeed.components.jndi.SpringJNDIStarter;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
 /**
  * Jetspeed Serializer Application
  * 
@@ -43,12 +45,24 @@
  *      PROFILE = extract/import profile settings (for export requires USER) 
  *      NOOVERWRITE = don't overwrite existing file (for export)
  *      BACKUP = backup before process
- *       
- * The overall XML file needs to indicate whether passwords used in credentials
- * are plain text or whether they are encoded. The export algoritm can determine -
- * prior to reading users - which encode/decode scheme was used and if <none> or
- * <implements PasswordEncodingService> then we store plain passwords (Note that
- * that alone requires the resulting XML to be encoded!!!!!)
+
+ * <p>
+ * -dc driverClass, for example com.mysql.jdbc.Driver
+ * </p>
+ * <p>
+ * -ds url, ruls according to the driver used, URL needs to point to the correct
+ * database
+ * </p>
+ * <p>
+ * -du user, user with create/drop etc. rights on the database
+ * </p>
+ * <p>
+ * -dp password
+ * </p>
+ * 
+ * <p>
+ * -l log4j-level, ERROR (default), WARN, INFO 
+ * </p>
  * 
  * @author <a href="mailto:hajo@bluesunrise.com">Hajo Birthelmer</a>
  * @version $Id: $
@@ -75,6 +89,13 @@
         
         String defaultIndent = null;
 
+    	String driverClass = null; // jdbc driver
+    	String url = null; // jdbc url to database
+    	String user = null; // user
+    	String password = null; // password
+
+        String logLevel = null;
+        
         boolean doImport = false;
         boolean doExport = false;
  
@@ -92,7 +113,16 @@
           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("-O")) options = 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]);
         }
 
@@ -133,7 +163,19 @@
                 if (configFiles == null) applicationPath = configuration.getString("configFiles");
                 if (options == null) applicationPath = configuration.getString("options");
                 if (defaultIndent == null) applicationPath = configuration.getString("defaultIndent");
-                
+
+        		if (driverClass == null)
+    				driverClass = configuration.getString("driverClass");
+    			if (url == null)
+    				url = configuration.getString("url");
+    			if (user == null)
+    				user = configuration.getString("user");
+    			if (password == null)
+    				password = configuration.getString("password");
+    			if (logLevel == null)
+    				logLevel = configuration.getString("loglevel");
+    				
+    	
             }
         }
 
@@ -141,7 +183,8 @@
         if (applicationPath == null) applicationPath = "./";
         if (bootConfigFiles == null) bootConfigFiles = "assembly/boot/";
         if (configFiles == null) configFiles = "assembly/";
-        
+		if (logLevel == null) logLevel = "ERROR";
+      
 
         bootConfigFiles = bootConfigFiles + "*.xml";
         configFiles = configFiles + "*.xml";
@@ -195,10 +238,51 @@
             }
         }
         JetspeedSerializer serializer = null;
+
+		if (driverClass == null)
+			driverClass = System.getProperty(
+					"org.apache.jetspeed.database.driverClass",
+					"com.mysql.jdbc.Driver");
+		if (url == null)
+			url = System.getProperty("org.apache.jetspeed.database.url",
+					"jdbc:mysql://localhost/j2test");
+		if (user == null)
+			user = System.getProperty("org.apache.jetspeed.database.user",
+					"user");
+		if (password == null)
+			password = System.getProperty(
+					"org.apache.jetspeed.database.password", "password");
+
+		if (driverClass == null)
+			throw new IllegalArgumentException(
+					"Can't proceed without a valid driver");
+		if (url == null)
+			throw new IllegalArgumentException(
+					"Can't proceed without a valid url to the target database");
+		if (user == null)
+			throw new IllegalArgumentException(
+					"Can't proceed without a valid database user");
+
+        
         
         HashMap context = new HashMap();
  
-        
+		context.put(SpringJNDIStarter.DATASOURCE_DRIVER, driverClass);
+		context.put(SpringJNDIStarter.DATASOURCE_URL, url);
+		context.put(SpringJNDIStarter.DATASOURCE_USERNAME, user);
+		context.put(SpringJNDIStarter.DATASOURCE_PASSWORD, password);
+        
+		Logger  logger = Logger.getLogger("org.springframework");
+		Level level = logger.getLevel();
+		if (logLevel.equalsIgnoreCase("INFO"))
+			logger.setLevel(Level.INFO);
+		else
+			if (logLevel.equalsIgnoreCase("WARN"))
+				logger.setLevel(Level.WARN);
+			else
+				logger.setLevel(Level.ERROR);
+				
+
         SpringJNDIStarter starter = new SpringJNDIStarter(context,applicationPath,getTokens(bootConfigFiles),getTokens(configFiles));
         
         System.out.println("starter framework created " + starter);
@@ -237,6 +321,7 @@
             try
             {
                starter.tearDown();
+               logger.setLevel(level);;
             }
             catch (Exception e1)
             {
@@ -249,7 +334,7 @@
 
     }
         
-        
+       
         private static  String[] getTokens(String _line)
         {
             if ((_line == null) || (_line.length() == 0))

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=484723&r1=484722&r2=484723
==============================================================================
--- 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 Fri Dec  8 12:02:58 2006
@@ -21,7 +21,7 @@
 import java.security.Principal;
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Date;
+import java.sql.Date;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
@@ -78,6 +78,7 @@
 import org.apache.jetspeed.serializer.objects.JSMimeType;
 import org.apache.jetspeed.serializer.objects.JSMimeTypes;
 import org.apache.jetspeed.serializer.objects.JSNameValuePairs;
+import org.apache.jetspeed.serializer.objects.JSPWAttributes;
 import org.apache.jetspeed.serializer.objects.JSPermission;
 import org.apache.jetspeed.serializer.objects.JSPermissions;
 import org.apache.jetspeed.serializer.objects.JSPrincipalRule;
@@ -564,7 +565,8 @@
      */
     private void setSnapshotData()
     {
-        Date d = new Date();
+    	java.util.Date d1 = new java.util.Date();
+        Date d = new Date(d1.getTime());
         snapshot.setDateCreated(d.toString());
         snapshot.setSavedVersion(JSSnapshot.softwareVersion);
         snapshot.setSavedSubversion(JSSnapshot.softwareSubVersion);
@@ -961,8 +963,19 @@
     			    	logMe("add User done ");
 						user = userManager.getUser(jsuser.getName());
 					}
-					else
-					{}// we should not touch existing passwords....
+					try
+					{
+						userManager.setPasswordEnabled(jsuser.getName(), jsuser.getPwEnabled());						
+						userManager.setPasswordUpdateRequired(jsuser.getName(), jsuser.getPwRequiredUpdate());
+						java.sql.Date d = jsuser.getPwExpirationDate();
+						if (d != null)
+							userManager.setPasswordExpiration(jsuser.getName(), d);						
+					}
+					catch (Exception e)
+					{
+						// most likely caused by protected users (like "guest")
+						logMe("setting userinfo for "+ jsuser.getName() + " failed because of " + e.getLocalizedMessage());
+					}
 					
 				//credentials
 			        Subject subject = user.getSubject();
@@ -1394,6 +1407,8 @@
 
         binding.setAlias(String.class, "String");
         binding.setAlias(Integer.class, "int");
+        
+        binding.setAlias(JSPWAttributes.class,"credentials");
 
         binding.setClassAttribute(null);
 
@@ -1569,7 +1584,7 @@
         if (credential instanceof PasswordCredential)
         {
             PasswordCredential pw = (PasswordCredential) credential;
-            newUser.setUserCredential(pw.getUserName(), pw.getPassword());
+            newUser.setUserCredential(pw.getUserName(), pw.getPassword(),pw.getExpirationDate(),pw.isEnabled(), pw.isExpired(), pw.isUpdateRequired());
             return;
         } else if (isPublic)
             newUser.addPublicCredential(credential);

Added: portals/jetspeed-2/trunk/components/serializer/src/java/org/apache/jetspeed/serializer/objects/JSPWAttributes.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/components/serializer/src/java/org/apache/jetspeed/serializer/objects/JSPWAttributes.java?view=auto&rev=484723
==============================================================================
--- portals/jetspeed-2/trunk/components/serializer/src/java/org/apache/jetspeed/serializer/objects/JSPWAttributes.java (added)
+++ portals/jetspeed-2/trunk/components/serializer/src/java/org/apache/jetspeed/serializer/objects/JSPWAttributes.java Fri Dec  8 12:02:58 2006
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2000-2004 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.jetspeed.serializer.objects;
+
+/**
+ * Serialized Name Value Pairs
+ * <info>
+ *   <name>user.first.name</name>
+ *   <value>Paul</value>
+ * </info>
+ * 
+ * @author <a href="mailto:hajo@bluesunrsie.com">Hajo Birthelmer</a>
+ * @version $Id: $
+ */
+import java.util.HashMap;
+import java.util.Map;
+import java.util.prefs.*;
+
+public class JSPWAttributes extends JSNameValuePairs
+{
+
+
+    public JSPWAttributes()
+    {
+        super();
+    }
+}

Added: portals/jetspeed-2/trunk/components/serializer/src/java/org/apache/jetspeed/serializer/objects/JSProcessOrder.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/components/serializer/src/java/org/apache/jetspeed/serializer/objects/JSProcessOrder.java?view=auto&rev=484723
==============================================================================
--- portals/jetspeed-2/trunk/components/serializer/src/java/org/apache/jetspeed/serializer/objects/JSProcessOrder.java (added)
+++ portals/jetspeed-2/trunk/components/serializer/src/java/org/apache/jetspeed/serializer/objects/JSProcessOrder.java Fri Dec  8 12:02:58 2006
@@ -0,0 +1,94 @@
+/*
+ * Copyright 2000-2004 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.jetspeed.serializer.objects;
+
+import java.util.ArrayList;
+
+import org.apache.commons.lang.StringEscapeUtils;
+
+import javolution.xml.XMLBinding;
+import javolution.xml.XMLFormat;
+import javolution.xml.stream.XMLStreamException;
+
+public class JSProcessOrder
+{
+    private JSMimeTypes ordererList;
+
+    public JSProcessOrder()
+    {
+    }
+
+ 
+    /***************************************************************************
+     * SERIALIZER
+     */
+    private static final XMLFormat XML = new XMLFormat(JSProcessOrder.class)
+    {
+
+        public void write(Object o, OutputElement xml)
+                throws XMLStreamException
+        {
+        	
+            try
+            {
+            	JSProcessOrder g = (JSProcessOrder) o;
+                xml.add(g.getMimeTypes());
+
+            } catch (Exception e)
+            {
+                e.printStackTrace();
+            }
+        }
+
+        public void read(InputElement xml, Object o)
+        {
+            try
+            {
+            	JSProcessOrder g = (JSProcessOrder) o;
+                while (xml.hasNext())
+                {
+                    Object o1 = xml.getNext(); // mime
+
+                    if (o1 instanceof JSMimeTypes)
+                        g.ordererList = (JSMimeTypes) o1;
+                }
+            } catch (Exception e)
+            {
+                e.printStackTrace();
+            }
+        }
+    };
+
+
+    /**
+     * @return Returns the mimeTypes.
+     */
+    public JSMimeTypes getMimeTypes()
+    {
+        return ordererList;
+    }
+
+    /**
+     * @param mimeTypes
+     *            The mimeTypes to set.
+     */
+    public void setMimeTypes(JSMimeTypes ordererList)
+    {
+        this.ordererList = ordererList;
+    }
+
+}

Modified: portals/jetspeed-2/trunk/components/serializer/src/java/org/apache/jetspeed/serializer/objects/JSUser.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/components/serializer/src/java/org/apache/jetspeed/serializer/objects/JSUser.java?view=diff&rev=484723&r1=484722&r2=484723
==============================================================================
--- portals/jetspeed-2/trunk/components/serializer/src/java/org/apache/jetspeed/serializer/objects/JSUser.java (original)
+++ portals/jetspeed-2/trunk/components/serializer/src/java/org/apache/jetspeed/serializer/objects/JSUser.java Fri Dec  8 12:02:58 2006
@@ -17,6 +17,7 @@
 
 import java.security.Principal;
 import java.util.ArrayList;
+import java.sql.Date;
 import java.util.Iterator;
 import java.util.prefs.Preferences;
 
@@ -38,6 +39,8 @@
 
     private char[] password;
 
+    private JSPWAttributes pwData = null;
+
     private ArrayList roles = null;
 
     private ArrayList groups = null;
@@ -101,13 +104,92 @@
         return password;
     }
 
-    public void setUserCredential(String name, char[] password)
+    public void setUserCredential(String name, char[] password, Date expirationDate, boolean isEnabled, boolean isExpired, boolean requireUpdate)
     {
         setName(name);
         setPassword(password);
-
+        pwData = new JSPWAttributes();
+        if (password != null)
+        {
+	        pwData.getMyMap().put("password",this.getPasswordString());
+	        if (expirationDate != null)
+	        {
+	        	pwData.getMyMap().put("expirationDate",expirationDate.toString());
+	        }
+	        pwData.getMyMap().put("enabled",(isEnabled?"TRUE":"FALSE"));
+	        pwData.getMyMap().put("requiresUpdate",(requireUpdate?"TRUE":"FALSE"));
+        }
     }
 
+    protected void resetPassword()
+    {
+    	try
+    	{
+	    	if (pwData != null)
+	    	{
+	    		Object o = pwData.getMyMap().get("password");
+    		
+	    		String pw = StringEscapeUtils.unescapeHtml((String)o);
+	    		if ((pw != null) && (pw.length()>0))
+	    			password = pw.toCharArray();
+	    		else
+	    			password = null;
+	    	}
+    	}
+    	catch (Exception e)
+    	{
+			password = null;
+    	}
+    }
+    
+    public boolean getPwEnabled()
+    {
+       	return getPWBoolean("enabled",false);
+    }
+    public boolean getPwRequiredUpdate()
+    {
+       	return getPWBoolean("requiresUpdate",false);
+    }
+
+    
+
+    
+    
+    public Date getPwExpirationDate()
+    {
+    	if (pwData != null)
+    	{
+    		Object o = pwData.getMyMap().get("expirationDate");
+    		if (o == null)
+    			return null;
+    		if ( o instanceof Date)
+    			return (Date)o;
+    		
+    		Date d = Date.valueOf((String)o);
+    		return d;
+    		
+    	}
+    	return null;
+    }
+    
+    
+   private boolean getPWBoolean(String property, boolean defaultSetting)
+    {
+       	if (pwData == null)
+       		return defaultSetting;
+       	try
+       	{
+	   		Object o = pwData.getMyMap().get(property);
+			if (o == null)
+				return defaultSetting;
+			return ((String)o).equalsIgnoreCase("TRUE");
+       	}
+       	catch (Exception e)
+       	{
+       		return defaultSetting;
+       	}
+    }
+   
     public void setPassword(char[] password)
     {
         this.password = password;
@@ -228,8 +310,9 @@
                 String s = g.getName();
                 if ((s == null) || (s.length() == 0)) s = "guest";
                 xml.setAttribute("name", s);
-                xml.setAttribute("password", g.getPasswordString());
- 
+
+                
+                xml.add(g.getPwData());
 
                 /** named fields HERE */
  
@@ -255,11 +338,7 @@
             {
                 JSUser g = (JSUser) o;
                 g.name = StringEscapeUtils.unescapeHtml(xml.getAttribute("name", "unknown"));
-                String pw = StringEscapeUtils.unescapeHtml(xml.getAttribute("password",""));
-                if ((pw != null) && (pw.length()>0))
-                	g.password = pw.toCharArray();
-                else
-                	g.password = null;
+                
                 
                 Object o1 = null;
  
@@ -268,6 +347,13 @@
 				{
 					o1 = xml.getNext(); // mime
 					
+					
+					if (o1 instanceof JSPWAttributes)
+					{
+						g.pwData = (JSPWAttributes) o1;
+						g.resetPassword();
+					}
+					else
 					if (o1 instanceof JSUserGroups)
 						g.groupString = (JSUserGroups) o1;
 					else
@@ -380,6 +466,16 @@
 	public JSUserRoles getRoleString()
 	{
 		return roleString;
+	}
+
+	public JSPWAttributes getPwData()
+	{
+		return pwData;
+	}
+
+	public void setPwData(JSPWAttributes pwData)
+	{
+		this.pwData = pwData;
 	}
 
 }



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


Mime
View raw message