Index: /trunk/gsdl3/src/java/org/greenstone/gsdl3/action/DocumentAction.java
===================================================================
--- /trunk/gsdl3/src/java/org/greenstone/gsdl3/action/DocumentAction.java	(revision 5693)
+++ /trunk/gsdl3/src/java/org/greenstone/gsdl3/action/DocumentAction.java	(revision 5694)
@@ -87,4 +87,21 @@
 	    document_name = document_name+"."+sibling_num+".ss";
 	}
+	
+	boolean expand_document = false;
+	String ed_arg = (String) params.get(GSParams.EXPAND_DOCUMENT);
+	if (ed_arg != null && ed_arg.equals("1")) {
+	    expand_document = true;
+	}
+       
+
+	boolean expand_contents = false;
+	if (expand_document) { // we always expand the contents with the text
+	    expand_contents = true;
+	} else {
+	    String ec_arg = (String) params.get(GSParams.EXPAND_CONTENTS);
+	    if (ec_arg != null && ec_arg.equals("1")) {
+		expand_contents = true;
+	    }
+	}
 	// get the additional data needed for the page
 	getBackgroundData(page_response, collection, lang);
@@ -129,18 +146,25 @@
 	} else if (document_type.equals("hierarchy")){
 	    get_structure = true;
-	    // get the info needed for table of contents
-	    ds_param = this.doc.createElement(GSXML.PARAM_ELEM);
-	    ds_param_list.appendChild(ds_param);
-	    ds_param.setAttribute(GSXML.NAME_ATT, "structure");
-	    ds_param.setAttribute(GSXML.VALUE_ATT, "ancestors");
-	    ds_param = this.doc.createElement(GSXML.PARAM_ELEM);
-	    ds_param_list.appendChild(ds_param);
-	    ds_param.setAttribute(GSXML.NAME_ATT, "structure");
-	    ds_param.setAttribute(GSXML.VALUE_ATT, "children");
-	    if (get_siblings) {
+	    if (expand_contents) {
 		ds_param = this.doc.createElement(GSXML.PARAM_ELEM);
 		ds_param_list.appendChild(ds_param);
 		ds_param.setAttribute(GSXML.NAME_ATT, "structure");
-		ds_param.setAttribute(GSXML.VALUE_ATT, "siblings");
+		ds_param.setAttribute(GSXML.VALUE_ATT, "entire");
+	    } else {
+		// get the info needed for table of contents
+		ds_param = this.doc.createElement(GSXML.PARAM_ELEM);
+		ds_param_list.appendChild(ds_param);
+		ds_param.setAttribute(GSXML.NAME_ATT, "structure");
+		ds_param.setAttribute(GSXML.VALUE_ATT, "ancestors");
+		ds_param = this.doc.createElement(GSXML.PARAM_ELEM);
+		ds_param_list.appendChild(ds_param);
+		ds_param.setAttribute(GSXML.NAME_ATT, "structure");
+		ds_param.setAttribute(GSXML.VALUE_ATT, "children");
+		if (get_siblings) {
+		    ds_param = this.doc.createElement(GSXML.PARAM_ELEM);
+		    ds_param_list.appendChild(ds_param);
+		    ds_param.setAttribute(GSXML.NAME_ATT, "structure");
+		    ds_param.setAttribute(GSXML.VALUE_ATT, "siblings");
+		}
 	    }
 	} else {
@@ -280,20 +304,36 @@
 	dc_request.appendChild(dc_param_list);
 
-	// the doc list for the content request is the same as the one for the structure request
-	dc_request.appendChild(basic_doc_list);
-
+	// the doc list for the content request is the same as the one for the structure request unless we want the whole document, in which case its the same as for the metadata request.
+	if (expand_document) {
+	    dc_request.appendChild(dm_doc_list);
+	} else {
+	    dc_request.appendChild(basic_doc_list);
+	}
 	Element dc_response_message = (Element) this.mr.process(dc_message);
-	path = GSPath.appendLink(path, GSXML.DOC_NODE_ELEM);
-	Element dc_response_doc = (Element) GSXML.getNodeByPath(dc_response_message, path);
-	Element dc_response_doc_content = (Element) GSXML.getChildByTagName(dc_response_doc, GSXML.NODE_CONTENT_ELEM);
+	Element dc_response_doc_list = (Element) GSXML.getNodeByPath(dc_response_message, path);
+
+	if (expand_document) {
+	    // Merge the content with the structure information
+	    NodeList dc_response_docs = dc_response_doc_list.getChildNodes();
+	    for (int i = 0; i < doc_nodes.getLength(); i++) {
+		doc_nodes.item(i).appendChild(this.doc.importNode(GSXML.getChildByTagName((Element)dc_response_docs.item(i), "nodeContent"), true));
+		//GSXML.mergeMetadataLists(doc_nodes.item(i), dm_response_docs.item(i));
+	    }
+	} else {
+	    
+	    //path = GSPath.appendLink(path, GSXML.DOC_NODE_ELEM);
+	    Element dc_response_doc = (Element) GSXML.getChildByTagName(dc_response_doc_list, GSXML.DOC_NODE_ELEM);
+	    Element dc_response_doc_content = (Element) GSXML.getChildByTagName(dc_response_doc, GSXML.NODE_CONTENT_ELEM);
 	
 		    
-	boolean highlight_query_terms = true;
-	if (highlight_query_terms) {
-	    dc_response_doc.removeChild(dc_response_doc_content);
-	    
-	    dc_response_doc_content = highlightQueryTerms(request, dc_response_doc_content);
-	    dc_response_doc.appendChild(dc_response_doc.getOwnerDocument().importNode(dc_response_doc_content, true));
-	}
+	    boolean highlight_query_terms = true;
+	    if (highlight_query_terms) {
+		dc_response_doc.removeChild(dc_response_doc_content);
+	    
+		dc_response_doc_content = highlightQueryTerms(request, dc_response_doc_content);
+		dc_response_doc.appendChild(dc_response_doc.getOwnerDocument().importNode(dc_response_doc_content, true));
+	    }
+	    
+	/*
 	if (provide_annotations) {
 	    String service_selected = (String)params.get(ENRICH_DOC_ARG);
@@ -323,4 +363,6 @@
 	    } 
 	}
+
+	*/
 	// use the returned id rather than the sent one cos there may have
 	// been modifiers such as .pr that are removed.
@@ -357,5 +399,5 @@
 	    }
 	}
-
+	}
 	///ystem.out.println("(DocumentAction) Page:\n" + this.converter.getPrettyString(result));
 	return result;
@@ -383,5 +425,5 @@
 	// these could all be cached
 	Element info_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
-	String path = GSPath.appendLink(collection, "DocumentMetadataRetrieve");
+	String path = GSPath.appendLink(collection, "DocumentContentRetrieve");
 	// the format request - ignore for now, where does this request go to??
 	Element format_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_FORMAT, path, lang);
