Changeset 9401
- Timestamp:
- 2005-03-14T09:49:40+13:00 (19 years ago)
- Location:
- trunk/gsdl/src/recpt
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl/src/recpt/formattools.cpp
r7617 r9401 45 45 text_tmap &options, ostream& logout); 46 46 47 static 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 47 52 48 53 void metadata_t::clear() { 49 54 metaname.clear(); 50 55 metacommand = mNone; 51 parentcommand = pNone; 56 mqualifier.parent = pNone; 57 mqualifier.sibling = sNone; 58 mqualifier.child = cNone; 52 59 functionoptions.clear(); 53 60 } … … 490 497 here ++; 491 498 } 499 492 500 instring = meta; 493 501 if (com.empty()) 494 metaoption. parentcommand= pImmediate;502 metaoption.mqualifier.parent = pImmediate; 495 503 else if (com == "Top") 496 metaoption. parentcommand= pTop;504 metaoption.mqualifier.parent = pTop; 497 505 else if (com == "All") { 498 metaoption. parentcommand= pAll;506 metaoption.mqualifier.parent = pAll; 499 507 metaoption.functionoptions = op; 500 508 } … … 528 536 529 537 if (com.empty()) { 538 metaoption.mqualifier.sibling = sAll; 530 539 metaoption.functionoptions = " "; 531 540 } 532 541 else { 542 metaoption.mqualifier.sibling = sAll; 533 543 metaoption.functionoptions = op; 534 544 } 535 545 } 546 547 static 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 536 594 537 595 … … 546 604 if (meta.size() > 7 && (substr (meta.begin(), meta.begin()+6) == "parent")) { 547 605 getParents = true; 606 metaoption.metacommand |= mParent; 548 607 get_parent_options (meta, metaoption); 549 608 } … … 551 610 metaoption.metacommand |= mSibling; 552 611 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); 553 616 } 554 617 … … 877 940 878 941 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 942 static 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 965 static text_t get_parent_meta (ResultDocInfo_t &docinfo, const metadata_t &meta) 966 { 967 888 968 MetadataInfo_t *parent = docinfo.metadata[meta.metaname].parent; 889 969 text_t no_ns_metaname = remove_namespace(meta.metaname); 890 switch (meta. parentcommand) {970 switch (meta.mqualifier.parent) { 891 971 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; 931 974 932 975 case pImmediate: … … 976 1019 } 977 1020 return ""; 1021 1022 } 1023 1024 static 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 1075 static 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 ""; 978 1116 } 979 1117 … … 1070 1208 1071 1209 1072 static text_t expand_potential_metadata(ResultDocInfo_t &docinfo, 1073 const text_t& intext) 1210 static 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) 1074 1217 { 1075 1218 text_t outtext; … … 1090 1233 1091 1234 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); 1093 1237 } 1094 1238 else { … … 1102 1246 1103 1247 1104 static bool uses_expression(ResultDocInfo_t &docinfo, 1248 static bool uses_expression(const text_t& collection, recptproto* collectproto, 1249 ResultDocInfo_t &docinfo, 1250 displayclass &disp, 1105 1251 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) 1107 1255 { 1108 1256 // Note: the string may not be of the form: str1 op str2, however … … 1180 1328 // metadata terms 1181 1329 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); 1184 1334 1185 1335 return true; … … 1212 1362 // to see whether we output the "then" or the "else" clause 1213 1363 if (decision.command == dMeta) { 1214 if (get_meta (docinfo, decision.meta) != "") { 1364 if (get_meta (collection,collectproto,docinfo,disp,decision.meta,options, 1365 logout) != "") { 1215 1366 if (ifptr != NULL) 1216 1367 return get_formatted_string (collection,collectproto, docinfo, disp, ifptr, … … 1234 1385 // (such as [x] eq "y") 1235 1386 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)) { 1237 1388 if (eval_expression_true(lhs_expr,op_expr,rhs_expr,logout)) { 1238 1389 if (ifptr != NULL) { … … 1358 1509 case comMeta: 1359 1510 { 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); 1361 1512 return expand_metadata(metavalue, collection, collectproto, docinfo, disp, options, logout); 1362 1513 } -
trunk/gsdl/src/recpt/formattools.h
r7389 r9401 37 37 comTOC, comImage, comDocumentButtonDetach, comDocumentButtonHighlight, 38 38 comDocumentButtonExpandContents, comDocumentButtonExpandText, comOID, comRank}; 39 40 enum mcommand_t {mNone=0, mCgiSafe=1, mParent=2, mSibling=4, mChild=8}; 41 39 42 enum pcommand_t {pNone, pImmediate, pTop, pAll}; 43 enum scommand_t {sNone, sAll}; 44 enum ccommand_t {cNone, cAll, cNum}; 40 45 enum dcommand_t {dMeta, dText}; 41 enum mcommand_t {mNone=0, mCgiSafe=1, mParent=2, mSibling=4};42 46 43 47 struct metadata_t { … … 47 51 text_t metaname; 48 52 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 50 59 text_t functionoptions; 51 60 };
Note:
See TracChangeset
for help on using the changeset viewer.