Index: /gsdl/trunk/runtime-src/src/oaiservr/metaformatsaction.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/oaiservr/metaformatsaction.cpp	(revision 16715)
+++ /gsdl/trunk/runtime-src/src/oaiservr/metaformatsaction.cpp	(revision 16716)
@@ -6,13 +6,19 @@
 bool metaformatsaction::validateAction(recptproto *protocol, oaiargs &params)
 { 
-  int params_size = params.getSize();
-
-  // Remove any parameters that aren't valid for this action
+  // ----------------------------------------------------------------------------
+  //  1. Check for invalid arguments
+  // ----------------------------------------------------------------------------
+  bool invalid_argument_supplied = false;
   text_tmap::const_iterator param_iterator = params.begin();
   while (param_iterator != params.end())
   {
+    // Check for arguments that aren't valid for this action
     if (param_iterator->first != "verb" &&
 	param_iterator->first != "identifier")
     {
+      // We've found an invalid argument
+      invalid_argument_supplied = true;
+
+      // Delete the invalid argument from the list so it doesn't end up in the <request> tag that is returned
       params.erase(param_iterator->first);
     }
@@ -21,43 +27,55 @@
   }
 
-  int numArgs = 1; // the number of expected arguments
-  
-  // increase the number of expected arguments if the optional 'identifier' argument
-  // is given 
-  if (params["identifier"] != "") {
-    ++numArgs;
-  }
-
-  // If the total number of params isn't equal to the number of valid
-  // args (i.e. we have an arg but it isn't the identifier), throw an error  
-  if((params_size != numArgs)){
+  // If we found an invalid argument it's an error, so don't go any further 
+  if (invalid_argument_supplied)
+  {
     this->errorType = "badArgument";
     return false;
   }
 
-  // Variables to hold identifier in Greenstone format
-  text_t docID = params["identifier"]; 
-  text_t collection = "";
+  // ----------------------------------------------------------------------------
+  //  2. Handle any exclusive arguments
+  // ----------------------------------------------------------------------------
 
-  // The following two variables are used solely by the get_info() function call to test if
-  // the identifier supplied is an actual document. If it isn't, we need to throw an exception.
-  const text_tset metadata;
+  // None!
 
-  // Check for the existence, etc. of the record if an identifier is given.
-  if (docID != "") {
-    oaiclassifier::toGSDL(collection, docID);
-    
-    // Only throw an error if we're using v2.0. 
-    // v1.1 should simply return a response without a metadataFormat container. 1.1
-    // should still set the errorType so we know that the error was encountered
+  // ----------------------------------------------------------------------------
+  //  3. Handle any required arguments
+  // ----------------------------------------------------------------------------
 
-    // the information retrieved here is retained for the output_content function below
-    if (!get_info(docID, collection, "", metadata, false, protocol, this->gsdlResponse, cerr)){
+  // None!
+
+  // ----------------------------------------------------------------------------
+  // 4. Check any remaining arguments
+  // ----------------------------------------------------------------------------
+
+  // Check "identifier" argument
+  if (params["identifier"] != "")
+  {
+    text_t identifier = params["identifier"];
+
+    // Extract the collection name from the identifier specification
+    text_t collection = "";
+    oaiclassifier::toGSDL(collection, identifier);
+  
+    // Check a document with the specified identifier exists
+    text_tset metadata;
+    if (!get_info(identifier, collection, "", metadata, false, protocol, this->gsdlResponse, *logout))
+    {
       this->errorType = "idDoesNotExist";
-      if(this->configuration->getOAIVersion() >= 200) {
+
+      // Only throw an error if we're using v2.0. 
+      // v1.1 should simply return a response without a metadataFormat container. 1.1
+      // should still set the errorType so we know that the error was encountered
+      // the information retrieved here is retained for the output_content function below
+      if (this->configuration->getOAIVersion() >= 200)
+      {
 	return false;
       }
     }
   }
+
+  // If we've reached here everything must be fine
+  this->errorType = "";
   return true;
 }
