Ignore:
Timestamp:
1999-10-10T21:14:12+13:00 (25 years ago)
Author:
sjboddie
Message:
  • metadata now returns mp rather than array
  • redesigned browsing support (although it's not finished so

won't currently work ;-)

File:
1 edited

Legend:

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

    r636 r649  
    2828/*
    2929   $Log$
     30   Revision 1.12  1999/10/10 08:14:07  sjboddie
     31   - metadata now returns mp rather than array
     32   - redesigned browsing support (although it's not finished so
     33   won't currently work ;-)
     34
    3035   Revision 1.11  1999/09/28 20:38:19  rjmcnab
    3136   fixed a couple of bugs
     
    7378
    7479// a few function prototypes
    75 static text_t format_string (const ResultDocInfo_t &docinfo, format_t *formatlistptr,
     80static text_t format_string (ResultDocInfo_t &docinfo, format_t *formatlistptr,
    7681                 const text_t &link, const text_t &icon, const text_t &text);
    7782
    7883static bool parse_action (text_t::const_iterator &here, const text_t::const_iterator &end,
    79               format_t *formatlistptr, text_tarray &metadata, bool &getParents,
    80               text_tmap &metamap, int &metacount);
     84              format_t *formatlistptr, text_tset &metadata, bool &getParents);
    8185
    8286void metadata_t::clear() {
    8387  metaname.clear();
    84   metaindex = 0;
    8588  metacommand = mNone;
    8689  parentcommand = pNone;
    87   parentindex = 0;
    8890  parentoptions.clear();
    8991};
     
    120122  DocumentButtons.push_back ("Expand Contents");
    121123  DocumentText = "[Text]";
     124  formatstrings.erase (formatstrings.begin(), formatstrings.end());
     125}
     126
     127// returns false if key isn't in formatstringmap
     128bool get_formatstring (const text_t &key, const text_tmap &formatstringmap,
     129               text_t &formatstring) {
     130
     131  formatstring.clear();
     132  text_tmap::const_iterator it = formatstringmap.find(key);
     133  if (it == formatstringmap.end()) return false;
     134  formatstring = (*it).second;
     135  return true;
     136}
     137// tries to find "key1key2" then "key1" then "key2"
     138bool get_formatstring (const text_t &key1, const text_t &key2, 
     139               const text_tmap &formatstringmap,
     140               text_t &formatstring) {
     141
     142  formatstring.clear();
     143  text_tmap::const_iterator it = formatstringmap.find(key1 + key2);
     144  if (it != formatstringmap.end()) {
     145    formatstring = (*it).second;
     146    return true;
     147  }
     148  it = formatstringmap.find(key1);
     149  if (it != formatstringmap.end()) {
     150    formatstring = (*it).second;
     151    return true;
     152  }
     153  it = formatstringmap.find(key2);
     154  if (it != formatstringmap.end()) {
     155    formatstring = (*it).second;
     156    return true;
     157  }
     158  return false;
    122159}
    123160
     
    152189static void get_parent_options (text_t &instring, metadata_t &metaoption) {
    153190
    154   metaoption.clear();
    155191  text_t meta, com, op;
    156192  bool inbraces = false;
     
    175211  else if (com == "Top")
    176212    metaoption.parentcommand = pTop;
    177   else if (is_number(com)) {
    178     metaoption.parentcommand = pIndex;
    179     metaoption.metaindex = com.getint();
    180   } else if (com == "All") {
     213  else if (com == "All") {
    181214    metaoption.parentcommand = pAll;
    182215    metaoption.parentoptions = op;
     
    184217}
    185218
    186 static bool parse_meta (text_t &meta, int &count, decision_t &decision,
    187             text_tarray &metadata, bool &getParents, text_tmap &metamap) {
     219static void parse_meta (text_t &meta, metadata_t &metaoption,
     220            text_tset &metadata, bool &getParents) {
     221
     222  if (meta.size() > 8 && (substr(meta.begin(), meta.begin()+8) == "cgisafe:")) {
     223    metaoption.metacommand = mCgiSafe;
     224    meta = substr (meta.begin()+8, meta.end());
     225  }
    188226
    189227  if (meta.size() > 7 && (substr (meta.begin(), meta.begin()+6) == "parent")) {
    190228    getParents = true;
    191     metadata_t metaoption;
    192229    get_parent_options (meta, metaoption);
    193     decision.meta = metaoption;
    194   }
    195   text_tmap::const_iterator it;
    196   if ((it = metamap.find(meta)) != metamap.end()) {
    197       decision.meta.metaindex = (*it).second.getint();
    198   } else {
    199     metamap[meta] = count;
    200     metadata.push_back (meta);
    201     decision.meta.metaindex = count;
    202     count ++;
    203   }
    204   return true;
    205 }
    206 
    207 static bool parse_meta (text_t &meta, int &count, format_t *formatlistptr,
    208             text_tarray &metadata, bool &getParents, text_tmap &metamap) {
     230  }
     231
     232  metadata.insert (meta);
     233  metaoption.metaname = meta;
     234}
     235
     236static void parse_meta (text_t &meta, format_t *formatlistptr,
     237            text_tset &metadata, bool &getParents) {
    209238 
    210239  if (meta == "link")
     
    224253  else {
    225254    formatlistptr->command = comMeta;
    226 
    227     if (meta.size() > 8 && (substr(meta.begin(), meta.begin()+8) == "cgisafe:")) {
    228       formatlistptr->meta.metacommand = mCgiSafe;
    229       meta = substr (meta.begin()+8, meta.end());
    230     }
    231 
    232     if (meta.size() > 7 && (substr (meta.begin(), meta.begin()+6) == "parent")) {
    233       getParents = true;
    234       metadata_t metaoption;
    235       get_parent_options (meta, metaoption);
    236       formatlistptr->meta = metaoption;
    237     }
    238 
    239     text_tmap::const_iterator it;
    240     if ((it = metamap.find(meta)) != metamap.end()) {
    241       formatlistptr->meta.metaindex = (*it).second.getint();
    242     } else {
    243       metamap[meta] = count;
    244       metadata.push_back (meta);
    245       formatlistptr->meta.metaindex = count;
    246       count ++;
    247     }
    248     formatlistptr->meta.metaname = meta;
    249   }
    250   return true;
     255    parse_meta (meta, formatlistptr->meta, metadata, getParents);
     256  }
    251257}
    252258
    253259static bool parse_string (const text_t &formatstring, format_t *formatlistptr,
    254               text_tarray &metadata, bool &getParents,
    255               text_tmap &metamap, int &metacount) {
     260              text_tset &metadata, bool &getParents) {
    256261
    257262  text_t text;
     
    273278    text.clear();
    274279      }
    275       if (parse_action (++here, end, formatlistptr, metadata,
    276             getParents, metamap, metacount)) {
     280      if (parse_action (++here, end, formatlistptr, metadata, getParents)) {
    277281    formatlistptr->nextptr = new format_t();
    278282    formatlistptr = formatlistptr->nextptr;
     
    295299    here ++;
    296300      }
    297       if (parse_meta (meta, metacount, formatlistptr, metadata, getParents, metamap)) {
    298     formatlistptr->nextptr = new format_t();
    299     formatlistptr = formatlistptr->nextptr;
    300       }
     301      parse_meta (meta, formatlistptr, metadata, getParents);
     302      formatlistptr->nextptr = new format_t();
     303      formatlistptr = formatlistptr->nextptr;
    301304
    302305    } else
     
    317320
    318321static bool parse_action (text_t::const_iterator &here, const text_t::const_iterator &end,
    319               format_t *formatlistptr, text_tarray &metadata, bool &getParents,
    320               text_tmap &metamap, int &metacount) {
     322              format_t *formatlistptr, text_tset &metadata, bool &getParents) {
    321323
    322324  text_t::const_iterator it = findchar (here, end, '}');
     
    371373      // it's metadata
    372374      text_t meta = substr (beginbracket+1, endbracket);
    373       parse_meta (meta, metacount, or_ptr, metadata, getParents, metamap);
     375      parse_meta (meta, or_ptr, metadata, getParents);
    374376
    375377    } else {
     
    390392      if ((*beginbracket == '[') && (*endbracket == ']')) {
    391393        text_t meta = substr (beginbracket+1, endbracket);
    392         decision_t decision;
    393         parse_meta (meta, metacount, formatlistptr->decision,
    394             metadata, getParents, metamap);
     394        parse_meta (meta, formatlistptr->decision.meta, metadata, getParents);
    395395        commacount ++;
    396396        text.clear();
     
    399399    } else if (commacount == 1) {
    400400      formatlistptr->ifptr = new format_t();
    401       parse_string (text, formatlistptr->ifptr, metadata,
    402             getParents, metamap, metacount);
     401      parse_string (text, formatlistptr->ifptr, metadata, getParents);
    403402      commacount ++;
    404403      text.clear();
     
    406405    } else if (commacount == 2) {
    407406      formatlistptr->elseptr = new format_t();
    408       parse_string (text, formatlistptr->elseptr, metadata,
    409             getParents, metamap, metacount);
     407      parse_string (text, formatlistptr->elseptr, metadata, getParents);
    410408      commacount ++;
    411409      text.clear();
     
    424422
    425423bool parse_formatstring (const text_t &formatstring, format_t *formatlistptr,
    426              text_tarray &metadata, bool &getParents) {
     424             text_tset &metadata, bool &getParents) {
    427425
    428426  formatlistptr->clear();
    429   metadata.erase (metadata.begin(), metadata.end());
    430427  getParents = false;
    431428
    432   text_tmap metamap;
    433   int metacount = 0;
    434   return (parse_string (formatstring, formatlistptr, metadata,
    435             getParents, metamap, metacount));
     429  return (parse_string (formatstring, formatlistptr, metadata, getParents));
    436430}
    437431
     
    440434// be of the form yyyymmdd, this is of course, crap ;)
    441435
    442 static text_t get_meta (const ResultDocInfo_t &docinfo, const metadata_t &meta) {
    443   int metasize = docinfo.metadata.size();
    444   int mindex = meta.metaindex;
    445   if (metasize < 1 || metasize <= mindex) return "";
    446   int valuesize = docinfo.metadata[mindex].values.size();
     436static text_t get_meta (ResultDocInfo_t &docinfo, const metadata_t &meta) {
     437 
     438  // make sure we have the requested metadata
     439  MetadataInfo_tmap::iterator it = docinfo.metadata.find (meta.metaname);
     440  if (it == docinfo.metadata.end()) return "";
     441
     442  MetadataInfo_t *parent = docinfo.metadata[meta.metaname].parent;
    447443
    448444  switch (meta.parentcommand) {
    449445  case pNone:
    450446    if (meta.metaname == "Date")
    451       return format_date (docinfo.metadata[mindex].values.back());
     447      return format_date (docinfo.metadata[meta.metaname].values[0]);
    452448    if (meta.metacommand == mCgiSafe)
    453       return cgi_safe (docinfo.metadata[mindex].values.back());
    454     else return docinfo.metadata[mindex].values.back();
     449      return cgi_safe (docinfo.metadata[meta.metaname].values[0]);
     450    else return docinfo.metadata[meta.metaname].values[0];
    455451
    456452  case pImmediate:
    457     if (valuesize > 1) {
     453    if (parent != NULL) {
    458454      if (meta.metaname == "Date")
    459     return format_date (docinfo.metadata[mindex].values[metasize-2]);
    460     if (meta.metacommand == mCgiSafe)
    461       return cgi_safe (docinfo.metadata[mindex].values[metasize-2]);
    462     else return docinfo.metadata[mindex].values[metasize-2];
     455    return format_date (parent->values[0]);
     456      if (meta.metacommand == mCgiSafe)
     457    return cgi_safe (parent->values[0]);
     458      else return parent->values[0];
    463459    }
    464460    break;
    465461
    466462  case pTop:
    467     if (valuesize > 1) {
     463    if (parent != NULL) {
     464      while (parent->parent != NULL) parent = parent->parent;
     465
    468466      if (meta.metaname == "Date")
    469     return format_date (docinfo.metadata[mindex].values[0]);
    470     if (meta.metacommand == mCgiSafe)
    471       return cgi_safe (docinfo.metadata[mindex].values[0]);
    472     else return docinfo.metadata[mindex].values[0];
     467    return format_date (parent->values[0]);
     468      if (meta.metacommand == mCgiSafe)
     469    return cgi_safe (parent->values[0]);
     470      else return parent->values[0];
    473471    }
    474472    break;
    475473
    476   case pIndex:
    477     if (valuesize > meta.parentindex) {
    478       if (meta.metaname == "Date")
    479     return format_date (docinfo.metadata[mindex].values[meta.parentindex]);
    480       if (meta.metacommand == mCgiSafe)
    481     return cgi_safe (docinfo.metadata[mindex].values[meta.parentindex]);
    482       else return docinfo.metadata[mindex].values[meta.parentindex];
    483     }
    484     break;
    485 
    486474  case pAll:
    487     bool first = true;
    488     text_t tmp;
    489     if (valuesize > 1) {
    490       text_tarray::const_iterator here = docinfo.metadata[mindex].values.begin();
    491       // don't want last value as that's the value of the current level (i.e. it's
    492       // not a parent
    493       text_tarray::const_iterator end = docinfo.metadata[mindex].values.end() - 1;
     475    MetadataInfo_t *parent = docinfo.metadata[meta.metaname].parent;
     476    if (parent != NULL) {
     477      text_tarray tmparray;
     478      while (parent != NULL) {
     479    tmparray.push_back (parent->values[0]);
     480    parent = parent->parent;
     481      }
     482      bool first = true;
     483      text_t tmp;
     484      text_tarray::reverse_iterator here = tmparray.rbegin();
     485      text_tarray::reverse_iterator end = tmparray.rend();
    494486      while (here != end) {
    495487    if (!first) tmp += meta.parentoptions;
     
    499491    here ++;
    500492      }
     493      if (meta.metacommand == mCgiSafe) return cgi_safe (tmp);
     494      else return tmp;
    501495    }
    502     if (meta.metacommand == mCgiSafe) return cgi_safe (tmp);
    503     else return tmp;
    504496  }
    505497  return "";
    506498}
    507499
    508 static text_t get_or (const ResultDocInfo_t &docinfo, format_t *orptr,
     500static text_t get_or (ResultDocInfo_t &docinfo, format_t *orptr,
    509501              const text_t &link, const text_t &icon, const text_t &text) {
    510502
     
    520512}
    521513
    522 static text_t get_if (const ResultDocInfo_t &docinfo, const decision_t &decision,
     514static text_t get_if (ResultDocInfo_t &docinfo, const decision_t &decision,
    523515              format_t *ifptr, format_t *elseptr, const text_t &link,
    524516              const text_t &icon, const text_t &text) {
     
    538530}
    539531
    540 text_t format_string (const ResultDocInfo_t &docinfo, format_t *formatlistptr,
     532text_t format_string (ResultDocInfo_t &docinfo, format_t *formatlistptr,
    541533              const text_t &link, const text_t &icon, const text_t &text) {
    542534
     
    569561
    570562
    571 text_t get_formatted_string (const ResultDocInfo_t &docinfo, format_t *formatlistptr,
     563text_t get_formatted_string (ResultDocInfo_t &docinfo, format_t *formatlistptr,
    572564                 const text_t &link, const text_t &icon) {
    573565
     
    583575
    584576
    585 text_t get_formatted_string (const ResultDocInfo_t &docinfo, format_t *formatlistptr) {
     577text_t get_formatted_string (ResultDocInfo_t &docinfo, format_t *formatlistptr) {
    586578
    587579  text_t link = "<a href=\"_httpdocument_&cl=search&d=" + docinfo.OID + "\">";
     
    598590
    599591
    600 text_t get_formatted_string (const ResultDocInfo_t &docinfo, format_t *formatlistptr,
     592text_t get_formatted_string (ResultDocInfo_t &docinfo, format_t *formatlistptr,
    601593                 const text_t &text) {
    602594
     
    613605
    614606
    615 text_t get_formatted_string (const ResultDocInfo_t &docinfo, format_t *formatlistptr,
     607text_t get_formatted_string (ResultDocInfo_t &docinfo, format_t *formatlistptr,
    616608                 const text_t &link, const text_t &icon, const text_t &text) {
    617609
Note: See TracChangeset for help on using the changeset viewer.