Index: /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/LibraryCommandline.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/LibraryCommandline.java	(revision 28971)
+++ /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/LibraryCommandline.java	(revision 28972)
@@ -38,14 +38,8 @@
  * A program to take cgi args from the command line and return html
  * 
- * @author Katherine Don
- * @version $Revision$
  */
 
 final public class LibraryCommandline
 {
-
-	protected XMLConverter converter = null;
-	protected Document doc = null;
-
 	protected HashMap<String, String> saved_args = null;
 	protected GSParams params = null;
@@ -54,6 +48,4 @@
 	public LibraryCommandline()
 	{
-		this.converter = new XMLConverter();
-		this.doc = converter.newDOM();
 		this.saved_args = new HashMap<String, String>();
 		this.params = new GSParams();
@@ -143,7 +135,7 @@
 		Element xml_message = generateRequest(query);
 		System.out.println("*********************");
-		System.out.println(converter.getPrettyString(xml_message));
+		System.out.println(XMLConverter.getPrettyString(xml_message));
 		Node xml_result = recept.process(xml_message);
-		return this.converter.getPrettyString(xml_result);
+		return XMLConverter.getPrettyString(xml_result);
 	}
 
@@ -151,8 +143,9 @@
 	{
 
-		Element xml_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
-		Element xml_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_PAGE, "", new UserContext());
+	  Document msg_doc = XMLConverter.newDOM();
+		Element xml_message = msg_doc.createElement(GSXML.MESSAGE_ELEM);
+		Element xml_request = GSXML.createBasicRequest(msg_doc, GSXML.REQUEST_TYPE_PAGE, "", new UserContext());
 		xml_message.appendChild(xml_request);
-		Element xml_param_list = this.doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
+		Element xml_param_list = msg_doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
 		xml_request.appendChild(xml_param_list);
 
@@ -200,5 +193,5 @@
 			{
 				// make a param now
-				Element param = doc.createElement(GSXML.PARAM_ELEM);
+				Element param = msg_doc.createElement(GSXML.PARAM_ELEM);
 				param.setAttribute(GSXML.NAME_ATT, name);
 				param.setAttribute(GSXML.VALUE_ATT, GSXML.xmlSafe(value));
@@ -220,5 +213,5 @@
 			if (name.equals(GSParams.LANGUAGE))
 				continue;
-			Element param = this.doc.createElement(GSXML.PARAM_ELEM);
+			Element param = msg_doc.createElement(GSXML.PARAM_ELEM);
 			param.setAttribute(GSXML.NAME_ATT, name);
 			param.setAttribute(GSXML.VALUE_ATT, GSXML.xmlSafe(saved_args.get(name)));
Index: /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/LibraryServlet.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/LibraryServlet.java	(revision 28971)
+++ /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/LibraryServlet.java	(revision 28972)
@@ -86,10 +86,4 @@
 	protected final String DEFAULT_LANG = "en";
 
-	/** container Document to create XML Nodes */
-	protected Document doc = null;
-
-	/** a converter class to parse XML and create Docs */
-	protected XMLConverter converter = null;
-
 	/**
 	 * the cgi stuff - the Receptionist can add new args to this
@@ -186,6 +180,6 @@
 			config_params.put(GSConstants.SITE_NAME, site_name);
 		}
-		this.converter = new XMLConverter();
-		this.doc = XMLConverter.newDOM();
+		//this.converter = new XMLConverter();
+		//this.doc = XMLConverter.newDOM();
 
 		// the receptionist -the servlet will talk to this
@@ -243,5 +237,6 @@
 			Communicator communicator = null;
 			// we need to create the XML to configure the communicator
-			Element site_elem = this.doc.createElement(GSXML.SITE_ELEM);
+			Document doc = XMLConverter.newDOM();
+			Element site_elem = doc.createElement(GSXML.SITE_ELEM);
 			site_elem.setAttribute(GSXML.TYPE_ATT, remote_site_type);
 			site_elem.setAttribute(GSXML.NAME_ATT, remote_site_name);
@@ -292,5 +287,5 @@
 		//Allow the message router and the document to be accessed from anywhere in this servlet context
 		this.getServletContext().setAttribute("GSRouter", this.recept.getMessageRouter());
-		this.getServletContext().setAttribute("GSDocument", this.doc);
+		//this.getServletContext().setAttribute("GSDocument", this.doc);
 	}
 
@@ -464,11 +459,12 @@
 
 			//Get the groups for the user
-			Element acquireGroupMessage = this.doc.createElement(GSXML.MESSAGE_ELEM);
-			Element acquireGroupRequest = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_PROCESS, "GetUserInformation", userContext);
+			Document msg_doc = XMLConverter.newDOM();
+			Element acquireGroupMessage = msg_doc.createElement(GSXML.MESSAGE_ELEM);
+			Element acquireGroupRequest = GSXML.createBasicRequest(msg_doc, GSXML.REQUEST_TYPE_PROCESS, "GetUserInformation", userContext);
 			acquireGroupMessage.appendChild(acquireGroupRequest);
 
-			Element paramList = this.doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
+			Element paramList = msg_doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
 			acquireGroupRequest.appendChild(paramList);
-			paramList.appendChild(GSXML.createParameter(this.doc, GSXML.USERNAME_ATT, request.getUserPrincipal().getName()));
+			paramList.appendChild(GSXML.createParameter(msg_doc, GSXML.USERNAME_ATT, request.getUserPrincipal().getName()));
 
 			Element aquireGroupsResponseMessage = (Element) this.recept.process(acquireGroupMessage);
@@ -520,6 +516,7 @@
 
 		// the request to the receptionist
-		Element xml_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
-		Element xml_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_PAGE, "", userContext);
+		Document msg_doc = XMLConverter.newDOM();
+		Element xml_message = msg_doc.createElement(GSXML.MESSAGE_ELEM);
+		Element xml_request = GSXML.createBasicRequest(msg_doc, GSXML.REQUEST_TYPE_PAGE, "", userContext);
 		xml_request.setAttribute(GSXML.OUTPUT_ATT, output);
 
@@ -655,5 +652,5 @@
 			//  create the param list for the greenstone request - includes
 			// the params from the current request and any others from the saved session
-			Element xml_param_list = this.doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
+			Element xml_param_list = msg_doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
 			xml_request.appendChild(xml_param_list);
 
@@ -680,5 +677,5 @@
 					else
 					{
-						Element param = this.doc.createElement(GSXML.PARAM_ELEM);
+						Element param = msg_doc.createElement(GSXML.PARAM_ELEM);
 						param.setAttribute(GSXML.NAME_ATT, name);
 						param.setAttribute(GSXML.VALUE_ATT, GSXML.xmlSafe(value));
@@ -709,5 +706,5 @@
 
 					// lang and uid are stored but we dont want it in the param list cos its already in the request
-					Element param = this.doc.createElement(GSXML.PARAM_ELEM);
+					Element param = msg_doc.createElement(GSXML.PARAM_ELEM);
 					param.setAttribute(GSXML.NAME_ATT, name);
 					String value = GSXML.xmlSafe((String) session.getAttribute(name));
@@ -784,5 +781,5 @@
 		encodeURLs(xml_result, response);
 
-		String xml_string = this.converter.getPrettyString(xml_result);
+		String xml_string = XMLConverter.getPrettyString(xml_result);
 
 		if (output.equals("json"))
@@ -851,6 +848,7 @@
 				{
 					//The user entered in either the wrong username or the wrong password
-					Element loginPageMessage = this.doc.createElement(GSXML.MESSAGE_ELEM);
-					Element loginPageRequest = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_PAGE, "", userContext);
+				  Document loginPageDoc = XMLConverter.newDOM();
+					Element loginPageMessage = loginPageDoc.createElement(GSXML.MESSAGE_ELEM);
+					Element loginPageRequest = GSXML.createBasicRequest(loginPageDoc, GSXML.REQUEST_TYPE_PAGE, "", userContext);
 					loginPageRequest.setAttribute(GSXML.ACTION_ATT, "p");
 					loginPageRequest.setAttribute(GSXML.SUBACTION_ATT, "login");
@@ -859,13 +857,13 @@
 					loginPageMessage.appendChild(loginPageRequest);
 
-					Element paramList = this.doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
+					Element paramList = loginPageDoc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
 					loginPageRequest.appendChild(paramList);
 
-					Element messageParam = this.doc.createElement(GSXML.PARAM_ELEM);
+					Element messageParam = loginPageDoc.createElement(GSXML.PARAM_ELEM);
 					messageParam.setAttribute(GSXML.NAME_ATT, "loginMessage");
 					messageParam.setAttribute(GSXML.VALUE_ATT, "Either your username or password was incorrect, please try again.");
 					paramList.appendChild(messageParam);
 
-					Element urlParam = this.doc.createElement(GSXML.PARAM_ELEM);
+					Element urlParam = loginPageDoc.createElement(GSXML.PARAM_ELEM);
 					urlParam.setAttribute(GSXML.NAME_ATT, "redirectURL");
 					String queryString = "";
@@ -878,5 +876,5 @@
 
 					Node loginPageResponse = this.recept.process(loginPageMessage);
-					out.println(this.converter.getPrettyString(loginPageResponse));
+					out.println(XMLConverter.getPrettyString(loginPageResponse));
 
 					return false;
@@ -888,15 +886,16 @@
 		if (request.getAuthType() != null)
 		{
-			Element userInformation = this.doc.createElement(GSXML.USER_INFORMATION_ELEM);
+		  Element userInformation = xml_request.getOwnerDocument().createElement(GSXML.USER_INFORMATION_ELEM);
 			userInformation.setAttribute(GSXML.USERNAME_ATT, request.getUserPrincipal().getName());
 
-			Element userInfoMessage = this.doc.createElement(GSXML.MESSAGE_ELEM);
-			Element userInfoRequest = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_SECURITY, "GetUserInformation", userContext);
+			Document msg_doc = XMLConverter.newDOM();
+			Element userInfoMessage = msg_doc.createElement(GSXML.MESSAGE_ELEM);
+			Element userInfoRequest = GSXML.createBasicRequest(msg_doc, GSXML.REQUEST_TYPE_SECURITY, "GetUserInformation", userContext);
 			userInfoMessage.appendChild(userInfoRequest);
 
-			Element paramList = this.doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
+			Element paramList = msg_doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
 			userInfoRequest.appendChild(paramList);
 
-			Element param = this.doc.createElement(GSXML.PARAM_ELEM);
+			Element param = msg_doc.createElement(GSXML.PARAM_ELEM);
 			param.setAttribute(GSXML.NAME_ATT, GSXML.USERNAME_ATT);
 			param.setAttribute(GSXML.VALUE_ATT, request.getUserPrincipal().getName());
@@ -925,6 +924,7 @@
 		{
 			//Get the security info for this collection
-			Element securityMessage = this.doc.createElement(GSXML.MESSAGE_ELEM);
-			Element securityRequest = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_SECURITY, collection, userContext);
+		  Document msg_doc = XMLConverter.newDOM();
+			Element securityMessage = msg_doc.createElement(GSXML.MESSAGE_ELEM);
+			Element securityRequest = GSXML.createBasicRequest(msg_doc, GSXML.REQUEST_TYPE_SECURITY, collection, userContext);
 			securityMessage.appendChild(securityRequest);
 			if (document != null && !document.equals(""))
@@ -957,6 +957,7 @@
 				if (!found)
 				{
-					Element loginPageMessage = this.doc.createElement(GSXML.MESSAGE_ELEM);
-					Element loginPageRequest = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_PAGE, "", userContext);
+				  Document loginPageDoc = XMLConverter.newDOM();
+					Element loginPageMessage = loginPageDoc.createElement(GSXML.MESSAGE_ELEM);
+					Element loginPageRequest = GSXML.createBasicRequest(loginPageDoc, GSXML.REQUEST_TYPE_PAGE, "", userContext);
 					loginPageRequest.setAttribute(GSXML.ACTION_ATT, "p");
 					loginPageRequest.setAttribute(GSXML.SUBACTION_ATT, "login");
@@ -965,8 +966,8 @@
 					loginPageMessage.appendChild(loginPageRequest);
 
-					Element paramList = this.doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
+					Element paramList = loginPageDoc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
 					loginPageRequest.appendChild(paramList);
 
-					Element messageParam = this.doc.createElement(GSXML.PARAM_ELEM);
+					Element messageParam = loginPageDoc.createElement(GSXML.PARAM_ELEM);
 					messageParam.setAttribute(GSXML.NAME_ATT, "loginMessage");
 					if (request.getAuthType() == null)
@@ -980,5 +981,5 @@
 					paramList.appendChild(messageParam);
 
-					Element urlParam = this.doc.createElement(GSXML.PARAM_ELEM);
+					Element urlParam = loginPageDoc.createElement(GSXML.PARAM_ELEM);
 					urlParam.setAttribute(GSXML.NAME_ATT, "redirectURL");
 					if (request.getQueryString() != null && request.getQueryString().length() > 0)
@@ -993,5 +994,5 @@
 
 					Node loginPageResponse = this.recept.process(loginPageMessage);
-					out.println(this.converter.getPrettyString(loginPageResponse));
+					out.println(XMLConverter.getPrettyString(loginPageResponse));
 
 					return false;
