Index: /trunk/gsdl/src/recpt/extlinkaction.cpp
===================================================================
--- /trunk/gsdl/src/recpt/extlinkaction.cpp	(revision 868)
+++ /trunk/gsdl/src/recpt/extlinkaction.cpp	(revision 869)
@@ -27,4 +27,5 @@
 #include <string.h>
 #include "extlinkaction.h"
+#include "OIDtools.h"
 #include "cgiutils.h"
 
@@ -80,22 +81,27 @@
 
 
-
-void extlinkaction::get_cgihead_info (cgiargsclass &args, recptprotolistclass * /*protos*/,
+void extlinkaction::get_cgihead_info (cgiargsclass &args, recptprotolistclass *protos,
 				      response_t &response, text_t &response_data, 
-				      ostream &/*logout*/) 
-{
-  if (args["el"] == "direct")
-    {
+				      ostream &logout) {
+
+  text_t link;
+  if (get_link (args, protos, link, logout)) {
+    response = location;
+    response_data = link;
+    return;
+  }
+
+  // external link
+  if (!link.empty()) {
+    if (args["el"] == "direct") {
       response = location;
-      response_data =  args["href"];
+      response_data = link;
+      return;
     }
-  else
-    {
-      response = content;
-      response_data = "text/html";
-    }
-}
-
-
+  }
+
+  response = content;
+  response_data = "text/html";
+}
 
 void extlinkaction::define_internal_macros (displayclass &disp, cgiargsclass &args, 
@@ -108,29 +114,135 @@
   // _prevdoc_             link to previous document
   
-  disp.setmacro("nexturl", "extlink", cgi_safe(args["href"]));
+  disp.setmacro("nexturl", "extlink", args["href"]);
   disp.setmacro("prevdoc", "extlink", args["d"]);
 }
 
 
-bool extlinkaction::do_action (cgiargsclass &args, recptprotolistclass * /*protos*/, 
+// if link is found returns true and url in link, otherwise returns
+// false
+bool extlinkaction::get_link (cgiargsclass &args, recptprotolistclass *protos,
+			      text_t &link, ostream &logout) {
+
+    text_t &arg_href = args["href"];
+    text_t &thiscollection = args["c"];
+    if (arg_href.empty()) return false;
+
+    if (args["rl"] == "1") {
+
+      FilterResponse_t response;
+      text_tset metadata;
+      metadata.insert ("section");
+	  
+      recptproto *collectproto = protos->getrecptproto (thiscollection, logout);
+
+      if (get_info (arg_href, thiscollection, metadata, false, collectproto, response, logout)) {
+	if (!response.docInfo[0].metadata["section"].values[0].empty()) {
+	  link = "_httpdoc_&d=" + response.docInfo[0].metadata["section"].values[0];
+	  return true;
+	}
+      }
+
+      // need to see if link exists in any other collection
+      // if cross-collection searching/browsing is turned on 
+      if (args["ccs"] == "1" && !args["cc"].empty()) {
+	text_tarray collections;
+	splitchar (args["cc"].begin(), args["cc"].end(), ',', collections);
+
+	text_tarray::const_iterator col_here = collections.begin();
+	text_tarray::const_iterator col_end = collections.end();
+
+	while (col_here != col_end) {
+	  
+	  // don't need to check current collection again
+	  if (*col_here == thiscollection) {col_here ++; continue;}
+	  
+	  recptproto *collectproto = protos->getrecptproto (*col_here, logout);
+	  if (collectproto == NULL) {col_here ++; continue;}
+
+	  if (get_info (arg_href, *col_here, metadata, false, collectproto, response, logout)) {
+	    if (!response.docInfo[0].metadata["section"].values[0].empty()) {
+	      link = "_httpdoc_&c=" + *col_here + "&d=" +
+		response.docInfo[0].metadata["section"].values[0];
+	      return true;
+	    }
+	  }
+	  col_here ++;
+	}
+      }
+      return false;
+      
+    } else {
+      // link is external 
+      link = arg_href;
+      return false;
+    }
+}
+
+
+bool extlinkaction::do_action (cgiargsclass &args, recptprotolistclass *protos, 
 			       browsermapclass * /*browsers*/, displayclass &disp,
 			       outconvertclass &outconvert, ostream &textout,
-			       ostream &/*logout*/) {
-
-  if (args["el"] != "direct")
-    {
-      if (args["href"] != "")
-	{
-	  textout << outconvert << disp << ("_extlink:header_\n")
-		  << ("_extlink:foundcontent_\n")
-		  << ("_extlink:footer_\n");
+			       ostream &logout) {
+
+  if (args["href"].empty()) {
+    // oops, this shouldn't happen
+    textout << outconvert << disp << ("_extlink:header_\n")
+	    << ("_extlink:notfoundcontent_\n")
+	    << ("_extlink:footer_\n");
+    return true;
+  }
+
+  if (args["rl"] == "1") {
+    // need to see if link exists in any other collection
+    // if cross-collection searching/browsing is turned on 
+    if (args["ccs"] == "1" && !args["cc"].empty()) {
+      
+      FilterResponse_t response;
+      text_tset metadata;
+      metadata.insert ("section");
+      text_tarray collections;
+      splitchar (args["cc"].begin(), args["cc"].end(), ',', collections);
+      
+      text_tarray::const_iterator col_here = collections.begin();
+      text_tarray::const_iterator col_end = collections.end();
+      
+      while (col_here != col_end) {
+	
+	// don't need to check current collection
+	if (*col_here == args["c"]) {col_here ++; continue;}
+	
+	recptproto *collectproto = protos->getrecptproto (*col_here, logout);
+	
+	if (get_info (args["href"], *col_here, metadata, false, collectproto, response, logout)) {
+	  if (!response.docInfo[0].metadata["section"].values[0].empty()) {
+	    text_t collectionname = *col_here;
+	    metadata.erase (metadata.begin(), metadata.end());
+	    metadata.insert ("collectionname");
+	    FilterResponse_t nresponse;
+	    if (get_info ("collection", *col_here, metadata, false, collectproto, nresponse, logout)) {
+	      if (!nresponse.docInfo[0].metadata["collectionname"].values[0].empty())
+		collectionname = nresponse.docInfo[0].metadata["collectionname"].values[0];
+	    }
+	    textout << outconvert << disp << ("_extlink:header_\n")
+		    << ("_extlink:foundintcontent_(" + *col_here + ", " + collectionname + 
+			", " + response.docInfo[0].metadata["section"].values[0] + "\n")
+		    << ("_extlink:footer_\n");
+	    return true;
+	  }
 	}
-      else
-	{
-	  textout << outconvert << disp << ("_extlink:header_\n")
-		  << ("_extlink:notfoundcontent_\n")
-		  << ("_extlink:footer_\n");
-	}
+	col_here ++;
+      }
     }
+    textout << outconvert << disp << ("_extlink:header_\n")
+	    << ("_extlink:notfoundcontent_\n")
+	    << ("_extlink:footer_\n");
+    
+    
+  } else {
+    // link is external 
+    textout << outconvert << disp << ("_extlink:header_\n")
+	    << ("_extlink:foundcontent_\n")
+	    << ("_extlink:footer_\n");
+  }
 
   return true;
@@ -138,3 +250,2 @@
 
 
-
Index: /trunk/gsdl/src/recpt/extlinkaction.h
===================================================================
--- /trunk/gsdl/src/recpt/extlinkaction.h	(revision 868)
+++ /trunk/gsdl/src/recpt/extlinkaction.h	(revision 869)
@@ -51,4 +51,9 @@
 		  ostream &logout);
 
+
+protected:
+  bool get_link (cgiargsclass &args, recptprotolistclass *protos,
+		 text_t &link, ostream &logout);
+
 };
 
