Changeset 36156
- Timestamp:
- 2022-05-09T10:00:26+12:00 (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/gli/src/org/greenstone/gatherer/cdm/CollectionConfigXMLReadWrite.java
r34245 r36156 279 279 } 280 280 281 static private void doBaseIndexInternal(Document to, Node searchNode, String new_indexes_str, String new_index_str, String existing_index_str) { 282 283 Element toElement = to.getDocumentElement(); 284 Element indexes_element = to.createElement(new_indexes_str);//<Indexes> // INDEXES_ELEMENT 285 indexes_element.setAttribute(StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR); 286 //indexes_element.setAttribute(StaticStrings.MGPP_ATTRIBUTE, StaticStrings.TRUE_STR); 287 288 NodeList index_children = ((Element) searchNode).getElementsByTagName(existing_index_str);//index INDEx_LOW_STR 289 int num_nodes = index_children.getLength(); 290 291 for (int i = 0; i < num_nodes; i++) 292 { 293 294 Element index_element = to.createElement(new_index_str);//<Index> INDEX_ELEMENT 295 Element e = (Element) index_children.item(i); 296 String index_str = e.getAttribute(StaticStrings.NAME_ATTRIBUTE); 297 String index_str_display = index_str;//for creating collectionmetadata for this index 298 299 // look for options inside the index, eg 300 // <option name="solrfieldtype" value="text_ja" /> 301 String options_str = ""; 302 NodeList option_children = e.getElementsByTagName(StaticStrings.OPTION_STR); 303 if(option_children != null) { 304 for (int j = 0; j < option_children.getLength(); j++) { 305 Element el = (Element) option_children.item(j); 306 307 String name_str = el.getAttribute(StaticStrings.NAME_ATTRIBUTE); 308 options_str = options_str + ((name_str.equals("")) ? "" : (" " + name_str)); 309 310 String value_str = el.getAttribute(StaticStrings.VALUE_ATTRIBUTE); 311 options_str = options_str + ((name_str.equals("")) ? "" : (" " + value_str)); 312 313 if (name_str.equals("") && !value_str.equals("")) 314 { 315 continue; //invalid condition 316 } 317 318 Element option_element = null; 319 option_element = to.createElement(StaticStrings.OPTION_ELEMENT); 320 option_element.setAttribute(StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR); 321 322 if (!name_str.equals("")) 323 { 324 option_element.setAttribute(StaticStrings.NAME_ATTRIBUTE, name_str); 325 } 326 if (value_str != null && !value_str.equals("")) 327 { 328 XMLTools.setNodeText(option_element, value_str); 329 } 330 index_element.appendChild(option_element); 331 } 332 } 333 334 // Handling 'index' element 335 // Double check to make sure it's not colon separated style index. 336 if (index_str.indexOf(StaticStrings.COLON_CHARACTER) != -1) 337 { 338 System.err.println("Something is wrong! the "+existing_index_str+" should NOT be level:source tuplets style."); 339 index_str = index_str.substring(index_str.indexOf(StaticStrings.COLON_CHARACTER) + 1); 340 341 } 342 //Each index may have a list of comma-separated strings. 343 //split them into 'content' elements in the internal structure 344 StringTokenizer content_tokenizer = new StringTokenizer(index_str, StaticStrings.COMMA_CHARACTER); 345 while (content_tokenizer.hasMoreTokens()) 346 { 347 // Replace index_str to be qualified name, eg. dc.Subject and keywords insread of dc.Subject. 348 349 Element content_element = to.createElement(StaticStrings.CONTENT_ELEMENT); 350 String content_str = content_tokenizer.nextToken(); 351 // Since the contents of indexes have to be certain keywords, or metadata elements, if the content isn't a keyword and doesn't yet have a namespace, append the extracted metadata namespace. 352 if (content_str.indexOf(StaticStrings.NS_SEP) == -1 && !(content_str.equals(StaticStrings.TEXT_STR) || content_str.equals(StaticStrings.ALLFIELDS_STR))) 353 { 354 content_str = StaticStrings.EXTRACTED_NAMESPACE + content_str; 355 } 356 content_element.setAttribute(StaticStrings.NAME_ATTRIBUTE, content_str); 357 index_element.appendChild(content_element); 358 content_element = null; 359 } //while ends 360 361 indexes_element.appendChild(index_element); 362 363 index_element = null; 364 365 // Handling 'displayItem' element of this 'index' element 366 // 'e' is the parent element 'index' of 'displayItem' element 367 ArrayList collectionmetadata_list = doDisplayItemList(to, e, StaticStrings.NAME_ATTRIBUTE, index_str_display); 368 appendArrayList(toElement, collectionmetadata_list); 369 370 } // for loop ends 371 toElement.appendChild(indexes_element); 372 //return toElement; 373 374 } 281 375 //This is actually doing indexes for both mgpp and lucene 282 376 static private void doMGPPIndexes(Document to, Node searchNode) 283 377 { 284 Element toElement = to.getDocumentElement(); 285 Element indexes_element = to.createElement(StaticStrings.INDEXES_ELEMENT);//<Indexes> 286 indexes_element.setAttribute(StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR); 287 indexes_element.setAttribute(StaticStrings.MGPP_ATTRIBUTE, StaticStrings.TRUE_STR); 288 289 NodeList index_children = ((Element) searchNode).getElementsByTagName(StaticStrings.INDEX_LOW_STR);//index 290 int num_nodes = index_children.getLength(); 291 292 for (int i = 0; i < num_nodes; i++) 293 { 294 295 Element index_element = to.createElement(StaticStrings.INDEX_ELEMENT);//<Index> 296 Element e = (Element) index_children.item(i); 297 String index_str = e.getAttribute(StaticStrings.NAME_ATTRIBUTE); 298 String index_str_display = index_str;//for creating collectionmetadata for this index 299 300 301 String options_str = ""; 302 NodeList option_children = e.getElementsByTagName(StaticStrings.OPTION_STR); 303 if(option_children != null) { 304 for (int j = 0; j < option_children.getLength(); j++) { 305 Element el = (Element) option_children.item(j); 306 307 String name_str = el.getAttribute(StaticStrings.NAME_ATTRIBUTE); 308 options_str = options_str + ((name_str.equals("")) ? "" : (" " + name_str)); 309 310 String value_str = el.getAttribute(StaticStrings.VALUE_ATTRIBUTE); 311 options_str = options_str + ((name_str.equals("")) ? "" : (" " + value_str)); 312 313 if (name_str.equals("") && !value_str.equals("")) 314 { 315 continue; //invalid condition 316 } 317 318 Element option_element = null; 319 option_element = to.createElement(StaticStrings.OPTION_ELEMENT); 320 option_element.setAttribute(StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR); 321 322 if (!name_str.equals("")) 323 { 324 option_element.setAttribute(StaticStrings.NAME_ATTRIBUTE, name_str); 325 } 326 if (value_str != null && !value_str.equals("")) 327 { 328 XMLTools.setNodeText(option_element, value_str); 329 } 330 index_element.appendChild(option_element); 331 } 332 } 333 334 // Handling 'index' element 335 // Double check to make sure it's not colon separated style index. 336 if (index_str.indexOf(StaticStrings.COLON_CHARACTER) != -1) 337 { 338 System.err.println("Something is wrong! the index should NOT be level:source tuplets style."); 339 index_str = index_str.substring(index_str.indexOf(StaticStrings.COLON_CHARACTER) + 1); 340 341 } 342 //Each index may have a list of comma-separated strings. 343 //split them into 'content' elements in the internal structure 344 StringTokenizer content_tokenizer = new StringTokenizer(index_str, StaticStrings.COMMA_CHARACTER); 345 while (content_tokenizer.hasMoreTokens()) 346 { 347 // Replace index_str to be qualified name, eg. dc.Subject and keywords insread of dc.Subject. 348 349 Element content_element = to.createElement(StaticStrings.CONTENT_ELEMENT); 350 String content_str = content_tokenizer.nextToken(); 351 // Since the contents of indexes have to be certain keywords, or metadata elements, if the content isn't a keyword and doesn't yet have a namespace, append the extracted metadata namespace. 352 if (content_str.indexOf(StaticStrings.NS_SEP) == -1 && !(content_str.equals(StaticStrings.TEXT_STR) || content_str.equals(StaticStrings.ALLFIELDS_STR))) 353 { 354 content_str = StaticStrings.EXTRACTED_NAMESPACE + content_str; 355 } 356 content_element.setAttribute(StaticStrings.NAME_ATTRIBUTE, content_str); 357 index_element.appendChild(content_element); 358 content_element = null; 359 } //while ends 360 361 indexes_element.appendChild(index_element); 362 363 index_element = null; 364 365 // Handling 'displayItem' element of this 'index' element 366 // 'e' is the parent element 'index' of 'displayItem' element 367 ArrayList collectionmetadata_list = doDisplayItemList(to, e, StaticStrings.NAME_ATTRIBUTE, index_str_display); 368 appendArrayList(toElement, collectionmetadata_list); 369 370 } // for loop ends 371 toElement.appendChild(indexes_element); 378 doBaseIndexInternal(to, searchNode, StaticStrings.INDEXES_ELEMENT, StaticStrings.INDEX_ELEMENT, StaticStrings.INDEX_LOW_STR); 379 Element toElement = to.getDocumentElement(); 380 Element indexes_element = (Element) XMLTools.getChildByTagName(toElement, StaticStrings.INDEXES_ELEMENT); 381 indexes_element.setAttribute(StaticStrings.MGPP_ATTRIBUTE, StaticStrings.TRUE_STR); 382 383 // Element toElement = to.getDocumentElement(); 384 // Element indexes_element = to.createElement(StaticStrings.INDEXES_ELEMENT);//<Indexes> 385 // indexes_element.setAttribute(StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR); 386 // indexes_element.setAttribute(StaticStrings.MGPP_ATTRIBUTE, StaticStrings.TRUE_STR); 387 388 // NodeList index_children = ((Element) searchNode).getElementsByTagName(StaticStrings.INDEX_LOW_STR);//index 389 // int num_nodes = index_children.getLength(); 390 391 // for (int i = 0; i < num_nodes; i++) 392 // { 393 394 // Element index_element = to.createElement(StaticStrings.INDEX_ELEMENT);//<Index> 395 // Element e = (Element) index_children.item(i); 396 // String index_str = e.getAttribute(StaticStrings.NAME_ATTRIBUTE); 397 // String index_str_display = index_str;//for creating collectionmetadata for this index 398 399 // // look for options inside the index, eg 400 // // <option name="solrfieldtype" value="text_ja" /> 401 // String options_str = ""; 402 // NodeList option_children = e.getElementsByTagName(StaticStrings.OPTION_STR); 403 // if(option_children != null) { 404 // for (int j = 0; j < option_children.getLength(); j++) { 405 // Element el = (Element) option_children.item(j); 406 407 // String name_str = el.getAttribute(StaticStrings.NAME_ATTRIBUTE); 408 // options_str = options_str + ((name_str.equals("")) ? "" : (" " + name_str)); 409 410 // String value_str = el.getAttribute(StaticStrings.VALUE_ATTRIBUTE); 411 // options_str = options_str + ((name_str.equals("")) ? "" : (" " + value_str)); 412 413 // if (name_str.equals("") && !value_str.equals("")) 414 // { 415 // continue; //invalid condition 416 // } 417 418 // Element option_element = null; 419 // option_element = to.createElement(StaticStrings.OPTION_ELEMENT); 420 // option_element.setAttribute(StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR); 421 422 // if (!name_str.equals("")) 423 // { 424 // option_element.setAttribute(StaticStrings.NAME_ATTRIBUTE, name_str); 425 // } 426 // if (value_str != null && !value_str.equals("")) 427 // { 428 // XMLTools.setNodeText(option_element, value_str); 429 // } 430 // index_element.appendChild(option_element); 431 // } 432 // } 433 434 // // Handling 'index' element 435 // // Double check to make sure it's not colon separated style index. 436 // if (index_str.indexOf(StaticStrings.COLON_CHARACTER) != -1) 437 // { 438 // System.err.println("Something is wrong! the index should NOT be level:source tuplets style."); 439 // index_str = index_str.substring(index_str.indexOf(StaticStrings.COLON_CHARACTER) + 1); 440 441 // } 442 // //Each index may have a list of comma-separated strings. 443 // //split them into 'content' elements in the internal structure 444 // StringTokenizer content_tokenizer = new StringTokenizer(index_str, StaticStrings.COMMA_CHARACTER); 445 // while (content_tokenizer.hasMoreTokens()) 446 // { 447 // // Replace index_str to be qualified name, eg. dc.Subject and keywords insread of dc.Subject. 448 449 // Element content_element = to.createElement(StaticStrings.CONTENT_ELEMENT); 450 // String content_str = content_tokenizer.nextToken(); 451 // // Since the contents of indexes have to be certain keywords, or metadata elements, if the content isn't a keyword and doesn't yet have a namespace, append the extracted metadata namespace. 452 // if (content_str.indexOf(StaticStrings.NS_SEP) == -1 && !(content_str.equals(StaticStrings.TEXT_STR) || content_str.equals(StaticStrings.ALLFIELDS_STR))) 453 // { 454 // content_str = StaticStrings.EXTRACTED_NAMESPACE + content_str; 455 // } 456 // content_element.setAttribute(StaticStrings.NAME_ATTRIBUTE, content_str); 457 // index_element.appendChild(content_element); 458 // content_element = null; 459 // } //while ends 460 461 // indexes_element.appendChild(index_element); 462 463 // index_element = null; 464 465 // // Handling 'displayItem' element of this 'index' element 466 // // 'e' is the parent element 'index' of 'displayItem' element 467 // ArrayList collectionmetadata_list = doDisplayItemList(to, e, StaticStrings.NAME_ATTRIBUTE, index_str_display); 468 // appendArrayList(toElement, collectionmetadata_list); 469 470 // } // for loop ends 471 // toElement.appendChild(indexes_element); 372 472 373 473 // create another set of <indexes> which will be used when user switches to MG … … 408 508 } 409 509 510 static private void doSorts(Document to, Node searchNode) { 511 doBaseIndexInternal(to, searchNode, StaticStrings.SORTS_ELEMENT, StaticStrings.SORT_ELEMENT, StaticStrings.SORT_LOW_STR); 512 } 513 static private void doSortsOld(Document to, Node searchNode) 514 { 515 Element toElement = to.getDocumentElement(); 516 NodeList sort_children = ((Element) searchNode).getElementsByTagName(StaticStrings.SORT_LOW_STR); 517 int num_nodes = sort_children.getLength(); 518 519 // there are no sort fields 520 if (num_nodes < 1) 521 { 522 return; 523 } 524 525 Element sorts = to.createElement(StaticStrings.SORTS_ELEMENT); 526 527 for (int i = 0; i < num_nodes; i++) 528 { 529 Element sort_element = to.createElement(StaticStrings.SORT_ELEMENT); 530 Element sort_child = (Element) sort_children.item(i); 531 String name_str = sort_child.getAttribute(StaticStrings.NAME_ATTRIBUTE); 532 sort_element.setAttribute(StaticStrings.NAME_STR, name_str); 533 sorts.appendChild(sort_element); 534 535 // Contructing 'collectionmetadata' elements from the 'displayItem' of this 'sort' element 536 ArrayList displayItem_list = XMLTools.getNamedElementList(sort_child, StaticStrings.DISPLAYITEM_STR, StaticStrings.NAME_ATTRIBUTE, StaticStrings.NAME_STR); 537 if (displayItem_list == null) 538 { 539 // there is no display item for this element 540 continue; 541 } 542 for (int j = 0; j < displayItem_list.size(); j++) 543 { 544 Element item = (Element) displayItem_list.get(j); 545 String text = XMLTools.getNodeText(item); 546 //If there is nothing to display, don't bother creating the element 547 // Either lang or key should be set. If key set, no textnode. 548 // if lang set, should have textnode. Check if it's meaningful 549 if (item.hasAttribute(StaticStrings.LANG_STR) && text.equals("")) 550 { 551 continue; 552 } 553 554 // get the value in 'lang=langcode' or 'key=keyname' 555 // We can have either a key attribute (with optional dictionary attribute, else dictionary is implicit) 556 // OR we can have a lang attr, with the nodetext containing the actual display strin.g 557 String lang = item.getAttribute(StaticStrings.LANG_ATTRIBUTE); 558 String key = item.getAttribute(StaticStrings.KEY_ATTRIBUTE); 559 560 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); 564 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 } 582 583 // TODO 584 static private void doDefaultSort(Document to, Node searchNode) 585 { 586 Element toElement = to.getDocumentElement(); 587 588 Element from_e = (Element) XMLTools.getChildByTagName(searchNode, StaticStrings.SORT_DEFAULT_ELEMENT); 589 if (from_e == null) { 590 return; // there is no default 591 } 592 Element default_sort = to.createElement(StaticStrings.SORT_DEFAULT_ELEMENT); 593 594 default_sort.setAttribute(StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR); 595 String name = from_e.getAttribute(StaticStrings.NAME_ATTRIBUTE); 596 default_sort.setAttribute(StaticStrings.NAME_ATTRIBUTE, name); 597 appendProperly(toElement, default_sort); 598 } 599 static private void doFacets(Document to, Node searchNode) { 600 doBaseIndexInternal(to, searchNode, StaticStrings.FACETS_ELEMENT, StaticStrings.FACET_ELEMENT, StaticStrings.FACET_LOW_STR); 601 } 602 603 604 static private void doFacetsOld(Document to, Node searchNode) 605 { 606 Element toElement = to.getDocumentElement(); 607 NodeList facet_children = ((Element) searchNode).getElementsByTagName(StaticStrings.FACET_LOW_STR); 608 int num_nodes = facet_children.getLength(); 609 610 // there are no facet fields 611 if (num_nodes < 1) 612 { 613 return; 614 } 615 616 Element facets = to.createElement(StaticStrings.FACETS_ELEMENT); 617 618 for (int i = 0; i < num_nodes; i++) 619 { 620 Element facet_element = to.createElement(StaticStrings.FACET_ELEMENT); 621 Element facet_child = (Element) facet_children.item(i); 622 String name_str = facet_child.getAttribute(StaticStrings.NAME_ATTRIBUTE); 623 facet_element.setAttribute(StaticStrings.NAME_STR, name_str); 624 facets.appendChild(facet_element); 625 626 // Contructing 'collectionmetadata' elements from the 'displayItem' of this 'facet' element 627 ArrayList displayItem_list = XMLTools.getNamedElementList(facet_child, StaticStrings.DISPLAYITEM_STR, StaticStrings.NAME_ATTRIBUTE, StaticStrings.NAME_STR); 628 if (displayItem_list == null) 629 { 630 // there is no display item for this element 631 continue; 632 } 633 for (int j = 0; j < displayItem_list.size(); j++) 634 { 635 Element item = (Element) displayItem_list.get(j); 636 String text = XMLTools.getNodeText(item); 637 //If there is nothing to display, don't bother creating the element 638 // Either lang or key should be set. If key set, no textnode. 639 // if lang set, should have textnode. Check if it's meaningful 640 if (item.hasAttribute(StaticStrings.LANG_STR) && text.equals("")) 641 { 642 continue; 643 } 644 645 // get the value in 'lang=langcode' or 'key=keyname' 646 // We can have either a key attribute (with optional dictionary attribute, else dictionary is implicit) 647 // OR we can have a lang attr, with the nodetext containing the actual display strin.g 648 String lang = item.getAttribute(StaticStrings.LANG_ATTRIBUTE); 649 String key = item.getAttribute(StaticStrings.KEY_ATTRIBUTE); 650 651 652 Element collectionmetadata = to.createElement(StaticStrings.COLLECTIONMETADATA_ELEMENT); 653 collectionmetadata.setAttribute(StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR); 654 collectionmetadata.setAttribute(StaticStrings.NAME_ATTRIBUTE, name_str); 655 656 if(!lang.equals("")) { 657 collectionmetadata.setAttribute(StaticStrings.LANGUAGE_ATTRIBUTE, lang); 658 XMLTools.setNodeText(collectionmetadata, text); 659 } 660 if(!key.equals("")) { 661 collectionmetadata.setAttribute(StaticStrings.KEY_ATTRIBUTE, key); 662 String dictionary = item.getAttribute(StaticStrings.DICTIONARY_ATTRIBUTE); 663 if(!dictionary.equals("")) { 664 collectionmetadata.setAttribute(StaticStrings.DICTIONARY_ATTRIBUTE, dictionary); 665 } 666 } 667 668 appendProperly(toElement, collectionmetadata); 669 } 670 } 671 toElement.appendChild(facets); 672 } 673 674 410 675 //This processes <sort> (lucene), or <sort> and <facet> (solr) subelements of <search> also <defaultSort> 411 676 // Note that GLI at present does not allow the user to set or modify these. 412 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. 413 678 // it just copies them into storage. 414 static private void doSolrFacetsAndSorts (Document to, Node searchNode)679 static private void doSolrFacetsAndSortsdeletE(Document to, Node searchNode) 415 680 { 416 681 Element toElement = to.getDocumentElement(); … … 2104 2369 //Get the 'search' element from 'to' which has already been created in 'convertBuildType' 2105 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 2106 2377 2107 2378 //THere are two sets of indexes elements, find the one which is assigned 'true' … … 2119 2390 } 2120 2391 2121 //find out it's mg or mgpp/lucene 2122 String mg = search.getAttribute(StaticStrings.TYPE_ATTRIBUTE); 2123 boolean mg_indexer = false; 2124 if (mg.equals(StaticStrings.MG_STR)) 2125 { 2126 mg_indexer = true;//it's mg, then the level is set as attribute of 2127 } 2128 if (mg_indexer == false) 2129 { 2130 // It's mgpp. Construct 'level' and 'defaultLevel' elements separately. 2131 convertLevels(from, to, search); 2132 } 2133 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 } 2134 2427 for (int j = 0; j < index_elements_length; j++) 2135 2428 { … … 2140 2433 } 2141 2434 2142 Element index_ele = to.createElement( StaticStrings.INDEX_LOW_STR);//index2435 Element index_ele = to.createElement(output_index_str);//index 2143 2436 2144 2437 // Used for creating displayItem for this element 'index_ele' further below … … 2148 2441 2149 2442 StringBuffer index_value = new StringBuffer(); 2150 if (mg_indexer == true)2151 {2152 // For mg indexer, there is a 'level' attribute in the index element of the internal structure2153 // But mgpp/lucene don't2154 level_str = index_element.getAttribute(StaticStrings.LEVEL_ATTRIBUTE);2155 if (level_str.length() > 0)2156 {2157 index_value.append(level_str).append(StaticStrings.COLON_CHARACTER);2158 //index_value = index_value.StaticStrings.COLON_CHARACTER;2159 }2160 }2161 2443 2162 2444 NodeList content_elements = index_element.getElementsByTagName(StaticStrings.CONTENT_ELEMENT); … … 2205 2487 { 2206 2488 //try the full name, i.e. with 'ex.' 2207 if (mg_indexer == true)2208 {2209 // but first append level info if we are mg2210 full_index_name = level_str + StaticStrings.COLON_CHARACTER + full_index_name;2211 }2212 2489 collectionmetadata_list = XMLTools.getNamedElementList(source, StaticStrings.COLLECTIONMETADATA_ELEMENT, StaticStrings.NAME_ATTRIBUTE, full_index_name); 2213 2490 } … … 2260 2537 } //for loop ends 2261 2538 2539 2540 } 2541 static private void convertMGIndex(Document from, Document to) 2542 { 2543 Element source = from.getDocumentElement(); 2544 //Get the 'search' element from 'to' which has already been created in 'convertBuildType' 2545 Element search = (Element) XMLTools.getChildByTagName(to.getDocumentElement(), StaticStrings.SEARCH_STR); 2546 2547 //THere are two sets of indexes elements, find the one which is assigned 'true' 2548 Element indexes = XMLTools.getNamedElement(source, StaticStrings.INDEXES_ELEMENT, StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR); 2549 if (indexes == null) 2550 { 2551 return; 2552 } 2553 NodeList index_elements = indexes.getElementsByTagName(StaticStrings.INDEX_ELEMENT); 2554 int index_elements_length = index_elements.getLength(); 2555 2556 if (index_elements_length == 0) 2557 { // no indexes 2558 return; 2559 } 2560 2561 // //find out it's mg or mgpp/lucene 2562 // String mg = search.getAttribute(StaticStrings.TYPE_ATTRIBUTE); 2563 // boolean mg_indexer = false; 2564 // if (mg.equals(StaticStrings.MG_STR)) 2565 // { 2566 // mg_indexer = true;//it's mg, then the level is set as attribute of 2567 // } 2568 // if (mg_indexer == false) 2569 // { 2570 // // It's mgpp. Construct 'level' and 'defaultLevel' elements separately. 2571 // convertLevels(from, to, search); 2572 // } 2573 2574 for (int j = 0; j < index_elements_length; j++) 2575 { 2576 Element index_element = (Element) index_elements.item(j); 2577 if (index_element.getAttribute(StaticStrings.ASSIGNED_ATTRIBUTE).equals(StaticStrings.FALSE_STR)) 2578 { 2579 continue; 2580 } 2581 2582 Element index_ele = to.createElement(StaticStrings.INDEX_LOW_STR);//index 2583 2584 // Used for creating displayItem for this element 'index_ele' further below 2585 // full_index_names contain 'ex.' 2586 String full_index_name = ""; 2587 String level_str = ""; 2588 2589 StringBuffer index_value = new StringBuffer(); 2590 // if (mg_indexer == true) 2591 //{ 2592 // For mg indexer, there is a 'level' attribute in the index element of the internal structure 2593 // But mgpp/lucene don't 2594 level_str = index_element.getAttribute(StaticStrings.LEVEL_ATTRIBUTE); 2595 if (level_str.length() > 0) 2596 { 2597 index_value.append(level_str).append(StaticStrings.COLON_CHARACTER); 2598 //index_value = index_value.StaticStrings.COLON_CHARACTER; 2599 } 2600 //} 2601 2602 NodeList content_elements = index_element.getElementsByTagName(StaticStrings.CONTENT_ELEMENT); 2603 int content_elements_length = content_elements.getLength(); 2604 2605 for (int k = 0; k < content_elements_length; k++) 2606 { 2607 Element content_element = (Element) content_elements.item(k); 2608 if (content_element.getAttribute(StaticStrings.ASSIGNED_ATTRIBUTE).equals(StaticStrings.FALSE_STR)) 2609 { 2610 continue; 2611 } 2612 String name_str = content_element.getAttribute(StaticStrings.NAME_ATTRIBUTE); 2613 2614 full_index_name = full_index_name + name_str; 2615 if (k < content_elements_length - 1) 2616 { 2617 full_index_name = full_index_name + StaticStrings.COMMA_CHARACTER; 2618 } 2619 2620 if (name_str.startsWith(StaticStrings.EXTRACTED_NAMESPACE) && name_str.indexOf(StaticStrings.NS_SEP, StaticStrings.EXTRACTED_NAMESPACE.length()) == -1) 2621 { 2622 name_str = name_str.substring(StaticStrings.EXTRACTED_NAMESPACE.length()); 2623 } 2624 2625 index_value.append(name_str); 2626 name_str = null; 2627 // Make it comma separated string 2628 if (k < content_elements_length - 1) 2629 { 2630 index_value.append(StaticStrings.COMMA_CHARACTER); 2631 } 2632 content_element = null; 2633 }//for loop ends 2634 2635 String temp_str = index_value.toString(); 2636 index_ele.setAttribute(StaticStrings.NAME_ATTRIBUTE, temp_str); 2637 2638 // Now constructing 'displayItem' element for this 'index_ele' element 2639 // The index names in the collectionmetadata elements in the internal structure are not the names that 2640 // 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); 2643 2644 if (collectionmetadata_list == null) 2645 { 2646 //try the full name, i.e. with 'ex.', first appending level info as we are mg 2647 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); 2650 } 2651 2652 if (collectionmetadata_list != null) 2653 { 2654 2655 for (int k = 0; k < collectionmetadata_list.size(); k++) 2656 { 2657 Element collectionmetadata = (Element) collectionmetadata_list.get(k); 2658 if (collectionmetadata.getAttribute(StaticStrings.ASSIGNED_ATTRIBUTE).equals(StaticStrings.FALSE_STR)) 2659 { 2660 continue; 2661 } 2662 Element displayItem = constructDisplayItem(collectionmetadata, to); 2663 2664 index_ele.appendChild(displayItem); 2665 } 2666 } 2667 2668 //mg has no options 2669 // deal with any <option name='' value=''> children of this index 2670 // e.g. <option name='solrfieldtype' value='text_es'> 2671 // NodeList option_children = index_element.getElementsByTagName(StaticStrings.OPTION_ELEMENT); 2672 // for (int k = 0; k < option_children.getLength(); k++) 2673 // { 2674 // Element el = (Element) option_children.item(k); 2675 // if (el.getAttribute(StaticStrings.ASSIGNED_ATTRIBUTE).equals(StaticStrings.FALSE_STR)) 2676 // { 2677 // continue; 2678 // } 2679 // String name_str = el.getAttribute(StaticStrings.NAME_ATTRIBUTE); 2680 // String value_str = XMLTools.getNodeText(el); 2681 2682 // if (name_str == null && value_str == null) 2683 // { 2684 // continue; 2685 // } 2686 // Element option_element = to.createElement(StaticStrings.OPTION_STR); 2687 // if (!name_str.equals("")) { 2688 // option_element.setAttribute(StaticStrings.NAME_ATTRIBUTE, name_str); 2689 // } 2690 // if (!value_str.equals("")) { // or no value attribute without name attribute? 2691 // option_element.setAttribute(StaticStrings.VALUE_ATTRIBUTE, value_str); 2692 // } 2693 // index_ele.appendChild(option_element); 2694 // } 2695 2696 search.appendChild(index_ele); 2697 2698 } //for loop ends 2699 2262 2700 //Convert default index 2263 2701 convertDefaultIndex(from, to, search); … … 2265 2703 } 2266 2704 2705 2706 static private void convertSort(Document from, Document to) 2707 { 2708 Element source = from.getDocumentElement(); 2709 //Get the 'search' element from 'to' which has already been created in 'convertBuildType' 2710 Element search = (Element) XMLTools.getChildByTagName(to.getDocumentElement(), StaticStrings.SEARCH_STR); 2711 2712 // Get the Sorts element from the internal structure 2713 Element sorts = (Element) XMLTools.getChildByTagName(source, StaticStrings.SORTS_ELEMENT); 2714 if (sorts == null) 2715 { 2716 return; 2717 } 2718 NodeList sort_elements = sorts.getElementsByTagName(StaticStrings.SORT_ELEMENT); 2719 int sort_elements_length = sort_elements.getLength(); 2720 2721 if (sort_elements_length == 0) 2722 { 2723 return; 2724 } 2725 2726 for (int j = 0; j < sort_elements_length; j++) 2727 { 2728 Element element = (Element) sort_elements.item(j); 2729 if (element.getAttribute(StaticStrings.ASSIGNED_ATTRIBUTE).equals(StaticStrings.FALSE_STR)) 2730 { 2731 continue; 2732 } 2733 2734 // Create sort element 2735 Element new_sort = to.createElement(StaticStrings.SORT_LOW_STR); 2736 2737 String name_str = element.getAttribute(StaticStrings.NAME_ATTRIBUTE); 2738 new_sort.setAttribute(StaticStrings.NAME_ATTRIBUTE, name_str); 2739 2740 // Now constructing 'displayItem' element for this 'indexLanguage' element 2741 // from the collectionmetadata element 2742 // TODO this needs work to differentiate it from index 2743 ArrayList collectionmetadata_list = XMLTools.getNamedElementList(source, StaticStrings.COLLECTIONMETADATA_ELEMENT, StaticStrings.NAME_ATTRIBUTE, name_str); 2744 2745 if (collectionmetadata_list != null) 2746 { 2747 2748 for (int k = 0; k < collectionmetadata_list.size(); k++) 2749 { 2750 Element collectionmetadata = (Element) collectionmetadata_list.get(k); 2751 if (collectionmetadata.getAttribute(StaticStrings.ASSIGNED_ATTRIBUTE).equals(StaticStrings.FALSE_STR)) 2752 { 2753 continue; 2754 } 2755 Element displayItem = constructDisplayItem(collectionmetadata, to); 2756 new_sort.appendChild(displayItem); 2757 } 2758 } 2759 2760 search.appendChild(new_sort); 2761 2762 } //for loop ends 2763 2764 // Convert DefaultSort 2765 // Get the DefaultSort element from the internal structure 2766 Element default_sort = (Element) XMLTools.getChildByTagName(source, StaticStrings.SORT_DEFAULT_ELEMENT); 2767 if (default_sort != null) 2768 { 2769 String sort_name = default_sort.getAttribute(StaticStrings.NAME_ATTRIBUTE); 2770 Element new_default_sort = to.createElement(StaticStrings.SORT_DEFAULT_ELEMENT); 2771 new_default_sort.setAttribute(StaticStrings.NAME_ATTRIBUTE, sort_name); 2772 search.appendChild(new_default_sort); 2773 } 2774 } 2775 2776 static private void convertFacet(Document from, Document to) 2777 { 2778 Element source = from.getDocumentElement(); 2779 //Get the 'search' element from 'to' which has already been created in 'convertBuildType' 2780 Element search = (Element) XMLTools.getChildByTagName(to.getDocumentElement(), StaticStrings.SEARCH_STR); 2781 2782 // Get the Facets element from the internal structure 2783 Element facets = (Element) XMLTools.getChildByTagName(source, StaticStrings.FACETS_ELEMENT); 2784 if (facets == null) 2785 { 2786 return; 2787 } 2788 NodeList facet_elements = facets.getElementsByTagName(StaticStrings.FACET_ELEMENT); 2789 int facet_elements_length = facet_elements.getLength(); 2790 2791 if (facet_elements_length == 0) 2792 { 2793 return; 2794 } 2795 2796 for (int j = 0; j < facet_elements_length; j++) 2797 { 2798 Element element = (Element) facet_elements.item(j); 2799 if (element.getAttribute(StaticStrings.ASSIGNED_ATTRIBUTE).equals(StaticStrings.FALSE_STR)) 2800 { 2801 continue; 2802 } 2803 2804 // Create facet element 2805 Element new_facet = to.createElement(StaticStrings.FACET_LOW_STR); 2806 2807 String name_str = element.getAttribute(StaticStrings.NAME_ATTRIBUTE); 2808 new_facet.setAttribute(StaticStrings.NAME_ATTRIBUTE, name_str); 2809 2810 // Now constructing 'displayItem' element for this 'indexLanguage' element 2811 // from the collectionmetadata element 2812 // TODO this needs work to differentiate it from index 2813 ArrayList collectionmetadata_list = XMLTools.getNamedElementList(source, StaticStrings.COLLECTIONMETADATA_ELEMENT, StaticStrings.NAME_ATTRIBUTE, name_str); 2814 2815 if (collectionmetadata_list != null) 2816 { 2817 2818 for (int k = 0; k < collectionmetadata_list.size(); k++) 2819 { 2820 Element collectionmetadata = (Element) collectionmetadata_list.get(k); 2821 if (collectionmetadata.getAttribute(StaticStrings.ASSIGNED_ATTRIBUTE).equals(StaticStrings.FALSE_STR)) 2822 { 2823 continue; 2824 } 2825 Element displayItem = constructDisplayItem(collectionmetadata, to); 2826 new_facet.appendChild(displayItem); 2827 } 2828 } 2829 2830 search.appendChild(new_facet); 2831 2832 } //for loop ends 2833 2834 } 2267 2835 //convert <facet> and <sort> and <defaultSort> elements 2268 2836 //which go in 'search' element in collectionConfig.xml … … 2274 2842 // <sort> and <facet>. This function, and its inverse doSolrFacetsAndSorts, is only here to preserve such 2275 2843 // elements if they already exist in the collectionConfig.xml. At present they need to be manually added there. 2276 static private void convertSolrFacetsAndSorts (Document from, Document to)2844 static private void convertSolrFacetsAndSortsDELETE(Document from, Document to) 2277 2845 { 2278 2846 Element source = from.getDocumentElement(); … … 2750 3318 2751 3319 if(buildtype_value.equalsIgnoreCase("solr") || buildtype_value.equalsIgnoreCase("lucene")) { 2752 doSolrFacetsAndSorts(dOc, searchNode); // <facet><displayItem /></facet> and <sort><displayItem /></sort> 3320 //doSolrFacetsAndSorts(dOc, searchNode); // <facet><displayItem /></facet> and <sort><displayItem /></sort> 3321 doSorts(dOc, searchNode); 3322 doDefaultSort(dOc, searchNode); 3323 if (buildtype_value.equalsIgnoreCase("solr")) { 3324 doFacets(dOc, searchNode); 3325 } 2753 3326 // lucene will only have sort elements 2754 3327 } … … 2886 3459 static private Document convertInternalToCollectionConfig(Document dOc) 2887 3460 { 3461 ///ystem.err.println("internal documnet:"); 3462 ///ystem.err.println(XMLTools.xmlNodeToString(XMLTools.getChildByTagName(dOc.getDocumentElement(), "Facets"))); 3463 ///ystem.err.println(XMLTools.xmlNodeToString(XMLTools.getChildByTagName(dOc.getDocumentElement(), "Sorts"))); 2888 3464 //first parse an empty skeleton of xml config file 2889 3465 //The aim is to convert the internal structure into this skeleton … … 2897 3473 convertBuildType(dOc, skeleton); 2898 3474 convertDatabaseType(dOc, skeleton); 2899 convertIndex(dOc, skeleton); 2900 convertSolrFacetsAndSorts(dOc, skeleton); 3475 convertIndex(dOc, skeleton); // this will do index, defaultIndex, indexOptions, facets and sorting if needed 3476 //convertSolrFacetsAndSorts(dOc, skeleton); 3477 //convertSort(dOc, skeleton); 3478 //convertFacet(dOc, skeleton); 2901 3479 convertPlugins(dOc, skeleton);//also do the plugout element 2902 3480 convertClassifier(dOc, skeleton);
Note:
See TracChangeset
for help on using the changeset viewer.