Index: /trunk/gsdl/src/recpt/formattools.cpp
===================================================================
--- /trunk/gsdl/src/recpt/formattools.cpp	(revision 5787)
+++ /trunk/gsdl/src/recpt/formattools.cpp	(revision 5788)
@@ -32,17 +32,16 @@
 
 // a few function prototypes
+
 static text_t format_string (const text_t& collection, recptproto* collectproto,
 			     ResultDocInfo_t &docinfo, displayclass &disp, 
-			     format_t *formatlistptr,
-			     const text_t &link, const text_t &icon, 
-			     const text_t &text, bool highlight, ostream& logout);
+			     format_t *formatlistptr, text_tmap &options,
+			     ostream& logout);
 
 static bool parse_action (text_t::const_iterator &here, const text_t::const_iterator &end, 
 			  format_t *formatlistptr, text_tset &metadata, bool &getParents);
 
-text_t format_summary (const text_t& collection, recptproto* collectproto,
-		      ResultDocInfo_t &docinfo, displayclass &disp, 
-		      const text_t &text, bool highlight,
-		       ostream& logout);
+static text_t format_summary (const text_t& collection, recptproto* collectproto,
+			      ResultDocInfo_t &docinfo, displayclass &disp, 
+			      text_tmap &options, ostream& logout);
 
 
@@ -77,4 +76,5 @@
   DocumentContents = true;
   DocumentArrowsBottom = true; 
+  DocumentArrowsTop = false; 
   DocumentButtons.erase (DocumentButtons.begin(), DocumentButtons.end());
   //  DocumentButtons.push_back ("Expand Text");
@@ -86,4 +86,5 @@
   formatstrings.erase (formatstrings.begin(), formatstrings.end());
   DocumentUseHTML = false;
+  AllowExtendedOptions = false;
 }
 
@@ -525,4 +526,5 @@
 }
 
+
 static void parse_meta (text_t &meta, metadata_t &metaoption,
 			text_tset &metadata, bool &getParents) {
@@ -534,5 +536,4 @@
 
   if (meta.size() > 7 && (substr (meta.begin(), meta.begin()+6) == "parent")) {
-    metaoption.metacommand |= mParent;
     getParents = true;
     get_parent_options (meta, metaoption);
@@ -579,4 +580,22 @@
     formatlistptr->command = comSummary;
 
+  else if (meta == "DocImage")
+    formatlistptr->command = comImage; 
+
+  else if (meta == "DocTOC")
+    formatlistptr->command = comTOC; 
+
+  else if (meta == "DocumentButtonDetach")
+     formatlistptr->command = comDocumentButtonDetach;
+  
+  else if (meta == "DocumentButtonHighlight")
+     formatlistptr->command = comDocumentButtonHighlight;
+  
+  else if (meta == "DocumentButtonExpandContents")
+    formatlistptr->command = comDocumentButtonExpandContents; 
+
+  else if (meta == "DocumentButtonExpandText")
+     formatlistptr->command = comDocumentButtonExpandText; 
+  
   else {
     formatlistptr->command = comMeta;
@@ -878,20 +897,6 @@
     }
 
-
   case pImmediate:
     if (parent != NULL) {
-      if (meta.metaname == "Date") 
-	return format_date (parent->values[0]);
-      if (meta.metacommand == mCgiSafe) 
-	return cgi_safe (parent->values[0]);
-      else return parent->values[0];
-    }
-    break;
-
-
-  case pTop:
-    if (parent != NULL) {
-      while (parent->parent != NULL) parent = parent->parent;
-
       if (meta.metaname == "Date") 
 	return format_date (parent->values[0]);
@@ -902,8 +907,19 @@
     break;
 
+  case pTop:
+    if (parent != NULL) {
+      while (parent->parent != NULL) parent = parent->parent;
+
+      if (meta.metaname == "Date") 
+	return format_date (parent->values[0]);
+      if (meta.metacommand & mCgiSafe) 
+	return cgi_safe (parent->values[0]);
+      else return parent->values[0];
+    }
+    break;
+
   case pAll:
     MetadataInfo_t *parent = docinfo.metadata[meta.metaname].parent;
     if (parent != NULL) {
-
       text_tarray tmparray;
       while (parent != NULL) {
@@ -931,7 +947,5 @@
 static text_t get_or (const text_t& collection, recptproto* collectproto,
 		      ResultDocInfo_t &docinfo, displayclass &disp,
-		      format_t *orptr,
-		      const text_t &link, const text_t &icon, 
-		      const text_t &text, bool highlight,
+		      format_t *orptr, text_tmap &options,
 		      ostream& logout) {
 
@@ -940,5 +954,5 @@
 
     tmp = format_string (collection,collectproto, docinfo, disp, orptr, 
-			 link, icon, text, highlight, logout);
+			 options, logout);
     if (!tmp.empty()) return tmp;
 
@@ -951,7 +965,6 @@
 		      ResultDocInfo_t &docinfo, displayclass &disp, 
 		      const decision_t &decision,
-		      format_t *ifptr, format_t *elseptr, const text_t &link, 
-		      const text_t &icon, const text_t &text, bool highlight,
-		      ostream& logout) 
+		      format_t *ifptr, format_t *elseptr,
+		      text_tmap &options, ostream& logout) 
 {
 
@@ -962,10 +975,10 @@
       if (ifptr != NULL)
 	return get_formatted_string (collection,collectproto, docinfo, disp, ifptr, 
-				     link, icon, text, highlight, logout);
+				     options, logout);
     }
     else {
       if (elseptr != NULL)
 	return get_formatted_string (collection,collectproto, docinfo, disp, elseptr,
-				     link, icon, text, highlight, logout);
+				     options, logout);
     }
   }
@@ -985,9 +998,9 @@
       if (ifptr != NULL)
 	return get_formatted_string (collection, collectproto, docinfo, disp, ifptr, 
-				     link, icon, text, highlight, logout);
+				     options, logout);
     } else {
       if (elseptr != NULL)
 	return get_formatted_string (collection, collectproto, docinfo, disp, elseptr,
-				     link, icon, text, highlight, logout);
+				     options, logout);
     }
   }
@@ -1008,11 +1021,48 @@
 }
 
-
+static text_t expand_metadata(const text_t &metavalue, const text_t& collection,
+			      recptproto* collectproto, ResultDocInfo_t &docinfo,
+			      displayclass &disp, text_tmap &options,
+			      ostream &logout) {
+      
+   if (includes_metadata(metavalue))
+      {
+	 // text has embedded metadata in it => expand it
+	 FilterRequest_t request;
+	 FilterResponse_t response;
+
+	 request.getParents = false;
+	  
+	 format_t *expanded_formatlistptr = new format_t();
+	 parse_formatstring (metavalue, expanded_formatlistptr, 
+			     request.fields, request.getParents);
+	  
+	 // retrieve metadata
+	 get_info(docinfo.OID, collection, request.fields, request.getParents,
+		  collectproto, response, logout);
+	 
+	 if (!response.docInfo.empty())
+	    {
+	       text_t expanded_metavalue
+		  = get_formatted_string(collection, collectproto, 
+					 response.docInfo[0], disp, expanded_formatlistptr, 
+					 options, logout);
+	      
+	       return expanded_metavalue;
+	    }
+	 else
+	    {
+	       return metavalue;
+	    }
+      }
+   else
+      {
+	 return metavalue;
+      }
+}
 
 text_t format_string (const text_t& collection, recptproto* collectproto,
 		      ResultDocInfo_t &docinfo, displayclass &disp, 
-		      format_t *formatlistptr,
-		      const text_t &link, const text_t &icon,
-		      const text_t &text, bool highlight,
+		      format_t *formatlistptr, text_tmap &options,
 		      ostream& logout) {
 
@@ -1020,138 +1070,71 @@
 
   switch (formatlistptr->command) {
-  case comText:
-    return formatlistptr->text;
-  case comLink:
-    return link;
-  case comEndLink:
-    if (link.empty()) return "";
-    else return "</a>";
-  case comHref:
-    return get_href(link);
-  case comIcon:
-    return icon;
-  case comNum:
-    return docinfo.result_num;
-  case comRel: //if [RelatedDocuments] appears in format string, collect relation data
-    return get_related_docs(collection, collectproto, docinfo, logout);
-  case comSummary:
-    return format_summary(collection,collectproto,docinfo,disp,text,highlight,logout);
-  case comMeta:
-
-    {
-      const text_t& metavalue =  get_meta (docinfo, formatlistptr->meta);
-
-      if (includes_metadata(metavalue))
+     case comText:
+	return formatlistptr->text;
+     case comLink:
+	return options["link"];
+     case comEndLink:
+	if (options["link"].empty()) return "";
+	else return "</a>";
+     case comHref:
+	return get_href(options["link"]);
+     case comIcon:
+	return options["icon"];
+     case comNum:
+	return docinfo.result_num;
+     case comRel: //if [RelatedDocuments] appears in format string, collect relation data
+	return get_related_docs(collection, collectproto, docinfo, logout);
+     case comSummary:
+	return format_summary(collection, collectproto, docinfo, disp, options, logout);
+     case comMeta:
 	{
-	  // text has embedded metadata in it => expand it
-	  FilterRequest_t request;
-	  FilterResponse_t response;
-
-	  request.getParents = false;
-	  
-	  format_t *expanded_formatlistptr = new format_t();
-	  parse_formatstring (metavalue, expanded_formatlistptr, 
-			      request.fields, request.getParents);
-	  
-	  // retrieve metadata
-	  get_info(docinfo.OID, collection, request.fields, request.getParents,
-		   collectproto, response, logout);
-	  
-	  if (!response.docInfo.empty())
-	    {
-	      text_t expanded_metavalue
-		= get_formatted_string(collection, collectproto, 
-				       response.docInfo[0], disp, expanded_formatlistptr, 
-				       link, icon, highlight, logout);
-	      
-	      return expanded_metavalue;
-	    }
-	  else
-	    {
-	      return metavalue;
-	    }
+	   const text_t& metavalue =  get_meta (docinfo, formatlistptr->meta);
+	   return expand_metadata(metavalue, collection, collectproto, docinfo, disp, options, logout);
 	}
-      else
-	{
-	  return metavalue;
-	}
-    }
-  case comDoc:
-    return text;
-  case comHighlight:
-    if (highlight) return "<b>";
-    break;
-  case comEndHighlight:
-    if (highlight) return "</b>";
-    break;
-  case comIf:
-    return get_if (collection, collectproto, docinfo, disp, 
-		   formatlistptr->decision, formatlistptr->ifptr, 
-		   formatlistptr->elseptr, link, icon, text, highlight,
-		   logout);
-  case comOr:
-    return get_or (collection,collectproto, docinfo, disp, formatlistptr->orptr, 
-		   link, icon, text, highlight, logout);
+     case comDoc:
+	return options["text"];
+     case comImage:
+	return expand_metadata(options["DocImage"], collection, collectproto, docinfo, disp, options, logout);
+     case comTOC:
+	return options["DocTOC"];
+     case comDocumentButtonDetach:
+	return options["DocumentButtonDetach"];
+     case comDocumentButtonHighlight:
+	return options["DocumentButtonHighlight"];
+     case comDocumentButtonExpandContents:
+	return options["DocumentButtonExpandContents"];
+     case comDocumentButtonExpandText:
+	return options["DocumentButtonExpandText"];
+     case comHighlight:
+	if (options["highlight"] == "1") return "<b>";
+	break;
+     case comEndHighlight:
+	if (options["highlight"] == "1") return "</b>";
+	break;
+     case comIf:
+	return get_if (collection, collectproto, docinfo, disp, 
+		       formatlistptr->decision, formatlistptr->ifptr, 
+		       formatlistptr->elseptr, options, logout);
+     case comOr:
+	return get_or (collection,collectproto, docinfo, disp, formatlistptr->orptr, 
+		       options, logout);
   }
   return "";
-}
-
-
-
-
-text_t get_formatted_string (const text_t& collection, recptproto* collectproto,
-			     ResultDocInfo_t& docinfo, displayclass &disp,
-			     format_t* formatlistptr,
-			     const text_t& link, const text_t& icon, 
-			     const text_t& text, const bool highlight,
-			     ostream& logout) {
-
-  text_t ft;
-  while (formatlistptr != NULL) 
-    {
-      ft += format_string (collection, collectproto, docinfo, disp, formatlistptr, 
-			   link, icon, text, highlight, logout);
-      formatlistptr = formatlistptr->nextptr;
-    }
-
-  return ft;
 }
 
 text_t get_formatted_string (const text_t& collection, recptproto* collectproto,
 			     ResultDocInfo_t &docinfo, displayclass &disp,
-			     format_t *formatlistptr,
-			     const text_t &link, const text_t &icon, 
-			     const bool highlight,
+			     format_t *formatlistptr, text_tmap &options,
 			     ostream& logout) {
 
-  text_t text = "";
-
-  return get_formatted_string(collection, collectproto, docinfo, disp, formatlistptr,
-                              link, icon, text, highlight, logout);
-}
-
-text_t get_formatted_string (const text_t& collection, recptproto* collectproto,
-			     ResultDocInfo_t &docinfo, displayclass &disp,
-			     format_t *formatlistptr,
-			     const text_t& text,
-			     ostream& logout) {
-
-  text_t link = "<a href=\"_httpdocument_&cl=search&d=" + docinfo.OID + "\">";
-  text_t icon = "_icontext_";
-  bool highlight = false;
-
-  return get_formatted_string(collection, collectproto, docinfo, disp, formatlistptr,
-			      link, icon, text, highlight, logout);
-}
-
-text_t get_formatted_string (const text_t& collection, recptproto* collectproto,
-			     ResultDocInfo_t &docinfo, displayclass &disp,
-			     format_t *formatlistptr,
-			     ostream& logout) {
-
-  text_t text = "";
-
-  return get_formatted_string(collection, collectproto, docinfo, disp, formatlistptr,
-			      text, logout);
+   text_t ft;
+   while (formatlistptr != NULL) 
+      {
+	 ft += format_string (collection, collectproto, docinfo, disp, formatlistptr, 
+			      options, logout);
+	 formatlistptr = formatlistptr->nextptr;
+      }
+   
+   return ft;
 }
 
@@ -1162,7 +1145,6 @@
 
 text_t format_summary (const text_t& collection, recptproto* collectproto,
-		      ResultDocInfo_t &docinfo, displayclass &disp, 
-		      const text_t &text, bool highlight,
-		      ostream& logout) {
+		       ResultDocInfo_t &docinfo, displayclass &disp, 
+		       text_tmap &options, ostream& logout) {
 
   // GRB: added code here to ensure that the cstr (and other collections)
@@ -1176,14 +1158,14 @@
 
   text_t textToSummarise, query;
-  if(text.empty()) { // get document text
-      DocumentRequest_t docrequest;
-      DocumentResponse_t docresponse;
-      comerror_t err;
-      docrequest.OID = docinfo.OID;
-      collectproto->get_document (collection, docrequest, docresponse, err, logout);
-      textToSummarise = docresponse.doc;
+  if(options["text"].empty()) { // get document text
+     DocumentRequest_t docrequest;
+     DocumentResponse_t docresponse;
+     comerror_t err;
+     docrequest.OID = docinfo.OID;
+     collectproto->get_document (collection, docrequest, docresponse, err, logout);
+     textToSummarise = docresponse.doc;
   } else // in practice, this would not happen, because text is only 
          // loaded with the [Text] command
-      textToSummarise = text;
+     textToSummarise = options["text"];
   disp.expandstring("_cgiargq_",query);
   return summarise(textToSummarise,query,80);
