Changeset 1443 for trunk


Ignore:
Timestamp:
2000-08-25T12:57:05+12:00 (24 years ago)
Author:
davidb
Message:

Changes to support nested {If} and {Or} statements in macro files.
Also expansion of metadata if it includes further metadata. The two
can be intermixed -- metadata can include metadata that has {If}
and {Or} statements.

Location:
trunk/gsdl/src/recpt
Files:
9 edited

Legend:

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

    r1347 r1443  
    8484  comerror_t err;
    8585  FilterRequest_t request;
     86  request.clear();
    8687
    8788  request.filterName = "NullFilter";
  • trunk/gsdl/src/recpt/browsetools.cpp

    r1285 r1443  
    114114    return;
    115115
    116   textout << outconvert << disp << get_formatted_string (response.docInfo[0], formatlistptr);
     116  textout << outconvert << disp
     117      << get_formatted_string (args["c"],collectproto,
     118                   response.docInfo[0], formatlistptr,
     119                   logout);
    117120}
    118121
     
    488491  if (haschildren) {
    489492    bool use_table = is_table_content (formatlistptr);
    490     bptr->output_section_group (response, args, "", tabcount, formatlistptr, use_table,
     493    // collection used to be "" // **** // check with Stef!!!!
     494    bptr->output_section_group (response, args, args["c"], tabcount, formatlistptr, use_table,
    491495                metadata, getParents, collectproto, disp, outconvert,
    492496                textout, logout);
  • trunk/gsdl/src/recpt/datelistbrowserclass.cpp

    r1285 r1443  
    5858
    5959int datelistbrowserclass::output_section_group (FilterResponse_t &sections, cgiargsclass &args,
    60                         const text_t &/*collection*/, int colnumber, format_t *formatlistptr,
     60                        const text_t &collection, int colnumber, format_t *formatlistptr,
    6161                        bool use_table, text_tset &/*metadata*/, bool &/*getParents*/,
    62                         recptproto * /*collectproto*/, displayclass &disp,
    63                         outconvertclass &outconvert, ostream &textout, ostream &/*logout*/) {
     62                        recptproto * collectproto, displayclass &disp,
     63                        outconvertclass &outconvert, ostream &textout, ostream &logout) {
    6464
    6565  text_t lastyear = "0000";
     
    125125   
    126126    textout << outconvert << disp
    127             << get_formatted_string (*thissection, formatlistptr, link, icon) << "\n";
     127            << get_formatted_string (collection, collectproto,
     128                     *thissection, formatlistptr,
     129                     link, icon, false,
     130                     logout) << "\n";
    128131   
    129132    if (!use_table) textout << "</td>";
  • trunk/gsdl/src/recpt/documentaction.cpp

    r1419 r1443  
    718718 
    719719    if (wanttext != 1) {
    720       text_t doctext = get_formatted_string (docinfo, formatlistptr, docresponse.doc);
     720      text_t doctext
     721      = get_formatted_string (collection, collectproto,
     722                  docinfo, formatlistptr, docresponse.doc,
     723                  logout);
    721724     
    722725      if (highlight)
  • trunk/gsdl/src/recpt/extlinkaction.cpp

    r1285 r1443  
    113113  // _nexturl_             link to external page
    114114  // _prevdoc_             link to previous document
    115  
     115  //  disp.setmacro("nexturl", "extlink", cgi_safe(args["href"]));
     116  // problem in whist, above line changed.  Perhaps decode_cgi_arg ??
     117  // see also HTML plugin
    116118  disp.setmacro("nexturl", "extlink", args["href"]);
    117119  disp.setmacro("prevdoc", "extlink", args["d"]);
  • trunk/gsdl/src/recpt/formattools.cpp

    r1285 r1443  
    2626#include "formattools.h"
    2727#include "cgiutils.h"
     28#include "OIDtools.h"
     29
    2830#include <assert.h>
    2931
    3032// a few function prototypes
    31 static text_t format_string (ResultDocInfo_t &docinfo, format_t *formatlistptr,
     33static text_t format_string (const text_t& collection, recptproto* collectproto,
     34                 ResultDocInfo_t &docinfo, format_t *formatlistptr,
    3235                 const text_t &link, const text_t &icon,
    33                  const text_t &text, bool highlight);
     36                 const text_t &text, bool highlight, ostream& logout);
    3437
    3538static bool parse_action (text_t::const_iterator &here, const text_t::const_iterator &end,
     
    269272      }
    270273      if (parse_action (++here, end, formatlistptr, metadata, getParents)) {
     274
    271275    formatlistptr->nextptr = new format_t();
    272276    formatlistptr = formatlistptr->nextptr;
     
    324328  else return false;
    325329
    326   int curlycount = 0;
    327330  int commacount = 0;
    328331  text_t text;
     
    333336      if (here != end) text.push_back(*here);
    334337     
    335     } else if (*here == '{') {curlycount ++; text.push_back(*here);}
    336     else if (*here == '}' && curlycount > 0) {
    337       curlycount --;
    338       text.push_back(*here);
    339     }
    340 
    341     else if ((*here == ',' || *here == '}') && curlycount <= 0) {
     338    }
     339 
     340    else if (*here == ',' || *here == '}' || *here == '{') {
    342341
    343342      if (formatlistptr->command == comOr) {
    344343    // the {Or}{this, or this, or this, or this} statement
    345     // or'ed statements may be either [metadata] or plain text
    346344    format_t *or_ptr;
    347345   
     
    358356    }
    359357
    360     text_t::const_iterator beginbracket = text.begin();
    361     text_t::const_iterator endbracket = (text.end() - 1);
    362     if ((*beginbracket == '[') && (*endbracket == ']')) {
    363       // it's metadata
    364       text_t meta = substr (beginbracket+1, endbracket);
    365       parse_meta (meta, or_ptr, metadata, getParents);
    366 
    367     } else {
    368       parse_string (text, or_ptr, metadata, getParents);
    369     }
     358    if (!text.empty())
     359      {
     360        if (!parse_string(text, or_ptr, metadata, getParents)) { return false; }
     361      }
     362
     363    if (*here == '{')
     364      {
     365        // Supports: {Or}{[Booktitle],[Title],{If}{[XXXX],aaa,bbb}}
     366        // but not : {Or}{[Booktitle],[Title]{If}{[XXXX],aaa,bbb}}
     367        // The latter can always be re-written:
     368        // {Or}{[Booktitle],{If}{[Title],[Title]{If}{[XXXX],aaa,bbb}}}
     369       
     370        if (!text.empty()) // already used up allocated format_t
     371          {
     372        // => allocate new one for detected action
     373        or_ptr->nextptr = new format_t();
     374        or_ptr = or_ptr->nextptr;
     375          }
     376        if (!parse_action(++here, end, or_ptr, metadata, getParents))
     377          {
     378        return false;
     379          }
     380      }
     381    else
     382      {
     383        if (*here == '}') break;
     384      }
    370385    text.clear();
    371386
     
    374389    if (commacount == 0) {
    375390      // If decision only supports metadata at present
    376      
     391
    377392      // remove the surrounding square brackets
    378393      text_t::const_iterator beginbracket = text.begin();
     
    385400      }
    386401     
    387     } else if (commacount == 1) {
    388       formatlistptr->ifptr = new format_t();
    389       parse_string (text, formatlistptr->ifptr, metadata, getParents);
    390       commacount ++;
    391       text.clear();
     402    } else {
     403      format_t** nextlistptr = NULL;
     404      if (commacount == 1) {
     405          nextlistptr = &formatlistptr->ifptr;
     406      } else if (commacount == 2 ) {
     407        nextlistptr = &formatlistptr->elseptr;
     408      } else {
     409        return false;
     410      }
     411
     412      if (!text.empty()) {
     413        if (*nextlistptr == NULL) {
     414          *nextlistptr = new format_t();
     415        } else {
     416
     417          // skip to the end of any format_t statements already added
     418          while ((*nextlistptr)->nextptr != NULL)
     419          {
     420        nextlistptr = &(*nextlistptr)->nextptr;
     421          }
     422
     423          (*nextlistptr)->nextptr = new format_t();
     424          nextlistptr = &(*nextlistptr)->nextptr;
     425        }
     426
     427        if (!parse_string (text, *nextlistptr, metadata, getParents))
     428          {
     429        return false;
     430          }
     431        text.clear();
     432      }
    392433     
    393     } else if (commacount == 2) {
    394       formatlistptr->elseptr = new format_t();
    395       parse_string (text, formatlistptr->elseptr, metadata, getParents);
    396       commacount ++;
    397       text.clear();
     434      if (*here == '{')
     435        {
     436          if (*nextlistptr == NULL) {
     437        *nextlistptr = new format_t();
     438          } else {
     439        (*nextlistptr)->nextptr = new format_t();
     440        nextlistptr = &(*nextlistptr)->nextptr;
     441          }
     442
     443          if (!parse_action(++here, end, *nextlistptr, metadata, getParents))
     444        {
     445          return false;
     446        }
     447        }
     448      else
     449        {
     450          if (*here == '}') break;
     451          commacount ++;
     452        }
    398453    }
    399454      }
    400       if (*here == '}') break;
    401455     
    402456    } else text.push_back(*here);
     
    493547}
    494548
    495 static text_t get_or (ResultDocInfo_t &docinfo, format_t *orptr,
     549static text_t get_or (const text_t& collection, recptproto* collectproto,
     550              ResultDocInfo_t &docinfo, format_t *orptr,
    496551              const text_t &link, const text_t &icon,
    497               const text_t &text, bool highlight) {
     552              const text_t &text, bool highlight,
     553              ostream& logout) {
    498554
    499555  text_t tmp;
    500556  while (orptr != NULL) {
    501557
    502     tmp = format_string (docinfo, orptr, link, icon, text, highlight);
     558    tmp = format_string (collection,collectproto, docinfo,orptr,
     559             link,icon,text,highlight, logout);
    503560    if (!tmp.empty()) return tmp;
    504561
     
    508565}
    509566
    510 static text_t get_if (ResultDocInfo_t &docinfo, const decision_t &decision,
     567static text_t get_if (const text_t& collection, recptproto* collectproto,
     568              ResultDocInfo_t &docinfo, const decision_t &decision,
    511569              format_t *ifptr, format_t *elseptr, const text_t &link,
    512               const text_t &icon, const text_t &text, bool highlight) {
     570              const text_t &icon, const text_t &text, bool highlight,
     571              ostream& logout)
     572{
    513573
    514574  // not much of a choice yet ...
     
    516576    if (get_meta (docinfo, decision.meta) != "") {
    517577      if (ifptr != NULL)
    518     return get_formatted_string (docinfo, ifptr, link, icon, text, highlight);
     578    return get_formatted_string (collection,collectproto, docinfo,ifptr,
     579                     link,icon,text,highlight, logout);
    519580    }
    520581    else {
    521582      if (elseptr != NULL)
    522     return get_formatted_string (docinfo, elseptr, link, icon, text, highlight);
     583    return get_formatted_string (collection,collectproto, docinfo,elseptr,
     584                     link,icon,text,highlight, logout);
    523585    }
    524586  }
     
    526588}
    527589
    528 text_t format_string (ResultDocInfo_t &docinfo, format_t *formatlistptr,
     590bool includes_metadata(const text_t& text)
     591{
     592  text_t::const_iterator here = text.begin();
     593  text_t::const_iterator end = text.end();
     594  while (here != end) {
     595    if (*here == '[') return true;
     596    here ++;
     597  }
     598
     599  return false;
     600}
     601
     602text_t format_string (const text_t& collection, recptproto* collectproto,
     603              ResultDocInfo_t &docinfo, format_t *formatlistptr,
    529604              const text_t &link, const text_t &icon,
    530               const text_t &text, bool highlight) {
     605              const text_t &text, bool highlight,
     606              ostream& logout) {
    531607
    532608  if (formatlistptr == NULL) return "";
     
    545621    return docinfo.result_num;
    546622  case comMeta:
    547     return get_meta (docinfo, formatlistptr->meta);
     623
     624    {
     625      const text_t& metavalue =  get_meta (docinfo, formatlistptr->meta);
     626
     627      if (includes_metadata(metavalue))
     628    {
     629      // text has embedded metadata in it => expand it
     630      FilterRequest_t request;
     631      FilterResponse_t response;
     632
     633      request.getParents = false;
     634     
     635      format_t *expanded_formatlistptr = new format_t();
     636      parse_formatstring (metavalue, expanded_formatlistptr,
     637                  request.fields, request.getParents);
     638     
     639      // retrieve metadata
     640      get_info(docinfo.OID, collection, request.fields, request.getParents,
     641           collectproto, response, logout);
     642     
     643      if (!response.docInfo.empty())
     644        {
     645          text_t expanded_metavalue
     646        = get_formatted_string(collection,collectproto,
     647                       response.docInfo[0],expanded_formatlistptr,
     648                       link,icon,highlight,
     649                       logout);
     650         
     651          return expanded_metavalue;
     652        }
     653      else
     654        {
     655          return metavalue;
     656        }
     657    }
     658      else
     659    {
     660      return metavalue;
     661    }
     662    }
    548663  case comDoc:
    549664    return text;
     
    555670    break;
    556671  case comIf:
    557     return get_if (docinfo, formatlistptr->decision, formatlistptr->ifptr,
    558            formatlistptr->elseptr, link, icon, text, highlight);
     672    return get_if (collection, collectproto,
     673           docinfo, formatlistptr->decision, formatlistptr->ifptr,
     674           formatlistptr->elseptr, link, icon, text, highlight,
     675           logout);
    559676  case comOr:
    560     return get_or (docinfo, formatlistptr->orptr, link, icon, text, highlight);
     677    return get_or (collection,collectproto, docinfo,formatlistptr->orptr,
     678           link,icon,text,highlight, logout);
    561679  }
    562680  return "";
     
    564682
    565683
    566 text_t get_formatted_string (ResultDocInfo_t &docinfo, format_t *formatlistptr,
    567                  const text_t &link, const text_t &icon) {
    568 
    569   text_t text;
     684
     685
     686text_t get_formatted_string (const text_t& collection, recptproto* collectproto,
     687                 ResultDocInfo_t& docinfo, format_t* formatlistptr,
     688                 const text_t& link, const text_t& icon,
     689                 const text_t& text, const bool highlight,
     690                 ostream& logout) {
    570691
    571692  text_t ft;
    572   while (formatlistptr != NULL) {
    573     ft += format_string (docinfo, formatlistptr, link, icon, text, false);
    574     formatlistptr = formatlistptr->nextptr;
    575   }
     693  while (formatlistptr != NULL)
     694    {
     695      ft += format_string (collection, collectproto, docinfo, formatlistptr,
     696               link, icon, text, highlight, logout);
     697      formatlistptr = formatlistptr->nextptr;
     698    }
     699
    576700  return ft;
    577701}
    578702
    579 
    580 text_t get_formatted_string (ResultDocInfo_t &docinfo, format_t *formatlistptr) {
     703text_t get_formatted_string (const text_t& collection, recptproto* collectproto,
     704                 ResultDocInfo_t &docinfo, format_t *formatlistptr,
     705                 const text_t &link, const text_t &icon,
     706                 const bool highlight,
     707                 ostream& logout) {
     708
     709  text_t text = "";
     710
     711  return get_formatted_string(collection, collectproto, docinfo, formatlistptr,
     712                              link, icon, text, highlight, logout);
     713}
     714
     715text_t get_formatted_string (const text_t& collection, recptproto* collectproto,
     716                 ResultDocInfo_t &docinfo, format_t *formatlistptr,
     717                 const text_t& text,
     718                 ostream& logout) {
    581719
    582720  text_t link = "<a href=\"_httpdocument_&cl=search&d=" + docinfo.OID + "\">";
    583721  text_t icon = "_icontext_";
    584   text_t text;
    585 
    586   text_t ft;
    587   while (formatlistptr != NULL) {
    588     ft += format_string (docinfo, formatlistptr, link, icon, text, false);
    589     formatlistptr = formatlistptr->nextptr;
    590   }
    591   return ft;
    592 }
    593 
    594 
    595 text_t get_formatted_string (ResultDocInfo_t &docinfo, format_t *formatlistptr,
    596                  const text_t &text) {
    597 
    598   text_t link = "<a href=\"_httpdocument_&cl=search&d=" + docinfo.OID + "\">";
    599   text_t icon = "_icontext_";
    600 
    601   text_t ft;
    602   while (formatlistptr != NULL) {
    603     ft += format_string (docinfo, formatlistptr, link, icon, text, false);
    604     formatlistptr = formatlistptr->nextptr;
    605   }
    606   return ft;
    607 }
    608 
    609 
    610 text_t get_formatted_string (ResultDocInfo_t &docinfo, format_t *formatlistptr,
    611                  const text_t &link, const text_t &icon, const text_t &text) {
    612 
    613   text_t ft;
    614   while (formatlistptr != NULL) {
    615     ft += format_string (docinfo, formatlistptr, link, icon, text, false);
    616     formatlistptr = formatlistptr->nextptr;
    617   }
    618   return ft;
    619 }
    620 
    621 text_t get_formatted_string (ResultDocInfo_t &docinfo, format_t *formatlistptr,
    622                  const text_t &link, const text_t &icon, bool highlight) {
    623 
    624   text_t text, ft;
    625   while (formatlistptr != NULL) {
    626     ft += format_string (docinfo, formatlistptr, link, icon, text, highlight);
    627     formatlistptr = formatlistptr->nextptr;
    628   }
    629   return ft;
    630 }
    631 
    632 text_t get_formatted_string (ResultDocInfo_t &docinfo, format_t *formatlistptr,
    633                  const text_t &link, const text_t &icon,
    634                  const text_t &text, bool highlight) {
    635 
    636   text_t ft;
    637   while (formatlistptr != NULL) {
    638     ft += format_string (docinfo, formatlistptr, link, icon, text, highlight);
    639     formatlistptr = formatlistptr->nextptr;
    640   }
    641   return ft;
    642 }
     722  bool highlight = false;
     723
     724  return get_formatted_string(collection, collectproto, docinfo, formatlistptr,
     725                  link, icon, text, highlight, logout);
     726}
     727
     728text_t get_formatted_string (const text_t& collection, recptproto* collectproto,
     729                 ResultDocInfo_t &docinfo, format_t *formatlistptr,
     730                 ostream& logout) {
     731
     732  text_t text = "";
     733
     734  return get_formatted_string(collection, collectproto, docinfo, formatlistptr,
     735                  text, logout);
     736}
     737
  • trunk/gsdl/src/recpt/formattools.h

    r1285 r1443  
    3030#include "text_t.h"
    3131#include "comtypes.h"
     32#include "recptproto.h"
    3233
    3334enum command_t {comIf, comOr, comMeta, comText, comLink, comEndLink, comNum, comIcon,
     
    99100             text_tset &metadata, bool &getParents);
    100101
    101 text_t get_formatted_string (ResultDocInfo_t &docinfo, format_t *formatlistptr,
    102                  const text_t &link, const text_t &icon);
    103102
    104 text_t get_formatted_string (ResultDocInfo_t &docinfo, format_t *formatlistptr);
     103text_t get_formatted_string (const text_t& collection, recptproto* collectproto,
     104                 ResultDocInfo_t &docinfo, format_t *formatlistptr,
     105                 const text_t &link, const text_t &icon,
     106                 const text_t& t, const bool highlight,
     107                 ostream& logout);
    105108
    106 text_t get_formatted_string (ResultDocInfo_t &docinfo, format_t *formatlistptr,
    107                  const text_t &text);
     109text_t get_formatted_string (const text_t& collection, recptproto* collectproto,
     110                 ResultDocInfo_t &docinfo, format_t *formatlistptr,
     111                 const text_t &link, const text_t &icon,
     112                 const bool highlight,
     113                 ostream& logout);
    108114
    109 text_t get_formatted_string (ResultDocInfo_t &docinfo, format_t *formatlistptr,
    110                  const text_t &link, const text_t &icon, const text_t &text);
     115text_t get_formatted_string (const text_t& collection, recptproto* collectproto,
     116                 ResultDocInfo_t &docinfo, format_t *formatlistptr,
     117                 const text_t &text,
     118                 ostream& logout);
    111119
    112 text_t get_formatted_string (ResultDocInfo_t &docinfo, format_t *formatlistptr,
    113                  const text_t &link, const text_t &icon, bool highlight);
     120text_t get_formatted_string (const text_t& collection, recptproto* collectproto,
     121                 ResultDocInfo_t &docinfo, format_t *formatlistptr,
     122                 ostream& logout);
    114123
    115 text_t get_formatted_string (ResultDocInfo_t &docinfo, format_t *formatlistptr,
    116                  const text_t &link, const text_t &icon,
    117                  const text_t &text, bool highlight);
    118124
    119125
    120126#endif
     127
     128
  • trunk/gsdl/src/recpt/hlistbrowserclass.cpp

    r1285 r1443  
    8282
    8383int hlistbrowserclass::output_section_group (ResultDocInfo_t &section, cgiargsclass &args,
    84                          const text_t &/*collection*/, int colnumber,
     84                         const text_t& collection, int colnumber,
    8585                         format_t *formatlistptr, bool use_table,
    8686                         text_tset &metadata, bool &getParents,
     
    136136
    137137    textout << outconvert << disp
    138         << get_formatted_string (*tsibling, formatlistptr, link, icon, highlight);
     138        << get_formatted_string (collection, collectproto,
     139                     *tsibling, formatlistptr, link, icon, highlight,
     140                     logout);
    139141
    140142    textout << "</td>\n";
  • trunk/gsdl/src/recpt/vlistbrowserclass.cpp

    r1285 r1443  
    5252                         format_t *formatlistptr, bool use_table,
    5353                         text_tset &/*metadata*/, bool &/*getParents*/,
    54                          recptproto * /*collectproto*/, displayclass &disp,
     54                         recptproto * collectproto, displayclass &disp,
    5555                         outconvertclass &outconvert, ostream &textout,
    56                          ostream &/*logout*/) {
     56                         ostream& logout) {
    5757
    5858  text_t link, icon;
     
    8080  }
    8181
    82   textout << outconvert << disp << get_formatted_string (section, formatlistptr,
    83                              link, icon, highlight);
     82  textout << outconvert << disp
     83      << get_formatted_string (collection, collectproto,
     84                   section, formatlistptr,
     85                   link, icon, highlight, logout);
    8486 
    8587  if (use_table  || colnumber > 0) textout << "</tr></table>\n";
     
    9294                         format_t *formatlistptr, bool use_table,
    9395                         text_tset &/*metadata*/, bool &/*getParents*/,
    94                          recptproto * /*collectproto*/, displayclass &disp,
     96                         recptproto * collectproto, displayclass &disp,
    9597                         outconvertclass &outconvert, ostream &textout,
    96                          ostream &/*logout*/) {
     98                         ostream& logout) {
    9799
    98100  text_t link, icon;
     
    129131
    130132    if (use_table || colnumber > 0) textout << "<tr valign=top>";
    131     textout << outconvert << disp << get_formatted_string (*thissection, formatlistptr,
    132                                link, icon, highlight);
     133    textout << outconvert << disp
     134        << get_formatted_string (collection, collectproto,
     135                     *thissection, formatlistptr,
     136                     link, icon, highlight, logout);
     137
    133138    if (use_table || colnumber > 0) textout << "</tr>";
    134139    textout << "\n";
Note: See TracChangeset for help on using the changeset viewer.