Changeset 249


Ignore:
Timestamp:
1999-04-30T14:00:48+12:00 (25 years ago)
Author:
sjboddie
Message:

lots of stuff to do with getting documentaction working

Location:
trunk/gsdl/src/colservr
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/src/colservr/browsefilter.cpp

    r238 r249  
    1212/*
    1313   $Log$
     14   Revision 1.3  1999/04/30 02:00:45  sjboddie
     15   lots of stuff to do with getting documentaction working
     16
    1417   Revision 1.2  1999/04/19 23:56:05  rjmcnab
    1518   Finished the gdbm metadata stuff
     
    151154      // replace " with the parent node name and split the contains string
    152155      // into the result set
    153       text_tset resultset;
     156      text_tarray resultset;
    154157      text_t tmptext;
    155158      text_t &contains = info["contains"];
     
    159162    if (*contains_here == '"') tmptext += parentnode;
    160163    else if (*contains_here == ';') {
    161       if (!tmptext.empty()) resultset.insert (tmptext);
     164      if (!tmptext.empty()) resultset.push_back (tmptext);
    162165      tmptext.clear();
    163166    } else tmptext.push_back(*contains_here);
     
    166169      }
    167170      // insert the last result in the set
    168       if (!tmptext.empty()) resultset.insert (tmptext);
     171      if (!tmptext.empty()) resultset.push_back (tmptext);
    169172     
    170173      // do an intersection with the input set
     
    177180      int resultnum = 1;
    178181      ResultDocInfo_t resultdoc;
    179       text_tset::iterator result_here = resultset.begin();
    180       text_tset::iterator result_end = resultset.end();
     182      text_tarray::iterator result_here = resultset.begin();
     183      text_tarray::iterator result_end = resultset.end();
    181184
    182185      while (result_here != result_end) {
  • trunk/gsdl/src/colservr/collectserver.cpp

    r226 r249  
    1313/*
    1414   $Log$
     15   Revision 1.7  1999/04/30 02:00:45  sjboddie
     16   lots of stuff to do with getting documentaction working
     17
    1518   Revision 1.6  1999/04/06 22:20:29  rjmcnab
    1619   Got browsefilter working.
     
    3841
    3942#include "collectserver.h"
     43#include "infodbclass.h"
     44#include "OIDtools.h"
    4045#include <assert.h>
    4146
     
    168173}
    169174
    170 void collectserver::filter (const FilterRequest_t &request,
     175void collectserver::filter (FilterRequest_t &request,
    171176                FilterResponse_t &response,
    172177                comerror_t &err, ostream &logout) {
    173178  outconvertclass text_t2ascii;
     179
     180  // translate any ".fc", ".pr" etc. stuff in the docSet
     181  text_t translatedOID;
     182  text_tset translatedOIDs;
     183  text_tset::iterator doc_here = request.docSet.begin();
     184  text_tset::iterator doc_end = request.docSet.end();
     185  while (doc_here != doc_end) {
     186    if (needs_translating (*doc_here)) {
     187      sourcelistclass::iterator source_here = sources.begin();
     188      sourcelistclass::iterator source_end = sources.end();
     189      while (source_here != source_end) {
     190    assert ((*source_here).s != NULL);
     191    if (((*source_here).s != NULL) &&
     192        ((*source_here).s->translate_OID (*doc_here, translatedOID, err, logout))) {
     193      if (err != noError) return;
     194      break;
     195    }
     196    source_here++;
     197      }
     198      translatedOIDs.insert (translatedOID);
     199    } else {
     200      translatedOIDs.insert (*doc_here);
     201    }
     202    doc_here ++;
     203  }
     204  request.docSet = translatedOIDs;
    174205
    175206  response.clear();
  • trunk/gsdl/src/colservr/collectserver.h

    r226 r249  
    9494                  comerror_t &err, ostream &logout);
    9595
    96   virtual void filter (const FilterRequest_t &request,
     96  virtual void filter (FilterRequest_t &request,
    9797               FilterResponse_t &response,
    9898               comerror_t &err, ostream &logout);
  • trunk/gsdl/src/colservr/filter.cpp

    r235 r249  
    1212/*
    1313   $Log$
     14   Revision 1.5  1999/04/30 02:00:46  sjboddie
     15   lots of stuff to do with getting documentaction working
     16
    1417   Revision 1.4  1999/04/12 03:45:02  rjmcnab
    1518   Finished the query filter.
     
    224227}
    225228
     229void intersect (text_tarray &set1, const text_tset &set2) {
     230  text_tarray resultset;
     231
     232  text_tarray::const_iterator set1_here = set1.begin();
     233  text_tarray::const_iterator set1_end = set1.end();
     234
     235  while (set1_here != set1_end) {
     236    if (in_set (set2, *set1_here))
     237      resultset.push_back (*set1_here);
     238    set1_here ++;
     239  }
     240  set1 = resultset;
     241}
     242
    226243
    227244// tests to see if el is in set
  • trunk/gsdl/src/colservr/filter.h

    r235 r249  
    112112// intersect places the result in set1
    113113void intersect (text_tset &set1, const text_tset &set2);
     114void intersect (text_tarray &set1, const text_tset &set2);
    114115
    115116// tests to see if el is in set
  • trunk/gsdl/src/colservr/infodbclass.cpp

    r226 r249  
    1212/*
    1313   $Log$
     14   Revision 1.3  1999/04/30 02:00:46  sjboddie
     15   lots of stuff to do with getting documentaction working
     16
    1417   Revision 1.2  1999/04/06 22:20:31  rjmcnab
    1518   Got browsefilter working.
     
    2528#include "gsdlunicode.h"
    2629#include "fileutil.h"
    27 
     30#include "OIDtools.h"
    2831 
    2932// constructors
     
    9194  gdbmfile = NULL;
    9295  openfile.clear();
     96}
     97
     98// replaces the .fc, .lc, .pr, .ns and .ps syntax (first child,
     99// last child, parent, next sibling, previous sibling)
     100// it expects child, parent, etc. to exist if syntax has been used
     101// so you should test before using
     102text_t gdbmclass::translate_OID (const text_t &inOID, infodbclass &info) {
     103
     104  if (inOID.empty() || inOID.size() < 4) return inOID;
     105  if (findchar (inOID.begin(), inOID.end(), '.') == inOID.end()) return inOID;
     106
     107  text_t OID = inOID;
     108  text_tarray tailarray;
     109  text_t tail = substr (OID.end()-3, OID.end());
     110  while (tail == ".fc" || tail == ".lc" || tail == ".pr" ||
     111     tail == ".ns" || tail == ".ps") {
     112    tailarray.push_back(tail);
     113    OID.erase (OID.end()-3, OID.end());
     114    tail = substr (OID.end()-3, OID.end());
     115  }
     116
     117  if (!tailarray.size()) return inOID;
     118  text_tarray::const_iterator begin = tailarray.begin();
     119  text_tarray::const_iterator here = tailarray.end() - 1;
     120
     121  while (here >= begin) {
     122
     123    if (*here == ".fc")
     124      get_first_child (OID, info);
     125    else if (*here == ".lc")
     126      get_last_child (OID, info);
     127    else if (*here == ".pr")
     128      OID = get_parent (OID);
     129    else if (*here == ".ns")
     130      get_next_sibling (OID, info);
     131    else if (*here == ".ps")
     132      get_previous_sibling (OID, info);
     133   
     134    here --;
     135  }
     136  return OID;
     137}
     138
     139void gdbmclass::get_first_child (text_t &OID, infodbclass &info) {
     140
     141  text_t firstchild;
     142  if (getinfo (OID, info)) {
     143    text_t &contains = info["contains"];
     144    if (!contains.empty()) {
     145      text_t parent = OID;
     146      getdelimitstr (contains.begin(), contains.end(), ';', firstchild);
     147      if (firstchild.empty()) OID = contains;
     148      else OID = firstchild;
     149      if (*(OID.begin()) == '"') translate_parent (OID, parent);
     150    }
     151  }
     152}
     153
     154void gdbmclass::get_last_child (text_t &OID, infodbclass &info) {
     155
     156  text_tarray children;
     157  if (getinfo (OID, info)) {
     158    text_t &contains = info["contains"];
     159    if (!contains.empty()) {
     160      text_t parent = OID;
     161      splitchar (contains.begin(), contains.end(), ';', children);
     162      OID = children.back();
     163      if (*(OID.begin()) == '"') translate_parent (OID, parent);
     164    }
     165  }
     166}
     167 
     168void gdbmclass::get_next_sibling (text_t &OID, infodbclass &info) {
     169
     170  text_tarray siblings;
     171  text_t parent = get_parent (OID);
     172         
     173  if (getinfo (parent, info)) {
     174    text_t &contains = info["contains"];
     175    if (!contains.empty()) {
     176      splitchar (contains.begin(), contains.end(), ';', siblings);
     177      text_tarray::const_iterator here = siblings.begin();
     178      text_tarray::const_iterator end = siblings.end();
     179      text_t shrunk_OID = OID;
     180      shrink_parent (shrunk_OID);
     181      while (here != end) {
     182    if (*here == shrunk_OID && (here+1 != end)) {
     183      OID = *(here+1);
     184      if (*(OID.begin()) == '"') translate_parent (OID, parent);
     185      break;
     186    }
     187    here ++;
     188      }
     189    }
     190  }
     191}
     192
     193void gdbmclass::get_previous_sibling (text_t &OID, infodbclass &info) {
     194
     195  text_tarray siblings;
     196  text_t parent = get_parent (OID);
     197
     198  if (getinfo (parent, info)) {
     199    text_t &contains = info["contains"];
     200    if (!contains.empty()) {
     201      splitchar (contains.begin(), contains.end(), ';', siblings);
     202      text_tarray::const_iterator here = siblings.begin();
     203      text_tarray::const_iterator end = siblings.end();
     204      text_t shrunk_OID = OID;
     205      shrink_parent (shrunk_OID);
     206      while (here != end) {
     207    if (*here == shrunk_OID && (here != siblings.begin())) {
     208      OID = *(here-1);
     209      if (*(OID.begin()) == '"') translate_parent (OID, parent);
     210      break;
     211    }
     212    here ++;
     213      }
     214    }
     215  }
    93216}
    94217
  • trunk/gsdl/src/colservr/infodbclass.h

    r226 r249  
    8787  void closedatabase ();
    8888
     89  // replaces the .c, .p, .n, .l syntax (child, parent, next, previous)
     90  // it expects child, parent, etc. to exist if syntax has been used
     91  // so you should test before using
     92  text_t translate_OID (const text_t &OID, infodbclass &info);
     93
    8994  // returns true on success
    9095  bool getinfo (text_t key, infodbclass &info);
     
    98103  GDBM_FILE gdbmfile;
    99104  ostream *logout;
    100  
     105
     106  void get_first_child (text_t &OID, infodbclass &info);
     107  void get_last_child (text_t &OID, infodbclass &info);
     108  void get_next_sibling (text_t &OID, infodbclass &info);
     109  void get_previous_sibling (text_t &OID, infodbclass &info);
     110
    101111  // returns true on success
    102112  bool getkeydata (text_t key, text_t &data);
  • trunk/gsdl/src/colservr/mggdbmsource.cpp

    r243 r249  
    1212/*
    1313   $Log$
     14   Revision 1.7  1999/04/30 02:00:47  sjboddie
     15   lots of stuff to do with getting documentaction working
     16
    1417   Revision 1.6  1999/04/21 22:40:44  sjboddie
    1518   made another change to the one I just committed. if requested metadata doesn't
     
    3841#include "mggdbmsource.h"
    3942#include "fileutil.h"
    40 
     43#include "OIDtools.h"
    4144
    4245
     
    8689}
    8790
    88 bool mggdbmsourceclass::get_metadata (const text_t &/*requestParams*/, const text_t &/*refParams*/,
    89                       const text_tarray &fields, const text_t &OID,
    90                       MetadataInfo_tarray &metadata,
    91                       comerror_t &err, ostream &logout) {
     91bool mggdbmsourceclass::translate_OID (const text_t &OIDin, text_t &OIDout,
     92                       comerror_t &err, ostream &logout) {
     93
    9294  outconvertclass text_t2ascii;
    93 
    94   metadata.erase(metadata.begin(), metadata.end());
    9595
    9696  err = noError;
     
    115115  }
    116116
     117  infodbclass info;
     118  OIDout = gdbmptr->translate_OID (OIDin, info);
     119  return true;
     120}
     121
     122bool mggdbmsourceclass::get_metadata (const text_t &/*requestParams*/, const text_t &/*refParams*/,
     123                      const text_tarray &fields, const text_t &OID,
     124                      MetadataInfo_tarray &metadata,
     125                      comerror_t &err, ostream &logout) {
     126  outconvertclass text_t2ascii;
     127
     128  metadata.erase(metadata.begin(), metadata.end());
     129
     130  err = noError;
     131  if (gdbmptr == NULL) {
     132    // most likely a configuration problem
     133    logout << text_t2ascii
     134       << "configuration error: mggdbmsource contains a null gdbmclass\n\n";
     135    err = configurationError;
     136    return true;
     137  }
     138
     139  // open the database
     140  gdbmptr->setlogout(&logout);
     141  if (!gdbmptr->opendatabase (gdbm_filename)) {
     142    // most likely a system problem (we have already checked that the
     143    // gdbm database exists)
     144    logout << text_t2ascii
     145       << "system problem: open on gdbm database \""
     146       << gdbm_filename << "\" failed\n\n";
     147    err = systemProblem;
     148    return true;
     149  }
     150
    117151  // get the metadata
    118152  infodbclass info;
     
    126160
    127161  // collect together the metadata
     162  bool donenextprevtest = false;
     163  bool hasnext, hasprevious;
    128164  MetadataInfo_t this_metadata;
    129165  text_t *pos_metadata;
     
    134170    this_metadata.isRef = false;
    135171    pos_metadata = info.getinfo(*fields_here);
    136     if (pos_metadata != NULL && *fields_here != "contains")
     172   
     173    if ((*fields_here == "hasnext" || *fields_here == "hasprevious")) {
     174
     175      // collect metadata
     176      if (!donenextprevtest) {
     177    donenextprevtest = true;
     178
     179    // cache parent contents array
     180    text_t thisparent = get_parent (OID);
     181    if (thisparent != parentOID) {
     182      parentOID = thisparent;
     183      parentcontents.erase(parentcontents.begin(), parentcontents.end());
     184      if (gdbmptr->getinfo(parentOID, parentinfo)) {
     185        text_t &parentinfocontains = parentinfo["contains"];
     186      if (!parentinfocontains.empty())
     187        splitchar (parentinfocontains.begin(), parentinfocontains.end(), ';', parentcontents);
     188      }
     189    }
     190
     191    // do tests
     192    text_tarray::const_iterator parentcontents_here = parentcontents.begin();
     193    text_tarray::const_iterator parentcontents_end = parentcontents.end();
     194    text_t shrunk_OID = OID;
     195    shrink_parent (shrunk_OID);
     196    while (parentcontents_here != parentcontents_end) {
     197      if (*parentcontents_here == shrunk_OID) {
     198        if (parentcontents_here == parentcontents.begin()) hasprevious = false;
     199        else hasprevious = true;
     200
     201        parentcontents_here++;
     202
     203        if (parentcontents_here == parentcontents.end()) hasnext = false;
     204        else hasnext = true;
     205
     206        break;
     207      } 
     208       
     209      parentcontents_here ++;
     210    }
     211      } 
     212   
     213      // fill in metadata
     214      if ((*fields_here == "hasnext" && hasnext) ||
     215      (*fields_here == "hasprevious" && hasprevious))
     216    this_metadata.values.push_back("1");
     217      else
     218    this_metadata.values.push_back("0");
     219
     220    }
     221    else if (pos_metadata != NULL && *fields_here != "contains")
    137222      this_metadata.values.push_back(*pos_metadata);
    138223    else
  • trunk/gsdl/src/colservr/mggdbmsource.h

    r236 r249  
    2929  text_t collectdir;
    3030
     31  text_t parentOID;
     32  infodbclass parentinfo;
     33  text_tarray parentcontents;
     34
    3135  text_t gdbm_filename;
    3236  gdbmclass *gdbmptr;
     
    4650  void configure (const text_t &key, const text_tarray &cfgline);
    4751  bool init (ostream &logout);
     52  bool translate_OID (const text_t &OIDin, text_t &OIDout,
     53              comerror_t &err, ostream &logout);
    4854  bool get_metadata (const text_t &requestParams, const text_t &refParams,
    4955             const text_tarray &fields, const text_t &OID,
  • trunk/gsdl/src/colservr/source.cpp

    r226 r249  
    1212/*
    1313   $Log$
     14   Revision 1.3  1999/04/30 02:00:48  sjboddie
     15   lots of stuff to do with getting documentaction working
     16
    1417   Revision 1.2  1999/04/06 22:20:32  rjmcnab
    1518   Got browsefilter working.
     
    4548}
    4649
     50
     51// translate_OID translates OIDs using ".pr", ."fc" etc.
     52bool sourceclass::translate_OID (const text_t &/*OIDin*/, text_t &/*OIDout*/,
     53                 comerror_t &err, ostream &/*logout*/) {
     54  err = noError;
     55
     56  return false;
     57}
     58
     59
    4760// get_metadata fills out the metadata if possible, if it is not responsable
    4861// for the given OID then it will return false.
  • trunk/gsdl/src/colservr/source.h

    r226 r249  
    3030  // before any other methods are called
    3131  virtual bool init (ostream &logout);
     32
     33  // translate_OID translates OIDs using ".pr", ."fc" etc.
     34  virtual bool translate_OID (const text_t &OIDin, text_t &OIDout,
     35                  comerror_t &err, ostream &logout);
    3236
    3337  // get_metadata fills out the metadata if possible, if it is not responsable
Note: See TracChangeset for help on using the changeset viewer.