Index: trunk/gsdl3/src/java/org/greenstone/gsdl3/core/Receptionist.java
===================================================================
--- trunk/gsdl3/src/java/org/greenstone/gsdl3/core/Receptionist.java	(revision 3512)
+++ trunk/gsdl3/src/java/org/greenstone/gsdl3/core/Receptionist.java	(revision 3570)
@@ -12,5 +12,12 @@
 import java.io.File;
 import java.util.HashMap;
-
+import java.util.Enumeration;
+
+/** core class for web interface generation. Receives requests consisting
+ * of an xml representation of cgi args, and returns the page of data - in 
+ * html by default. The requests are processed by the appropriate action class
+ *
+ * @see Action
+ */
 public class Receptionist implements ModuleInterface {
 
@@ -23,8 +30,9 @@
     /** container Document to create XML Nodes */
     protected Document doc_=null; 
+   
     /** a converter class to parse XML and create Docs */
     protected XMLConverter converter_=null;
 
-    /** the message router that it talks to */
+    /** the message router that the actions will talk to */
     protected ModuleInterface mr_=null;
 
@@ -32,10 +40,8 @@
     protected HashMap action_map_=null;
 
-    protected Translate translation_=null;
     public Receptionist() {
 	converter_ = new XMLConverter();
 	doc_ = converter_.newDOM();
 	action_map_= new HashMap();
-	translation_ = new Translate();
 	cgi_ = new CGIArgConverter();
     }
@@ -44,6 +50,6 @@
     public void setConfigVars(ConfigVars config) {
 	config_ = config;
-	translation_.setConfigVars(config);
-    }
+    }
+
     /** sets the message router  - it should already be created and 
      * configured before  being passed to the receptionist*/
@@ -52,20 +58,19 @@
     }
 
+    /** configures the receptionist */
     public boolean configure() {
 
 	if (config_==null) {
-	    System.err.println("You must set the config variables before calling configure");
+	    System.err.println("Receptionist Error: config variables must be set before calling configure");
 	    return false;
 	}
 	if (mr_==null) {	   
-	    System.err.println("You must set  the mr  before calling configure");
+	    System.err.println("Receptionist Error: message router must be set  before calling configure");
 	    return false;
 	}
 
-	// for now, assume default is en, so load that
-	translation_.setDefaultLanguage("en");
-	// for now, just statically add in the actions
-	// actions may disappear if xslt is all that is needed
-	// or they should be dynamically loaded
+	// add in the default actions - others can be dynamically 
+	// loaded as needed
+	// if you want an action to have a short name it needs to go here
 	Action a = new PageAction();
 	a.setConfigVars(config_);
@@ -82,10 +87,10 @@
 	action_map_.put("q", a);
 
-	a = new BrowseAction();
-	a.setConfigVars(config_);
-	a.setCGIConverter(cgi_);
-	a.setMessageRouter(mr_);
-	a.configure();
-	action_map_.put("b", a);
+  	a = new BrowseAction();
+  	a.setConfigVars(config_);
+  	a.setCGIConverter(cgi_);
+  	a.setMessageRouter(mr_);
+  	a.configure();
+  	action_map_.put("b", a);
 
 	a = new ResourceAction();
@@ -102,34 +107,53 @@
 	a.configure();
 	action_map_.put("a", a);
+
+
 	return true;
     }
-
+    /** process using strings - just calls process using Elements */
     public String process(String xml_in) {
 
-	Document message_doc = converter_.getDOM(xml_in);
-	Element message = message_doc.getDocumentElement();
-	// there should only be one request per message
+	Element message = converter_.getDOM(xml_in).getDocumentElement();
+	Element page = process(message);
+	return converter_.getString(page);
+    }
+
+    /** process - produce a page of data in response to a request 
+     * if something goes wrong, it returns null - 
+     * TODO:  return a suitable message to the user */
+    public Element process(Element message) {
+
+	// get the request out of the message - assume that there is only one
 	Element request = (Element)GSXML.getChildByTagName(message, GSXML.REQUEST_ELEM);
 	if (request == null) {
-	    return GSHTML.errorPage("no request in the message");
-	}
-
+	    System.err.println("Receptionist Error: message had no request!");
+	    return null; 
+	}
+	// check that the request type is correct
 	String type = request.getAttribute(GSXML.TYPE_ATT); // returns "" if no att of this name
 	if (!type.equals(GSXML.REQUEST_TYPE_ACTION)) {
-	    return GSHTML.errorPage("wrong type in request - should be action");
+	    System.err.println("Receptionist Error: request type should be '"+GSXML.REQUEST_TYPE_ACTION+"', but it was '"+type+"'!");
+	    return null;
 	}	
-
+	// work out which action to pass to
 	String action = request.getAttribute(GSXML.ACTION_ATT);
 	if (action.equals("")) {
-	    return GSHTML.errorPage(" no action specified");
-	}
-	// pass to appropriate action
+	    System.err.println("Receptionist Error: no action specified in the request!");
+	    return null;
+	}
+	// convert cgi short names to long names in the param list
+	Element param_list = (Element)GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
+	if (!cgi_.toLong(param_list)) {
+	    System.err.println("Receptionist Error: couldn't convert short names to long names in the param list!");
+	    return null;
+	}
 	
+	// pass request to appropriate action	
 	Action a = (Action)action_map_.get(action);
-	if (a==null) {
+	String action_name=null;
+	if (a==null) { // not in the map yet
 	    // try to load a new action
 	    try {
-		String action_name = action.substring(0,1).toUpperCase()+action.substring(1)+"Action";
-		System.out.println("new action name="+action_name);
+		action_name = action.substring(0,1).toUpperCase()+action.substring(1)+"Action";
 		Action ac = (Action)Class.forName("org.greenstone.gsdl3.action."+action_name).newInstance();
 		ac.setConfigVars(config_);
@@ -141,25 +165,41 @@
 	    } catch (Exception e) {
 		
-		return GSHTML.errorPage("no action for "+action+", and couldn't create a new one: error message:"+e.getMessage());
+		System.err.println("Receptionist Error: a new action ("+action_name+") was specified and it couldn't be created. Error message:"+e.getMessage());
+		return null;
 	    }
 	}
 
-	// add in the translation bit - should we do it here? or give the actions access to the translation object?
-	String lang = message.getAttribute(GSXML.LANG_ATT);
-	Element trans = translation_.getLanguageTree(lang);
-	message.appendChild(message_doc.importNode(trans, true));
-
-	// add in the system vars bit
+	// add in the  system stuff - display and config
+	Document message_doc = message.getOwnerDocument();
+	String lang = request.getAttribute(GSXML.LANG_ATT);
+	Element display = getDisplayElement(lang);
+	message.appendChild(message_doc.importNode(display, true));
 	message.appendChild(message_doc.importNode(config_.config_xml_, true));
 
-	String page = a.process(message);
+	Element page = a.process(message);
 	return page;
-    }
-
-    public Element process(Element xml_in) {
-	return xml_in; // for now
-
-    }
-
+	
+    }
+
+    /** returns an xml element containing all the text strings 
+     * needed for an interface 
+     * currenlty only uses the current interface - should add in 
+     * needed ones from the default interface if current != default */
+    protected Element getDisplayElement(String lang) {
+
+	Element display = doc_.createElement(GSXML.DISPLAY_ELEM);
+	// looks for properties files based on interface name
+	String resource_name = "interface_"+config_.interface_name_;
+
+	Dictionary dict = new Dictionary(resource_name, lang);
+	Enumeration enum = dict.getKeys();
+	while (enum.hasMoreElements()) {
+	    String key = (String)enum.nextElement();
+	    String value = dict.get(key);
+	    Element e = GSXML.createTextElement(doc_, key, value);
+	    display.appendChild(e);
+	}
+	return display;
+    }
 
 }
