Index: /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/action/DocumentAction.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/action/DocumentAction.java	(revision 25815)
+++ /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/action/DocumentAction.java	(revision 25816)
@@ -74,6 +74,5 @@
 			provide_annotations = true;
 		}
-		return true;
-	}
+		return true;	}
 
 	public Node process(Node message_node)
@@ -120,7 +119,8 @@
 		}
 		String document_type = (String) params.get(GSParams.DOCUMENT_TYPE);
-		if (document_type == null || document_type.equals(""))
-		{
-			document_type = "hierarchy";
+		if (document_type != null && document_type.equals(""))
+		{
+		  //document_type = "hierarchy";
+		  document_type = null; // we'll get it later if not already specified
 		}
 		//whether to retrieve siblings or not
@@ -175,7 +175,4 @@
 		Element the_document = this.doc.createElement(GSXML.DOCUMENT_ELEM);
 		page_response.appendChild(the_document);
-
-		// set the doctype from the cgi arg as an attribute
-		the_document.setAttribute(GSXML.DOC_TYPE_ATT, document_type);
 
 		// create a basic doc list containing the current node
@@ -193,4 +190,17 @@
 			current_doc.setAttribute(GSXML.ID_MOD_ATT, doc_id_modifier);
 		}
+
+		if (document_type == null) {
+		  logger.error("getting document type");
+		  document_type = getDocumentType(basic_doc_list, collection, userContext, page_response);
+		  logger.error("new doc type = "+document_type);
+		}
+		if (document_type != null) {
+		  // set the doctype from the cgi arg or from the server as an attribute
+		  the_document.setAttribute(GSXML.DOC_TYPE_ATT, document_type);
+		}
+		else {
+		  logger.error("doctype is null!!!***********");
+	}
 
 		// Create a parameter list to specify the required structure information
@@ -286,5 +296,5 @@
 			ds_request.appendChild(ds_param_list);
 
-			// create a doc_node_list and put in the doc_node that we are interested in
+			// add the node list we created earlier
 			ds_request.appendChild(basic_doc_list);
 
@@ -679,5 +689,4 @@
 			// a new message for the mr
 			Element enrich_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
-
 			NodeList e_services = services_resp.getElementsByTagName(GSXML.SERVICE_ELEM);
 			boolean service_found = false;
@@ -710,4 +719,44 @@
 
 	}
+
+  protected String getDocumentType(Element basic_doc_list, String collection, UserContext userContext, Element page_response) 
+  {
+    
+    Element ds_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
+    String to = GSPath.appendLink(collection, "DocumentStructureRetrieve");// Hard-wired?
+    Element ds_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_PROCESS, to, userContext);
+    ds_message.appendChild(ds_request);
+
+    // Create a parameter list to specify the required structure information
+    Element ds_param_list = this.doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
+    Element ds_param = this.doc.createElement(GSXML.PARAM_ELEM);
+    ds_param_list.appendChild(ds_param);
+    ds_param.setAttribute(GSXML.NAME_ATT, "info");
+    ds_param.setAttribute(GSXML.VALUE_ATT, "documentType");
+    
+    ds_request.appendChild(ds_param_list);
+    
+    // add the node list we created earlier
+    ds_request.appendChild(basic_doc_list);
+    
+    logger.error("doctype request = "+this.converter.getPrettyString(ds_request));
+    // Process the document structure retrieve message
+    Element ds_response_message = (Element) this.mr.process(ds_message);
+    logger.error("doctype response = "+this.converter.getPrettyString(ds_response_message));
+    if (processErrorElements(ds_response_message, page_response))
+      {
+	return null;
+      }
+
+    String[] links = { GSXML.RESPONSE_ELEM, GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER, GSXML.DOC_NODE_ELEM, "nodeStructureInfo"};
+    String path = GSPath.createPath(links);
+    Element info_elem = (Element) GSXML.getNodeByPath(ds_response_message, path);
+      Element doctype_elem = GSXML.getNamedElement(info_elem, "info", "name", "documentType");
+    if (doctype_elem != null) {
+      String doc_type = doctype_elem.getAttribute("value");
+      return doc_type;
+    }
+    return null;
+  }
 
 	/**
