Index: trunk/gsdl3/src/java/org/greenstone/gsdl3/action/PageAction.java
===================================================================
--- trunk/gsdl3/src/java/org/greenstone/gsdl3/action/PageAction.java	(revision 6300)
+++ trunk/gsdl3/src/java/org/greenstone/gsdl3/action/PageAction.java	(revision 11230)
@@ -50,51 +50,49 @@
 	String uid = request.getAttribute(GSXML.USER_ID_ATT);
 	// first, get the message router info
-	Element coll_list_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
+	Element info_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
 	Element coll_list_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_DESCRIBE, "", lang, uid);
-	coll_list_message.appendChild(coll_list_request);
-	Element coll_list_response = (Element)this.mr.process(coll_list_message);
-	if (coll_list_response==null) {
+	info_message.appendChild(coll_list_request);
+	Element info_response_message = (Element)this.mr.process(info_message);
+	if (info_response_message==null) {
 	    System.err.println("PageAction Error: couldn't query the message router!");
 	    return null;
 	}
-	
+	Element info_response = (Element)GSXML.getChildByTagName(info_response_message, GSXML.RESPONSE_ELEM);
+	if (info_response==null) {
+	    System.err.println("PageAction Error: couldn't query the message router!");
+	    return null;
+	}
+	    
 	// second, get the metadata for each collection - we only want specific
 	// elements but for now, we'll just get it all
-	NodeList colls = coll_list_response.getElementsByTagName(GSXML.COLLECTION_ELEM);
-	// we will send all the requests in a single message
-	Element metadata_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
-	for (int i=0; i<colls.getLength(); i++) {
-	    Element c = (Element)colls.item(i);
-	    String name = c.getAttribute(GSXML.NAME_ATT);	    
-	    
-	    Element metadata_request = GSXML.createBasicRequest(this.doc,  GSXML.REQUEST_TYPE_DESCRIBE, name, lang, uid);
-	    metadata_message.appendChild(metadata_request);
-	}
-
-	Element metadata_response = (Element)this.mr.process(metadata_message);
-
-	NodeList coll_responses = metadata_response.getElementsByTagName(GSXML.RESPONSE_ELEM);
-	// check that have same number of responses as collections
-	if (colls.getLength() != coll_responses.getLength()) {
-	    System.err.println("PageAction Error: didn't get a response for each collection - somethings gone wrong!");
-	    // for now, dont use the metadata
-	} else {
-	    for (int i=0; i<colls.getLength(); i++) {
-		Element c1 = (Element)colls.item(i);
-		Element c2 = (Element)coll_responses.item(i);
-		if (c1.getAttribute(GSXML.NAME_ATT).equals(c2.getAttribute(GSXML.FROM_ATT))) {
-		    //add the collection data into the original response
-		    GSXML.mergeElements(c1, (Element)GSXML.getChildByTagName(c2, GSXML.COLLECTION_ELEM));
-		} else {
-		    System.err.println("PageAction Error: response does not correspond to request!");
-		} 
+	Element collection_list = (Element)GSXML.getChildByTagName(info_response, GSXML.COLLECTION_ELEM+GSXML.LIST_MODIFIER);
+	if (collection_list != null) {
+	    NodeList colls = GSXML.getChildrenByTagName(collection_list, GSXML.COLLECTION_ELEM);
+	    if (colls.getLength()>0) {
+		sendMultipleRequests(colls, null, GSXML.REQUEST_TYPE_DESCRIBE, lang, uid);
+	    }
+	}
+
+	// get metadata for any services
+	Element service_list = (Element)GSXML.getChildByTagName(info_response, GSXML.SERVICE_ELEM+GSXML.LIST_MODIFIER);
+	if (service_list != null) {
+	    NodeList services = GSXML.getChildrenByTagName(service_list, GSXML.SERVICE_ELEM);
+	    if (services.getLength() > 0) {
+		sendMultipleRequests(services, null, GSXML.REQUEST_TYPE_DESCRIBE, lang, uid);
+	    }
+	}
+
+	// get metadata for service clusters
+	Element cluster_list = (Element)GSXML.getChildByTagName(info_response, GSXML.CLUSTER_ELEM+GSXML.LIST_MODIFIER);
+	if (cluster_list != null) {
+	    NodeList clusters = GSXML.getChildrenByTagName(cluster_list, GSXML.CLUSTER_ELEM);
+	    if (clusters.getLength() > 0) {
+		sendMultipleRequests(clusters, null, GSXML.REQUEST_TYPE_DESCRIBE, lang, uid);
 		
 	    }
 	}
 	
-	//now the full response message is in coll_list_response
-	// return the response element
-	Element response = (Element) GSXML.getChildByTagName(coll_list_response, GSXML.RESPONSE_ELEM);
-	return response;
+	// all the components have been merged into info_response
+	return info_response;
 	
     } // homePage
@@ -130,37 +128,8 @@
 	// but for now, we'll just get it all
 	NodeList services = coll_about_response.getElementsByTagName(GSXML.SERVICE_ELEM);
-	// we will send all the requests in a single message
-	Element info_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
-	for (int i=0; i<services.getLength(); i++) {
-	    Element c = (Element)services.item(i);
-	    String name = c.getAttribute(GSXML.NAME_ATT);
-	    String address = GSPath.appendLink(coll_name, name);
-	    Element info_request = GSXML.createBasicRequest(this.doc,  GSXML.REQUEST_TYPE_DESCRIBE, address, lang, uid);
-	    info_message.appendChild(info_request);
-	}
-
-	Element info_response = (Element)this.mr.process(info_message);
-
-	NodeList service_responses = info_response.getElementsByTagName(GSXML.RESPONSE_ELEM);
-	// check that have same number of responses as collections
-	if (services.getLength() != service_responses.getLength()) {
-	    System.err.println("PageAction Error: didn't get a response for each service - somethings gone wrong!");
-	    // for now, dont use the metadata
-	} else {
-	    for (int i=0; i<services.getLength(); i++) {
-		Element c1 = (Element)services.item(i);
-		Element c2 = (Element)GSXML.getChildByTagName((Element)service_responses.item(i), GSXML.SERVICE_ELEM);
-		if (c1.getAttribute(GSXML.NAME_ATT).equals(c2.getAttribute(GSXML.NAME_ATT))) {
-		    //add the service data into the original response
-		    GSXML.mergeElements(c1, c2);
-		} else {
-		    System.err.println("PageAction Error: response does not correspond to request!");
-		} 
-		
-	    }
-	}
-	
-	//now the full response message is in coll_list_response
-	// return the response element
+	if (services.getLength() > 0) {
+	    sendMultipleRequests(services, coll_name, GSXML.REQUEST_TYPE_DESCRIBE, lang, uid);
+	}
+	
 	Element response = (Element) GSXML.getChildByTagName(coll_about_response, GSXML.RESPONSE_ELEM);
 	return response;
@@ -200,8 +169,47 @@
 	Element coll_about_response = (Element)this.mr.process(coll_about_message);
 
-	// add the response to the page get teh response element and return it
 	Element response = (Element) GSXML.getChildByTagName(coll_about_response, GSXML.RESPONSE_ELEM);
 	return response;
 	
     }
+
+
+    protected boolean sendMultipleRequests(NodeList items, String path_prefix, String request_type, String lang, String uid) {
+
+	// we will send all the requests in a single message
+	Element message = this.doc.createElement(GSXML.MESSAGE_ELEM);
+	for (int i=0; i<items.getLength(); i++) {
+	    Element c = (Element)items.item(i);
+	    String path = c.getAttribute(GSXML.NAME_ATT);	    
+	    if (path_prefix != null) {
+		path = GSPath.appendLink(path_prefix, path);
+	    }
+	    Element request = GSXML.createBasicRequest(this.doc, request_type, path, lang, uid);
+	    message.appendChild(request);
+	}
+	
+	Element response_message = (Element)this.mr.process(message);
+	    
+	NodeList responses = response_message.getElementsByTagName(GSXML.RESPONSE_ELEM);
+	// check that have same number of responses as requests
+	if (items.getLength() != responses.getLength()) {
+	    System.err.println("PageAction Error: didn't get a response for each request - somethings gone wrong!");
+	    return false;
+	} 
+	
+	for (int i=0; i<items.getLength(); i++) {
+	    Element c1 = (Element)items.item(i);
+	    Element c2 = (Element)GSXML.getChildByTagName((Element)responses.item(i), c1.getTagName());
+	    if (c1.getAttribute(GSXML.NAME_ATT).equals(c2.getAttribute(GSXML.NAME_ATT))) {
+		//add the new data into the original element
+		GSXML.mergeElements(c1, c2);
+	    } else {
+		System.err.println("PageAction Error: response does not correspond to request!");
+	    } 
+	    
+	}
+	
+	return true;
+    
+    }
 }
