Index: trunk/gsdl3/src/java/org/greenstone/gsdl3/LibraryServlet.java
===================================================================
--- trunk/gsdl3/src/java/org/greenstone/gsdl3/LibraryServlet.java	(revision 3651)
+++ trunk/gsdl3/src/java/org/greenstone/gsdl3/LibraryServlet.java	(revision 3652)
@@ -3,5 +3,7 @@
 import org.greenstone.gsdl3.core.*;
 import org.greenstone.gsdl3.util.*;
-
+import org.greenstone.gsdl3.action.PageAction; // used to get the default action
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
 import java.io.*;
 import javax.servlet.*;
@@ -30,4 +32,9 @@
      * in the servlet params */
     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;
+
     /** initialise the servlet
      */
@@ -74,4 +81,7 @@
 	recept_.configure();
 
+	converter_ = new XMLConverter();
+	doc_ = converter_.newDOM();
+
     }
     
@@ -84,54 +94,72 @@
 	PrintWriter out = response.getWriter();
 
-	// if the interface owns the default - keep this here, otherwise move
-	// it to receptionist
-	String lang = request.getParameter("l");
+	String lang = request.getParameter(GSCGI.LANGUAGE_ARG);
 	if (lang==null || lang.equals("")) {
 	    lang = default_lang_; // the default
 	}
+	String output = request.getParameter(GSCGI.OUTPUT_ARG);
+	if (output==null || output.equals("")) {
+	    output = "html"; // uses html by default
+	}
+
 	// the request to the receptionist	
-	String xml_request="<message><request lang='"+lang+"' type='action' output='html' action=";
-
-	String action = request.getParameter("a");
+	Element xml_message = doc_.createElement(GSXML.MESSAGE_ELEM);
+	Element xml_request = doc_.createElement(GSXML.REQUEST_ELEM);
+	xml_message.appendChild(xml_request);
+	xml_request.setAttribute(GSXML.LANG_ATT, lang);
+	xml_request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_CGI);
+	xml_request.setAttribute(GSXML.OUTPUT_ATT, output);
+	
+	String action = request.getParameter(GSCGI.ACTION_ARG);
+	String subaction = request.getParameter(GSCGI.SUBACTION_ARG);
 	if (action==null || action.equals("")) {
-	    // display the home page
-	    // a=p&sa=home
-	    xml_request +="'p' subaction='home'/>";
-	} else {
-	    String subaction = request.getParameter("sa");
-	    xml_request += "'"+action+"'";
-	    if (subaction != null) {
-		xml_request += " subaction='"+subaction+"'";
-	    }
-	    xml_request += "><paramList>";
-	    Enumeration params = request.getParameterNames();
-	    while(params.hasMoreElements()) {
-		String name = (String)params.nextElement();
-		if (!name.equals("a") && !name.equals("sa") && !name.equals("l")) { // these ones are in the header so leave out
-		    String value="";
-		    String []values = request.getParameterValues(name);
-		    value = values[0];
-		    if (values.length > 1) {
-			for (int i=1; i< values.length; i++) {
-			    value += ","+values[i];
-			}
+	    // should we do all the following stuff if using default page?
+	    // display the home page  - the default page
+	    action = "p";
+	    subaction = PageAction.HOME_PAGE;
+	    xml_request.setAttribute(GSXML.ACTION_ATT, action);
+	    xml_request.setAttribute(GSXML.SUBACTION_ATT, subaction);
+	    
+	    Element xml_result = recept_.process(xml_message);
+	    out.println(converter_.getString(xml_result));
+	    return;
+	} 
+	
+	xml_request.setAttribute(GSXML.ACTION_ATT, action);
+	if (subaction != null) {
+	    xml_request.setAttribute(GSXML.SUBACTION_ATT, subaction);
+	}
+	Element xml_param_list = doc_.createElement(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
+	xml_request.appendChild(xml_param_list);
+	Enumeration params = request.getParameterNames();
+	while(params.hasMoreElements()) {
+	    String name = (String)params.nextElement();
+	    if (!name.equals(GSCGI.ACTION_ARG) && !name.equals(GSCGI.SUBACTION_ARG) && !name.equals(GSCGI.LANGUAGE_ARG) && !name.equals(GSCGI.OUTPUT_ARG)) { // these ones are in the header so leave out
+		String value="";
+		String []values = request.getParameterValues(name);
+		value = values[0];
+		if (values.length > 1) {
+		    for (int i=1; i< values.length; i++) {
+			value += ","+values[i];
 		    }
-		    xml_request += "<param name='"+name+"' value='"+GSXML.xmlSafe(value)+"'/>";
-		    
 		}
-	    }
-	    xml_request += "</paramList></request>";
-	    if (action.equals("a")&&subaction.equals("r")) { // applet action
-		response.setContentType("text/plain");
+		Element param = doc_.createElement(GSXML.PARAM_ELEM);
+		param.setAttribute(GSXML.NAME_ATT, name);
+		param.setAttribute(GSXML.VALUE_ATT, GSXML.xmlSafe(value));
+		xml_param_list.appendChild(param);
+		
 	    }
 	}
-	xml_request += "</message>";
 
-	String result = recept_.process(xml_request);
-
-	out.println(result);
-
-
-	
+	if (!output.equals("html")) {
+	    response.setContentType("text/xml"); // for now use text
+	}
+	// hopefully can get rid of following
+	if (action.equals("a")&&subaction.equals("r")) { // applet action
+	    response.setContentType("text/xml");
+	}
+    
+	Element xml_result = recept_.process(xml_message);
+	out.println(converter_.getString(xml_result));
     }
 }
