Changeset 5788
- Timestamp:
- 2003-11-05T16:07:59+13:00 (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl/src/recpt/formattools.cpp
r5787 r5788 32 32 33 33 // a few function prototypes 34 34 35 static text_t format_string (const text_t& collection, recptproto* collectproto, 35 36 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); 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 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); 43 static text_t format_summary (const text_t& collection, recptproto* collectproto, 44 ResultDocInfo_t &docinfo, displayclass &disp, 45 text_tmap &options, ostream& logout); 47 46 48 47 … … 77 76 DocumentContents = true; 78 77 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; 88 89 } 89 90 … … 525 526 } 526 527 528 527 529 static void parse_meta (text_t &meta, metadata_t &metaoption, 528 530 text_tset &metadata, bool &getParents) { … … 534 536 535 537 if (meta.size() > 7 && (substr (meta.begin(), meta.begin()+6) == "parent")) { 536 metaoption.metacommand |= mParent;537 538 getParents = true; 538 539 get_parent_options (meta, metaoption); … … 579 580 formatlistptr->command = comSummary; 580 581 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 581 600 else { 582 601 formatlistptr->command = comMeta; … … 878 897 } 879 898 880 881 899 case pImmediate: 882 900 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 896 901 if (meta.metaname == "Date") 897 902 return format_date (parent->values[0]); … … 902 907 break; 903 908 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 904 921 case pAll: 905 922 MetadataInfo_t *parent = docinfo.metadata[meta.metaname].parent; 906 923 if (parent != NULL) { 907 908 924 text_tarray tmparray; 909 925 while (parent != NULL) { … … 931 947 static text_t get_or (const text_t& collection, recptproto* collectproto, 932 948 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, 936 950 ostream& logout) { 937 951 … … 940 954 941 955 tmp = format_string (collection,collectproto, docinfo, disp, orptr, 942 link, icon, text, highlight, logout);956 options, logout); 943 957 if (!tmp.empty()) return tmp; 944 958 … … 951 965 ResultDocInfo_t &docinfo, displayclass &disp, 952 966 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) 956 969 { 957 970 … … 962 975 if (ifptr != NULL) 963 976 return get_formatted_string (collection,collectproto, docinfo, disp, ifptr, 964 link, icon, text, highlight, logout);977 options, logout); 965 978 } 966 979 else { 967 980 if (elseptr != NULL) 968 981 return get_formatted_string (collection,collectproto, docinfo, disp, elseptr, 969 link, icon, text, highlight, logout);982 options, logout); 970 983 } 971 984 } … … 985 998 if (ifptr != NULL) 986 999 return get_formatted_string (collection, collectproto, docinfo, disp, ifptr, 987 link, icon, text, highlight, logout);1000 options, logout); 988 1001 } else { 989 1002 if (elseptr != NULL) 990 1003 return get_formatted_string (collection, collectproto, docinfo, disp, elseptr, 991 link, icon, text, highlight, logout);1004 options, logout); 992 1005 } 993 1006 } … … 1008 1021 } 1009 1022 1010 1023 static 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 } 1011 1063 1012 1064 text_t format_string (const text_t& collection, recptproto* collectproto, 1013 1065 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, 1017 1067 ostream& logout) { 1018 1068 … … 1020 1070 1021 1071 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: 1045 1090 { 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); 1073 1093 } 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); 1095 1121 } 1096 1122 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;1118 1123 } 1119 1124 1120 1125 text_t get_formatted_string (const text_t& collection, recptproto* collectproto, 1121 1126 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, 1125 1128 ostream& logout) { 1126 1129 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; 1156 1139 } 1157 1140 … … 1162 1145 1163 1146 text_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) { 1167 1149 1168 1150 // GRB: added code here to ensure that the cstr (and other collections) … … 1176 1158 1177 1159 text_t textToSummarise, query; 1178 if( text.empty()) { // get document text1179 1180 1181 1182 1183 1184 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; 1185 1167 } else // in practice, this would not happen, because text is only 1186 1168 // loaded with the [Text] command 1187 textToSummarise = text;1169 textToSummarise = options["text"]; 1188 1170 disp.expandstring("_cgiargq_",query); 1189 1171 return summarise(textToSummarise,query,80);
Note:
See TracChangeset
for help on using the changeset viewer.