Index: main/trunk/greenstone3/src/java/org/greenstone/gsdl3/action/DocumentAction.java
===================================================================
--- main/trunk/greenstone3/src/java/org/greenstone/gsdl3/action/DocumentAction.java	(revision 36977)
+++ main/trunk/greenstone3/src/java/org/greenstone/gsdl3/action/DocumentAction.java	(revision 36978)
@@ -21,4 +21,6 @@
 // Greenstone classes
 import org.greenstone.gsdl3.core.ModuleInterface;
+import org.greenstone.gsdl3.service.AbstractDocumentRetrieve;
+import org.greenstone.gsdl3.service.DocXMLUtil;
 import org.greenstone.gsdl3.util.*;
 import org.greenstone.util.GlobalProperties;
@@ -125,4 +127,13 @@
 			return result;
 		}
+                
+		String doc_id_modifier = "";
+		String sibling_num = (String) params.get(GOTO_PAGE_ARG);
+		if (sibling_num != null && !sibling_num.equals(""))
+		{
+			// we have to modify the doc name
+			doc_id_modifier = "." + sibling_num + ".ss";
+		}
+
 
 		UserContext userContext = new UserContext(request);
@@ -134,4 +145,29 @@
 		// get the additional data needed for the page
 		getBackgroundData(page_response, collection, userContext);
+
+                // create a basic doc list containing the current node
+                // we will use this to query whether the id is valid, and to get document type
+		Element basic_doc_list = doc.createElement(GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER);
+		Element current_doc = doc.createElement(GSXML.DOC_NODE_ELEM);
+		basic_doc_list.appendChild(current_doc);
+		if (document_id != null)
+		{
+			current_doc.setAttribute(GSXML.NODE_ID_ATT, document_id + doc_id_modifier);
+		}
+		else
+		{
+			current_doc.setAttribute(GSXML.HREF_ID_ATT, href);
+			// do we need this??
+			current_doc.setAttribute(GSXML.ID_MOD_ATT, doc_id_modifier);
+		}
+
+                // lets do a quick check here for valid doc id.
+                if (document_id != null) {
+                  boolean is_valid = checkValidOID(basic_doc_list, collection, userContext, page_response );
+                  if (!is_valid) {
+                    GSXML.addError(page_response, "Invalid doc id ("+document_id+")", GSXML.ERROR_TYPE_INVALID_ID);
+                    return result;
+                  }
+                }
 		Element format_elem = (Element) GSXML.getChildByTagName(page_response, GSXML.FORMAT_ELEM);
 
@@ -180,12 +216,4 @@
 		}
 
-		String doc_id_modifier = "";
-		String sibling_num = (String) params.get(GOTO_PAGE_ARG);
-		if (sibling_num != null && !sibling_num.equals(""))
-		{
-			// we have to modify the doc name
-			doc_id_modifier = "." + sibling_num + ".ss";
-		}
-
 		boolean expand_document = false;
 		String ed_arg = (String) params.get(EXPAND_DOCUMENT_ARG);
@@ -226,19 +254,5 @@
 		page_response.appendChild(the_document);
 
-		// create a basic doc list containing the current node
-		Element basic_doc_list = doc.createElement(GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER);
-		Element current_doc = doc.createElement(GSXML.DOC_NODE_ELEM);
-		basic_doc_list.appendChild(current_doc);
-		if (document_id != null)
-		{
-			current_doc.setAttribute(GSXML.NODE_ID_ATT, document_id + doc_id_modifier);
-		}
-		else
-		{
-			current_doc.setAttribute(GSXML.HREF_ID_ATT, href);
-			// do we need this??
-			current_doc.setAttribute(GSXML.ID_MOD_ATT, doc_id_modifier);
-		}
-		
+// used to create basic_doc_list here		
 		if (document_type == null)
 		{
@@ -342,5 +356,5 @@
 			// Build a request to obtain the document structure
 			Element ds_message = doc.createElement(GSXML.MESSAGE_ELEM);
-			String to = GSPath.appendLink(collection, "DocumentStructureRetrieve");// Hard-wired?
+			String to = GSPath.appendLink(collection, AbstractDocumentRetrieve.DOCUMENT_STRUCTURE_RETRIEVE_SERVICE);
 			Element ds_request = GSXML.createBasicRequest(doc, GSXML.REQUEST_TYPE_PROCESS, to, userContext);
 			ds_message.appendChild(ds_request);
@@ -421,5 +435,5 @@
 		// Build a request to obtain some document metadata
 		Element dm_message = doc.createElement(GSXML.MESSAGE_ELEM);
-		String to = GSPath.appendLink(collection, "DocumentMetadataRetrieve"); // Hard-wired?
+		String to = GSPath.appendLink(collection, AbstractDocumentRetrieve.DOCUMENT_METADATA_RETRIEVE_SERVICE);
 		Element dm_request = GSXML.createBasicRequest(doc, GSXML.REQUEST_TYPE_PROCESS, to, userContext);
 		dm_message.appendChild(dm_request);
@@ -575,5 +589,5 @@
 		// Build a request to obtain some document content
 		Element dc_message = doc.createElement(GSXML.MESSAGE_ELEM);
-		to = GSPath.appendLink(collection, "DocumentContentRetrieve"); // Hard-wired?
+		to = GSPath.appendLink(collection, AbstractDocumentRetrieve.DOCUMENT_CONTENT_RETRIEVE_SERVICE);
 		Element dc_request = GSXML.createBasicRequest(doc, GSXML.REQUEST_TYPE_PROCESS, to, userContext);
 		dc_message.appendChild(dc_request);
@@ -783,8 +797,36 @@
 	}
 
+  protected boolean checkValidOID(Element basic_doc_list, String collection, UserContext userContext, Element page_response) {
+    Document doc = basic_doc_list.getOwnerDocument();
+    
+    Element v_message = doc.createElement(GSXML.MESSAGE_ELEM);
+    String to = GSPath.appendLink(collection, AbstractDocumentRetrieve.VALIDATE_DOCUMENT_ID_SERVICE);
+    Element v_request = GSXML.createBasicRequest(doc, GSXML.REQUEST_TYPE_PROCESS, to, userContext);
+    v_message.appendChild(v_request);
+
+    // add the node list 
+    v_request.appendChild(basic_doc_list);
+    Element v_response_message = (Element) this.mr.process(v_message);
+    if (processErrorElements(v_response_message, page_response))
+    {
+      return false;
+    }
+    String[] links = { GSXML.RESPONSE_ELEM, GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER, GSXML.DOC_NODE_ELEM };
+    String path = GSPath.createPath(links);
+    Element info_elem = (Element) GSXML.getNodeByPath(v_response_message, path);
+    if (info_elem == null) {
+      return false;
+    }
+    if (info_elem.getAttribute("valid").equals("true")) {
+      return true;
+    }
+    return false;
+
+  }
+
   protected Element getFormattedArchiveDoc(Document doc, String collection, String document_id, String document_type, Element result, Element page_response, UserContext userContext ) {
     // call get archive doc
     Element dx_message = doc.createElement(GSXML.MESSAGE_ELEM);
-    String to = "DocXMLGetSection";
+    String to = DocXMLUtil.DOC_XML_GET_SECTION_SERVICE;
     Element dx_request = GSXML.createBasicRequest(doc, GSXML.REQUEST_TYPE_PROCESS, to, userContext);
     dx_message.appendChild(dx_request);
@@ -881,5 +923,5 @@
 		// these could all be cached
 		Element info_message = doc.createElement(GSXML.MESSAGE_ELEM);
-		String path = GSPath.appendLink(collection, "DocumentContentRetrieve");
+		String path = GSPath.appendLink(collection, AbstractDocumentRetrieve.DOCUMENT_CONTENT_RETRIEVE_SERVICE);
 		// the format request - ignore for now, where does this request go to??
 		Element format_request = GSXML.createBasicRequest(doc, GSXML.REQUEST_TYPE_FORMAT, path, userContext);
@@ -957,5 +999,5 @@
 		
 		Element ds_message = doc.createElement(GSXML.MESSAGE_ELEM);
-		String to = GSPath.appendLink(collection, "DocumentStructureRetrieve");// Hard-wired?
+		String to = GSPath.appendLink(collection, AbstractDocumentRetrieve.DOCUMENT_STRUCTURE_RETRIEVE_SERVICE);
 		Element ds_request = GSXML.createBasicRequest(doc, GSXML.REQUEST_TYPE_PROCESS, to, userContext);
 		ds_message.appendChild(ds_request);
@@ -1332,5 +1374,5 @@
      
      Element hl_message = doc.createElement(GSXML.MESSAGE_ELEM);
-     to = GSPath.appendLink(collection, "DocumentContentRetrieve");
+     to = GSPath.appendLink(collection, AbstractDocumentRetrieve.DOCUMENT_CONTENT_RETRIEVE_SERVICE);
      Element dc_request = GSXML.createBasicRequest(doc, GSXML.REQUEST_TYPE_PROCESS, to, userContext);
      hl_message.appendChild(dc_request);
