Index: trunk/gsdl/src/recpt/OIDtools.cpp
===================================================================
--- trunk/gsdl/src/recpt/OIDtools.cpp	(revision 213)
+++ trunk/gsdl/src/recpt/OIDtools.cpp	(revision 248)
@@ -12,4 +12,8 @@
 /*
    $Log$
+   Revision 1.5  1999/04/30 01:59:37  sjboddie
+   lots of stuff - getting documentaction working (documentaction replaces
+   old browseaction)
+
    Revision 1.4  1999/03/29 02:14:25  sjboddie
 
@@ -49,4 +53,6 @@
 
   top.clear();
+  if (OID.empty()) return;
+
   text_t::const_iterator begin = OID.begin();
   text_t::const_iterator end = OID.end();
@@ -81,11 +87,4 @@
 }
 
-
-// don't know how to do this yet either ...
-bool contains_text (const text_t &/*OID*/) {
-  return true;
-}
-
-
 // get_parents_array loads the parents array with all the parents of the
 // document or classification specified by OID
@@ -105,20 +104,104 @@
 
 
-// get_children_array loads the children array with all the children of the 
-// document or classification specified by OID
-void get_children_array (const text_t &OID, text_tarray &children) {
-
-  children.erase(children.begin(), children.end());
-
-  // just stuff some rubish in for now
-  children.push_back (OID + ".1");
-  children.push_back (OID + ".2");
-  children.push_back (OID + ".3");
-  children.push_back (OID + ".4");
-  children.push_back (OID + ".5");
-  children.push_back (OID + ".6");
-  children.push_back (OID + ".7");
-}
-
+// get_info does a protocol call and returns (in response) the metadata 
+// associated with OID. The metadata array should be loaded with whatever
+// metadata fields are to be requested.
+
+bool get_info (const text_t &OID, const text_t &collection,
+	       const text_tarray &metadata, recptproto *collectproto,
+	       FilterResponse_t &response, ostream &logout) {
+
+  response.clear();
+
+  comerror_t err;
+  FilterRequest_t request;
+
+  request.filterName = "NullFilter";
+  request.filterResultOptions = FRmetadata;
+  request.fields = metadata;
+  request.docSet.insert (OID);
+  
+  collectproto->filter (collection, request, response, err, logout);
+  if (err != noError) {
+    outconvertclass text_t2ascii;
+    logout << text_t2ascii
+	   << "Error: call to filter failed for " << OID
+	   << " in OIDtools::get_info (" 
+	   << get_comerror_string (err) << ")\n";
+    return false;
+  }
+  return true;
+}
+
+// get_children does a protocol call and returns (in response) the OIDs and 
+// metadata of all the children of OID. The metadata array should be loaded
+// with whatever metadata fields are to be requested.
+
+bool get_children (const text_t &OID, const text_t &collection, 
+		   const text_tarray &metadata, recptproto *collectproto, 
+		   FilterResponse_t &response, ostream &logout) {
+  
+  response.clear();
+
+  comerror_t err;
+  FilterRequest_t request;
+  OptionValue_t option;
+
+  option.name = "ParentNode";
+  option.value = OID;
+  request.filterOptions.push_back (option);
+  request.filterName = "BrowseFilter";
+  request.filterResultOptions = FROID | FRmetadata;
+  request.fields = metadata;
+
+  collectproto->filter (collection, request, response, err, logout);
+
+  if (err != noError) {
+    outconvertclass text_t2ascii;
+    logout << text_t2ascii
+	   << "Error: call to filter failed for " << OID 
+	   << " in OIDtools::get_children (" 
+	   << get_comerror_string (err) << ")\n";
+    return false;
+  }
+  return true;
+}
+
+// get_first_child does a protocol call and returns (in child) the OID
+// of the first child of OID if it exists
+bool get_first_child (const text_t &OID, text_t &child, const text_t &collection, 
+		      recptproto *collectproto, ostream logout) {
+
+  comerror_t err;
+  FilterResponse_t response;
+  FilterRequest_t request;
+  OptionValue_t option;
+
+  request.filterName = "BrowseFilter";
+  option.name = "EndResults";
+  option.value = "1";
+  request.filterOptions.push_back (option);
+  option.name = "ParentNode";
+  option.value = OID;
+  request.filterOptions.push_back (option);
+  request.filterResultOptions = FROID;
+  
+  collectproto->filter (collection, request, response, err, logout);
+  
+  if (err != noError) {
+    outconvertclass text_t2ascii;
+    logout << text_t2ascii
+	   << "Error: call to filter failed for " << OID 
+	   << " in OIDtools::get_first_child (" 
+	   << get_comerror_string (err) << ")\n";
+    return false;
+  } 
+    
+  if (response.docInfo[0].OID.empty())
+    return false;
+  else
+    child = response.docInfo[0].OID;
+  return true;
+}
 
 // get_parent returns the parent of the document or classification
@@ -139,11 +222,40 @@
 }
 
-
-// get_first_child loads child with the first
-// child of OID
-void get_first_child(const text_t &OID, text_t &child) {
-  // shove something in for now - I think we'll need to 
-  // look up db here
-  child.clear();
-  child += OID + ".1";
-}
+// takes an OID like ".2.3 and replaces the " with parent
+void translate_parent (text_t &OID, const text_t &parent) {
+
+  text_t::const_iterator here = OID.begin();
+  text_t::const_iterator end = OID.end();
+  text_t temp;
+
+  while (here != end) {
+    if (*here == '"') temp += parent;
+    else temp.push_back (*here);
+    here ++;
+  }
+  OID = temp;
+}
+
+// shrink_parent does the opposite to translate_parent
+void shrink_parent (text_t &OID) {
+  
+  text_t::iterator parit = findchar (OID.begin(), OID.end(), '.');
+  if (parit == OID.end()) return;
+
+  OID.erase (OID.begin(), parit);
+  OID = "\"" + OID;
+}
+
+// checks if OID uses ".fc", ".lc", ".pr", ".ns",
+// or ".ps" syntax (first child, last child, parent,
+// next sibling, previous sibling)
+bool needs_translating (const text_t &OID) {
+
+  if (OID.size() < 4) return false;
+
+  text_t tail = substr (OID.end()-3, OID.end());
+  if (tail == ".fc" || tail == ".lc" || tail == ".pr" || 
+      tail == ".ns" || tail == ".ps") return true;
+
+  return false;
+}
