Index: main/trunk/greenstone3/src/java/org/greenstone/gsdl3/action/PageAction.java
===================================================================
--- main/trunk/greenstone3/src/java/org/greenstone/gsdl3/action/PageAction.java	(revision 32990)
+++ main/trunk/greenstone3/src/java/org/greenstone/gsdl3/action/PageAction.java	(revision 32991)
@@ -19,10 +19,12 @@
 public class PageAction extends Action
 {
-	static Logger logger = Logger.getLogger(org.greenstone.gsdl3.action.PageAction.class.getName());
-
-	public static final String HOME_PAGE = "home";
+  
+    static Logger logger = Logger.getLogger(org.greenstone.gsdl3.action.PageAction.class.getName());
+
+       	public static final String HOME_PAGE = "home";
 	public static final String ABOUT_PAGE = "about";
 	public static final String PREFS_PAGE = "pref";
 	public static final String GLI4GS3_PAGE = "gli4gs3";
+  public static final String VERIFY_PAGE = "verify";
 
   // this gets set to the groupInfo service name if there is one.
@@ -53,4 +55,5 @@
 			page_name = HOME_PAGE;
 		}
+
 		Element result = doc.createElement(GSXML.MESSAGE_ELEM);
 		Element response;
@@ -58,30 +61,17 @@
 		{
 		  response = homePage(request);
-			//} else if (page_name.equals(ABOUT_PAGE)) {
-		}
-		else if (page_name.equals(ABOUT_PAGE) || page_name.equals(PREFS_PAGE))
-		{
-		  response = aboutOrPrefsPage(request, page_name);
+			
 		}
 		else if (page_name.equals(GLI4GS3_PAGE))
 		{
 		  response = gli4gs3Page(request);
-		}
-		else
-		{ // unknown page
-		  response = unknownPage(request);
-		}
-
-		Element formatMessage = doc.createElement(GSXML.MESSAGE_ELEM);
-		Element formatRequest = GSXML.createBasicRequest(doc, GSXML.REQUEST_TYPE_FORMAT, collection, new UserContext(request));
-		formatMessage.appendChild(formatRequest);
-		Element formatResponseMessage = (Element) this.mr.process(formatMessage);
-		Element formatResponse = (Element) GSXML.getChildByTagName(formatResponseMessage, GSXML.RESPONSE_ELEM);
-
-		Element globalFormat = (Element) GSXML.getChildByTagName(formatResponse, GSXML.FORMAT_ELEM);
-		if (globalFormat != null)
-		{
-		  response.appendChild(response.getOwnerDocument().importNode(globalFormat, true));
-		}
+		} else 	if (collection.equals("")) {
+		  // we are not in a collection. eg could be library prefs or other page
+		  response = generalLibraryPage(request, page_name);
+		} else {
+		  // we are in a collection
+		  response = collectionPage(request, page_name, collection);
+		}
+		
 
 		result.appendChild(doc.importNode(response, true));
@@ -90,9 +80,99 @@
 		return result;
 	}
+
+  // A general library page just adds site metadata and interface options.
+  // customise: prefs: add language list
+  protected Element generalLibraryPage(Element request, String page_name) {
+
+    Document doc = XMLConverter.newDOM();
+    UserContext userContext = new UserContext(request);
+    Element response = doc.createElement(GSXML.RESPONSE_ELEM);
+    addSiteMetadata(response, userContext);
+    addInterfaceOptions(response);
+    if (page_name.equals(PREFS_PAGE) && this.language_list != null) {
+      response.appendChild(doc.importNode(this.language_list, true));
+    }
+    return response;
+  }
+
+  protected Element collectionPage(Element request, String page_name, String collection) {
+
+    Document doc = XMLConverter.newDOM();
+    
+    UserContext userContext = new UserContext(request);
+    // extract the params from the cgi-request, 
+    Element cgi_paramList = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
+    HashMap<String, Serializable> params = GSXML.extractParams(cgi_paramList, false);
+    
+    // get the collection or cluster description
+    Element coll_about_message = doc.createElement(GSXML.MESSAGE_ELEM);
+    
+    Element coll_about_request = GSXML.createBasicRequest(doc, GSXML.REQUEST_TYPE_DESCRIBE, collection, userContext);
+    coll_about_message.appendChild(coll_about_request);
+    
+    Element coll_about_response = (Element) this.mr.process(coll_about_message);
+    
+    Element response = (Element) GSXML.getChildByTagName(coll_about_response, GSXML.RESPONSE_ELEM);
+
+    if (response == null) {
+      // what should we be returning?
+      return null;
+    }
+    
+    //add the site metadata
+    addSiteMetadata(response, userContext);
+    addInterfaceOptions(response);
+
+    if (page_name.equals(PREFS_PAGE) && this.language_list != null) {
+      response.appendChild(response.getOwnerDocument().importNode(this.language_list, true));
+    }
+
+    // is this collection part of a group? 
+    String group = (String) params.get(GSParams.GROUP);
+    if (group != null && !group.equals("")) {
+      // ...yes it is. get the group path info
+      Element group_info_response = getGroupInfo(group, userContext); 
+      Element path_list = (Element) GSXML.getChildByTagName(group_info_response,
+							    GSXML.PATH_ELEM + GSXML.LIST_MODIFIER);
+      if (path_list != null) {
+	response.appendChild(response.getOwnerDocument().importNode(path_list, true));
+      }
+    }
+
+    if (page_name.equals(ABOUT_PAGE)) {
+      // get service descriptions. Actually only want displayItems
+      NodeList services = coll_about_response.getElementsByTagName(GSXML.SERVICE_ELEM);
+      if (services.getLength() > 0)
+	{
+	  sendMultipleRequests(doc, services, collection, GSXML.REQUEST_TYPE_DESCRIBE, userContext);
+	}
+
+    }
+    // old code had adding a ct param to the paramList - for about/prefs page, only used for gs2 interface. Since we don't support that anymore, am leaving it out.
+
+    // add the global collection format info
+    Element formatMessage = doc.createElement(GSXML.MESSAGE_ELEM);
+    Element formatRequest = GSXML.createBasicRequest(doc, GSXML.REQUEST_TYPE_FORMAT, collection, userContext);
+    formatMessage.appendChild(formatRequest);
+    Element formatResponseMessage = (Element) this.mr.process(formatMessage);
+    Element formatResponse = (Element) GSXML.getChildByTagName(formatResponseMessage, GSXML.RESPONSE_ELEM);
+    
+    Element globalFormat = (Element) GSXML.getChildByTagName(formatResponse, GSXML.FORMAT_ELEM);
+    if (globalFormat != null)
+      {
+	response.appendChild(response.getOwnerDocument().importNode(globalFormat, true));
+      }
+
+    if (page_name.equals(VERIFY_PAGE)) {
+      addSecurityInfo(request, collection, response);
+    }
+    
+    return response;
+  }
+
 
   protected Element homePage(Element request)
 	{
 	  Document doc = XMLConverter.newDOM();
-		
 
 		UserContext userContext = new UserContext(request);
@@ -151,5 +231,4 @@
 		
 		if (!this.groupInfoServiceName.equals("NO_GROUPS")) {
-
 		  String group = null;
 		  Element cgi_paramList = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
@@ -170,4 +249,6 @@
 		  if (collection_list != null) {
 		    info_response.appendChild(doc.importNode(collection_list, true));
+		  } else {
+		    logger.warn("Home page had no collection list");
 		  }
 		  Element group_list = (Element) GSXML.getChildByTagName(group_info_response,
@@ -211,5 +292,5 @@
 				sendMultipleRequests(doc, colls, null, GSXML.REQUEST_TYPE_DESCRIBE, userContext);
 			}
-		}
+		} 
 
 		// get metadata for any services
@@ -264,144 +345,26 @@
   }
   
-  protected Element aboutOrPrefsPage(Element request, String page_name)
-	{
-	  Document doc = XMLConverter.newDOM();
-		
-		UserContext userContext = new UserContext(request);
-		// extract the params from the cgi-request, 
-		Element cgi_paramList = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
-		HashMap<String, Serializable> params = GSXML.extractParams(cgi_paramList, false);
-
-		String coll_name = (String) params.get(GSParams.COLLECTION);
-		if (coll_name == null || coll_name.equals(""))
-		{
-		  // return a response with no collection info - must be prefs from home page
-			Element response = doc.createElement(GSXML.RESPONSE_ELEM);
-			addSiteMetadata(response, userContext);
-			addInterfaceOptions(response);
-			if (this.language_list != null) {
-			  response.appendChild(doc.importNode(this.language_list, true));
-			}
-			return response;
-		}
-
-		// get the collection or cluster description
-		Element coll_about_message = doc.createElement(GSXML.MESSAGE_ELEM);
-
-		Element coll_about_request = GSXML.createBasicRequest(doc, GSXML.REQUEST_TYPE_DESCRIBE, coll_name, userContext);
-		coll_about_message.appendChild(coll_about_request);
-		Element coll_about_response = (Element) this.mr.process(coll_about_message);
-
-		// add collection type attribute to paramList
-		String col_type = "";
-		NodeList collect_elem = coll_about_response.getElementsByTagName(GSXML.COLLECTION_ELEM);
-		if (collect_elem.getLength() != 0)
-		{
-			for (int i = 0; i < collect_elem.getLength(); i++)
-			{
-				Element e = (Element) collect_elem.item(i);
-				col_type = e.getAttribute(GSXML.TYPE_ATT);
-			}
-		}
-		else
-		{
-			logger.error(GSXML.COLLECTION_ELEM + " element is null");
-		}
-
-		// adding a ct param to paramlist. only needed for gs2 interface, not default
-		NodeList paramList_list = request.getElementsByTagName(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
-		if (paramList_list.getLength() != 0)
-		{
-			for (int i = 0; i < paramList_list.getLength(); i++)
-			{
-				Element e = (Element) paramList_list.item(i);
-				Element ct = GSXML.createParameter(request.getOwnerDocument(), GSParams.COLLECTION_TYPE, col_type.equalsIgnoreCase("mg") ? "0" : "1");
-				e.appendChild(ct);
-			}
-		}
-		else
-		{
-			logger.info("paramList is null!!");
-		}
-
-		if (coll_about_response == null)
-		{
-			return null;
-		}
-
-		// second, get the info for each service - we only want display items 
-		// but for now, we'll just get it all
-		NodeList services = coll_about_response.getElementsByTagName(GSXML.SERVICE_ELEM);
-		if (services.getLength() > 0)
-		{
-			sendMultipleRequests(doc, services, coll_name, GSXML.REQUEST_TYPE_DESCRIBE, userContext);
-		}
-
-		Element response = (Element) GSXML.getChildByTagName(coll_about_response, GSXML.RESPONSE_ELEM);
-
-		// is this collection part of a group? 
-		String group = (String) params.get(GSParams.GROUP);
-		if (group != null && !group.equals("")) {
-		  // ...yes it is. get the group path info
-		  Element group_info_response = getGroupInfo(group, userContext); 
-		  Element path_list = (Element) GSXML.getChildByTagName(group_info_response,
-									GSXML.PATH_ELEM + GSXML.LIST_MODIFIER);
-		  if (path_list != null) {
-		    response.appendChild(response.getOwnerDocument().importNode(path_list, true));
-		  }
-		}
-		
-		//add the site metadata
-		addSiteMetadata(response, userContext);
-		addInterfaceOptions(response);
-		if (page_name.equals(PREFS_PAGE) && this.language_list != null) {
-		  response.appendChild(response.getOwnerDocument().importNode(this.language_list, true));
-		}
-		return response;
-	}
-
-
-	/** if we dont know the page type, use this method */
-	protected Element unknownPage(Element request)
-	{
-	  Document doc = XMLConverter.newDOM();
-		
-		UserContext userContext = new UserContext(request);
-		String page_name = request.getAttribute(GSXML.SUBACTION_ATT);
-
-		// extract the params from the cgi-request, 
-		Element cgi_paramList = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
-		HashMap<String, Serializable> params = GSXML.extractParams(cgi_paramList, false);
-
-		String coll_name = (String) params.get(GSParams.COLLECTION);
-		if (coll_name == null || coll_name.equals(""))
-		{
-			// just return an empty response
-			Element response = doc.createElement(GSXML.RESPONSE_ELEM);
-			addSiteMetadata(response, userContext);
-			addInterfaceOptions(response);
-			return response;
-		}
-
-		// else get the coll description - actually this is the same as for the about page - should we merge these two methods??
-
-		// if there is a service specified should we get the service description instead??
-		// get the collection or cluster description
-		Element coll_about_message = doc.createElement(GSXML.MESSAGE_ELEM);
-
-		Element coll_about_request = GSXML.createBasicRequest(doc, GSXML.REQUEST_TYPE_DESCRIBE, coll_name, userContext);
-		coll_about_message.appendChild(coll_about_request);
-
-		Element coll_about_response = (Element) this.mr.process(coll_about_message);
-
-		Element response = (Element) GSXML.getChildByTagName(coll_about_response, GSXML.RESPONSE_ELEM);
-
-		//add the site metadata
-		addSiteMetadata(response, userContext);
-		addInterfaceOptions(response);
-
-		return response;
-
-	}
+
+  protected boolean addSecurityInfo(Element request, String collection, Element response) {
+    logger.error("in add security");
+    Document doc = XMLConverter.newDOM();
+    Element securityMessage = doc.createElement(GSXML.MESSAGE_ELEM);
+    Element securityRequest = GSXML.createBasicRequest(doc, GSXML.REQUEST_TYPE_SECURITY, collection, new UserContext(request));
+    securityMessage.appendChild(securityRequest);
+    
+    Element securityResponse = (Element) GSXML.getChildByTagName(this.mr.process(securityMessage), GSXML.RESPONSE_ELEM);
+    logger.error("security response = "+XMLConverter.getPrettyString(securityResponse));
+    
+    Document r_doc = response.getOwnerDocument();
+    // just get the top level node and attributes
+    // Element new_sec = (Element)r_doc.importNode(securityResponse, true); //createElement(GSXML.SECURITY_ELEMENT);
+    Element new_sec = GSXML.duplicateWithNewName(r_doc, securityResponse, "security", true);
+    // just in case this is present
+    new_sec.removeAttribute("secretKey");
+    logger.error("new security element = "+XMLConverter.getPrettyString(new_sec));
+    response.appendChild(new_sec);
+    return true;
+    
+  }
 
 	protected boolean sendMultipleRequests(Document doc, NodeList items, String path_prefix, String request_type, UserContext userContext)
