Index: /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/DerbyWrapper.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/DerbyWrapper.java	(revision 25124)
+++ /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/DerbyWrapper.java	(revision 25125)
@@ -114,5 +114,5 @@
 			conn.commit();
 		}
-		catch(Exception ex)
+		catch (Exception ex)
 		{
 			ex.printStackTrace();
@@ -125,5 +125,5 @@
 		String sql_list_all_user = "SELECT username, password, accountstatus, comment FROM " + USERS;
 
-		ArrayList<HashMap<String, String>> users = new ArrayList<HashMap<String,String>>();
+		ArrayList<HashMap<String, String>> users = new ArrayList<HashMap<String, String>>();
 		ResultSet rs = state.executeQuery(sql_list_all_user);
 		while (rs.next())
@@ -134,15 +134,15 @@
 			user.put("as", rs.getString("accountstatus"));
 			user.put("comment", rs.getString("comment"));
-			
+
 			users.add(user);
 		}
-		
-		for(HashMap<String, String> user : users)
+
+		for (HashMap<String, String> user : users)
 		{
 			ResultSet gs = state.executeQuery("SELECT role FROM roles WHERE username = '" + user.get("username") + "'");
 			String group = "";
-			while(gs.next())
-			{
-				if(!group.equals(""))
+			while (gs.next())
+			{
+				if (!group.equals(""))
 				{
 					group += ",";
@@ -152,5 +152,5 @@
 			userQueryResult.addUserTerm(user.get("username"), user.get("password"), group, user.get("as"), user.get("comment"));
 		}
-		
+
 		if (userQueryResult.getSize() == 0)
 		{
@@ -171,12 +171,12 @@
 			String sql_insert_user = "insert into " + USERS + " values ('" + username + "', '" + password + "', '" + accountstatus + "', '" + comment + "')";
 			state.execute(sql_insert_user);
-			
+
 			String[] groupArray = groups.split(",");
-			for(String g : groupArray)
+			for (String g : groupArray)
 			{
 				String sql_insert_group = "insert into " + ROLES + " values ('" + username + "', '" + g + "')";
 				state.execute(sql_insert_group);
 			}
-			
+
 			conn.commit();
 		}
@@ -196,5 +196,5 @@
 			return "Error:" + e.getMessage();
 		}
-		
+
 		return "succeed";
 	}
@@ -281,6 +281,6 @@
 			sql_find_user += append_sql;
 		}
-		
-		ArrayList<HashMap<String, String>> users = new ArrayList<HashMap<String,String>>();
+
+		ArrayList<HashMap<String, String>> users = new ArrayList<HashMap<String, String>>();
 		ResultSet rs = state.executeQuery(sql_find_user);
 		while (rs.next())
@@ -291,17 +291,17 @@
 			user.put("as", rs.getString("accountstatus"));
 			user.put("comment", rs.getString("comment"));
-			
+
 			users.add(user);
 		}
 		conn.commit();
-		
-		for(HashMap<String, String> user : users)
+
+		for (HashMap<String, String> user : users)
 		{
 			ResultSet gs = state.executeQuery("SELECT role FROM " + ROLES + " WHERE username = '" + user.get("username") + "'");
-			
+
 			String group = "";
-			while(gs.next())
-			{
-				if(!group.equals(""))
+			while (gs.next())
+			{
+				if (!group.equals(""))
 				{
 					group += ",";
@@ -309,10 +309,67 @@
 				group += gs.getString("role");
 			}
-			
-			System.out.println("GROUP = " + group);
-			
+
 			userQueryResult.addUserTerm(user.get("username"), user.get("password"), group, user.get("as"), user.get("comment"));
 		}
-		
+
+		if (userQueryResult.getSize() > 0)
+		{
+			return userQueryResult;
+		}
+		else
+		{
+			System.out.println("couldn't find the user");
+			return null;
+		}
+	}
+
+	public UserQueryResult findUser(String username) throws SQLException
+	{
+		UserQueryResult userQueryResult = new UserQueryResult();
+
+		conn.setAutoCommit(false);
+		String sql_find_user = "SELECT  username, password, accountstatus, comment FROM " + USERS;
+		String append_sql = "";
+
+		if (username != null)
+		{
+			append_sql = " WHERE username = '" + username + "'";
+		}
+		if (!append_sql.equals(""))
+		{
+			sql_find_user += append_sql;
+		}
+
+		ArrayList<HashMap<String, String>> users = new ArrayList<HashMap<String, String>>();
+		ResultSet rs = state.executeQuery(sql_find_user);
+		while (rs.next())
+		{
+			HashMap<String, String> user = new HashMap<String, String>();
+			user.put("username", rs.getString("username"));
+			user.put("password", rs.getString("password"));
+			user.put("as", rs.getString("accountstatus"));
+			user.put("comment", rs.getString("comment"));
+
+			users.add(user);
+		}
+		conn.commit();
+
+		for (HashMap<String, String> user : users)
+		{
+			ResultSet gs = state.executeQuery("SELECT role FROM " + ROLES + " WHERE username = '" + user.get("username") + "'");
+
+			String group = "";
+			while (gs.next())
+			{
+				if (!group.equals(""))
+				{
+					group += ",";
+				}
+				group += gs.getString("role");
+			}
+
+			userQueryResult.addUserTerm(user.get("username"), user.get("password"), group, user.get("as"), user.get("comment"));
+		}
+
 		if (userQueryResult.getSize() > 0)
 		{
@@ -336,5 +393,5 @@
 				sql_modify_user_info += "password='" + new_password + "'";
 			}
-	
+
 			if (accountstatus != null && comment != null)
 			{
@@ -344,15 +401,15 @@
 			System.out.println(sql_modify_user_info);
 			state.execute(sql_modify_user_info);
-			
+
 			String sql_delete_groups = "delete from " + ROLES + " where username='" + username + "'";
 			state.execute(sql_delete_groups);
-			
+
 			String[] groupsArray = groups.split(",");
-			for(String g : groupsArray)
+			for (String g : groupsArray)
 			{
 				String sql_insert_group = "insert into " + ROLES + " values ('" + username + "', '" + g + "')";
 				state.execute(sql_insert_group);
 			}
-			
+
 			conn.commit();
 		}
@@ -390,7 +447,7 @@
 			ResultSet groupsSet = state.executeQuery("SELECT role FROM " + ROLES + " WHERE username = '" + returned_username + "'");
 			String returned_groups = "";
-			while(groupsSet.next())
-			{
-				if(!returned_groups.equals(""))
+			while (groupsSet.next())
+			{
+				if (!returned_groups.equals(""))
 				{
 					returned_groups += ",";
