Changeset 36188
- Timestamp:
- 2022-05-16T14:43:36+12:00 (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/gli/src/org/greenstone/gatherer/cdm/CollectionConfigXMLReadWrite.java
r36156 r36188 75 75 ************************************************************************************************************ */ 76 76 77 static private ArrayList getMatchingSearchMetaElements(Element source, String meta_name, String meta_type) { 78 return XMLTools.getNamedElementList(source, StaticStrings.SEARCHMETADATA_ELEMENT, new String[]{StaticStrings.NAME_ATTRIBUTE, StaticStrings.TYPE_ATTRIBUTE}, new String[]{ meta_name, meta_type}); 79 80 } 77 81 /** 78 * Arguments: metadataListNode->the 'displayItemList' element in 79 * collectionConfig.xml name_value->the value of the 'name' attribute of 80 * 'index' element; att_value->the value of the 'name' attribute of 81 * 'displayItem' element return: an ArrayList of the contructed 82 * Arguments: 83 * * metadataListNode->the 'displayItemList' element in 84 * collectionConfig.xml, or any other element that contains displayItems, eg <index> 85 * * name_value->the value of the 'name' attribute of 86 * the new collectionmeta element; 87 * * att_value->the value of the 'name' attribute of 88 * 'displayItem' element - we only process the displayItems whose name attribute == att_value. apart from the top level displayItemList where we have collectiondescription etc, this will be 'name' 89 * * return: an ArrayList of the contructed 82 90 * 'CollectionMetadata' elements 83 91 */ 84 static private ArrayList doDisplayItemList(Document to, Node displayListNode, String att_value, String name_value) 92 static private ArrayList doDisplayItemList(Document to, Node displayListNode, String att_value, String name_value) { 93 return doDisplayItemList(to, displayListNode, att_value, name_value, null); 94 } 95 96 static private ArrayList doDisplayItemList(Document to, Node displayListNode, String att_value, String name_value, String type) 85 97 { 86 98 Element toElement = to.getDocumentElement(); … … 121 133 String key = item.getAttribute(StaticStrings.KEY_ATTRIBUTE); 122 134 123 Element e = to.createElement(StaticStrings.COLLECTIONMETADATA_ELEMENT); 135 Element e; 136 if (type ==null) { 137 e = to.createElement(StaticStrings.COLLECTIONMETADATA_ELEMENT); 138 } else { 139 e = to.createElement(StaticStrings.SEARCHMETADATA_ELEMENT); 140 } 124 141 e.setAttribute(StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR); 125 142 e.setAttribute(StaticStrings.NAME_ATTRIBUTE, name_value); 126 143 144 if (type != null) { 145 e.setAttribute(StaticStrings.TYPE_ATTRIBUTE, type); 146 } 127 147 if(!lang.equals("")) { 128 148 e.setAttribute(StaticStrings.LANGUAGE_ATTRIBUTE, lang); … … 143 163 } 144 164 return display_item_list; 145 } 165 } // doDisplayItemList 146 166 147 167 static private ArrayList doMetadataList(Document to, Node metadataListNode, String ele_name, String att_value) … … 179 199 } 180 200 return metadata_list; 181 } 201 } // doMetadataList 182 202 183 203 // 'to' is the internal structure … … 240 260 // Handling 'displayItem' elements and Constructing 'collectionmetadata' elements 241 261 // Use the fully qualified index names 242 ArrayList collectionmetadata_list = doDisplayItemList(to, e, StaticStrings.NAME_ ATTRIBUTE, index_str_display);262 ArrayList collectionmetadata_list = doDisplayItemList(to, e, StaticStrings.NAME_STR, index_str_display, SearchMeta.TYPE_INDEX); // todo should be name_str??? 243 263 appendArrayList(toElement, collectionmetadata_list); 244 264 } //for loop ends … … 263 283 264 284 // Contructing 'collectionmetadata' elements for 'mgpp' indexes 265 Element collectionmetadata = to.createElement(StaticStrings. COLLECTIONMETADATA_ELEMENT);285 Element collectionmetadata = to.createElement(StaticStrings.SEARCHMETADATA_ELEMENT); 266 286 collectionmetadata.setAttribute(StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR); 267 287 collectionmetadata.setAttribute(StaticStrings.NAME_ATTRIBUTE, index_strs[i]); 268 288 collectionmetadata.setAttribute(StaticStrings.LANGUAGE_ATTRIBUTE, StaticStrings.ENGLISH_LANGUAGE_STR); 289 collectionmetadata.setAttribute("type", SearchMeta.TYPE_INDEX); 269 290 if (index_strs[i].indexOf(StaticStrings.NS_SEP) != -1) 270 291 { … … 365 386 // Handling 'displayItem' element of this 'index' element 366 387 // 'e' is the parent element 'index' of 'displayItem' element 367 ArrayList collectionmetadata_list = doDisplayItemList(to, e, StaticStrings.NAME_ATTRIBUTE, index_str_display );388 ArrayList collectionmetadata_list = doDisplayItemList(to, e, StaticStrings.NAME_ATTRIBUTE, index_str_display, existing_index_str); 368 389 appendArrayList(toElement, collectionmetadata_list); 369 390 … … 372 393 //return toElement; 373 394 374 } 395 } // doBaseIndexInternal 375 396 //This is actually doing indexes for both mgpp and lucene 376 397 static private void doMGPPIndexes(Document to, Node searchNode) … … 490 511 491 512 // Contructing 'collectionmetadata' elements for 'mg' indexes 492 Element collectionmetadata = to.createElement(StaticStrings. COLLECTIONMETADATA_ELEMENT);513 Element collectionmetadata = to.createElement(StaticStrings.SEARCHMETADATA_ELEMENT); 493 514 collectionmetadata.setAttribute(StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR); 515 collectionmetadata.setAttribute("type", SearchMeta.TYPE_INDEX); 494 516 String temp = StaticStrings.DOCUMENT_STR.concat(StaticStrings.COLON_CHARACTER).concat(index_strs[i]); 495 517 collectionmetadata.setAttribute(StaticStrings.NAME_ATTRIBUTE, temp); … … 506 528 toElement.appendChild(mg_indexes); 507 529 508 } 530 } // doMGPPIndexes 509 531 510 532 static private void doSorts(Document to, Node searchNode) { 511 533 doBaseIndexInternal(to, searchNode, StaticStrings.SORTS_ELEMENT, StaticStrings.SORT_ELEMENT, StaticStrings.SORT_LOW_STR); 512 534 } 513 static private void doSortsOld(Document to, Node searchNode)514 {515 516 517 535 // static private void doSortsOld(Document to, Node searchNode) 536 // { 537 // Element toElement = to.getDocumentElement(); 538 // NodeList sort_children = ((Element) searchNode).getElementsByTagName(StaticStrings.SORT_LOW_STR); 539 // int num_nodes = sort_children.getLength(); 518 540 519 520 521 522 523 541 // // there are no sort fields 542 // if (num_nodes < 1) 543 // { 544 // return; 545 // } 524 546 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 547 // Element sorts = to.createElement(StaticStrings.SORTS_ELEMENT); 548 549 // for (int i = 0; i < num_nodes; i++) 550 // { 551 // Element sort_element = to.createElement(StaticStrings.SORT_ELEMENT); 552 // Element sort_child = (Element) sort_children.item(i); 553 // String name_str = sort_child.getAttribute(StaticStrings.NAME_ATTRIBUTE); 554 // sort_element.setAttribute(StaticStrings.NAME_STR, name_str); 555 // sorts.appendChild(sort_element); 556 557 // // Contructing 'collectionmetadata' elements from the 'displayItem' of this 'sort' element 558 // ArrayList displayItem_list = XMLTools.getNamedElementList(sort_child, StaticStrings.DISPLAYITEM_STR, StaticStrings.NAME_ATTRIBUTE, StaticStrings.NAME_STR); 559 // if (displayItem_list == null) 560 // { 561 // // there is no display item for this element 562 // continue; 563 // } 564 // for (int j = 0; j < displayItem_list.size(); j++) 565 // { 566 // Element item = (Element) displayItem_list.get(j); 567 // String text = XMLTools.getNodeText(item); 568 // //If there is nothing to display, don't bother creating the element 569 // // Either lang or key should be set. If key set, no textnode. 570 // // if lang set, should have textnode. Check if it's meaningful 571 // if (item.hasAttribute(StaticStrings.LANG_STR) && text.equals("")) 572 // { 573 // continue; 574 // } 553 575 554 555 556 557 558 576 // // get the value in 'lang=langcode' or 'key=keyname' 577 // // We can have either a key attribute (with optional dictionary attribute, else dictionary is implicit) 578 // // OR we can have a lang attr, with the nodetext containing the actual display strin.g 579 // String lang = item.getAttribute(StaticStrings.LANG_ATTRIBUTE); 580 // String key = item.getAttribute(StaticStrings.KEY_ATTRIBUTE); 559 581 560 582 561 Element collectionmetadata = to.createElement(StaticStrings.COLLECTIONMETADATA_ELEMENT); 562 collectionmetadata.setAttribute(StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR); 563 collectionmetadata.setAttribute(StaticStrings.NAME_ATTRIBUTE, name_str); 583 // Element collectionmetadata = to.createElement(StaticStrings.COLLECTIONMETADATA_ELEMENT); 584 // collectionmetadata.setAttribute(StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR); 585 // collectionmetadata.setAttribute(StaticStrings.NAME_ATTRIBUTE, name_str); 586 // collectionmetadata.setAttribute("type", "sort"); 587 // if(!lang.equals("")) { 588 // collectionmetadata.setAttribute(StaticStrings.LANGUAGE_ATTRIBUTE, lang); 589 // XMLTools.setNodeText(collectionmetadata, text); 590 // } 591 // if(!key.equals("")) { 592 // collectionmetadata.setAttribute(StaticStrings.KEY_ATTRIBUTE, key); 593 // String dictionary = item.getAttribute(StaticStrings.DICTIONARY_ATTRIBUTE); 594 // if(!dictionary.equals("")) { 595 // collectionmetadata.setAttribute(StaticStrings.DICTIONARY_ATTRIBUTE, dictionary); 596 // } 597 // } 564 598 565 if(!lang.equals("")) { 566 collectionmetadata.setAttribute(StaticStrings.LANGUAGE_ATTRIBUTE, lang); 567 XMLTools.setNodeText(collectionmetadata, text); 568 } 569 if(!key.equals("")) { 570 collectionmetadata.setAttribute(StaticStrings.KEY_ATTRIBUTE, key); 571 String dictionary = item.getAttribute(StaticStrings.DICTIONARY_ATTRIBUTE); 572 if(!dictionary.equals("")) { 573 collectionmetadata.setAttribute(StaticStrings.DICTIONARY_ATTRIBUTE, dictionary); 574 } 575 } 576 577 appendProperly(toElement, collectionmetadata); 578 } 579 } 580 toElement.appendChild(sorts); 581 } 599 // appendProperly(toElement, collectionmetadata); 600 // } 601 // } 602 // toElement.appendChild(sorts); 603 // } 582 604 583 605 // TODO … … 602 624 603 625 604 static private void doFacetsOld(Document to, Node searchNode)605 {606 607 608 626 // static private void doFacetsOld(Document to, Node searchNode) 627 // { 628 // Element toElement = to.getDocumentElement(); 629 // NodeList facet_children = ((Element) searchNode).getElementsByTagName(StaticStrings.FACET_LOW_STR); 630 // int num_nodes = facet_children.getLength(); 609 631 610 611 612 613 614 632 // // there are no facet fields 633 // if (num_nodes < 1) 634 // { 635 // return; 636 // } 615 637 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 638 // Element facets = to.createElement(StaticStrings.FACETS_ELEMENT); 639 640 // for (int i = 0; i < num_nodes; i++) 641 // { 642 // Element facet_element = to.createElement(StaticStrings.FACET_ELEMENT); 643 // Element facet_child = (Element) facet_children.item(i); 644 // String name_str = facet_child.getAttribute(StaticStrings.NAME_ATTRIBUTE); 645 // facet_element.setAttribute(StaticStrings.NAME_STR, name_str); 646 // facets.appendChild(facet_element); 647 648 // // Contructing 'collectionmetadata' elements from the 'displayItem' of this 'facet' element 649 // ArrayList displayItem_list = XMLTools.getNamedElementList(facet_child, StaticStrings.DISPLAYITEM_STR, StaticStrings.NAME_ATTRIBUTE, StaticStrings.NAME_STR); 650 // if (displayItem_list == null) 651 // { 652 // // there is no display item for this element 653 // continue; 654 // } 655 // for (int j = 0; j < displayItem_list.size(); j++) 656 // { 657 // Element item = (Element) displayItem_list.get(j); 658 // String text = XMLTools.getNodeText(item); 659 // //If there is nothing to display, don't bother creating the element 660 // // Either lang or key should be set. If key set, no textnode. 661 // // if lang set, should have textnode. Check if it's meaningful 662 // if (item.hasAttribute(StaticStrings.LANG_STR) && text.equals("")) 663 // { 664 // continue; 665 // } 644 666 645 646 647 648 649 667 // // get the value in 'lang=langcode' or 'key=keyname' 668 // // We can have either a key attribute (with optional dictionary attribute, else dictionary is implicit) 669 // // OR we can have a lang attr, with the nodetext containing the actual display strin.g 670 // String lang = item.getAttribute(StaticStrings.LANG_ATTRIBUTE); 671 // String key = item.getAttribute(StaticStrings.KEY_ATTRIBUTE); 650 672 651 673 652 653 654 674 // Element collectionmetadata = to.createElement(StaticStrings.COLLECTIONMETADATA_ELEMENT); 675 // collectionmetadata.setAttribute(StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR); 676 // collectionmetadata.setAttribute(StaticStrings.NAME_ATTRIBUTE, name_str); 655 677 656 657 658 659 660 661 662 663 664 665 666 678 // if(!lang.equals("")) { 679 // collectionmetadata.setAttribute(StaticStrings.LANGUAGE_ATTRIBUTE, lang); 680 // XMLTools.setNodeText(collectionmetadata, text); 681 // } 682 // if(!key.equals("")) { 683 // collectionmetadata.setAttribute(StaticStrings.KEY_ATTRIBUTE, key); 684 // String dictionary = item.getAttribute(StaticStrings.DICTIONARY_ATTRIBUTE); 685 // if(!dictionary.equals("")) { 686 // collectionmetadata.setAttribute(StaticStrings.DICTIONARY_ATTRIBUTE, dictionary); 687 // } 688 // } 667 689 668 appendProperly(toElement, collectionmetadata); 669 } 670 } 671 toElement.appendChild(facets); 672 } 673 674 675 //This processes <sort> (lucene), or <sort> and <facet> (solr) subelements of <search> also <defaultSort> 676 // Note that GLI at present does not allow the user to set or modify these. 677 // This function, and its inverse convertSolrFacetsAndSorts, are only here to preserve such elements if they already exist in the collectionConfig.xml. At present they need to be manually added there. 678 // it just copies them into storage. 679 static private void doSolrFacetsAndSortsdeletE(Document to, Node searchNode) 680 { 681 Element toElement = to.getDocumentElement(); 682 Element solr_element = to.createElement(StaticStrings.SOLR_ELEMENT);//<Solr> 683 solr_element.setAttribute(StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR); 684 solr_element.setAttribute(StaticStrings.MGPP_ATTRIBUTE, StaticStrings.TRUE_STR); 685 686 687 NodeList sort_children = ((Element) searchNode).getElementsByTagName(StaticStrings.SORT_LOW_STR);//<sort> 688 689 int num_nodes = sort_children.getLength(); 690 691 for (int i = 0; i < num_nodes; i++) { 692 solr_element.appendChild(to.importNode((Element) sort_children.item(i), true)); 693 } 694 Element sort_def = (Element)XMLTools.getChildByTagName(searchNode, StaticStrings.SORT_DEFAULT_ELEMENT); 695 if (sort_def != null) { 696 solr_element.appendChild(to.importNode(sort_def, true)); 697 } 698 699 NodeList facet_children = ((Element) searchNode).getElementsByTagName(StaticStrings.FACET_LOW_STR);//facet 700 num_nodes = facet_children.getLength(); 701 702 for (int i = 0; i < num_nodes; i++) 703 { 704 solr_element.appendChild(to.importNode((Element) facet_children.item(i), true)); 705 } 706 707 // finished processing sort and facet elements 708 toElement.appendChild(solr_element); 709 710 711 } 690 // appendProperly(toElement, collectionmetadata); 691 // } 692 // } 693 // toElement.appendChild(facets); 694 // } 695 696 712 697 713 698 static private void doGlobalFormat(Document to, Element from) … … 784 769 } 785 770 appendProperly(toElement, default_index_element); 786 } 771 } //doDefaultIndex 787 772 788 773 // For mg, this method is still called, but make it 'assigned=false' … … 1110 1095 toElement.appendChild(subcollection_element); 1111 1096 } 1112 } 1097 } // doSubCollection 1113 1098 1114 1099 //Handle levels (document, section). In the internal structure, the element is called 'IndexOption' … … 1135 1120 } 1136 1121 1137 Element index_option = to.createElement(StaticStrings.INDEXOPTIONS_ELEMENT);1138 index_option .setAttribute(StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR);1139 index_option .setAttribute(StaticStrings.NAME_STR, StaticStrings.LEVELS_STR);1122 Element index_options = to.createElement(StaticStrings.INDEXOPTIONS_ELEMENT); 1123 index_options.setAttribute(StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR); 1124 index_options.setAttribute(StaticStrings.NAME_STR, StaticStrings.LEVELS_STR); 1140 1125 1141 1126 for (int i = 0; i < level_nodes; i++) … … 1145 1130 Element option_element = to.createElement(StaticStrings.OPTION_ELEMENT); 1146 1131 option_element.setAttribute(StaticStrings.NAME_STR, level_str); 1147 index_option .appendChild(option_element);1132 index_options.appendChild(option_element); 1148 1133 1149 1134 // Contructing 'collectionmetadata' elements from the 'displayItem' of this 'level' element 1150 ArrayList displayItem_list = XMLTools.getNamedElementList(level_element, StaticStrings.DISPLAYITEM_STR, StaticStrings.NAME_ATTRIBUTE, StaticStrings.NAME_STR); 1151 if (displayItem_list == null) 1152 { 1153 return; 1154 } 1155 for (int j = 0; j < displayItem_list.size(); j++) 1156 { 1157 Element item = (Element) displayItem_list.get(j); 1158 String text = XMLTools.getNodeText(item); 1159 1160 //If there is nothing to display, don't bother creating the element 1161 // Either lang or key should be set. If lang set, then should have textnode. 1162 if (item.hasAttribute(StaticStrings.LANG_STR) && text.equals("")) { 1163 continue; 1164 } 1135 ArrayList collectionmetadata_list = doDisplayItemList(to, level_element, StaticStrings.NAME_STR, level_str, SearchMeta.TYPE_LEVEL); 1136 appendArrayList(toElement, collectionmetadata_list); 1137 } 1138 appendProperly(toElement, index_options); 1139 } // doLevel 1140 1141 // ArrayList displayItem_list = XMLTools.getNamedElementList(level_element, StaticStrings.DISPLAYITEM_STR, StaticStrings.NAME_ATTRIBUTE, StaticStrings.NAME_STR); 1142 // if (displayItem_list == null) 1143 // { 1144 // return; 1145 // } 1146 // for (int j = 0; j < displayItem_list.size(); j++) 1147 // { 1148 // Element item = (Element) displayItem_list.get(j); 1149 // String text = XMLTools.getNodeText(item); 1150 1151 // //If there is nothing to display, don't bother creating the element 1152 // // Either lang or key should be set. If lang set, then should have textnode. 1153 // if (item.hasAttribute(StaticStrings.LANG_STR) && text.equals("")) { 1154 // continue; 1155 // } 1165 1156 1166 String lang = item.getAttribute(StaticStrings.LANG_ATTRIBUTE);1167 String key = item.getAttribute(StaticStrings.KEY_ATTRIBUTE);1157 // String lang = item.getAttribute(StaticStrings.LANG_ATTRIBUTE); 1158 // String key = item.getAttribute(StaticStrings.KEY_ATTRIBUTE); 1168 1159 1169 Element collectionmetadata = to.createElement(StaticStrings.COLLECTIONMETADATA_ELEMENT); 1170 collectionmetadata.setAttribute(StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR); 1171 collectionmetadata.setAttribute(StaticStrings.NAME_ATTRIBUTE, level_str); 1172 1173 if(!lang.equals("")) { 1174 collectionmetadata.setAttribute(StaticStrings.LANGUAGE_ATTRIBUTE, lang); 1175 XMLTools.setNodeText(collectionmetadata, text); 1176 } 1160 // Element collectionmetadata = to.createElement(StaticStrings.COLLECTIONMETADATA_ELEMENT); 1161 // collectionmetadata.setAttribute(StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR); 1162 // collectionmetadata.setAttribute(StaticStrings.NAME_ATTRIBUTE, level_str); 1163 // collectionmetadata.setAttribute("type", "level"); 1164 1165 // if(!lang.equals("")) { 1166 // collectionmetadata.setAttribute(StaticStrings.LANGUAGE_ATTRIBUTE, lang); 1167 // XMLTools.setNodeText(collectionmetadata, text); 1168 // } 1177 1169 1178 if(!key.equals("")) {1179 collectionmetadata.setAttribute(StaticStrings.KEY_ATTRIBUTE, key);1180 String dictionary = item.getAttribute(StaticStrings.DICTIONARY_ATTRIBUTE);1181 if(!dictionary.equals("")) {1182 collectionmetadata.setAttribute(StaticStrings.DICTIONARY_ATTRIBUTE, dictionary);1183 }1184 }1185 1186 appendProperly(toElement, collectionmetadata);1187 }1188 }1189 appendProperly(toElement, index_option);1190 1170 // if(!key.equals("")) { 1171 // collectionmetadata.setAttribute(StaticStrings.KEY_ATTRIBUTE, key); 1172 // String dictionary = item.getAttribute(StaticStrings.DICTIONARY_ATTRIBUTE); 1173 // if(!dictionary.equals("")) { 1174 // collectionmetadata.setAttribute(StaticStrings.DICTIONARY_ATTRIBUTE, dictionary); 1175 // } 1176 // } 1177 1178 // appendProperly(toElement, collectionmetadata); 1179 // } 1180 //} 1181 1182 //} 1191 1183 1192 1184 //Handle 'indexSubcollection' element of collectionConfig.xml, which is called 'SubcollectionIndexes' in the internal structure. These contain the subcollection indexes (i.e. the filter or filter combinations), and displayed words for the filter names. … … 1223 1215 1224 1216 // Contructing 'collectionmetadata' elements from the 'displayItem' of this 'indexSubcollection' element 1225 ArrayList displayItem_list = XMLTools.getNamedElementList(index_sub_child, StaticStrings.DISPLAYITEM_STR, StaticStrings.NAME_ATTRIBUTE, StaticStrings.NAME_STR); 1226 if (displayItem_list == null) 1227 { 1228 // there is no display item for this element 1229 continue; 1230 } 1231 for (int j = 0; j < displayItem_list.size(); j++) 1232 { 1233 Element item = (Element) displayItem_list.get(j); 1234 String text = XMLTools.getNodeText(item); 1217 ArrayList collectionmetadata_list = doDisplayItemList(to, index_sub_child, StaticStrings.NAME_STR, name_str, SearchMeta.TYPE_PARTITION); // todo should be name_str??? 1218 appendArrayList(toElement, collectionmetadata_list); 1219 } 1220 appendProperly(toElement, subcollection_indexes); 1221 } // doIndexSubCollection 1222 // ArrayList displayItem_list = XMLTools.getNamedElementList(index_sub_child, StaticStrings.DISPLAYITEM_STR, StaticStrings.NAME_ATTRIBUTE, StaticStrings.NAME_STR); 1223 // if (displayItem_list == null) 1224 // { 1225 // // there is no display item for this element 1226 // continue; 1227 // } 1228 // for (int j = 0; j < displayItem_list.size(); j++) 1229 // { 1230 // Element item = (Element) displayItem_list.get(j); 1231 // String text = XMLTools.getNodeText(item); 1235 1232 1236 1233 1237 //If there is nothing to display, don't bother creating the element 1238 // Either lang or key should be set. If key set, no textnode. 1239 // if lang set, should have textnode. Check if it's meaningful 1240 if (item.hasAttribute(StaticStrings.LANG_STR) && text.equals("")) 1241 { 1242 continue; 1243 } 1244 1245 String lang = item.getAttribute(StaticStrings.LANG_ATTRIBUTE); 1246 String key = item.getAttribute(StaticStrings.KEY_ATTRIBUTE); 1247 1248 Element collectionmetadata = to.createElement(StaticStrings.COLLECTIONMETADATA_ELEMENT); 1249 collectionmetadata.setAttribute(StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR); 1250 collectionmetadata.setAttribute(StaticStrings.NAME_ATTRIBUTE, name_str); 1251 if(!lang.equals("")) { 1252 collectionmetadata.setAttribute(StaticStrings.LANGUAGE_ATTRIBUTE, lang); 1253 XMLTools.setNodeText(collectionmetadata, text); 1254 } 1255 if(!key.equals("")) { 1256 collectionmetadata.setAttribute(StaticStrings.KEY_ATTRIBUTE, key); 1257 String dictionary = item.getAttribute(StaticStrings.DICTIONARY_ATTRIBUTE); 1258 if(!dictionary.equals("")) { 1259 collectionmetadata.setAttribute(StaticStrings.DICTIONARY_ATTRIBUTE, dictionary); 1260 } 1261 } 1234 // //If there is nothing to display, don't bother creating the element 1235 // // Either lang or key should be set. If key set, no textnode. 1236 // // if lang set, should have textnode. Check if it's meaningful 1237 // if (item.hasAttribute(StaticStrings.LANG_STR) && text.equals("")) 1238 // { 1239 // continue; 1240 // } 1241 1242 // String lang = item.getAttribute(StaticStrings.LANG_ATTRIBUTE); 1243 // String key = item.getAttribute(StaticStrings.KEY_ATTRIBUTE); 1244 1245 // Element collectionmetadata = to.createElement(StaticStrings.COLLECTIONMETADATA_ELEMENT); 1246 // collectionmetadata.setAttribute(StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR); 1247 // collectionmetadata.setAttribute(StaticStrings.NAME_ATTRIBUTE, name_str); 1248 // collectionmetadata.setAttribute("type", "subcollection"); 1249 // if(!lang.equals("")) { 1250 // collectionmetadata.setAttribute(StaticStrings.LANGUAGE_ATTRIBUTE, lang); 1251 // XMLTools.setNodeText(collectionmetadata, text); 1252 // } 1253 // if(!key.equals("")) { 1254 // collectionmetadata.setAttribute(StaticStrings.KEY_ATTRIBUTE, key); 1255 // String dictionary = item.getAttribute(StaticStrings.DICTIONARY_ATTRIBUTE); 1256 // if(!dictionary.equals("")) { 1257 // collectionmetadata.setAttribute(StaticStrings.DICTIONARY_ATTRIBUTE, dictionary); 1258 // } 1259 // } 1262 1260 1263 appendProperly(toElement, collectionmetadata); 1264 } 1265 } 1266 appendProperly(toElement, subcollection_indexes); 1267 } 1261 // appendProperly(toElement, collectionmetadata); 1262 // } 1263 //} 1264 1268 1265 1269 1266 //Handle 'indexLanguage' element of collectionConfig.xml, which is called 'Languages' in the internal structure. These contain the language indexes, and displayed words for those language index names. … … 1291 1288 1292 1289 // Contructing 'collectionmetadata' elements from the 'displayItem' of this 'indexLanguage' element 1293 ArrayList displayItem_list = XMLTools.getNamedElementList(index_sub_child, StaticStrings.DISPLAYITEM_STR, StaticStrings.NAME_ATTRIBUTE, StaticStrings.NAME_STR); 1294 if (displayItem_list == null) 1295 { 1296 // there is no display item for this element 1297 continue; 1298 } 1299 for (int j = 0; j < displayItem_list.size(); j++) 1300 { 1301 Element item = (Element) displayItem_list.get(j); 1302 String text = XMLTools.getNodeText(item); 1303 //If there is nothing to display, don't bother creating the element 1304 // Either lang or key should be set. If key set, no textnode. 1305 // if lang set, should have textnode. Check if it's meaningful 1306 if (item.hasAttribute(StaticStrings.LANG_STR) && text.equals("")) 1307 { 1308 continue; 1309 } 1310 1311 // get the value in 'lang=langcode' or 'key=keyname' 1312 // We can have either a key attribute (with optional dictionary attribute, else dictionary is implicit) 1313 // OR we can have a lang attr, with the nodetext containing the actual display strin.g 1314 String lang = item.getAttribute(StaticStrings.LANG_ATTRIBUTE); 1315 String key = item.getAttribute(StaticStrings.KEY_ATTRIBUTE); 1316 1317 1318 Element collectionmetadata = to.createElement(StaticStrings.COLLECTIONMETADATA_ELEMENT); 1319 collectionmetadata.setAttribute(StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR); 1320 collectionmetadata.setAttribute(StaticStrings.NAME_ATTRIBUTE, name_str); 1321 1322 if(!lang.equals("")) { 1323 collectionmetadata.setAttribute(StaticStrings.LANGUAGE_ATTRIBUTE, lang); 1324 XMLTools.setNodeText(collectionmetadata, text); 1325 } 1326 if(!key.equals("")) { 1327 collectionmetadata.setAttribute(StaticStrings.KEY_ATTRIBUTE, key); 1328 String dictionary = item.getAttribute(StaticStrings.DICTIONARY_ATTRIBUTE); 1329 if(!dictionary.equals("")) { 1330 collectionmetadata.setAttribute(StaticStrings.DICTIONARY_ATTRIBUTE, dictionary); 1331 } 1332 } 1333 1334 appendProperly(toElement, collectionmetadata); 1335 } 1336 } 1290 ArrayList collectionmetadata_list = doDisplayItemList(to, index_sub_child, StaticStrings.NAME_STR, name_str, SearchMeta.TYPE_LANGUAGE); // todo should be name_str??? 1291 appendArrayList(toElement, collectionmetadata_list); 1292 1293 } 1337 1294 toElement.appendChild(language_indexes); 1338 } 1295 } //doIndexLanguage 1296 1297 // ArrayList displayItem_list = XMLTools.getNamedElementList(index_sub_child, StaticStrings.DISPLAYITEM_STR, StaticStrings.NAME_ATTRIBUTE, StaticStrings.NAME_STR); 1298 // if (displayItem_list == null) 1299 // { 1300 // // there is no display item for this element 1301 // continue; 1302 // } 1303 // for (int j = 0; j < displayItem_list.size(); j++) 1304 // { 1305 // Element item = (Element) displayItem_list.get(j); 1306 // String text = XMLTools.getNodeText(item); 1307 // //If there is nothing to display, don't bother creating the element 1308 // // Either lang or key should be set. If key set, no textnode. 1309 // // if lang set, should have textnode. Check if it's meaningful 1310 // if (item.hasAttribute(StaticStrings.LANG_STR) && text.equals("")) 1311 // { 1312 // continue; 1313 // } 1314 1315 // // get the value in 'lang=langcode' or 'key=keyname' 1316 // // We can have either a key attribute (with optional dictionary attribute, else dictionary is implicit) 1317 // // OR we can have a lang attr, with the nodetext containing the actual display strin.g 1318 // String lang = item.getAttribute(StaticStrings.LANG_ATTRIBUTE); 1319 // String key = item.getAttribute(StaticStrings.KEY_ATTRIBUTE); 1320 1321 1322 // Element collectionmetadata = to.createElement(StaticStrings.COLLECTIONMETADATA_ELEMENT); 1323 // collectionmetadata.setAttribute(StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR); 1324 // collectionmetadata.setAttribute(StaticStrings.NAME_ATTRIBUTE, name_str); 1325 // collectionmetadata.setAttribute("type", "lang"); 1326 1327 // if(!lang.equals("")) { 1328 // collectionmetadata.setAttribute(StaticStrings.LANGUAGE_ATTRIBUTE, lang); 1329 // XMLTools.setNodeText(collectionmetadata, text); 1330 // } 1331 // if(!key.equals("")) { 1332 // collectionmetadata.setAttribute(StaticStrings.KEY_ATTRIBUTE, key); 1333 // String dictionary = item.getAttribute(StaticStrings.DICTIONARY_ATTRIBUTE); 1334 // if(!dictionary.equals("")) { 1335 // collectionmetadata.setAttribute(StaticStrings.DICTIONARY_ATTRIBUTE, dictionary); 1336 // } 1337 // } 1338 1339 // appendProperly(toElement, collectionmetadata); 1340 // } 1339 1341 1340 1342 // Handling search types … … 1649 1651 continue; 1650 1652 } 1653 // if we have a type, then we are index/sort/facet etc 1654 if (!e.getAttribute(StaticStrings.TYPE_ATTRIBUTE).equals("")) { 1655 continue; 1656 } 1657 1651 1658 String text = XMLTools.getNodeText(e); 1652 1659 String lang = e.getAttribute(StaticStrings.LANGUAGE_ATTRIBUTE); … … 1660 1667 name_value = name_mapping; 1661 1668 } 1662 1669 System.err.println("makign dispay elem, "+name_value+", "+ text); 1663 1670 Element displayItem = constructElement(StaticStrings.DISPLAYITEM_STR, name_value, StaticStrings.LANG_STR, lang, text, StaticStrings.KEY_ATTRIBUTE, key, StaticStrings.DICTIONARY_ATTRIBUTE, dictionary, to); 1664 1671 //Element displayItem = constructDisplayItem(e, to, name_value); … … 1881 1888 1882 1889 to.getDocumentElement().appendChild(browse_element); 1883 } 1890 } // convertClassifier 1884 1891 1885 1892 static private Element convertFormat(Document to, Element e) … … 2074 2081 to.getDocumentElement().appendChild(dbtype); 2075 2082 } 2076 2077 static private void convertDefaultIndex(Document from, Document to, Element search) 2083 // 2084 static private void convertBaseDefaultIndex(Document from, Document to, Element search, String internal_default_index_str, String output_default_index_str) 2085 { 2086 Element source = from.getDocumentElement(); 2087 2088 Element default_index_element = (Element) XMLTools.getChildByTagName(source, internal_default_index_str); 2089 if (default_index_element == null) 2090 { 2091 return; 2092 } 2093 2094 String indexer = search.getAttribute(StaticStrings.TYPE_ATTRIBUTE); 2095 String level_str = default_index_element.getAttribute(StaticStrings.LEVEL_ATTRIBUTE); 2096 // Debugging purposes 2097 if (level_str.equals("") && indexer.equals(StaticStrings.MG_STR)) 2098 { 2099 System.out.println("Bug: DefaultIndex should have its level attribute not empty."); 2100 } 2101 2102 NodeList content_elements = default_index_element.getElementsByTagName(StaticStrings.CONTENT_ELEMENT); 2103 int content_elements_length = content_elements.getLength(); 2104 2105 // Don't output anything if no indexes are set 2106 if (content_elements_length == 0) 2107 { 2108 return;// 2109 } 2110 2111 String index_str = ""; 2112 2113 if (indexer.equals(StaticStrings.MG_STR)) 2114 { 2115 //combine level with indexes 2116 index_str = level_str + StaticStrings.COLON_CHARACTER; 2117 } 2118 else 2119 { //for mgpp/lucene, just take index 2120 //do nothing 2121 } 2122 2123 for (int k = 0; k < content_elements_length; k++) 2124 { 2125 Element content_element = (Element) content_elements.item(k); 2126 if (content_element.getAttribute(StaticStrings.ASSIGNED_ATTRIBUTE).equals(StaticStrings.FALSE_STR)) 2127 { 2128 continue; 2129 } 2130 String name_str = content_element.getAttribute(StaticStrings.NAME_ATTRIBUTE); 2131 2132 if (name_str.startsWith(StaticStrings.EXTRACTED_NAMESPACE) && name_str.indexOf(StaticStrings.NS_SEP, StaticStrings.EXTRACTED_NAMESPACE.length()) == -1) 2133 { 2134 name_str = name_str.substring(StaticStrings.EXTRACTED_NAMESPACE.length()); 2135 } 2136 2137 index_str = index_str + name_str; 2138 2139 // Make it comma separated string 2140 if (k < content_elements_length - 1) 2141 { 2142 index_str = index_str + StaticStrings.COMMA_CHARACTER; 2143 } 2144 content_element = null; 2145 }//for loop ends 2146 2147 Element default_index = to.createElement(output_default_index_str); 2148 default_index.setAttribute(StaticStrings.NAME_ATTRIBUTE, index_str); 2149 search.appendChild(default_index); 2150 2151 } // convertBaseDefaultIndex 2152 2153 static private void convertDefaultIndexOld(Document from, Document to, Element search) 2078 2154 { 2079 2155 Element source = from.getDocumentElement(); … … 2256 2332 // Now constructing 'displayItem' element for this 'indexSubcollection' element 2257 2333 // from the collectionmetadata element 2258 ArrayList collectionmetadata_list = XMLTools.getNamedElementList(source, StaticStrings.COLLECTIONMETADATA_ELEMENT, StaticStrings.NAME_ATTRIBUTE, index_value); 2334 // *** here 2335 ArrayList collectionmetadata_list = getMatchingSearchMetaElements(source, index_value, SearchMeta.TYPE_PARTITION); 2336 //ArrayList collectionmetadata_list = XMLTools.getNamedElementList(source, StaticStrings.COLLECTIONMETADATA_ELEMENT, StaticStrings.NAME_ATTRIBUTE, index_value); 2259 2337 2260 2338 if (collectionmetadata_list != null) … … 2314 2392 // Now constructing 'displayItem' element for this 'indexLanguage' element 2315 2393 // from the collectionmetadata element 2316 ArrayList collectionmetadata_list = XMLTools.getNamedElementList(source, StaticStrings.COLLECTIONMETADATA_ELEMENT, StaticStrings.NAME_ATTRIBUTE, name_str); 2394 // *** here 2395 ArrayList collectionmetadata_list = getMatchingSearchMetaElements(source, name_str, SearchMeta.TYPE_LANGUAGE); 2396 //ArrayList collectionmetadata_list = XMLTools.getNamedElementList(source, StaticStrings.COLLECTIONMETADATA_ELEMENT, StaticStrings.NAME_ATTRIBUTE, name_str); 2317 2397 2318 2398 if (collectionmetadata_list != null) … … 2361 2441 } 2362 2442 2363 //convert indexes and their displayItems, which go in 'search' element in collectionConfig.xml 2364 //parameter 'to' is the document to be saved as collectionConfig.xml 2365 //parameter 'from' is the internal xml structure 2366 static private void convertIndex(Document from, Document to) 2367 { 2368 Element source = from.getDocumentElement(); 2369 //Get the 'search' element from 'to' which has already been created in 'convertBuildType' 2370 Element search = (Element) XMLTools.getChildByTagName(to.getDocumentElement(), StaticStrings.SEARCH_STR); 2371 String buildtype = search.getAttribute(StaticStrings.TYPE_ATTRIBUTE); 2372 if (buildtype.equals(StaticStrings.MG_STR)){ 2373 convertMGIndex(from, to); 2374 return; 2375 } 2376 2377 2378 //THere are two sets of indexes elements, find the one which is assigned 'true' 2379 Element indexes = XMLTools.getNamedElement(source, StaticStrings.INDEXES_ELEMENT, StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR); 2380 if (indexes == null) 2381 { 2382 return; 2383 } 2384 NodeList index_elements = indexes.getElementsByTagName(StaticStrings.INDEX_ELEMENT); 2385 int index_elements_length = index_elements.getLength(); 2386 2387 if (index_elements_length == 0) 2388 { // no indexes 2389 return; 2390 } 2391 2392 // do the levels 2393 convertLevels(from, to, search); 2394 2395 // indexes 2396 convertBaseIndex(from, to, search, StaticStrings.INDEXES_ELEMENT, StaticStrings.INDEX_ELEMENT, StaticStrings.INDEX_LOW_STR); 2397 //Convert default index 2398 convertDefaultIndex(from, to, search); 2399 2400 // sortfields 2401 if (buildtype.equals(StaticStrings.LUCENE_STR) || buildtype.equals(StaticStrings.SOLR_STR)) { 2402 convertBaseIndex(from, to, search, StaticStrings.SORTS_ELEMENT, StaticStrings.SORT_ELEMENT, StaticStrings.SORT_LOW_STR); 2403 } 2404 // facet fields 2405 if (buildtype.equals(StaticStrings.SOLR_STR)) { 2406 convertBaseIndex(from, to, search, StaticStrings.FACETS_ELEMENT, StaticStrings.FACET_ELEMENT, StaticStrings.FACET_LOW_STR); 2407 } 2408 convertIndexOptions(from, to, search); 2409 2410 } 2411 2412 private static void convertBaseIndex(Document from, Document to, Element search, String internal_indexes_str, String internal_index_str, String output_index_str) { 2413 2414 Element source = from.getDocumentElement(); 2415 Element indexes = XMLTools.getNamedElement(source, internal_indexes_str, StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR); 2416 if (indexes == null) 2417 { 2418 return; 2419 } 2420 NodeList index_elements = indexes.getElementsByTagName(internal_index_str); 2421 int index_elements_length = index_elements.getLength(); 2422 2423 if (index_elements_length == 0) 2424 { // no indexes 2425 return; 2426 } 2427 for (int j = 0; j < index_elements_length; j++) 2428 { 2429 Element index_element = (Element) index_elements.item(j); 2430 if (index_element.getAttribute(StaticStrings.ASSIGNED_ATTRIBUTE).equals(StaticStrings.FALSE_STR)) 2431 { 2432 continue; 2433 } 2434 2435 Element index_ele = to.createElement(output_index_str);//index 2436 2437 // Used for creating displayItem for this element 'index_ele' further below 2438 // full_index_names contain 'ex.' 2439 String full_index_name = ""; 2440 String level_str = ""; 2441 2442 StringBuffer index_value = new StringBuffer(); 2443 2444 NodeList content_elements = index_element.getElementsByTagName(StaticStrings.CONTENT_ELEMENT); 2445 int content_elements_length = content_elements.getLength(); 2446 2447 for (int k = 0; k < content_elements_length; k++) 2448 { 2449 Element content_element = (Element) content_elements.item(k); 2450 if (content_element.getAttribute(StaticStrings.ASSIGNED_ATTRIBUTE).equals(StaticStrings.FALSE_STR)) 2451 { 2452 continue; 2453 } 2454 String name_str = content_element.getAttribute(StaticStrings.NAME_ATTRIBUTE); 2455 2456 full_index_name = full_index_name + name_str; 2457 if (k < content_elements_length - 1) 2458 { 2459 full_index_name = full_index_name + StaticStrings.COMMA_CHARACTER; 2460 } 2461 2462 if (name_str.startsWith(StaticStrings.EXTRACTED_NAMESPACE) && name_str.indexOf(StaticStrings.NS_SEP, StaticStrings.EXTRACTED_NAMESPACE.length()) == -1) 2463 { 2464 name_str = name_str.substring(StaticStrings.EXTRACTED_NAMESPACE.length()); 2465 } 2466 2467 index_value.append(name_str); 2468 name_str = null; 2469 // Make it comma separated string 2470 if (k < content_elements_length - 1) 2471 { 2472 index_value.append(StaticStrings.COMMA_CHARACTER); 2473 } 2474 content_element = null; 2475 }//for loop ends 2476 2477 String temp_str = index_value.toString(); 2478 index_ele.setAttribute(StaticStrings.NAME_ATTRIBUTE, temp_str); 2479 2480 // Now constructing 'displayItem' element for this 'index_ele' element 2481 // The index names in the collectionmetadata elements in the internal structure are not the names that 2482 // are used in the content elements (i.e. ex.Source or dc.Subject and keywords), but the names that are 2483 // in the configuration files (i.e. Source or dc.Subject) 2484 ArrayList collectionmetadata_list = XMLTools.getNamedElementList(source, StaticStrings.COLLECTIONMETADATA_ELEMENT, StaticStrings.NAME_ATTRIBUTE, temp_str); 2485 2486 if (collectionmetadata_list == null) 2487 { 2488 //try the full name, i.e. with 'ex.' 2489 collectionmetadata_list = XMLTools.getNamedElementList(source, StaticStrings.COLLECTIONMETADATA_ELEMENT, StaticStrings.NAME_ATTRIBUTE, full_index_name); 2490 } 2491 2492 if (collectionmetadata_list != null) 2493 { 2494 2495 for (int k = 0; k < collectionmetadata_list.size(); k++) 2496 { 2497 Element collectionmetadata = (Element) collectionmetadata_list.get(k); 2498 if (collectionmetadata.getAttribute(StaticStrings.ASSIGNED_ATTRIBUTE).equals(StaticStrings.FALSE_STR)) 2499 { 2500 continue; 2501 } 2502 Element displayItem = constructDisplayItem(collectionmetadata, to); 2503 2504 index_ele.appendChild(displayItem); 2505 } 2506 } 2507 2508 // deal with any <option name='' value=''> children of this index 2509 // e.g. <option name='solrfieldtype' value='text_es'> 2510 NodeList option_children = index_element.getElementsByTagName(StaticStrings.OPTION_ELEMENT); 2511 for (int k = 0; k < option_children.getLength(); k++) 2512 { 2513 Element el = (Element) option_children.item(k); 2514 if (el.getAttribute(StaticStrings.ASSIGNED_ATTRIBUTE).equals(StaticStrings.FALSE_STR)) 2515 { 2516 continue; 2517 } 2518 String name_str = el.getAttribute(StaticStrings.NAME_ATTRIBUTE); 2519 String value_str = XMLTools.getNodeText(el); 2520 2521 if (name_str == null && value_str == null) 2522 { 2523 continue; 2524 } 2525 Element option_element = to.createElement(StaticStrings.OPTION_STR); 2526 if (!name_str.equals("")) { 2527 option_element.setAttribute(StaticStrings.NAME_ATTRIBUTE, name_str); 2528 } 2529 if (!value_str.equals("")) { // or no value attribute without name attribute? 2530 option_element.setAttribute(StaticStrings.VALUE_ATTRIBUTE, value_str); 2531 } 2532 index_ele.appendChild(option_element); 2533 } 2534 2535 search.appendChild(index_ele); 2536 2537 } //for loop ends 2538 2539 2540 } 2443 //convert indexes and their displayItems, which go in 'search' element in collectionConfig.xml 2444 //parameter 'to' is the document to be saved as collectionConfig.xml 2445 //parameter 'from' is the internal xml structure 2446 static private void convertIndex(Document from, Document to) 2447 { 2448 Element source = from.getDocumentElement(); 2449 //Get the 'search' element from 'to' which has already been created in 'convertBuildType' 2450 Element search = (Element) XMLTools.getChildByTagName(to.getDocumentElement(), StaticStrings.SEARCH_STR); 2451 String buildtype = search.getAttribute(StaticStrings.TYPE_ATTRIBUTE); 2452 if (buildtype.equals(StaticStrings.MG_STR)){ 2453 convertMGIndex(from, to); 2454 return; 2455 } 2456 2457 2458 //THere are two sets of indexes elements, find the one which is assigned 'true' 2459 Element indexes = XMLTools.getNamedElement(source, StaticStrings.INDEXES_ELEMENT, StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR); 2460 if (indexes == null) 2461 { 2462 return; 2463 } 2464 NodeList index_elements = indexes.getElementsByTagName(StaticStrings.INDEX_ELEMENT); 2465 int index_elements_length = index_elements.getLength(); 2466 2467 if (index_elements_length == 0) 2468 { // no indexes 2469 return; 2470 } 2471 2472 // do the levels 2473 convertLevels(from, to, search); 2474 2475 // indexes 2476 convertBaseIndex(from, to, search, StaticStrings.INDEXES_ELEMENT, StaticStrings.INDEX_ELEMENT, StaticStrings.INDEX_LOW_STR); 2477 //Convert default index 2478 convertBaseDefaultIndex(from, to, search, StaticStrings.INDEX_DEFAULT_ELEMENT, StaticStrings.INDEX_DEFAULT_ELEMENT_LOWERCASE); 2479 2480 // sortfields 2481 if (buildtype.equals(StaticStrings.LUCENE_STR) || buildtype.equals(StaticStrings.SOLR_STR)) { 2482 convertBaseIndex(from, to, search, StaticStrings.SORTS_ELEMENT, StaticStrings.SORT_ELEMENT, StaticStrings.SORT_LOW_STR); 2483 convertBaseDefaultIndex(from, to, search, StaticStrings.SORT_DEFAULT_ELEMENT, StaticStrings.SORT_DEFAULT_ELEMENT); 2484 } 2485 // facet fields 2486 if (buildtype.equals(StaticStrings.SOLR_STR)) { 2487 convertBaseIndex(from, to, search, StaticStrings.FACETS_ELEMENT, StaticStrings.FACET_ELEMENT, StaticStrings.FACET_LOW_STR); 2488 } 2489 convertIndexOptions(from, to, search); 2490 2491 } // convertIndex 2492 2493 2494 // this code is used for indexes, sortfields, facets 2495 // internal_indexes_str = Indexes/Sorts/Facets - internal doc 2496 // internal_index_str = Index/Sort/Facet - internal doc 2497 // output_index_str = index/sortfield/facet - what goes in collectionConfig 2498 private static void convertBaseIndex(Document from, Document to, Element search, String internal_indexes_str, String internal_index_str, String output_index_str) 2499 { 2500 2501 Element source = from.getDocumentElement(); 2502 Element indexes = XMLTools.getNamedElement(source, internal_indexes_str, StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR); 2503 if (indexes == null) 2504 { 2505 return; 2506 } 2507 2508 2509 NodeList index_elements = indexes.getElementsByTagName(internal_index_str); 2510 int index_elements_length = index_elements.getLength(); 2511 2512 if (index_elements_length == 0) 2513 { // no indexes 2514 return; 2515 } 2516 for (int j = 0; j < index_elements_length; j++) 2517 { 2518 Element index_element = (Element) index_elements.item(j); 2519 if (index_element.getAttribute(StaticStrings.ASSIGNED_ATTRIBUTE).equals(StaticStrings.FALSE_STR)) 2520 { 2521 continue; 2522 } 2523 2524 Element index_ele = to.createElement(output_index_str);//index 2525 2526 // Used for creating displayItem for this element 'index_ele' further below 2527 // full_index_names contain 'ex.' 2528 String full_index_name = ""; 2529 String level_str = ""; 2530 2531 StringBuffer index_value = new StringBuffer(); 2532 2533 NodeList content_elements = index_element.getElementsByTagName(StaticStrings.CONTENT_ELEMENT); 2534 int content_elements_length = content_elements.getLength(); 2535 2536 for (int k = 0; k < content_elements_length; k++) 2537 { 2538 Element content_element = (Element) content_elements.item(k); 2539 if (content_element.getAttribute(StaticStrings.ASSIGNED_ATTRIBUTE).equals(StaticStrings.FALSE_STR)) 2540 { 2541 continue; 2542 } 2543 String name_str = content_element.getAttribute(StaticStrings.NAME_ATTRIBUTE); 2544 2545 full_index_name = full_index_name + name_str; 2546 if (k < content_elements_length - 1) 2547 { 2548 full_index_name = full_index_name + StaticStrings.COMMA_CHARACTER; 2549 } 2550 2551 if (name_str.startsWith(StaticStrings.EXTRACTED_NAMESPACE) && name_str.indexOf(StaticStrings.NS_SEP, StaticStrings.EXTRACTED_NAMESPACE.length()) == -1) 2552 { 2553 name_str = name_str.substring(StaticStrings.EXTRACTED_NAMESPACE.length()); 2554 } 2555 2556 index_value.append(name_str); 2557 name_str = null; 2558 // Make it comma separated string 2559 if (k < content_elements_length - 1) 2560 { 2561 index_value.append(StaticStrings.COMMA_CHARACTER); 2562 } 2563 content_element = null; 2564 } //k for loop ends 2565 2566 // ok to here 2567 String temp_str = index_value.toString(); 2568 index_ele.setAttribute(StaticStrings.NAME_ATTRIBUTE, temp_str); 2569 2570 // Now constructing 'displayItem' element for this 'index_ele' element 2571 // The index names in the collectionmetadata elements in the internal structure are not the names that 2572 // are used in the content elements (i.e. ex.Source or dc.Subject and keywords), but the names that are 2573 // in the configuration files (i.e. Source or dc.Subject) 2574 // *** here 2575 ArrayList collectionmetadata_list = getMatchingSearchMetaElements(source, temp_str, output_index_str); // TODO??? searchmeta type?? 2576 //ArrayList collectionmetadata_list = XMLTools.getNamedElementList(source, StaticStrings.COLLECTIONMETADATA_ELEMENT, new String[]{StaticStrings.NAME_ATTRIBUTE, StaticStrings.TYPE_ATTRIBUTE}, new String[]{ temp_str, output_index_str}); 2577 2578 2579 if (collectionmetadata_list == null) 2580 { 2581 //try the full name, i.e. with 'ex.' 2582 collectionmetadata_list = getMatchingSearchMetaElements(source, full_index_name, output_index_str); 2583 //collectionmetadata_list = XMLTools.getNamedElementList(source, StaticStrings.COLLECTIONMETADATA_ELEMENT, new String[]{StaticStrings.NAME_ATTRIBUTE, StaticStrings.TYPE_ATTRIBUTE}, new String[]{ full_index_name, output_index_str}); 2584 } 2585 2586 if (collectionmetadata_list != null) 2587 { 2588 2589 for (int k = 0; k < collectionmetadata_list.size(); k++) 2590 { 2591 Element collectionmetadata = (Element) collectionmetadata_list.get(k); 2592 if (collectionmetadata.getAttribute(StaticStrings.ASSIGNED_ATTRIBUTE).equals(StaticStrings.FALSE_STR)) 2593 { 2594 continue; 2595 } 2596 Element displayItem = constructDisplayItem(collectionmetadata, to); 2597 2598 index_ele.appendChild(displayItem); 2599 } 2600 } 2601 // goes wrong here 2602 2603 2604 2605 // deal with any <option name='' value=''> children of this index 2606 // e.g. <option name='solrfieldtype' value='text_es'> 2607 NodeList option_children = index_element.getElementsByTagName(StaticStrings.OPTION_ELEMENT); 2608 for (int k = 0; k < option_children.getLength(); k++) 2609 { 2610 Element el = (Element) option_children.item(k); 2611 if (el.getAttribute(StaticStrings.ASSIGNED_ATTRIBUTE).equals(StaticStrings.FALSE_STR)) 2612 { 2613 continue; 2614 } 2615 String name_str = el.getAttribute(StaticStrings.NAME_ATTRIBUTE); 2616 String value_str = XMLTools.getNodeText(el); 2617 2618 if (name_str == null && value_str == null) 2619 { 2620 continue; 2621 } 2622 Element option_element = to.createElement(StaticStrings.OPTION_STR); 2623 if (!name_str.equals("")) { 2624 option_element.setAttribute(StaticStrings.NAME_ATTRIBUTE, name_str); 2625 } 2626 if (!value_str.equals("")) { // or no value attribute without name attribute? 2627 option_element.setAttribute(StaticStrings.VALUE_ATTRIBUTE, value_str); 2628 } 2629 index_ele.appendChild(option_element); 2630 } 2631 2632 search.appendChild(index_ele); 2633 2634 } //for loop ends 2635 2636 2637 2638 } // convertBaseIndex 2639 2541 2640 static private void convertMGIndex(Document from, Document to) 2542 2641 { … … 2639 2738 // The index names in the collectionmetadata elements in the internal structure are not the names that 2640 2739 // are used in the content elements (i.e. ex.Source or dc.Subject and keywords), but the names that are 2641 // in the configuration files (i.e. Source or dc.Subject) 2642 ArrayList collectionmetadata_list = XMLTools.getNamedElementList(source, StaticStrings.COLLECTIONMETADATA_ELEMENT, StaticStrings.NAME_ATTRIBUTE, temp_str); 2740 // in the configuration files (i.e. Source or dc.Subject)// *** here 2741 ArrayList collectionmetadata_list = getMatchingSearchMetaElements(source, temp_str, SearchMeta.TYPE_INDEX); 2742 //ArrayList collectionmetadata_list = XMLTools.getNamedElementList(source, StaticStrings.COLLECTIONMETADATA_ELEMENT, StaticStrings.NAME_ATTRIBUTE, temp_str); 2643 2743 2644 2744 if (collectionmetadata_list == null) … … 2646 2746 //try the full name, i.e. with 'ex.', first appending level info as we are mg 2647 2747 full_index_name = level_str + StaticStrings.COLON_CHARACTER + full_index_name; 2648 2649 collectionmetadata_list = XMLTools.getNamedElementList(source, StaticStrings.COLLECTIONMETADATA_ELEMENT, StaticStrings.NAME_ATTRIBUTE, full_index_name); 2748 // ** here 2749 collectionmetadata_list = getMatchingSearchMetaElements(source, full_index_name, SearchMeta.TYPE_INDEX); 2750 //collectionmetadata_list = XMLTools.getNamedElementList(source, StaticStrings.COLLECTIONMETADATA_ELEMENT, StaticStrings.NAME_ATTRIBUTE, full_index_name); 2650 2751 } 2651 2752 … … 2699 2800 2700 2801 //Convert default index 2701 convert DefaultIndex(from, to, search);2802 convertBaseDefaultIndex(from, to, search, StaticStrings.INDEX_DEFAULT_ELEMENT, StaticStrings.INDEX_DEFAULT_ELEMENT_LOWERCASE); 2702 2803 convertIndexOptions(from, to, search); 2703 } 2804 } // convertMGIndex 2704 2805 2705 2806 … … 2741 2842 // from the collectionmetadata element 2742 2843 // TODO this needs work to differentiate it from index 2743 ArrayList collectionmetadata_list = XMLTools.getNamedElementList(source, StaticStrings.COLLECTIONMETADATA_ELEMENT, StaticStrings.NAME_ATTRIBUTE, name_str); 2844 // *** here 2845 ArrayList collectionmetadata_list = getMatchingSearchMetaElements(source, name_str, SearchMeta.TYPE_SORT); 2846 //ArrayList collectionmetadata_list = XMLTools.getNamedElementList(source, StaticStrings.COLLECTIONMETADATA_ELEMENT, StaticStrings.NAME_ATTRIBUTE, name_str); 2744 2847 2745 2848 if (collectionmetadata_list != null) … … 2772 2875 search.appendChild(new_default_sort); 2773 2876 } 2774 } 2877 } //convertSort 2775 2878 2776 2879 static private void convertFacet(Document from, Document to) … … 2811 2914 // from the collectionmetadata element 2812 2915 // TODO this needs work to differentiate it from index 2916 // ** here 2813 2917 ArrayList collectionmetadata_list = XMLTools.getNamedElementList(source, StaticStrings.COLLECTIONMETADATA_ELEMENT, StaticStrings.NAME_ATTRIBUTE, name_str); 2814 2918 … … 2832 2936 } //for loop ends 2833 2937 2834 } 2938 } //convertFacet 2835 2939 //convert <facet> and <sort> and <defaultSort> elements 2836 2940 //which go in 'search' element in collectionConfig.xml 2837 2941 //parameter 'to' is the document to be saved as collectionConfig.xml 2838 2942 //parameter 'from' is the internal xml structure 2839 // for lucene and solr collections2840 // just a straight copy at present2841 // Note that GLI at present does not allow the user to set or modify the solr-specific elements2842 // <sort> and <facet>. This function, and its inverse doSolrFacetsAndSorts, is only here to preserve such2843 // elements if they already exist in the collectionConfig.xml. At present they need to be manually added there.2844 static private void convertSolrFacetsAndSortsDELETE(Document from, Document to)2845 {2846 Element source = from.getDocumentElement();2847 //Get the 'search' element from 'to' which has already been created in 'convertBuildType'2848 Element search = (Element) XMLTools.getChildByTagName(to.getDocumentElement(), StaticStrings.SEARCH_STR);2849 2850 //There are two sets of <Solr> elements, find the one which is assigned 'true' --- is this true???2851 Element solr = XMLTools.getNamedElement(source, StaticStrings.SOLR_ELEMENT, StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR);2852 if (solr == null)2853 {2854 return;2855 }2856 NodeList sort_elements = solr.getElementsByTagName(StaticStrings.SORT_LOW_STR);2857 int sort_elements_length = sort_elements.getLength();2858 2859 for (int j = 0; j < sort_elements_length; j++)2860 {2861 Element sort_ele = (Element) sort_elements.item(j);2862 search.appendChild(to.importNode(sort_ele, true));2863 }2864 Element sort_def = (Element)XMLTools.getChildByTagName(solr, StaticStrings.SORT_DEFAULT_ELEMENT);2865 if (sort_def != null) {2866 search.appendChild(to.importNode(sort_def, true));2867 }2868 NodeList facet_elements = solr.getElementsByTagName(StaticStrings.FACET_LOW_STR);2869 int facet_elements_length = facet_elements.getLength();2870 for (int j = 0; j < facet_elements_length; j++)2871 {2872 Element facet_ele = (Element) facet_elements.item(j);2873 search.appendChild(to.importNode(facet_ele, true));2874 }2875 2876 2877 }2878 2943 2879 2944 … … 2910 2975 2911 2976 //Now construct displayItem for this level element from collectionmetadata 2912 ArrayList collectionmetadata_list = XMLTools.getNamedElementList(source, StaticStrings.COLLECTIONMETADATA_ELEMENT, StaticStrings.NAME_ATTRIBUTE, name_str); 2977 // ** here 2978 ArrayList collectionmetadata_list = getMatchingSearchMetaElements(source, name_str, SearchMeta.TYPE_LEVEL); 2979 //ArrayList collectionmetadata_list = XMLTools.getNamedElementList(source, StaticStrings.SEARCHMETADATA_ELEMENT, StaticStrings.NAME_ATTRIBUTE, name_str); 2913 2980 2914 2981 if (collectionmetadata_list != null) … … 3252 3319 3253 3320 Node searchNode = XMLTools.getChildByTagNameIndexed(fromElement, StaticStrings.SEARCH_STR, 0); 3254 String buildtype_value = ((Element) searchNode).getAttribute(StaticStrings.TYPE_ATTRIBUTE);//might be mg|mgpp|lucene 3321 String buildtype_value = ((Element) searchNode).getAttribute(StaticStrings.TYPE_ATTRIBUTE);//might be mg|mgpp|lucene|solr 3255 3322 Element buildtype = doBuildType(dOc, buildtype_value); 3256 3323 appendProperly(toElement, buildtype); … … 3306 3373 appendArrayList(toElement, icon); 3307 3374 appendArrayList(toElement, name); 3375 3376 // add any other displayitems here?? 3377 // why do we do these separately? 3308 3378 } 3309 3379 … … 3357 3427 3358 3428 if (displayItemListNode != null) 3359 { 3429 { // this is to handle any extra elements from displayItemList (top level) of collectionConfig. but we filter out index etc ones. 3430 // However, I don't think we should have those there in the first place. 3360 3431 NodeList nl = ((Element) displayItemListNode).getElementsByTagName(StaticStrings.DISPLAYITEM_STR); 3361 3432 … … 3459 3530 static private Document convertInternalToCollectionConfig(Document dOc) 3460 3531 { 3461 ///ystem.err.println("internal documnet:"); 3462 ///ystem.err.println(XMLTools.xmlNodeToString(XMLTools.getChildByTagName(dOc.getDocumentElement(), "Facets"))); 3532 System.err.println("internal documnet:"); 3533 3534 System.err.println(XMLTools.xmlNodeListToString(dOc.getDocumentElement().getElementsByTagName("CollectionMetadata"))); 3535 System.err.println(XMLTools.xmlNodeListToString(dOc.getDocumentElement().getElementsByTagName("SearchMetadata"))); 3463 3536 ///ystem.err.println(XMLTools.xmlNodeToString(XMLTools.getChildByTagName(dOc.getDocumentElement(), "Sorts"))); 3464 3537 //first parse an empty skeleton of xml config file
Note:
See TracChangeset
for help on using the changeset viewer.