Changeset 10415


Ignore:
Timestamp:
2005-08-04T12:09:41+12:00 (19 years ago)
Author:
kjdon
Message:

fixed up the metadata format handling. made child metadata work, and made child:sibling, and parent:sibling work. full details about the new formats available in the faq

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

Legend:

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

    r10145 r10415  
    6060  mqualifier.sibling = sNone;
    6161  mqualifier.child   = cNone;
    62   functionoptions.clear();
     62  parentoptions.clear();
     63  siblingoptions.clear();
     64  childoptions.clear();
    6365}
    6466
     
    490492  text_t::const_iterator end = instring.end();
    491493  while (here != end) {
    492     if (*here == '(') inbraces = true;
     494    if (foundcolon) meta.push_back (*here);
     495    else if (*here == '(') inbraces = true;
    493496    else if (*here == ')') inbraces = false;
    494497    else if (*here == '\'' && !inquotes) inquotes = true;
    495498    else if (*here == '\'' && inquotes) inquotes = false;
    496499    else if (*here == ':' && !inbraces) foundcolon = true;
    497     else if (foundcolon) meta.push_back (*here);
    498500    else if (inquotes) op.push_back (*here);
    499501    else com.push_back (*here);
     
    508510  else if (com == "All") {
    509511    metaoption.mqualifier.parent = pAll;
    510     metaoption.functionoptions = op;
     512    metaoption.parentoptions = op;
    511513  }
    512514}
     
    517519  assert (instring.size() > 8);
    518520  if (instring.size() <= 8) return;
    519 
    520521  text_t meta, com, op;
    521522  bool inbraces = false;
     
    525526  text_t::const_iterator end = instring.end();
    526527  while (here != end) {
    527     if (*here == '(') inbraces = true;
     528    if (foundcolon) meta.push_back (*here);
     529    else if (*here == '(') inbraces = true;
    528530    else if (*here == ')') inbraces = false;
    529531    else if (*here == '\'' && !inquotes) inquotes = true;
    530532    else if (*here == '\'' && inquotes) inquotes = false;
    531     else if (*here == ':' && !inbraces) foundcolon = true;
    532     else if (foundcolon) meta.push_back (*here);
     533    else if (*here == ':' && !inbraces) foundcolon = true;   
    533534    else if (inquotes) op.push_back (*here);
    534535    else com.push_back (*here);
     
    537538
    538539  instring = meta;
     540  metaoption.siblingoptions.clear();
    539541
    540542  if (com.empty()) {
    541543    metaoption.mqualifier.sibling = sAll;
    542     metaoption.functionoptions = " ";
     544    metaoption.siblingoptions = " ";
     545  }
     546  else if (com == "first") {
     547    metaoption.mqualifier.sibling = sNum;
     548    metaoption.siblingoptions = "0";
     549  }
     550  else if (com == "last") {
     551    metaoption.mqualifier.sibling = sNum;
     552    metaoption.siblingoptions = "-2"; // == last
     553  }
     554  else if (com.getint()>0) {
     555    metaoption.mqualifier.sibling = sNum;
     556    int pos = com.getint()-1;
     557    metaoption.siblingoptions +=pos;
    543558  }
    544559  else {
    545560    metaoption.mqualifier.sibling = sAll;
    546     metaoption.functionoptions = op;
     561    metaoption.siblingoptions = op;
    547562  }
    548563}
     
    552567  assert (instring.size() > 6);
    553568  if (instring.size() <= 6) return;
    554 
    555569  text_t meta, com, op;
    556570  bool inbraces = false;
     
    560574  text_t::const_iterator end = instring.end();
    561575  while (here != end) {
    562     if (*here == '(') inbraces = true;
     576    if (foundcolon) meta.push_back (*here);
     577    else if (*here == '(') inbraces = true;
    563578    else if (*here == ')') inbraces = false;
    564579    else if (*here == '\'' && !inquotes) inquotes = true;
    565580    else if (*here == '\'' && inquotes) inquotes = false;
    566581    else if (*here == ':' && !inbraces) foundcolon = true;
    567     else if (foundcolon) meta.push_back (*here);
    568582    else if (inquotes) op.push_back (*here);
    569583    else com.push_back (*here);
     
    572586
    573587  instring = meta;
    574 
    575588  if (com.empty()) {
    576589    metaoption.mqualifier.child = cAll;
    577     metaoption.functionoptions = " ";
     590    metaoption.childoptions = " ";
    578591  }
    579592  else if (com == "first") {
    580593    metaoption.mqualifier.child = cNum;
    581     metaoption.functionoptions = ".fc";
     594    metaoption.childoptions = ".fc";
    582595  }
    583596  else if (com == "last") {
    584597    metaoption.mqualifier.child = cNum;
    585     metaoption.functionoptions = ".lc";
     598    metaoption.childoptions = ".lc";
    586599  }
    587600  else if (com.getint()>0) {
    588601    metaoption.mqualifier.child = cNum;
    589     metaoption.functionoptions = com;
     602    metaoption.childoptions = "."+com;
    590603  }
    591604  else {
    592605    metaoption.mqualifier.child = cAll;
    593     metaoption.functionoptions = op;
     606    metaoption.childoptions = op;
    594607  }
    595608}
     
    610623    get_parent_options (meta, metaoption);
    611624  }
    612   else if (meta.size() > 8 && (substr (meta.begin(), meta.begin()+7) == "sibling")) {
     625  else if (meta.size() > 6 && (substr (meta.begin(), meta.begin()+5) == "child")) {
     626    metaoption.metacommand |= mChild;
     627    get_child_options (meta, metaoption);
     628    metadata.insert("contains");
     629  }
     630  // parent and child can have sibling also
     631  if (meta.size() > 8 && (substr (meta.begin(), meta.begin()+7) == "sibling")) {
    613632    metaoption.metacommand |= mSibling;
    614633    get_sibling_options (meta, metaoption);
    615634  }
    616   else if (meta.size() > 6 && (substr (meta.begin(), meta.begin()+5) == "child")) {
    617     metaoption.metacommand |= mChild;
    618     get_child_options (meta, metaoption);
    619   }
    620 
     635 
    621636  // check for ex. which may occur in format statements
    622637  if (meta.size()>3 && (substr(meta.begin(), meta.begin()+3) == "ex.")) {
     
    958973}
    959974
    960 
    961 static text_t get_all_meta (MetadataInfo_t &metainfo, const metadata_t &meta)
     975// position -1 for all, -2 for the last, 0 for the first, or x for a particular piece
     976// metainfo has all the values for the metadata, meta has the request metadata name and options, position tells which values to get
     977static text_t get_formatted_meta_text(MetadataInfo_t &metainfo, const metadata_t &meta, int position, bool no_cgisafe = false)
    962978{
    963979  text_t no_ns_metaname = remove_namespace(meta.metaname);
    964 
    965980  text_t tmp;
    966981  bool first = true;
     
    968983  const int start_i=0;
    969984  const int end_i = metainfo.values.size()-1;
    970    
    971   for (int i=start_i; i<=end_i; ++i) {
    972     if (!first) tmp += meta.functionoptions;
     985 
     986  if (position == -1) { // all
     987    for (int i=start_i; i<=end_i; ++i) {
     988      if (!first) tmp += meta.siblingoptions;
     989      if (no_ns_metaname == "Date") tmp += format_date (metainfo.values[i]);
     990      else if (no_ns_metaname == "Language") tmp += iso639(metainfo.values[i]);
     991      else tmp += metainfo.values[i];
     992      first = false;
    973993     
    974     if (no_ns_metaname == "Date") tmp += format_date (metainfo.values[i]);
    975     else if (no_ns_metaname == "Language") tmp += iso639(metainfo.values[i]);
    976     else tmp += metainfo.values[i];
    977     first = false;
    978   }
    979    
    980   if (meta.metacommand & mCgiSafe) return cgi_safe (tmp);
     994    }
     995  } else {
     996    if (position == -2) { // end
     997      position = end_i;
     998    } else if (position < start_i || position > end_i) {
     999      return "";
     1000    }
     1001    if (no_ns_metaname == "Date") tmp += format_date (metainfo.values[position]);
     1002    else if (no_ns_metaname == "Language") tmp += iso639(metainfo.values[position]);
     1003    else tmp += metainfo.values[position];
     1004  }
     1005  if (meta.metacommand & mCgiSafe && !no_cgisafe) return cgi_safe (tmp);
    9811006  else return tmp;
    9821007}
    9831008
    984 static text_t get_parent_meta (ResultDocInfo_t &docinfo, const metadata_t &meta)
     1009static text_t get_parent_meta (ResultDocInfo_t &docinfo, const metadata_t &meta, int siblings_values)
    9851010{
    9861011 
    9871012  MetadataInfo_t *parent = docinfo.metadata[meta.metaname].parent;
    988   text_t no_ns_metaname = remove_namespace(meta.metaname);
    9891013  switch (meta.mqualifier.parent) {
    9901014  case pNone:
     
    9941018  case pImmediate:
    9951019    if (parent != NULL) {
    996       if (no_ns_metaname == "Date")
    997     return format_date (parent->values[0]);
    998       if (meta.metacommand & mCgiSafe)
    999     return cgi_safe (parent->values[0]);
    1000       else return parent->values[0];
     1020      return get_formatted_meta_text(*parent, meta, siblings_values);
    10011021    }
    10021022    break;
     
    10051025    if (parent != NULL) {
    10061026      while (parent->parent != NULL) parent = parent->parent;
    1007 
    1008       if (no_ns_metaname == "Date")
    1009     return format_date (parent->values[0]);
    1010       if (meta.metacommand & mCgiSafe)
    1011     return cgi_safe (parent->values[0]);
    1012       else return parent->values[0];
     1027      return get_formatted_meta_text(*parent, meta, siblings_values);
    10131028    }
    10141029    break;
     
    10191034      text_tarray tmparray;
    10201035      while (parent != NULL) {
    1021     tmparray.push_back (parent->values[0]);
     1036    tmparray.push_back (get_formatted_meta_text(*parent, meta, siblings_values, true)); // set no_cgisafe to true, as we'll do it once we have all the metadata
    10221037    parent = parent->parent;
    10231038      }
     1039      // now join them up - use teh parent separator
    10241040      bool first = true;
    10251041      text_t tmp;
     
    10271043      text_tarray::reverse_iterator end = tmparray.rend();
    10281044      while (here != end) {
    1029     if (!first) tmp += meta.functionoptions;
    1030     if (no_ns_metaname == "Date") tmp += format_date (*here);
    1031     else tmp += *here;
     1045    if (!first) tmp += meta.parentoptions;
     1046    tmp += *here;
    10321047    first = false;
    10331048    ++here;
     
    10451060                  ResultDocInfo_t &docinfo, displayclass &disp,
    10461061                  const metadata_t &meta, text_tmap &options,
    1047                   ostream& logout)
     1062                  ostream& logout, int siblings_values)
    10481063{
    1049   if (docinfo.metadata["contains"].values.size()>0) {
    1050    
    1051     text_t& contains = docinfo.metadata["contains"].values[0];
    1052 
    1053     const text_t& child_metaname = meta.metaname;
    1054     const text_t& child_field = meta.functionoptions;
    1055 
    1056     text_tset child_metadata;
    1057     child_metadata.insert(child_metaname);
    1058 
    1059     FilterResponse_t child_response;
    1060    
     1064  if (docinfo.metadata["contains"].values[0].size()==0) return ""; // no children
     1065 
     1066  const text_t& child_metaname = meta.metaname;
     1067  const text_t& child_field = meta.childoptions;
     1068  text_tset child_metadata;
     1069  child_metadata.insert(child_metaname);
     1070
     1071  FilterResponse_t child_response;
     1072  if (meta.mqualifier.child == cNum) {
     1073    // just one child
    10611074    //get the information associated with the metadata for child doc
    1062     if (get_info (docinfo.OID+child_field, collection, "", child_metadata,
    1063           false, collectproto, child_response, logout)) {
    1064 
    1065       if (!child_response.docInfo.empty()) {
    1066     ResultDocInfo_t& child_docinfo = child_response.docInfo[0];
    1067    
    1068     MetadataInfo_t& metaname_rec = child_docinfo.metadata[child_metaname];
    1069    
    1070     text_t child_metavalue = "";
    1071    
    1072     if (meta.mqualifier.child == cNum) {
    1073       if (metaname_rec.values.size()>0) {
    1074         child_metavalue = metaname_rec.values[0];
    1075       }
    1076     }
    1077     else if (meta.mqualifier.child == cAll) {
    1078       child_metavalue = get_all_meta(metaname_rec,meta);
    1079     }
    1080    
    1081     return expand_metadata(child_metavalue,collection,collectproto,
     1075    if (!get_info (docinfo.OID+child_field, collection, "", child_metadata,
     1076           false, collectproto, child_response, logout)) return ""; // invalid child number
     1077
     1078      if (child_response.docInfo.empty()) return false; // no info for the child
     1079 
     1080      ResultDocInfo_t& child_docinfo = child_response.docInfo[0];
     1081      MetadataInfo_t& metaname_rec = child_docinfo.metadata[child_metaname];
     1082 
     1083      text_t child_metavalue = get_formatted_meta_text(metaname_rec,meta,siblings_values);
     1084      return expand_metadata(child_metavalue,collection,collectproto,
     1085             child_docinfo,disp,options,logout);
     1086  }
     1087 
     1088   
     1089  if (meta.mqualifier.child != cAll) return false; // invalid qualifier
     1090 
     1091  // we need to get all children
     1092  text_t result = "";
     1093  text_tarray children;
     1094  text_t contains = docinfo.metadata["contains"].values[0];
     1095  splitchar (contains.begin(), contains.end(), ';', children);
     1096  text_tarray::const_iterator here = children.begin();
     1097  text_tarray::const_iterator end = children.end();
     1098  bool first = true;
     1099  while (here !=end) {
     1100    text_t oid = *here;
     1101    here++;
     1102    if (*(oid.begin()) == '"') translate_parent (oid, docinfo.OID);
     1103   
     1104   
     1105    //get the information associated with the metadata for child doc
     1106    if (!get_info (oid, collection, "", child_metadata,
     1107           false, collectproto, child_response, logout) ||
     1108    child_response.docInfo.empty()) {
     1109      first = false;
     1110      continue;
     1111    }
     1112   
     1113   
     1114    ResultDocInfo_t& child_docinfo = child_response.docInfo[0];
     1115    MetadataInfo_t& metaname_rec = child_docinfo.metadata[child_metaname];
     1116   
     1117    text_t child_metavalue = get_formatted_meta_text(metaname_rec,meta,siblings_values);
     1118    if (!first) result += child_field;
     1119    first = false;
     1120    // need to do this here cos otherwise we are in the wrong document
     1121    result +=  expand_metadata(child_metavalue,collection,collectproto,
    10821122                   child_docinfo,disp,options,logout);
    1083       }
    1084     }
    1085   }
    1086 
    1087   return "";
    1088 }
    1089 
     1123  }
     1124  return result;
     1125   
     1126}
    10901127
    10911128
     
    11021139  if (it == docinfo.metadata.end()) return "";
    11031140
    1104   text_t no_ns_metaname = remove_namespace(meta.metaname);
    1105 
     1141  int siblings_values = 0; // default is no siblings, just the first metadata available
     1142  if (meta.metacommand & mSibling) {
     1143    if (meta.mqualifier.sibling == sAll) {
     1144      siblings_values = -1; //all
     1145    } else if (meta.mqualifier.sibling == sNum) {
     1146      siblings_values = meta.siblingoptions.getint();
     1147    }
     1148  }
    11061149  if (meta.metacommand & mParent) {
    1107     return get_parent_meta(docinfo,meta);
    1108   }
     1150    return get_parent_meta(docinfo,meta,siblings_values);
     1151  }
     1152
    11091153  else if (meta.metacommand & mChild) {
    11101154    return get_child_meta(collection,collectproto,docinfo,disp,meta,
    1111               options,logout);
    1112   }
    1113   else if (meta.metacommand & mSibling) {
     1155                options,logout, siblings_values);
     1156  }
     1157  else if (meta.metacommand & mSibling) { // only siblings
    11141158    MetadataInfo_t& metaname_rec = docinfo.metadata[meta.metaname];
    1115     return get_all_meta(docinfo.metadata[meta.metaname],meta);
     1159    return get_formatted_meta_text(docinfo.metadata[meta.metaname],meta, siblings_values);
    11161160  }
    11171161  else {
     
    11221166    int metaname_index
    11231167      = (classifier_metaname == meta.metaname) ? docinfo.classifier_metadata_offset : 0;
    1124     text_t metadata_item = docinfo.metadata[meta.metaname].values[metaname_index];
    1125    
    1126     if (no_ns_metaname == "Date")
    1127       return format_date (metadata_item);
    1128     else if (no_ns_metaname == "Language")
    1129       return iso639(metadata_item);
    1130     if (meta.metacommand & mCgiSafe)
    1131       return cgi_safe (metadata_item);
    1132     else return metadata_item;
    1133   }
    1134 
     1168    return get_formatted_meta_text(docinfo.metadata[meta.metaname], meta, metaname_index);
     1169  }
     1170 
    11351171  return "";
    11361172}
     
    14731509                  ostream &logout) {
    14741510     
    1475    if (includes_metadata(metavalue))
    1476       {
    1477      // text has embedded metadata in it => expand it
    1478      FilterRequest_t request;
    1479      FilterResponse_t response;
    1480 
    1481      request.getParents = false;
    1482      
    1483      format_t *expanded_formatlistptr = new format_t();
    1484      parse_formatstring (metavalue, expanded_formatlistptr,
    1485                  request.fields, request.getParents);
    1486      
    1487      // retrieve metadata
    1488      get_info(docinfo.OID, collection, "", request.fields, request.getParents,
    1489           collectproto, response, logout);
    1490      
    1491      if (!response.docInfo.empty())
    1492         {
    1493            text_t expanded_metavalue
    1494          = get_formatted_string(collection, collectproto,
    1495                      response.docInfo[0], disp, expanded_formatlistptr,
    1496                      options, logout);
    1497          
    1498            return expanded_metavalue;
    1499         }
    1500      else
    1501         {
    1502            return metavalue;
    1503         }
    1504       }
    1505    else
    1506       {
    1507      return metavalue;
    1508       }
     1511  if (includes_metadata(metavalue)) {
     1512   
     1513    // text has embedded metadata in it => expand it
     1514    FilterRequest_t request;
     1515    FilterResponse_t response;
     1516   
     1517    request.getParents = false;
     1518   
     1519    format_t *expanded_formatlistptr = new format_t();
     1520    parse_formatstring (metavalue, expanded_formatlistptr,
     1521            request.fields, request.getParents);
     1522   
     1523    // retrieve metadata
     1524    get_info(docinfo.OID, collection, "", request.fields, request.getParents,
     1525         collectproto, response, logout);
     1526   
     1527    if (!response.docInfo.empty()) {
     1528     
     1529      text_t expanded_metavalue
     1530    = get_formatted_string(collection, collectproto,
     1531                   response.docInfo[0], disp, expanded_formatlistptr,
     1532                   options, logout);
     1533     
     1534      return expanded_metavalue;
     1535    }
     1536    else {
     1537      return metavalue;
     1538    }
     1539  }
     1540  else {
     1541   
     1542    return metavalue;
     1543  }
    15091544}
    15101545
  • trunk/gsdl/src/recpt/formattools.h

    r9948 r10415  
    4141
    4242enum pcommand_t {pNone, pImmediate, pTop, pAll};
    43 enum scommand_t {sNone, sAll};
     43enum scommand_t {sNone, sAll, sNum};
    4444enum ccommand_t {cNone, cAll, cNum};
    4545enum dcommand_t {dMeta, dText};
     
    5757  } mqualifier;
    5858
    59   text_t functionoptions;
     59  text_t parentoptions;
     60  text_t siblingoptions;
     61  text_t childoptions;
    6062};
    6163
Note: See TracChangeset for help on using the changeset viewer.