Changeset 5788 for trunk


Ignore:
Timestamp:
2003-11-05T16:07:59+13:00 (20 years ago)
Author:
davidb
Message:

Fix for syntax error in formattools.cpp

File:
1 edited

Legend:

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

    r5787 r5788  
    3232
    3333// a few function prototypes
     34
    3435static text_t format_string (const text_t& collection, recptproto* collectproto,
    3536                 ResultDocInfo_t &docinfo, displayclass &disp,
    36                  format_t *formatlistptr,
    37                  const text_t &link, const text_t &icon,
    38                  const text_t &text, bool highlight, ostream& logout);
     37                 format_t *formatlistptr, text_tmap &options,
     38                 ostream& logout);
    3939
    4040static bool parse_action (text_t::const_iterator &here, const text_t::const_iterator &end,
    4141              format_t *formatlistptr, text_tset &metadata, bool &getParents);
    4242
    43 text_t format_summary (const text_t& collection, recptproto* collectproto,
    44               ResultDocInfo_t &docinfo, displayclass &disp,
    45               const text_t &text, bool highlight,
    46                ostream& logout);
     43static text_t format_summary (const text_t& collection, recptproto* collectproto,
     44                  ResultDocInfo_t &docinfo, displayclass &disp,
     45                  text_tmap &options, ostream& logout);
    4746
    4847
     
    7776  DocumentContents = true;
    7877  DocumentArrowsBottom = true;
     78  DocumentArrowsTop = false;
    7979  DocumentButtons.erase (DocumentButtons.begin(), DocumentButtons.end());
    8080  //  DocumentButtons.push_back ("Expand Text");
     
    8686  formatstrings.erase (formatstrings.begin(), formatstrings.end());
    8787  DocumentUseHTML = false;
     88  AllowExtendedOptions = false;
    8889}
    8990
     
    525526}
    526527
     528
    527529static void parse_meta (text_t &meta, metadata_t &metaoption,
    528530            text_tset &metadata, bool &getParents) {
     
    534536
    535537  if (meta.size() > 7 && (substr (meta.begin(), meta.begin()+6) == "parent")) {
    536     metaoption.metacommand |= mParent;
    537538    getParents = true;
    538539    get_parent_options (meta, metaoption);
     
    579580    formatlistptr->command = comSummary;
    580581
     582  else if (meta == "DocImage")
     583    formatlistptr->command = comImage;
     584
     585  else if (meta == "DocTOC")
     586    formatlistptr->command = comTOC;
     587
     588  else if (meta == "DocumentButtonDetach")
     589     formatlistptr->command = comDocumentButtonDetach;
     590 
     591  else if (meta == "DocumentButtonHighlight")
     592     formatlistptr->command = comDocumentButtonHighlight;
     593 
     594  else if (meta == "DocumentButtonExpandContents")
     595    formatlistptr->command = comDocumentButtonExpandContents;
     596
     597  else if (meta == "DocumentButtonExpandText")
     598     formatlistptr->command = comDocumentButtonExpandText;
     599 
    581600  else {
    582601    formatlistptr->command = comMeta;
     
    878897    }
    879898
    880 
    881899  case pImmediate:
    882900    if (parent != NULL) {
    883       if (meta.metaname == "Date")
    884     return format_date (parent->values[0]);
    885       if (meta.metacommand == mCgiSafe)
    886     return cgi_safe (parent->values[0]);
    887       else return parent->values[0];
    888     }
    889     break;
    890 
    891 
    892   case pTop:
    893     if (parent != NULL) {
    894       while (parent->parent != NULL) parent = parent->parent;
    895 
    896901      if (meta.metaname == "Date")
    897902    return format_date (parent->values[0]);
     
    902907    break;
    903908
     909  case pTop:
     910    if (parent != NULL) {
     911      while (parent->parent != NULL) parent = parent->parent;
     912
     913      if (meta.metaname == "Date")
     914    return format_date (parent->values[0]);
     915      if (meta.metacommand & mCgiSafe)
     916    return cgi_safe (parent->values[0]);
     917      else return parent->values[0];
     918    }
     919    break;
     920
    904921  case pAll:
    905922    MetadataInfo_t *parent = docinfo.metadata[meta.metaname].parent;
    906923    if (parent != NULL) {
    907 
    908924      text_tarray tmparray;
    909925      while (parent != NULL) {
     
    931947static text_t get_or (const text_t& collection, recptproto* collectproto,
    932948              ResultDocInfo_t &docinfo, displayclass &disp,
    933               format_t *orptr,
    934               const text_t &link, const text_t &icon,
    935               const text_t &text, bool highlight,
     949              format_t *orptr, text_tmap &options,
    936950              ostream& logout) {
    937951
     
    940954
    941955    tmp = format_string (collection,collectproto, docinfo, disp, orptr,
    942              link, icon, text, highlight, logout);
     956             options, logout);
    943957    if (!tmp.empty()) return tmp;
    944958
     
    951965              ResultDocInfo_t &docinfo, displayclass &disp,
    952966              const decision_t &decision,
    953               format_t *ifptr, format_t *elseptr, const text_t &link,
    954               const text_t &icon, const text_t &text, bool highlight,
    955               ostream& logout)
     967              format_t *ifptr, format_t *elseptr,
     968              text_tmap &options, ostream& logout)
    956969{
    957970
     
    962975      if (ifptr != NULL)
    963976    return get_formatted_string (collection,collectproto, docinfo, disp, ifptr,
    964                      link, icon, text, highlight, logout);
     977                     options, logout);
    965978    }
    966979    else {
    967980      if (elseptr != NULL)
    968981    return get_formatted_string (collection,collectproto, docinfo, disp, elseptr,
    969                      link, icon, text, highlight, logout);
     982                     options, logout);
    970983    }
    971984  }
     
    985998      if (ifptr != NULL)
    986999    return get_formatted_string (collection, collectproto, docinfo, disp, ifptr,
    987                      link, icon, text, highlight, logout);
     1000                     options, logout);
    9881001    } else {
    9891002      if (elseptr != NULL)
    9901003    return get_formatted_string (collection, collectproto, docinfo, disp, elseptr,
    991                      link, icon, text, highlight, logout);
     1004                     options, logout);
    9921005    }
    9931006  }
     
    10081021}
    10091022
    1010 
     1023static text_t expand_metadata(const text_t &metavalue, const text_t& collection,
     1024                  recptproto* collectproto, ResultDocInfo_t &docinfo,
     1025                  displayclass &disp, text_tmap &options,
     1026                  ostream &logout) {
     1027     
     1028   if (includes_metadata(metavalue))
     1029      {
     1030     // text has embedded metadata in it => expand it
     1031     FilterRequest_t request;
     1032     FilterResponse_t response;
     1033
     1034     request.getParents = false;
     1035     
     1036     format_t *expanded_formatlistptr = new format_t();
     1037     parse_formatstring (metavalue, expanded_formatlistptr,
     1038                 request.fields, request.getParents);
     1039     
     1040     // retrieve metadata
     1041     get_info(docinfo.OID, collection, request.fields, request.getParents,
     1042          collectproto, response, logout);
     1043     
     1044     if (!response.docInfo.empty())
     1045        {
     1046           text_t expanded_metavalue
     1047          = get_formatted_string(collection, collectproto,
     1048                     response.docInfo[0], disp, expanded_formatlistptr,
     1049                     options, logout);
     1050         
     1051           return expanded_metavalue;
     1052        }
     1053     else
     1054        {
     1055           return metavalue;
     1056        }
     1057      }
     1058   else
     1059      {
     1060     return metavalue;
     1061      }
     1062}
    10111063
    10121064text_t format_string (const text_t& collection, recptproto* collectproto,
    10131065              ResultDocInfo_t &docinfo, displayclass &disp,
    1014               format_t *formatlistptr,
    1015               const text_t &link, const text_t &icon,
    1016               const text_t &text, bool highlight,
     1066              format_t *formatlistptr, text_tmap &options,
    10171067              ostream& logout) {
    10181068
     
    10201070
    10211071  switch (formatlistptr->command) {
    1022   case comText:
    1023     return formatlistptr->text;
    1024   case comLink:
    1025     return link;
    1026   case comEndLink:
    1027     if (link.empty()) return "";
    1028     else return "</a>";
    1029   case comHref:
    1030     return get_href(link);
    1031   case comIcon:
    1032     return icon;
    1033   case comNum:
    1034     return docinfo.result_num;
    1035   case comRel: //if [RelatedDocuments] appears in format string, collect relation data
    1036     return get_related_docs(collection, collectproto, docinfo, logout);
    1037   case comSummary:
    1038     return format_summary(collection,collectproto,docinfo,disp,text,highlight,logout);
    1039   case comMeta:
    1040 
    1041     {
    1042       const text_t& metavalue =  get_meta (docinfo, formatlistptr->meta);
    1043 
    1044       if (includes_metadata(metavalue))
     1072     case comText:
     1073    return formatlistptr->text;
     1074     case comLink:
     1075    return options["link"];
     1076     case comEndLink:
     1077    if (options["link"].empty()) return "";
     1078    else return "</a>";
     1079     case comHref:
     1080    return get_href(options["link"]);
     1081     case comIcon:
     1082    return options["icon"];
     1083     case comNum:
     1084    return docinfo.result_num;
     1085     case comRel: //if [RelatedDocuments] appears in format string, collect relation data
     1086    return get_related_docs(collection, collectproto, docinfo, logout);
     1087     case comSummary:
     1088    return format_summary(collection, collectproto, docinfo, disp, options, logout);
     1089     case comMeta:
    10451090    {
    1046       // text has embedded metadata in it => expand it
    1047       FilterRequest_t request;
    1048       FilterResponse_t response;
    1049 
    1050       request.getParents = false;
    1051      
    1052       format_t *expanded_formatlistptr = new format_t();
    1053       parse_formatstring (metavalue, expanded_formatlistptr,
    1054                   request.fields, request.getParents);
    1055      
    1056       // retrieve metadata
    1057       get_info(docinfo.OID, collection, request.fields, request.getParents,
    1058            collectproto, response, logout);
    1059      
    1060       if (!response.docInfo.empty())
    1061         {
    1062           text_t expanded_metavalue
    1063         = get_formatted_string(collection, collectproto,
    1064                        response.docInfo[0], disp, expanded_formatlistptr,
    1065                        link, icon, highlight, logout);
    1066          
    1067           return expanded_metavalue;
    1068         }
    1069       else
    1070         {
    1071           return metavalue;
    1072         }
     1091       const text_t& metavalue =  get_meta (docinfo, formatlistptr->meta);
     1092       return expand_metadata(metavalue, collection, collectproto, docinfo, disp, options, logout);
    10731093    }
    1074       else
    1075     {
    1076       return metavalue;
    1077     }
    1078     }
    1079   case comDoc:
    1080     return text;
    1081   case comHighlight:
    1082     if (highlight) return "<b>";
    1083     break;
    1084   case comEndHighlight:
    1085     if (highlight) return "</b>";
    1086     break;
    1087   case comIf:
    1088     return get_if (collection, collectproto, docinfo, disp,
    1089            formatlistptr->decision, formatlistptr->ifptr,
    1090            formatlistptr->elseptr, link, icon, text, highlight,
    1091            logout);
    1092   case comOr:
    1093     return get_or (collection,collectproto, docinfo, disp, formatlistptr->orptr,
    1094            link, icon, text, highlight, logout);
     1094     case comDoc:
     1095    return options["text"];
     1096     case comImage:
     1097    return expand_metadata(options["DocImage"], collection, collectproto, docinfo, disp, options, logout);
     1098     case comTOC:
     1099    return options["DocTOC"];
     1100     case comDocumentButtonDetach:
     1101    return options["DocumentButtonDetach"];
     1102     case comDocumentButtonHighlight:
     1103    return options["DocumentButtonHighlight"];
     1104     case comDocumentButtonExpandContents:
     1105    return options["DocumentButtonExpandContents"];
     1106     case comDocumentButtonExpandText:
     1107    return options["DocumentButtonExpandText"];
     1108     case comHighlight:
     1109    if (options["highlight"] == "1") return "<b>";
     1110    break;
     1111     case comEndHighlight:
     1112    if (options["highlight"] == "1") return "</b>";
     1113    break;
     1114     case comIf:
     1115    return get_if (collection, collectproto, docinfo, disp,
     1116               formatlistptr->decision, formatlistptr->ifptr,
     1117               formatlistptr->elseptr, options, logout);
     1118     case comOr:
     1119    return get_or (collection,collectproto, docinfo, disp, formatlistptr->orptr,
     1120               options, logout);
    10951121  }
    10961122  return "";
    1097 }
    1098 
    1099 
    1100 
    1101 
    1102 text_t get_formatted_string (const text_t& collection, recptproto* collectproto,
    1103                  ResultDocInfo_t& docinfo, displayclass &disp,
    1104                  format_t* formatlistptr,
    1105                  const text_t& link, const text_t& icon,
    1106                  const text_t& text, const bool highlight,
    1107                  ostream& logout) {
    1108 
    1109   text_t ft;
    1110   while (formatlistptr != NULL)
    1111     {
    1112       ft += format_string (collection, collectproto, docinfo, disp, formatlistptr,
    1113                link, icon, text, highlight, logout);
    1114       formatlistptr = formatlistptr->nextptr;
    1115     }
    1116 
    1117   return ft;
    11181123}
    11191124
    11201125text_t get_formatted_string (const text_t& collection, recptproto* collectproto,
    11211126                 ResultDocInfo_t &docinfo, displayclass &disp,
    1122                  format_t *formatlistptr,
    1123                  const text_t &link, const text_t &icon,
    1124                  const bool highlight,
     1127                 format_t *formatlistptr, text_tmap &options,
    11251128                 ostream& logout) {
    11261129
    1127   text_t text = "";
    1128 
    1129   return get_formatted_string(collection, collectproto, docinfo, disp, formatlistptr,
    1130                               link, icon, text, highlight, logout);
    1131 }
    1132 
    1133 text_t get_formatted_string (const text_t& collection, recptproto* collectproto,
    1134                  ResultDocInfo_t &docinfo, displayclass &disp,
    1135                  format_t *formatlistptr,
    1136                  const text_t& text,
    1137                  ostream& logout) {
    1138 
    1139   text_t link = "<a href=\"_httpdocument_&cl=search&d=" + docinfo.OID + "\">";
    1140   text_t icon = "_icontext_";
    1141   bool highlight = false;
    1142 
    1143   return get_formatted_string(collection, collectproto, docinfo, disp, formatlistptr,
    1144                   link, icon, text, highlight, logout);
    1145 }
    1146 
    1147 text_t get_formatted_string (const text_t& collection, recptproto* collectproto,
    1148                  ResultDocInfo_t &docinfo, displayclass &disp,
    1149                  format_t *formatlistptr,
    1150                  ostream& logout) {
    1151 
    1152   text_t text = "";
    1153 
    1154   return get_formatted_string(collection, collectproto, docinfo, disp, formatlistptr,
    1155                   text, logout);
     1130   text_t ft;
     1131   while (formatlistptr != NULL)
     1132      {
     1133     ft += format_string (collection, collectproto, docinfo, disp, formatlistptr,
     1134                  options, logout);
     1135     formatlistptr = formatlistptr->nextptr;
     1136      }
     1137   
     1138   return ft;
    11561139}
    11571140
     
    11621145
    11631146text_t format_summary (const text_t& collection, recptproto* collectproto,
    1164               ResultDocInfo_t &docinfo, displayclass &disp,
    1165               const text_t &text, bool highlight,
    1166               ostream& logout) {
     1147               ResultDocInfo_t &docinfo, displayclass &disp,
     1148               text_tmap &options, ostream& logout) {
    11671149
    11681150  // GRB: added code here to ensure that the cstr (and other collections)
     
    11761158
    11771159  text_t textToSummarise, query;
    1178   if(text.empty()) { // get document text
    1179       DocumentRequest_t docrequest;
    1180       DocumentResponse_t docresponse;
    1181       comerror_t err;
    1182       docrequest.OID = docinfo.OID;
    1183       collectproto->get_document (collection, docrequest, docresponse, err, logout);
    1184       textToSummarise = docresponse.doc;
     1160  if(options["text"].empty()) { // get document text
     1161     DocumentRequest_t docrequest;
     1162     DocumentResponse_t docresponse;
     1163     comerror_t err;
     1164     docrequest.OID = docinfo.OID;
     1165     collectproto->get_document (collection, docrequest, docresponse, err, logout);
     1166     textToSummarise = docresponse.doc;
    11851167  } else // in practice, this would not happen, because text is only
    11861168         // loaded with the [Text] command
    1187       textToSummarise = text;
     1169     textToSummarise = options["text"];
    11881170  disp.expandstring("_cgiargq_",query);
    11891171  return summarise(textToSummarise,query,80);
Note: See TracChangeset for help on using the changeset viewer.