Changeset 10415
- Timestamp:
- 2005-08-04T12:09:41+12:00 (19 years ago)
- Location:
- trunk/gsdl/src/recpt
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl/src/recpt/formattools.cpp
r10145 r10415 60 60 mqualifier.sibling = sNone; 61 61 mqualifier.child = cNone; 62 functionoptions.clear(); 62 parentoptions.clear(); 63 siblingoptions.clear(); 64 childoptions.clear(); 63 65 } 64 66 … … 490 492 text_t::const_iterator end = instring.end(); 491 493 while (here != end) { 492 if (*here == '(') inbraces = true; 494 if (foundcolon) meta.push_back (*here); 495 else if (*here == '(') inbraces = true; 493 496 else if (*here == ')') inbraces = false; 494 497 else if (*here == '\'' && !inquotes) inquotes = true; 495 498 else if (*here == '\'' && inquotes) inquotes = false; 496 499 else if (*here == ':' && !inbraces) foundcolon = true; 497 else if (foundcolon) meta.push_back (*here);498 500 else if (inquotes) op.push_back (*here); 499 501 else com.push_back (*here); … … 508 510 else if (com == "All") { 509 511 metaoption.mqualifier.parent = pAll; 510 metaoption. functionoptions = op;512 metaoption.parentoptions = op; 511 513 } 512 514 } … … 517 519 assert (instring.size() > 8); 518 520 if (instring.size() <= 8) return; 519 520 521 text_t meta, com, op; 521 522 bool inbraces = false; … … 525 526 text_t::const_iterator end = instring.end(); 526 527 while (here != end) { 527 if (*here == '(') inbraces = true; 528 if (foundcolon) meta.push_back (*here); 529 else if (*here == '(') inbraces = true; 528 530 else if (*here == ')') inbraces = false; 529 531 else if (*here == '\'' && !inquotes) inquotes = true; 530 532 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; 533 534 else if (inquotes) op.push_back (*here); 534 535 else com.push_back (*here); … … 537 538 538 539 instring = meta; 540 metaoption.siblingoptions.clear(); 539 541 540 542 if (com.empty()) { 541 543 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; 543 558 } 544 559 else { 545 560 metaoption.mqualifier.sibling = sAll; 546 metaoption. functionoptions = op;561 metaoption.siblingoptions = op; 547 562 } 548 563 } … … 552 567 assert (instring.size() > 6); 553 568 if (instring.size() <= 6) return; 554 555 569 text_t meta, com, op; 556 570 bool inbraces = false; … … 560 574 text_t::const_iterator end = instring.end(); 561 575 while (here != end) { 562 if (*here == '(') inbraces = true; 576 if (foundcolon) meta.push_back (*here); 577 else if (*here == '(') inbraces = true; 563 578 else if (*here == ')') inbraces = false; 564 579 else if (*here == '\'' && !inquotes) inquotes = true; 565 580 else if (*here == '\'' && inquotes) inquotes = false; 566 581 else if (*here == ':' && !inbraces) foundcolon = true; 567 else if (foundcolon) meta.push_back (*here);568 582 else if (inquotes) op.push_back (*here); 569 583 else com.push_back (*here); … … 572 586 573 587 instring = meta; 574 575 588 if (com.empty()) { 576 589 metaoption.mqualifier.child = cAll; 577 metaoption. functionoptions = " ";590 metaoption.childoptions = " "; 578 591 } 579 592 else if (com == "first") { 580 593 metaoption.mqualifier.child = cNum; 581 metaoption. functionoptions = ".fc";594 metaoption.childoptions = ".fc"; 582 595 } 583 596 else if (com == "last") { 584 597 metaoption.mqualifier.child = cNum; 585 metaoption. functionoptions = ".lc";598 metaoption.childoptions = ".lc"; 586 599 } 587 600 else if (com.getint()>0) { 588 601 metaoption.mqualifier.child = cNum; 589 metaoption. functionoptions =com;602 metaoption.childoptions = "."+com; 590 603 } 591 604 else { 592 605 metaoption.mqualifier.child = cAll; 593 metaoption. functionoptions = op;606 metaoption.childoptions = op; 594 607 } 595 608 } … … 610 623 get_parent_options (meta, metaoption); 611 624 } 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")) { 613 632 metaoption.metacommand |= mSibling; 614 633 get_sibling_options (meta, metaoption); 615 634 } 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 621 636 // check for ex. which may occur in format statements 622 637 if (meta.size()>3 && (substr(meta.begin(), meta.begin()+3) == "ex.")) { … … 958 973 } 959 974 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 977 static text_t get_formatted_meta_text(MetadataInfo_t &metainfo, const metadata_t &meta, int position, bool no_cgisafe = false) 962 978 { 963 979 text_t no_ns_metaname = remove_namespace(meta.metaname); 964 965 980 text_t tmp; 966 981 bool first = true; … … 968 983 const int start_i=0; 969 984 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; 973 993 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); 981 1006 else return tmp; 982 1007 } 983 1008 984 static text_t get_parent_meta (ResultDocInfo_t &docinfo, const metadata_t &meta )1009 static text_t get_parent_meta (ResultDocInfo_t &docinfo, const metadata_t &meta, int siblings_values) 985 1010 { 986 1011 987 1012 MetadataInfo_t *parent = docinfo.metadata[meta.metaname].parent; 988 text_t no_ns_metaname = remove_namespace(meta.metaname);989 1013 switch (meta.mqualifier.parent) { 990 1014 case pNone: … … 994 1018 case pImmediate: 995 1019 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); 1001 1021 } 1002 1022 break; … … 1005 1025 if (parent != NULL) { 1006 1026 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); 1013 1028 } 1014 1029 break; … … 1019 1034 text_tarray tmparray; 1020 1035 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 1022 1037 parent = parent->parent; 1023 1038 } 1039 // now join them up - use teh parent separator 1024 1040 bool first = true; 1025 1041 text_t tmp; … … 1027 1043 text_tarray::reverse_iterator end = tmparray.rend(); 1028 1044 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; 1032 1047 first = false; 1033 1048 ++here; … … 1045 1060 ResultDocInfo_t &docinfo, displayclass &disp, 1046 1061 const metadata_t &meta, text_tmap &options, 1047 ostream& logout )1062 ostream& logout, int siblings_values) 1048 1063 { 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 1061 1074 //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, 1082 1122 child_docinfo,disp,options,logout); 1083 } 1084 } 1085 } 1086 1087 return ""; 1088 } 1089 1123 } 1124 return result; 1125 1126 } 1090 1127 1091 1128 … … 1102 1139 if (it == docinfo.metadata.end()) return ""; 1103 1140 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 } 1106 1149 if (meta.metacommand & mParent) { 1107 return get_parent_meta(docinfo,meta); 1108 } 1150 return get_parent_meta(docinfo,meta,siblings_values); 1151 } 1152 1109 1153 else if (meta.metacommand & mChild) { 1110 1154 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 1114 1158 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); 1116 1160 } 1117 1161 else { … … 1122 1166 int metaname_index 1123 1167 = (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 1135 1171 return ""; 1136 1172 } … … 1473 1509 ostream &logout) { 1474 1510 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 } 1509 1544 } 1510 1545 -
trunk/gsdl/src/recpt/formattools.h
r9948 r10415 41 41 42 42 enum pcommand_t {pNone, pImmediate, pTop, pAll}; 43 enum scommand_t {sNone, sAll };43 enum scommand_t {sNone, sAll, sNum}; 44 44 enum ccommand_t {cNone, cAll, cNum}; 45 45 enum dcommand_t {dMeta, dText}; … … 57 57 } mqualifier; 58 58 59 text_t functionoptions; 59 text_t parentoptions; 60 text_t siblingoptions; 61 text_t childoptions; 60 62 }; 61 63
Note:
See TracChangeset
for help on using the changeset viewer.