Changeset 9401 for trunk/gsdl


Ignore:
Timestamp:
2005-03-14T09:49:40+13:00 (19 years ago)
Author:
davidb
Message:

formattoools.cpp extended to supoorts 'child' request, within [Metadata]
in addition to existing 'partent' and 'sibling' requests.

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

Legend:

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

    r7617 r9401  
    4545                  text_tmap &options, ostream& logout);
    4646
     47static text_t expand_metadata(const text_t &metavalue, const text_t& collection,
     48                  recptproto* collectproto, ResultDocInfo_t &docinfo,
     49                  displayclass &disp, text_tmap &options,
     50                  ostream &logout);
     51
    4752
    4853void metadata_t::clear() {
    4954  metaname.clear();
    5055  metacommand = mNone;
    51   parentcommand = pNone;
     56  mqualifier.parent  = pNone;
     57  mqualifier.sibling = sNone;
     58  mqualifier.child   = cNone;
    5259  functionoptions.clear();
    5360}
     
    490497    here ++;
    491498  }
     499
    492500  instring = meta;
    493501  if (com.empty())
    494     metaoption.parentcommand = pImmediate;
     502    metaoption.mqualifier.parent = pImmediate;
    495503  else if (com == "Top")
    496     metaoption.parentcommand = pTop;
     504    metaoption.mqualifier.parent = pTop;
    497505  else if (com == "All") {
    498     metaoption.parentcommand = pAll;
     506    metaoption.mqualifier.parent = pAll;
    499507    metaoption.functionoptions = op;
    500508  }
     
    528536
    529537  if (com.empty()) {
     538    metaoption.mqualifier.sibling = sAll;
    530539    metaoption.functionoptions = " ";
    531540  }
    532541  else {
     542    metaoption.mqualifier.sibling = sAll;
    533543    metaoption.functionoptions = op;
    534544  }
    535545}
     546
     547static void get_child_options (text_t &instring, metadata_t &metaoption) {
     548
     549  assert (instring.size() > 6);
     550  if (instring.size() <= 6) return;
     551
     552  text_t meta, com, op;
     553  bool inbraces = false;
     554  bool inquotes = false;
     555  bool foundcolon = false;
     556  text_t::const_iterator here = instring.begin()+5;
     557  text_t::const_iterator end = instring.end();
     558  while (here != end) {
     559    if (*here == '(') inbraces = true;
     560    else if (*here == ')') inbraces = false;
     561    else if (*here == '\'' && !inquotes) inquotes = true;
     562    else if (*here == '\'' && inquotes) inquotes = false;
     563    else if (*here == ':' && !inbraces) foundcolon = true;
     564    else if (foundcolon) meta.push_back (*here);
     565    else if (inquotes) op.push_back (*here);
     566    else com.push_back (*here);
     567    here ++;
     568  }
     569
     570  instring = meta;
     571
     572  if (com.empty()) {
     573    metaoption.mqualifier.child = cAll;
     574    metaoption.functionoptions = " ";
     575  }
     576  else if (com == "first") {
     577    metaoption.mqualifier.child = cNum;
     578    metaoption.functionoptions = ".fc";
     579  }
     580  else if (com == "last") {
     581    metaoption.mqualifier.child = cNum;
     582    metaoption.functionoptions = ".lc";
     583  }
     584  else if (com.getint()>0) {
     585    metaoption.mqualifier.child = cNum;
     586    metaoption.functionoptions = com;
     587  }
     588  else {
     589    metaoption.mqualifier.child = cAll;
     590    metaoption.functionoptions = op;
     591  }
     592}
     593
    536594
    537595
     
    546604  if (meta.size() > 7 && (substr (meta.begin(), meta.begin()+6) == "parent")) {
    547605    getParents = true;
     606    metaoption.metacommand |= mParent;
    548607    get_parent_options (meta, metaoption);
    549608  }
     
    551610    metaoption.metacommand |= mSibling;
    552611    get_sibling_options (meta, metaoption);
     612  }
     613  else if (meta.size() > 6 && (substr (meta.begin(), meta.begin()+5) == "child")) {
     614    metaoption.metacommand |= mChild;
     615    get_child_options (meta, metaoption);
    553616  }
    554617
     
    877940
    878941
    879 // note: all the format_date stuff is assuming that all Date metadata is going to
    880 // be of the form yyyymmdd, this is of course, crap ;)
    881 
    882 static text_t get_meta (ResultDocInfo_t &docinfo, const metadata_t &meta) {
    883  
    884   // make sure we have the requested metadata
    885   MetadataInfo_tmap::iterator it = docinfo.metadata.find (meta.metaname);
    886   if (it == docinfo.metadata.end()) return "";
    887 
     942static text_t get_all_meta (MetadataInfo_t &metainfo, const metadata_t &meta)
     943{
     944  text_t no_ns_metaname = remove_namespace(meta.metaname);
     945
     946  text_t tmp;
     947  bool first = true;
     948 
     949  const int start_i=0;
     950  const int end_i = metainfo.values.size()-1;
     951   
     952  for (int i=start_i; i<=end_i; i++) {
     953    if (!first) tmp += meta.functionoptions;
     954     
     955    if (no_ns_metaname == "Date") tmp += format_date (metainfo.values[i]);
     956    else if (no_ns_metaname == "Language") tmp += iso639(metainfo.values[i]);
     957    else tmp += metainfo.values[i];
     958    first = false;
     959  }
     960   
     961  if (meta.metacommand & mCgiSafe) return cgi_safe (tmp);
     962  else return tmp;
     963}
     964
     965static text_t get_parent_meta (ResultDocInfo_t &docinfo, const metadata_t &meta)
     966{
     967 
    888968  MetadataInfo_t *parent = docinfo.metadata[meta.metaname].parent;
    889969  text_t no_ns_metaname = remove_namespace(meta.metaname);
    890   switch (meta.parentcommand) {
     970  switch (meta.mqualifier.parent) {
    891971  case pNone:
    892     {
    893       if (meta.metacommand & mSibling) {
    894     text_t tmp;
    895     bool first = true;
    896 
    897     MetadataInfo_t& metaname_rec = docinfo.metadata[meta.metaname];
    898 
    899     const int start_i=0;
    900     const int end_i = metaname_rec.values.size()-1;
    901 
    902     for (int i=start_i; i<=end_i; i++) {
    903       if (!first) tmp += meta.functionoptions;
    904      
    905       if (no_ns_metaname == "Date") tmp += format_date (metaname_rec.values[i]);
    906       else if (no_ns_metaname == "Language") tmp += iso639(metaname_rec.values[i]);
    907       else tmp += metaname_rec.values[i];
    908       first = false;
    909     }
    910 
    911     if (meta.metacommand & mCgiSafe) return cgi_safe (tmp);
    912     else return tmp;
    913 
    914       }
    915       else {
    916 
    917     text_t classifier_metaname = docinfo.classifier_metadata_type;
    918     int metaname_index
    919       = (classifier_metaname == meta.metaname) ? docinfo.classifier_metadata_offset : 0;
    920     text_t metadata_item = docinfo.metadata[meta.metaname].values[metaname_index];
    921    
    922     if (no_ns_metaname == "Date")
    923       return format_date (metadata_item);
    924     else if (no_ns_metaname == "Language")
    925       return iso639(metadata_item);
    926     if (meta.metacommand & mCgiSafe)
    927       return cgi_safe (metadata_item);
    928     else return metadata_item;
    929       }
    930     }
     972    return "Nothing!!";
     973    break;
    931974
    932975  case pImmediate:
     
    9761019  }
    9771020  return "";
     1021
     1022}
     1023
     1024static text_t get_child_meta (const text_t& collection, recptproto* collectproto,
     1025                  ResultDocInfo_t &docinfo, displayclass &disp,
     1026                  const metadata_t &meta, text_tmap &options,
     1027                  ostream& logout)
     1028{
     1029  if (docinfo.metadata["contains"].values.size()>0) {
     1030   
     1031    text_t& contains = docinfo.metadata["contains"].values[0];
     1032
     1033    const text_t& child_metaname = meta.metaname;
     1034    const text_t& child_field = meta.functionoptions;
     1035
     1036    text_tset child_metadata;
     1037    child_metadata.insert(child_metaname);
     1038
     1039    FilterResponse_t child_response;
     1040   
     1041    //get the information associated with the metadata for child doc
     1042    if (get_info (docinfo.OID+child_field, collection, "", child_metadata,
     1043          false, collectproto, child_response, logout)) {
     1044
     1045      if (!child_response.docInfo.empty()) {
     1046    ResultDocInfo_t& child_docinfo = child_response.docInfo[0];
     1047   
     1048    MetadataInfo_t& metaname_rec = child_docinfo.metadata[child_metaname];
     1049   
     1050    text_t child_metavalue = "";
     1051   
     1052    if (meta.mqualifier.child == cNum) {
     1053      if (metaname_rec.values.size()>0) {
     1054        child_metavalue = metaname_rec.values[0];
     1055      }
     1056    }
     1057    else if (meta.mqualifier.child == cAll) {
     1058      child_metavalue = get_all_meta(metaname_rec,meta);
     1059    }
     1060   
     1061    return expand_metadata(child_metavalue,collection,collectproto,
     1062                   child_docinfo,disp,options,logout);
     1063      }
     1064    }
     1065  }
     1066
     1067  return "";
     1068}
     1069
     1070
     1071
     1072// note: all the format_date stuff is assuming that all Date metadata is going to
     1073// be of the form yyyymmdd, this is of course, crap ;)
     1074
     1075static text_t get_meta (const text_t& collection, recptproto* collectproto,
     1076            ResultDocInfo_t &docinfo, displayclass &disp,
     1077            const metadata_t &meta, text_tmap &options,
     1078            ostream& logout) {
     1079 
     1080  // make sure we have the requested metadata
     1081  MetadataInfo_tmap::iterator it = docinfo.metadata.find (meta.metaname);
     1082  if (it == docinfo.metadata.end()) return "";
     1083
     1084  text_t no_ns_metaname = remove_namespace(meta.metaname);
     1085
     1086  if (meta.metacommand & mParent) {
     1087    return get_parent_meta(docinfo,meta);
     1088  }
     1089  else if (meta.metacommand & mChild) {
     1090    return get_child_meta(collection,collectproto,docinfo,disp,meta,
     1091              options,logout);
     1092  }
     1093  else if (meta.metacommand & mSibling) {
     1094    MetadataInfo_t& metaname_rec = docinfo.metadata[meta.metaname];
     1095    return get_all_meta(docinfo.metadata[meta.metaname],meta);
     1096  }
     1097  else {
     1098   
     1099    // straightforward metadata request (nothing fancy)
     1100
     1101    text_t classifier_metaname = docinfo.classifier_metadata_type;
     1102    int metaname_index
     1103      = (classifier_metaname == meta.metaname) ? docinfo.classifier_metadata_offset : 0;
     1104    text_t metadata_item = docinfo.metadata[meta.metaname].values[metaname_index];
     1105   
     1106    if (no_ns_metaname == "Date")
     1107      return format_date (metadata_item);
     1108    else if (no_ns_metaname == "Language")
     1109      return iso639(metadata_item);
     1110    if (meta.metacommand & mCgiSafe)
     1111      return cgi_safe (metadata_item);
     1112    else return metadata_item;
     1113  }
     1114
     1115  return "";
    9781116}
    9791117
     
    10701208
    10711209
    1072 static text_t expand_potential_metadata(ResultDocInfo_t &docinfo,
    1073                     const text_t& intext)
     1210static text_t expand_potential_metadata(const text_t& collection,
     1211                    recptproto* collectproto,
     1212                    ResultDocInfo_t &docinfo,
     1213                    displayclass &disp,
     1214                    const text_t& intext,
     1215                    text_tmap &options,
     1216                    ostream& logout)
    10741217{
    10751218  text_t outtext;
     
    10901233
    10911234    parse_meta (meta_text, meta, metadata, getParents);
    1092     outtext = get_meta (docinfo,meta);
     1235    outtext
     1236      = get_meta (collection,collectproto,docinfo,disp,meta,options,logout);
    10931237  }
    10941238  else {
     
    11021246
    11031247
    1104 static bool uses_expression(ResultDocInfo_t &docinfo,
     1248static bool uses_expression(const text_t& collection, recptproto* collectproto,
     1249                ResultDocInfo_t &docinfo,
     1250                displayclass &disp,
    11051251                const text_t& outstring, text_t& lhs_expr,
    1106                 text_t& op_expr, text_t& rhs_expr)
     1252                text_t& op_expr, text_t& rhs_expr,
     1253                text_tmap &options,
     1254                ostream& logout)
    11071255{
    11081256  // Note: the string may not be of the form: str1 op str2, however
     
    11801328  // metadata terms
    11811329
    1182   rhs_expr = expand_potential_metadata(docinfo,rhs_expr);
    1183   lhs_expr = expand_potential_metadata(docinfo,lhs_expr);
     1330  rhs_expr = expand_potential_metadata(collection,collectproto,docinfo,
     1331                       disp,rhs_expr,options,logout);
     1332  lhs_expr = expand_potential_metadata(collection,collectproto,docinfo,
     1333                       disp,lhs_expr,options,logout);
    11841334
    11851335  return true;
     
    12121362  // to see whether we output the "then" or the "else" clause
    12131363  if (decision.command == dMeta) {
    1214     if (get_meta (docinfo, decision.meta) != "") {
     1364    if (get_meta (collection,collectproto,docinfo,disp,decision.meta,options,
     1365          logout) != "") {
    12151366      if (ifptr != NULL)
    12161367    return get_formatted_string (collection,collectproto, docinfo, disp, ifptr,
     
    12341385    // (such as [x] eq "y")
    12351386    text_t lhs_expr, op_expr, rhs_expr;
    1236     if (uses_expression(docinfo, outstring,lhs_expr,op_expr,rhs_expr)) {
     1387    if (uses_expression(collection,collectproto,docinfo, disp, outstring,lhs_expr,op_expr,rhs_expr, options,logout)) {
    12371388      if (eval_expression_true(lhs_expr,op_expr,rhs_expr,logout)) {
    12381389    if (ifptr != NULL) {
     
    13581509     case comMeta:
    13591510    {
    1360        const text_t& metavalue =  get_meta (docinfo, formatlistptr->meta);
     1511       const text_t& metavalue =  get_meta (collection,collectproto,docinfo, disp,formatlistptr->meta,options,logout);
    13611512       return expand_metadata(metavalue, collection, collectproto, docinfo, disp, options, logout);
    13621513    }
  • trunk/gsdl/src/recpt/formattools.h

    r7389 r9401  
    3737        comTOC, comImage, comDocumentButtonDetach, comDocumentButtonHighlight,
    3838        comDocumentButtonExpandContents, comDocumentButtonExpandText, comOID, comRank};
     39
     40enum mcommand_t {mNone=0, mCgiSafe=1, mParent=2, mSibling=4, mChild=8};
     41
    3942enum pcommand_t {pNone, pImmediate, pTop, pAll};
     43enum scommand_t {sNone, sAll};
     44enum ccommand_t {cNone, cAll, cNum};
    4045enum dcommand_t {dMeta, dText};
    41 enum mcommand_t {mNone=0, mCgiSafe=1, mParent=2, mSibling=4};
    4246
    4347struct metadata_t {
     
    4751  text_t metaname;
    4852  int metacommand; // used to hold flags from mcommand_t
    49   pcommand_t parentcommand;
     53  struct {
     54    pcommand_t parent;
     55    scommand_t sibling;
     56    ccommand_t child;
     57  } mqualifier;
     58
    5059  text_t functionoptions;
    5160};
Note: See TracChangeset for help on using the changeset viewer.