Index: /trunk/gsdl3/src/java/org/greenstone/gsdl3/LibraryServlet.java
===================================================================
--- /trunk/gsdl3/src/java/org/greenstone/gsdl3/LibraryServlet.java	(revision 3345)
+++ /trunk/gsdl3/src/java/org/greenstone/gsdl3/LibraryServlet.java	(revision 3346)
@@ -7,34 +7,58 @@
 import javax.servlet.*;
 import javax.servlet.http.*;
+import java.util.Enumeration;
+import java.io.File;
 
 /** a servlet to serve the greenstone library - using servlets instead
  * of cgi
+ * the init method is called only once - the first time the servlet classes
+ * are loaded. Each time a request comes in to the servlet, the session()
+ * method is called in a new thread (calls doGet/doPut etc)
+ * takes the a=p&p=home type args and builds a simple request to send to 
+ * its receptionist, which returns the result in html, cos output=html
+ * is set in the request
+ * @see Receptionist
  */
 public class LibraryServlet extends HttpServlet {
     
-    private String gsdl_home_;
-    private String site_home_;
-    private MessageRouter mr_=null;
-
+    private ConfigVars config_=null; // holds all teh system set up vars
+    private Receptionist recept_=null;
+    private ModuleInterface message_router_=null;
+    /** initialise the servlet
+     */
     public void init(ServletConfig config) throws ServletException {
 	// always call super.init;
 	super.init(config);
-	gsdl_home_ = config.getInitParameter("gsdlhome");
-	if (gsdl_home_ == null) {
+
+	config_ = new ConfigVars();
+	String sites_home_ = config.getInitParameter("siteshome");
+	String site_name_ = config.getInitParameter("sitename");
+	String interfaces_home_ = config.getInitParameter("interfaceshome");
+	String interface_name_ = config.getInitParameter("interfacename");
+	if (sites_home_ == null || site_name_==null || interfaces_home_ ==null || interface_name_==null) {
 	    // must have this
-	    System.err.println("gsdlhome not set!");
-	    System.exit(1);
-	}
-	site_home_ = config.getInitParameter("sitehome");
-	if (site_home_ == null) {
-	    // must have this
-	    System.err.println("sitehome not set!");
+	    System.err.println("initialisation parameters not all set!");
+	    System.err.println(" you must have siteshome, sitename, interfaceshome, interfacename");
 	    System.exit(1);
 	}
 
-	// new message router
-	mr_ = new MessageRouter();
-	mr_.setSiteHome(site_home_);
-	mr_.configure();
+	config_.sites_home_ = sites_home_;
+	config_.site_name_ = site_name_;
+	config_.interfaces_home_ = interfaces_home_;
+	config_.interface_name_ =interface_name_;
+
+	config_.createXML();
+	
+	// new message router - create it and pass a handle to recept.
+	// the servlet wont use this directly
+	MessageRouter mr = new MessageRouter();
+	mr.setSiteHome(config_.sites_home_+File.separatorChar
+		       +config_.site_name_);
+	mr.configure();
+	// new receptionist
+	recept_ = new Receptionist();
+	recept_.setConfigVars(config_);
+	recept_.setMessageRouter(mr);
+	recept_.configure();
 
     }
@@ -46,30 +70,45 @@
 	response.setContentType("text/html");
 	PrintWriter out = response.getWriter();
-	
+
+	String lang = request.getParameter("l");
+	if (lang==null || lang.equals("")) {
+	    lang = "en"; // the default
+	}
+	// the request to the receptionist	
+	String xml_request="<message lang='"+lang+"'>";
+
 	String action = request.getParameter("a");
 	if (action==null || action.equals("")) {
-	    // the home page
-	    
-	    //String describe = "<message><request type='describe' info='collectionList'/></message>";
-	    //String result = mr_.process(describe);
-	    
+	    // display the home page
+	    // a=p&p=home
+	    xml_request +="<request type='action' output='html' info='p/home'/>";
+	} else {
+	    String subaction = request.getParameter("sa");
+	    xml_request += "<request type='action' info='"+action;
+	    if (subaction != null) {
+		xml_request += "/"+subaction;
+	    }
+	    xml_request += "'><paramList>";
+	    Enumeration params = request.getParameterNames();
+	    while(params.hasMoreElements()) {
+		String name = (String)params.nextElement();
+		if (!name.equals("a") && !name.equals("sa")) {
+		    String value = request.getParameter(name);
+		// for now, just add value as attribute - should un-url 
+		    // encode them etc and so some might need to be text not atts
+		    // or is that done already?
+		    xml_request += "<param name='"+name+"' value='"+value+"'/>";
+		}
+	    }
+	    xml_request += "</paramList></request>";
+	}
+	xml_request += "</message>";
 
-	    //try a transform - hard coded result to test the stylesheet
-	    String result = "<message><collectionList><collection name='mycol'><metadata name='icon'>logo.gif</metadata><metadata name='title'>my collection</metadata></collection><collection name='demo'><metadata name='icon'>fao.gif</metadata><metadata name='title'>mg demo</metadata></collection><collection name='mgppdemo'><metadata name='icon'>demo.gif</metadata><metadata name='title'>mgpp demo</metadata></collection></collectionList></message>";
+	System.out.println("request="+xml_request);
 
-	    XMLTransformer transformer = new XMLTransformer();
-	    String stylesheet = "/research/kjdon/home/gsdl3/transform/home.xsl";
-	    String transformed_result = transformer.transform(stylesheet, result);
-	    out.println(transformed_result);
-	}
-	else {
-	    // do the appropriate action
-	    out.println("<html>\n"+
-			"<head><title>Hello Greenstone Library</title></head>"+
-			"<body>\n"+
-			"<p>greenstone action:"+action+"</p>\n"+
-			"</body></html>");
-			
-	}
+	String result = recept_.process(xml_request);
+	out.println(result);
+
+
 	
     }
