Changeset 5787 for trunk/gsdl/src/recpt
- Timestamp:
- 2003-11-05T15:06:39+13:00 (21 years ago)
- Location:
- trunk/gsdl/src/recpt
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl/src/recpt/formattools.cpp
r4972 r5787 32 32 33 33 // a few function prototypes 34 35 34 static text_t format_string (const text_t& collection, recptproto* collectproto, 36 35 ResultDocInfo_t &docinfo, displayclass &disp, 37 format_t *formatlistptr, text_tmap &options, 38 ostream& logout); 36 format_t *formatlistptr, 37 const text_t &link, const text_t &icon, 38 const text_t &text, bool highlight, ostream& logout); 39 39 40 40 static bool parse_action (text_t::const_iterator &here, const text_t::const_iterator &end, 41 41 format_t *formatlistptr, text_tset &metadata, bool &getParents); 42 42 43 static text_t format_summary (const text_t& collection, recptproto* collectproto, 44 ResultDocInfo_t &docinfo, displayclass &disp, 45 text_tmap &options, ostream& logout); 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); 46 47 47 48 … … 50 51 metacommand = mNone; 51 52 parentcommand = pNone; 52 parentoptions.clear();53 functionoptions.clear(); 53 54 } 54 55 … … 76 77 DocumentContents = true; 77 78 DocumentArrowsBottom = true; 78 DocumentArrowsTop = false;79 79 DocumentButtons.erase (DocumentButtons.begin(), DocumentButtons.end()); 80 80 // DocumentButtons.push_back ("Expand Text"); … … 86 86 formatstrings.erase (formatstrings.begin(), formatstrings.end()); 87 87 DocumentUseHTML = false; 88 AllowExtendedOptions = false;89 88 } 90 89 … … 488 487 else if (com == "All") { 489 488 metaoption.parentcommand = pAll; 490 metaoption.parentoptions = op; 489 metaoption.functionoptions = op; 490 } 491 } 492 493 494 static void get_sibling_options (text_t &instring, metadata_t &metaoption) { 495 496 assert (instring.size() > 8); 497 if (instring.size() <= 8) return; 498 499 text_t meta, com, op; 500 bool inbraces = false; 501 bool inquotes = false; 502 bool foundcolon = false; 503 text_t::const_iterator here = instring.begin()+7; 504 text_t::const_iterator end = instring.end(); 505 while (here != end) { 506 if (*here == '(') inbraces = true; 507 else if (*here == ')') inbraces = false; 508 else if (*here == '\'' && !inquotes) inquotes = true; 509 else if (*here == '\'' && inquotes) inquotes = false; 510 else if (*here == ':' && !inbraces) foundcolon = true; 511 else if (foundcolon) meta.push_back (*here); 512 else if (inquotes) op.push_back (*here); 513 else com.push_back (*here); 514 here ++; 515 } 516 517 instring = meta; 518 519 if (com.empty()) { 520 metaoption.functionoptions = " "; 521 } 522 else { 523 metaoption.functionoptions = op; 491 524 } 492 525 } … … 496 529 497 530 if (meta.size() > 8 && (substr(meta.begin(), meta.begin()+8) == "cgisafe:")) { 498 metaoption.metacommand = mCgiSafe;531 metaoption.metacommand |= mCgiSafe; 499 532 meta = substr (meta.begin()+8, meta.end()); 500 533 } 501 534 502 535 if (meta.size() > 7 && (substr (meta.begin(), meta.begin()+6) == "parent")) { 536 metaoption.metacommand |= mParent; 503 537 getParents = true; 504 538 get_parent_options (meta, metaoption); 539 } 540 else if (meta.size() > 8 && (substr (meta.begin(), meta.begin()+7) == "sibling")) { 541 metaoption.metacommand |= mSibling; 542 get_sibling_options (meta, metaoption); 505 543 } 506 544 … … 541 579 formatlistptr->command = comSummary; 542 580 543 else if (meta == "DocImage")544 formatlistptr->command = comImage;545 546 else if (meta == "DocTOC")547 formatlistptr->command = comTOC;548 549 else if (meta == "DocumentButtonDetach")550 formatlistptr->command = comDocumentButtonDetach;551 552 else if (meta == "DocumentButtonHighlight")553 formatlistptr->command = comDocumentButtonHighlight;554 555 else if (meta == "DocumentButtonExpandContents")556 formatlistptr->command = comDocumentButtonExpandContents;557 558 else if (meta == "DocumentButtonExpandText")559 formatlistptr->command = comDocumentButtonExpandText;560 561 581 else { 562 582 formatlistptr->command = comMeta; … … 820 840 case pNone: 821 841 { 822 text_t classifier_metaname = docinfo.classifier_metadata_type; 823 int metaname_index 824 = (classifier_metaname == meta.metaname) ? docinfo.classifier_metadata_offset : 0; 825 text_t metadata_item = docinfo.metadata[meta.metaname].values[metaname_index]; 826 827 if (meta.metaname == "Date") 828 return format_date (metadata_item); 829 else if (meta.metaname == "Language") 830 return iso639(metadata_item); 831 if (meta.metacommand == mCgiSafe) 832 return cgi_safe (metadata_item); 833 else return metadata_item; 842 if (meta.metacommand & mSibling) { 843 text_t tmp; 844 bool first = true; 845 846 MetadataInfo_t& metaname_rec = docinfo.metadata[meta.metaname]; 847 848 const int start_i=0; 849 const int end_i = metaname_rec.values.size()-1; 850 851 for (int i=start_i; i<=end_i; i++) { 852 if (!first) tmp += meta.functionoptions; 853 if (meta.metaname == "Date") tmp += format_date (metaname_rec.values[i]); 854 else if (meta.metaname == "Language") tmp += iso639(metaname_rec.values[i]); 855 else tmp += metaname_rec.values[i]; 856 first = false; 857 } 858 859 if (meta.metacommand & mCgiSafe) return cgi_safe (tmp); 860 else return tmp; 861 862 } 863 else { 864 865 text_t classifier_metaname = docinfo.classifier_metadata_type; 866 int metaname_index 867 = (classifier_metaname == meta.metaname) ? docinfo.classifier_metadata_offset : 0; 868 text_t metadata_item = docinfo.metadata[meta.metaname].values[metaname_index]; 869 870 if (meta.metaname == "Date") 871 return format_date (metadata_item); 872 else if (meta.metaname == "Language") 873 return iso639(metadata_item); 874 if (meta.metacommand & mCgiSafe) 875 return cgi_safe (metadata_item); 876 else return metadata_item; 877 } 834 878 } 879 835 880 836 881 case pImmediate: … … 844 889 break; 845 890 891 846 892 case pTop: 847 893 if (parent != NULL) { … … 850 896 if (meta.metaname == "Date") 851 897 return format_date (parent->values[0]); 852 if (meta.metacommand ==mCgiSafe)898 if (meta.metacommand & mCgiSafe) 853 899 return cgi_safe (parent->values[0]); 854 900 else return parent->values[0]; … … 859 905 MetadataInfo_t *parent = docinfo.metadata[meta.metaname].parent; 860 906 if (parent != NULL) { 907 861 908 text_tarray tmparray; 862 909 while (parent != NULL) { … … 869 916 text_tarray::reverse_iterator end = tmparray.rend(); 870 917 while (here != end) { 871 if (!first) tmp += meta. parentoptions;918 if (!first) tmp += meta.functionoptions; 872 919 if (meta.metaname == "Date") tmp += format_date (*here); 873 920 else tmp += *here; … … 875 922 here ++; 876 923 } 877 if (meta.metacommand ==mCgiSafe) return cgi_safe (tmp);924 if (meta.metacommand & mCgiSafe) return cgi_safe (tmp); 878 925 else return tmp; 879 926 } … … 884 931 static text_t get_or (const text_t& collection, recptproto* collectproto, 885 932 ResultDocInfo_t &docinfo, displayclass &disp, 886 format_t *orptr, text_tmap &options, 933 format_t *orptr, 934 const text_t &link, const text_t &icon, 935 const text_t &text, bool highlight, 887 936 ostream& logout) { 888 937 … … 891 940 892 941 tmp = format_string (collection,collectproto, docinfo, disp, orptr, 893 options, logout);942 link, icon, text, highlight, logout); 894 943 if (!tmp.empty()) return tmp; 895 944 … … 902 951 ResultDocInfo_t &docinfo, displayclass &disp, 903 952 const decision_t &decision, 904 format_t *ifptr, format_t *elseptr, 905 text_tmap &options, ostream& logout) 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) 906 956 { 907 957 … … 912 962 if (ifptr != NULL) 913 963 return get_formatted_string (collection,collectproto, docinfo, disp, ifptr, 914 options, logout);964 link, icon, text, highlight, logout); 915 965 } 916 966 else { 917 967 if (elseptr != NULL) 918 968 return get_formatted_string (collection,collectproto, docinfo, disp, elseptr, 919 options, logout);969 link, icon, text, highlight, logout); 920 970 } 921 971 } … … 935 985 if (ifptr != NULL) 936 986 return get_formatted_string (collection, collectproto, docinfo, disp, ifptr, 937 options, logout);987 link, icon, text, highlight, logout); 938 988 } else { 939 989 if (elseptr != NULL) 940 990 return get_formatted_string (collection, collectproto, docinfo, disp, elseptr, 941 options, logout);991 link, icon, text, highlight, logout); 942 992 } 943 993 } … … 958 1008 } 959 1009 960 static text_t expand_metadata(const text_t &metavalue, const text_t& collection, 961 recptproto* collectproto, ResultDocInfo_t &docinfo, 962 displayclass &disp, text_tmap &options, 963 ostream &logout) { 964 965 if (includes_metadata(metavalue)) 966 { 967 // text has embedded metadata in it => expand it 968 FilterRequest_t request; 969 FilterResponse_t response; 970 971 request.getParents = false; 972 973 format_t *expanded_formatlistptr = new format_t(); 974 parse_formatstring (metavalue, expanded_formatlistptr, 975 request.fields, request.getParents); 976 977 // retrieve metadata 978 get_info(docinfo.OID, collection, request.fields, request.getParents, 979 collectproto, response, logout); 980 981 if (!response.docInfo.empty()) 982 { 983 text_t expanded_metavalue 984 = get_formatted_string(collection, collectproto, 985 response.docInfo[0], disp, expanded_formatlistptr, 986 options, logout); 987 988 return expanded_metavalue; 989 } 990 else 991 { 992 return metavalue; 993 } 994 } 995 else 996 { 997 return metavalue; 998 } 999 } 1010 1000 1011 1001 1012 text_t format_string (const text_t& collection, recptproto* collectproto, 1002 1013 ResultDocInfo_t &docinfo, displayclass &disp, 1003 format_t *formatlistptr, text_tmap &options, 1014 format_t *formatlistptr, 1015 const text_t &link, const text_t &icon, 1016 const text_t &text, bool highlight, 1004 1017 ostream& logout) { 1005 1018 … … 1007 1020 1008 1021 switch (formatlistptr->command) { 1009 case comText: 1010 return formatlistptr->text; 1011 case comLink: 1012 return options["link"]; 1013 case comEndLink: 1014 if (options["link"].empty()) return ""; 1015 else return "</a>"; 1016 case comHref: 1017 return get_href(options["link"]); 1018 case comIcon: 1019 return options["icon"]; 1020 case comNum: 1021 return docinfo.result_num; 1022 case comRel: //if [RelatedDocuments] appears in format string, collect relation data 1023 return get_related_docs(collection, collectproto, docinfo, logout); 1024 case comSummary: 1025 return format_summary(collection, collectproto, docinfo, disp, options, logout); 1026 case comMeta: 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)) 1027 1045 { 1028 const text_t& metavalue = get_meta (docinfo, formatlistptr->meta); 1029 return expand_metadata(metavalue, collection, collectproto, docinfo, disp, options, logout); 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 } 1030 1073 } 1031 case comDoc: 1032 return options["text"]; 1033 case comImage: 1034 return expand_metadata(options["DocImage"], collection, collectproto, docinfo, disp, options, logout); 1035 case comTOC: 1036 return options["DocTOC"]; 1037 case comDocumentButtonDetach: 1038 return options["DocumentButtonDetach"]; 1039 case comDocumentButtonHighlight: 1040 return options["DocumentButtonHighlight"]; 1041 case comDocumentButtonExpandContents: 1042 return options["DocumentButtonExpandContents"]; 1043 case comDocumentButtonExpandText: 1044 return options["DocumentButtonExpandText"]; 1045 case comHighlight: 1046 if (options["highlight"] == "1") return "<b>"; 1047 break; 1048 case comEndHighlight: 1049 if (options["highlight"] == "1") return "</b>"; 1050 break; 1051 case comIf: 1052 return get_if (collection, collectproto, docinfo, disp, 1053 formatlistptr->decision, formatlistptr->ifptr, 1054 formatlistptr->elseptr, options, logout); 1055 case comOr: 1056 return get_or (collection,collectproto, docinfo, disp, formatlistptr->orptr, 1057 options, logout); 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); 1058 1095 } 1059 1096 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; 1060 1118 } 1061 1119 1062 1120 text_t get_formatted_string (const text_t& collection, recptproto* collectproto, 1063 1121 ResultDocInfo_t &docinfo, displayclass &disp, 1064 format_t *formatlistptr, text_tmap &options, 1122 format_t *formatlistptr, 1123 const text_t &link, const text_t &icon, 1124 const bool highlight, 1065 1125 ostream& logout) { 1066 1126 1067 text_t ft; 1068 while (formatlistptr != NULL) 1069 { 1070 ft += format_string (collection, collectproto, docinfo, disp, formatlistptr, 1071 options, logout); 1072 formatlistptr = formatlistptr->nextptr; 1073 } 1074 1075 return ft; 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); 1076 1156 } 1077 1157 … … 1082 1162 1083 1163 text_t format_summary (const text_t& collection, recptproto* collectproto, 1084 ResultDocInfo_t &docinfo, displayclass &disp, 1085 text_tmap &options, ostream& logout) { 1164 ResultDocInfo_t &docinfo, displayclass &disp, 1165 const text_t &text, bool highlight, 1166 ostream& logout) { 1086 1167 1087 1168 // GRB: added code here to ensure that the cstr (and other collections) … … 1095 1176 1096 1177 text_t textToSummarise, query; 1097 if( options["text"].empty()) { // get document text1098 DocumentRequest_t docrequest;1099 DocumentResponse_t docresponse;1100 comerror_t err;1101 docrequest.OID = docinfo.OID;1102 collectproto->get_document (collection, docrequest, docresponse, err, logout);1103 textToSummarise = docresponse.doc;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; 1104 1185 } else // in practice, this would not happen, because text is only 1105 1186 // loaded with the [Text] command 1106 textToSummarise = options["text"];1187 textToSummarise = text; 1107 1188 disp.expandstring("_cgiargq_",query); 1108 1189 return summarise(textToSummarise,query,80); -
trunk/gsdl/src/recpt/formattools.h
r4972 r5787 39 39 enum pcommand_t {pNone, pImmediate, pTop, pAll}; 40 40 enum dcommand_t {dMeta, dText}; 41 enum mcommand_t {mNone , mCgiSafe};41 enum mcommand_t {mNone=0, mCgiSafe=1, mParent=2, mSibling=4}; 42 42 43 43 struct metadata_t { … … 46 46 47 47 text_t metaname; 48 mcommand_t metacommand;48 int metacommand; // used to hold flags from mcommand_t 49 49 pcommand_t parentcommand; 50 text_t parentoptions;50 text_t functionoptions; 51 51 }; 52 52
Note:
See TracChangeset
for help on using the changeset viewer.