Ignore:
Timestamp:
1999-05-10T15:40:44+12:00 (25 years ago)
Author:
sjboddie
Message:

lots of changes - slowly getting document action sorted out

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/src/recpt/OIDtools.cpp

    r248 r257  
    1212/*
    1313   $Log$
     14   Revision 1.6  1999/05/10 03:40:25  sjboddie
     15   lots of changes - slowly getting document action sorted out
     16
    1417   Revision 1.5  1999/04/30 01:59:37  sjboddie
    1518   lots of stuff - getting documentaction working (documentaction replaces
     
    3841
    3942
    40 // get first four characters of whatever string is passed in
    41 // OID. This returns the CLSU, HASH etc.
    42 void get_head (const text_t &OID, text_t &head) {
    43 
    44   head.clear();
    45   if (OID.size() < 4) return;
    46   head.appendrange (OID.begin(), (OID.begin() + 4));
    47 }
    48 
    49 
    5043// returns (in top) the top level of OID (i.e. everything
    5144// up until the first dot)
     
    7669
    7770
    78 // is_classification checks OID to see if it's a classification
    79 // or a document. I'm not sure how to do this - for now I'll just assume
    80 // all documents start with HASH and classifications start with something
    81 // else.
    82 bool is_classification (const text_t &OID) {
    83   text_t head;
    84   get_head (OID, head);
    85   if (head == "HASH") return false;
    86   return true;
    87 }
    88 
    8971// get_parents_array loads the parents array with all the parents of the
    90 // document or classification specified by OID
    91 // note that this function doesn't clear the parents array
     72// document or classification specified by OID
    9273void get_parents_array (const text_t &OID, text_tarray &parents) {
     74
     75  parents.erase (parents.begin(), parents.end());
    9376
    9477  text_t::const_iterator here = OID.begin ();
     
    134117}
    135118
     119// has_children returns true if OID has children
     120bool has_children (const text_t &OID, const text_t &collection,
     121           recptproto *collectproto, ostream &logout) {
     122
     123  FilterResponse_t response;
     124  text_tarray metadata;
     125  metadata.push_back ("haschildren");
     126
     127  if (get_info (OID, collection, metadata, collectproto,
     128        response, logout)) {
     129    if (response.docInfo[0].metadata[0].values[0] == "1")
     130      return true;
     131  }
     132  return false;
     133}
     134
     135
    136136// get_children does a protocol call and returns (in response) the OIDs and
    137137// metadata of all the children of OID. The metadata array should be loaded
     
    168168}
    169169
    170 // get_first_child does a protocol call and returns (in child) the OID
    171 // of the first child of OID if it exists
    172 bool get_first_child (const text_t &OID, text_t &child, const text_t &collection,
    173               recptproto *collectproto, ostream logout) {
    174 
    175   comerror_t err;
    176   FilterResponse_t response;
    177   FilterRequest_t request;
    178   OptionValue_t option;
    179 
    180   request.filterName = "BrowseFilter";
    181   option.name = "EndResults";
    182   option.value = "1";
    183   request.filterOptions.push_back (option);
    184   option.name = "ParentNode";
    185   option.value = OID;
    186   request.filterOptions.push_back (option);
    187   request.filterResultOptions = FROID;
    188  
    189   collectproto->filter (collection, request, response, err, logout);
    190  
    191   if (err != noError) {
    192     outconvertclass text_t2ascii;
    193     logout << text_t2ascii
    194        << "Error: call to filter failed for " << OID
    195        << " in OIDtools::get_first_child ("
    196        << get_comerror_string (err) << ")\n";
    197     return false;
    198   }
    199    
    200   if (response.docInfo[0].OID.empty())
    201     return false;
    202   else
    203     child = response.docInfo[0].OID;
    204   return true;
    205 }
    206 
    207170// get_parent returns the parent of the document or classification
    208171// specified by OID
     
    222185}
    223186
    224 // takes an OID like ".2.3 and replaces the " with parent
     187// takes an OID like ".2 and replaces the " with parent
    225188void translate_parent (text_t &OID, const text_t &parent) {
    226189
     
    240203void shrink_parent (text_t &OID) {
    241204 
    242   text_t::iterator parit = findchar (OID.begin(), OID.end(), '.');
    243   if (parit == OID.end()) return;
    244 
    245   OID.erase (OID.begin(), parit);
    246   OID = "\"" + OID;
     205  text_tarray tmp;
     206  splitchar (OID.begin(), OID.end(), '.', tmp);
     207  OID = "\"." + tmp.back();
    247208}
    248209
     
    260221  return false;
    261222}
     223
     224
     225void recurse_contents (const ResultDocInfo_t section, const bool &classify,
     226               int &totalcols, const text_t &collection,
     227               const text_tarray &metadata, recptproto *collectproto,
     228               FilterResponse_t &response, ostream &logout) {
     229 
     230  int haschildren = section.metadata[1].values[0].getint();
     231  const text_t &doctype = section.metadata[2].values[0];
     232  int cols;
     233
     234  if ((haschildren == 1) && ((!classify) || (doctype == "classify"))) {
     235    text_t parent = response.docInfo.back().OID;
     236    int parentcols = countchar (parent.begin(), parent.end(), '.');
     237    FilterResponse_t tmp;
     238    get_children (section.OID, collection, metadata, collectproto, tmp, logout);
     239    ResultDocInfo_tarray::const_iterator thisdoc = tmp.docInfo.begin();
     240    ResultDocInfo_tarray::const_iterator lastdoc = tmp.docInfo.end();
     241    while (thisdoc != lastdoc) {
     242      if (((*thisdoc).metadata[2].values[0] != "classify") && (classify))
     243    cols = parentcols + 1;
     244      else
     245    cols = countchar ((*thisdoc).OID.begin(), (*thisdoc).OID.end(), '.');
     246      if (cols > totalcols) totalcols = cols;
     247      response.docInfo.push_back (*thisdoc);
     248      recurse_contents (*thisdoc, classify, totalcols, collection,
     249            metadata, collectproto, response, logout);
     250      thisdoc ++;
     251    }
     252  }
     253}
     254
     255// get_contents returns OIDs and metadata of all contents
     256// below (and including) OID.
     257// metadata being returned for each is Title, haschildren,
     258// doctype, and hastxt
     259void get_contents (const text_t &topOID, const text_t &classifytype, int &totalcols,
     260           const text_t &collection, recptproto *collectproto,
     261           FilterResponse_t &response, ostream &logout) {
     262
     263  bool classify = false;
     264  response.clear();
     265  text_tarray metadata;
     266  metadata.push_back ("Title");
     267  metadata.push_back ("haschildren");
     268  metadata.push_back ("doctype");
     269  metadata.push_back ("hastxt");
     270
     271  // we don't want to recurse all the way down through each document
     272  // if we're expanding top level contents
     273  if (classifytype == "classify") classify = true;
     274
     275  // update totalcols
     276  totalcols = countchar (topOID.begin(), topOID.end(), '.');
     277
     278  // get topOIDs info
     279  if (get_info (topOID, collection, metadata, collectproto, response, logout))
     280      recurse_contents (response.docInfo[0], classify, totalcols, collection,
     281            metadata, collectproto, response, logout);
     282}
Note: See TracChangeset for help on using the changeset viewer.