- Timestamp:
- 2012-11-06T15:27:10+13:00 (11 years ago)
- Location:
- main/trunk/greenstone3/src/java/org/greenstone/gsdl3/collection
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/collection/Collection.java
r25989 r26446 36 36 import org.greenstone.gsdl3.util.GSXML; 37 37 import org.greenstone.gsdl3.util.OAIXML; 38 import org.greenstone.gsdl3.util.SimpleMacroResolver; 38 39 import org.greenstone.gsdl3.util.UserContext; 39 40 import org.greenstone.gsdl3.util.XMLTransformer; … … 55 56 static Logger logger = Logger.getLogger(org.greenstone.gsdl3.collection.Collection.class.getName()); 56 57 57 /** is this collection being tidied */58 /** is this collection being tidied and therefore can support realistic book view?*/ 58 59 protected boolean useBook = false; 59 /** is this collection public or private */ 60 /** is this collection public or private - public collections will 61 appear on the home page, whereas private collections won't*/ 60 62 protected boolean is_public = true; 63 /** collection type : mg, mgpp or lucene */ 64 protected String col_type = ""; 65 /** database type : gdbm, jdbm or sqlite */ 66 protected String db_type = ""; 61 67 62 68 /** does this collection provide the OAI service */ 63 protected boolean has_oai = true;69 protected boolean has_oai = false; 64 70 /** time when this collection was built */ 65 71 protected long lastmodified = 0; … … 75 81 protected ArrayList<HashMap<String, ArrayList<String>>> _securityExceptions = new ArrayList<HashMap<String, ArrayList<String>>>(); 76 82 77 /** 78 * An element containing the serviceRackList element of buildConfig.xml, 79 * used to determine whether it contains the OAIPMH serviceRack 80 */ 81 //protected Element service_rack_list = null; 82 83 83 84 protected XMLTransformer transformer = null; 84 85 … … 112 113 return false; 113 114 } 115 116 macro_resolver.addMacro("_httpcollection_", this.site_http_address + "/collect/" + this.cluster_name); 114 117 115 118 Element coll_config_xml = loadCollConfigFile(); … … 138 141 } 139 142 143 this.description.setAttribute(GSXML.TYPE_ATT, col_type); 144 this.description.setAttribute(GSXML.DB_TYPE_ATT, db_type); 145 140 146 _globalFormat = (Element) GSXML.getChildByTagName(coll_config_xml, GSXML.FORMAT_ELEM); 141 142 // process the metadata and display items 147 // process the metadata and display items and default library params 148 super.configureLocalData(coll_config_xml); 149 super.configureLocalData(build_config_xml); 150 // get extra collection specific stuff 143 151 findAndLoadInfo(coll_config_xml, build_config_xml); 144 152 … … 197 205 return null; 198 206 } 199 // get the xml for both files207 // get the xml 200 208 Document coll_config_doc = this.converter.getDOM(coll_config_file, CONFIG_ENCODING); 201 209 Element coll_config_elem = null; … … 237 245 protected boolean findAndLoadInfo(Element coll_config_xml, Element build_config_xml) 238 246 { 239 Element meta_list = (Element) GSXML.getChildByTagName(coll_config_xml, GSXML.METADATA_ELEM + GSXML.LIST_MODIFIER); 240 addMetadata(meta_list); 241 meta_list = (Element) GSXML.getChildByTagName(build_config_xml, GSXML.METADATA_ELEM + GSXML.LIST_MODIFIER); 242 addMetadata(meta_list); 243 244 meta_list = this.doc.createElement(GSXML.METADATA_ELEM + GSXML.LIST_MODIFIER); 245 GSXML.addMetadata(this.doc, meta_list, "httpPath", this.site_http_address + "/collect/" + this.cluster_name); 246 addMetadata(meta_list); 247 // Element meta_list = (Element) GSXML.getChildByTagName(coll_config_xml, GSXML.METADATA_ELEM + GSXML.LIST_MODIFIER); 248 // addMetadata(meta_list); 249 // meta_list = (Element) GSXML.getChildByTagName(build_config_xml, GSXML.METADATA_ELEM + GSXML.LIST_MODIFIER); 250 // addMetadata(meta_list); 251 addMetadata("httpPath", this.site_http_address + "/collect/" + this.cluster_name); 247 252 248 253 // display stuff 249 Element display_list = (Element) GSXML.getChildByTagName(coll_config_xml, GSXML.DISPLAY_TEXT_ELEM + GSXML.LIST_MODIFIER);250 if (display_list != null)251 {252 resolveMacros(display_list);253 addDisplayItems(display_list);254 }254 // Element display_list = (Element) GSXML.getChildByTagName(coll_config_xml, GSXML.DISPLAY_TEXT_ELEM + GSXML.LIST_MODIFIER); 255 // if (display_list != null) 256 // { 257 // resolveMacros(display_list); 258 // addDisplayItems(display_list); 259 // } 255 260 256 261 //check whether the html are tidy or not … … 259 264 { 260 265 Element plugin_list = (Element) GSXML.getChildByTagName(import_list, GSXML.PLUGIN_ELEM + GSXML.LIST_MODIFIER); 261 addPlugins(plugin_list);266 //addPlugins(plugin_list); 262 267 if (plugin_list != null) 263 268 { … … 274 279 } 275 280 } 276 meta_list = this.doc.createElement(GSXML.METADATA_ELEM + GSXML.LIST_MODIFIER); 277 if (useBook == true) 278 GSXML.addMetadata(this.doc, meta_list, "tidyoption", "tidy"); 279 else 280 GSXML.addMetadata(this.doc, meta_list, "tidyoption", "untidy"); 281 addMetadata(meta_list); 281 String tidy = (useBook == true ? "tidy" : "untidy"); 282 addMetadata("tidyoption", tidy); 282 283 283 284 // check whether we are public or not … … 389 390 clearServices(); 390 391 Element service_list = (Element) GSXML.getChildByTagName(build_config_xml, GSXML.SERVICE_CLASS_ELEM + GSXML.LIST_MODIFIER); 391 configureServiceRackList(service_list, coll_config_xml); 392 392 Element oai_service_rack = null; 393 if (service_list != null) { 394 configureServiceRackList(service_list, coll_config_xml); 395 oai_service_rack = GSXML.getNamedElement(service_list, GSXML.SERVICE_CLASS_ELEM, OAIXML.NAME, OAIXML.OAIPMH); 396 } 393 397 // collection Config may also contain manually added service racks 394 398 service_list = (Element) GSXML.getChildByTagName(coll_config_xml, GSXML.SERVICE_CLASS_ELEM + GSXML.LIST_MODIFIER); 395 399 if (service_list != null) 396 400 { 397 configureServiceRackList(service_list, build_config_xml); 398 399 // Check for oai 400 Element oai_service_rack = GSXML.getNamedElement(service_list, GSXML.SERVICE_CLASS_ELEM, OAIXML.NAME, OAIXML.OAIPMH); 401 if (oai_service_rack == null) 402 { 403 has_oai = false; 404 logger.info("No oai for collection: " + this.cluster_name); 405 406 } 407 else 408 { 409 has_oai = true; 410 411 // extract earliestDatestamp from the buildconfig.xml for OAI 412 Element metadata_list = (Element) GSXML.getChildByTagName(build_config_xml, GSXML.METADATA_ELEM + GSXML.LIST_MODIFIER); 413 414 if (metadata_list != null) 415 { 416 NodeList children = metadata_list.getElementsByTagName(GSXML.METADATA_ELEM); 417 // can't do getChildNodes(), because whitespace, such as newlines, creates Text nodes 418 for (int i = 0; i < children.getLength(); i++) 419 { 420 Element metadata = (Element) children.item(i); 421 if (metadata.getAttribute(GSXML.NAME_ATT).equals(OAIXML.EARLIEST_DATESTAMP)) 422 { 423 String earliestDatestampStr = GSXML.getValue(metadata); 424 if (!earliestDatestampStr.equals("")) 425 { 426 earliestDatestamp = Long.parseLong(earliestDatestampStr); 427 } 428 break; // found a metadata element with name=earliestDatestamp in buildconfig 429 } 430 } 431 } 432 433 // If at the end of this, there is no value for earliestDatestamp, print out a warning 434 logger.warn("No earliestDatestamp in buildConfig.xml for collection: " + this.cluster_name + ". Defaulting to 0."); 435 436 } 437 } 438 else 439 { // no list of services (no ServiceRackList), so no oai_service_rack either 440 // explicitly set has_oai to false here, since it's initialised to true by default 441 has_oai = false; 442 } 401 configureServiceRackList(service_list, build_config_xml); 402 // this oai used in preference to one in buildConfig.xml 403 oai_service_rack = GSXML.getNamedElement(service_list, GSXML.SERVICE_CLASS_ELEM, OAIXML.NAME, OAIXML.OAIPMH); 404 } 405 // Check for oai 406 407 if (oai_service_rack != null) 408 { 409 has_oai = true; 410 logger.info(this.cluster_name +" has OAI services"); 411 // extract earliestDatestamp from the buildconfig.xml for OAI 412 Element metadata_list = (Element) GSXML.getChildByTagName(build_config_xml, GSXML.METADATA_ELEM + GSXML.LIST_MODIFIER); 413 414 if (metadata_list != null) 415 { 416 NodeList children = metadata_list.getElementsByTagName(GSXML.METADATA_ELEM); 417 // can't do getChildNodes(), because whitespace, such as newlines, creates Text nodes 418 for (int i = 0; i < children.getLength(); i++) 419 { 420 Element metadata = (Element) children.item(i); 421 if (metadata.getAttribute(GSXML.NAME_ATT).equals(OAIXML.EARLIEST_DATESTAMP)) 422 { 423 String earliestDatestampStr = GSXML.getValue(metadata); 424 if (!earliestDatestampStr.equals("")) 425 { 426 earliestDatestamp = Long.parseLong(earliestDatestampStr); 427 } 428 break; // found a metadata element with name=earliestDatestamp in buildconfig 429 } 430 } 431 } 432 433 // If at the end of this, there is no value for earliestDatestamp, print out a warning 434 logger.warn("No earliestDatestamp in buildConfig.xml for collection: " + this.cluster_name + ". Defaulting to 0."); 435 436 } // if oai_service_rack != null 437 443 438 return true; 444 439 } 445 440 446 protected boolean resolveMacros(Element display_list)447 {448 if (display_list == null)449 return false;450 NodeList displaynodes = display_list.getElementsByTagName(GSXML.DISPLAY_TEXT_ELEM);451 if (displaynodes.getLength() > 0)452 {453 String http_site = this.site_http_address;454 String http_collection = this.site_http_address + "/collect/" + this.cluster_name;455 for (int k = 0; k < displaynodes.getLength(); k++)456 {457 Element d = (Element) displaynodes.item(k);458 String text = GSXML.getNodeText(d);459 text = StringUtils.replace(text, "_httpsite_", http_site);460 text = StringUtils.replace(text, "_httpcollection_", http_collection);461 GSXML.setNodeText(d, text);462 }463 }464 return true;465 }466 441 467 442 /** … … 485 460 } 486 461 487 if (subset.equals(GSXML.METADATA_ELEM + GSXML.LIST_MODIFIER) || subset.equals(GSXML.DISPLAY_TEXT_ELEM + GSXML.LIST_MODIFIER) || subset.equals(GSXML.PLUGIN_ELEM + GSXML.LIST_MODIFIER)) 488 { 462 if (subset.equals(GSXML.METADATA_ELEM + GSXML.LIST_MODIFIER) || subset.equals(GSXML.DISPLAY_TEXT_ELEM + GSXML.LIST_MODIFIER) || subset.equals("libraryParamList")) 463 { 464 configureLocalData(coll_config_elem); 465 configureLocalData(build_config_elem); 489 466 return findAndLoadInfo(coll_config_elem, build_config_elem); 490 467 … … 504 481 protected Element processMessage(Element request) 505 482 { 506 483 String type = request.getAttribute(GSXML.TYPE_ATT); 484 if (type.equals(GSXML.REQUEST_TYPE_FORMAT_STRING)) 485 { 486 return processFormatStringRequest(request); 487 } 488 else if (type.equals(GSXML.REQUEST_TYPE_SECURITY)) 489 { 490 return processSecurityRequest(request); 491 } 492 else if (type.equals(GSXML.REQUEST_TYPE_FORMAT)) 493 { 507 494 Element response = this.doc.createElement(GSXML.RESPONSE_ELEM); 508 495 response.setAttribute(GSXML.FROM_ATT, this.cluster_name); 509 String type = request.getAttribute(GSXML.TYPE_ATT); 510 String lang = request.getAttribute(GSXML.LANG_ATT); 511 response.setAttribute(GSXML.TYPE_ATT, type); 512 513 if (type.equals(GSXML.REQUEST_TYPE_FORMAT_STRING)) 514 { 515 String subaction = request.getAttribute("subaction"); 516 String service = request.getAttribute("service"); 517 518 String classifier = null; 519 if (service.equals("ClassifierBrowse")) 520 { 521 classifier = request.getAttribute("classifier"); 522 } 523 524 // check for version file 525 String directory = new File(GSFile.collectionConfigFile(this.site_home, this.cluster_name)).getParent() + File.separator; 526 527 String version_filename = ""; 528 if (service.equals("ClassifierBrowse")) 529 version_filename = directory + "browse_" + classifier + "_format_statement_version.txt"; 530 else 531 version_filename = directory + "query_format_statement_version.txt"; 532 533 File version_file = new File(version_filename); 534 535 if (subaction.equals("update")) 536 { 537 Element format_element = (Element) GSXML.getChildByTagName(request, GSXML.FORMAT_STRING_ELEM); 538 //String format_string = GSXML.getNodeText(format_element); 539 Element format_statement = (Element) format_element.getFirstChild(); 540 541 String version_number = "1"; 542 BufferedWriter writer; 543 544 try 545 { 546 547 if (version_file.exists()) 548 { 549 // Read version 550 BufferedReader reader = new BufferedReader(new FileReader(version_filename)); 551 version_number = reader.readLine(); 552 int aInt = Integer.parseInt(version_number) + 1; 553 version_number = Integer.toString(aInt); 554 reader.close(); 555 } 556 else 557 { 558 // Create 559 version_file.createNewFile(); 560 writer = new BufferedWriter(new FileWriter(version_filename)); 561 writer.write(version_number); 562 writer.close(); 563 } 564 565 // Write version file 566 String format_statement_filename = ""; 567 568 if (service.equals("ClassifierBrowse")) 569 format_statement_filename = directory + "browse_" + classifier + "_format_statement_v" + version_number + ".txt"; 570 else 571 format_statement_filename = directory + "query_format_statement_v" + version_number + ".txt"; 572 573 // Write format statement 574 String format_string = this.converter.getString(format_statement); //GSXML.xmlNodeToString(format_statement); 575 writer = new BufferedWriter(new FileWriter(format_statement_filename)); 576 writer.write(format_string); 577 writer.close(); 578 579 // Update version number 580 writer = new BufferedWriter(new FileWriter(version_filename)); 581 writer.write(version_number); 582 writer.close(); 583 584 } 585 catch (IOException e) 586 { 587 logger.error("IO Exception " + e); 588 } 589 } 590 591 if (subaction.equals("saveDocument")) 592 { 593 Element format_element = (Element) GSXML.getChildByTagName(request, GSXML.FORMAT_STRING_ELEM); 594 //String format_string = GSXML.getNodeText(format_element); 595 // Get display tag 596 Element display_format = (Element) format_element.getFirstChild(); 597 598 String collection_config = directory + "collectionConfig.xml"; 599 Document config = this.converter.getDOM(new File(collection_config), "UTF-8"); 600 601 Node current_node = GSXML.getChildByTagName(config, "CollectionConfig"); 602 603 // Get display child 604 if (GSXML.getChildByTagName(current_node, "display") == null) 605 { 606 // well then create a format tag 607 Element display_tag = config.createElement("display"); 608 current_node = (Node) current_node.appendChild(display_tag); 609 } 610 else 611 { 612 current_node = GSXML.getChildByTagName(current_node, "display"); 613 } 614 615 if (GSXML.getChildByTagName(current_node, "format") == null) 616 { 617 // well then create a format tag 618 Element format_tag = config.createElement("format"); 619 current_node.appendChild(format_tag); 620 } 621 622 current_node.replaceChild(config.importNode(display_format, true), GSXML.getChildByTagName(current_node, "format")); 623 624 String new_config = this.converter.getString(config); 625 626 new_config = StringUtils.replace(new_config, "<", "<"); 627 new_config = StringUtils.replace(new_config, ">", ">"); 628 new_config = StringUtils.replace(new_config, """, "\""); 629 630 try 631 { 632 // Write to file (not original! for now) 633 BufferedWriter writer = new BufferedWriter(new FileWriter(collection_config + ".new")); 634 writer.write(new_config); 635 writer.close(); 636 } 637 catch (IOException e) 638 { 639 logger.error("IO Exception " + e); 640 } 641 } 642 643 if (subaction.equals("save")) 644 { 645 Element format_element = (Element) GSXML.getChildByTagName(request, GSXML.FORMAT_STRING_ELEM); 646 Element format_statement = (Element) format_element.getFirstChild(); 647 648 try 649 { 650 // open collectionConfig.xml and read in to w3 Document 651 String collection_config = directory + "collectionConfig.xml"; 652 Document config = this.converter.getDOM(new File(collection_config), "UTF-8"); 653 654 //String tag_name = ""; 655 int k; 656 int index; 657 Element elem; 658 // Try importing entire tree to this.doc so we can add and remove children at ease 659 //Node current_node = this.doc.importNode(GSXML.getChildByTagName(config, "CollectionConfig"),true); 660 Node current_node = GSXML.getChildByTagName(config, "CollectionConfig"); 661 NodeList current_node_list; 662 663 if (service.equals("ClassifierBrowse")) 664 { 665 //tag_name = "browse"; 666 // if CLX then need to look in <classifier> X then <format> 667 // default is <browse><format> 668 669 current_node = GSXML.getChildByTagName(current_node, "browse"); 670 671 // find CLX 672 if (classifier != null) 673 { 674 current_node_list = GSXML.getChildrenByTagName(current_node, "classifier"); 675 index = Integer.parseInt(classifier.substring(2)) - 1; 676 677 // index should be given by X-1 678 current_node = current_node_list.item(index); 679 // what if classifier does not have a format tag? 680 if (GSXML.getChildByTagName(current_node, "format") == null) 681 { 682 // well then create a format tag 683 Element format_tag = config.createElement("format"); 684 current_node.appendChild(format_tag); 685 } 686 } 687 else 688 { 689 // To support all classifiers, set classifier to null? There is the chance here that the format tag does not exist 690 if (GSXML.getChildByTagName(current_node, "format") == null) 691 { 692 // well then create a format tag 693 Element format_tag = config.createElement("format"); 694 current_node.appendChild(format_tag); 695 } 696 } 697 } 698 else if (service.equals("AllClassifierBrowse")) 699 { 700 current_node = GSXML.getChildByTagName(current_node, "browse"); 701 if (GSXML.getChildByTagName(current_node, "format") == null) 702 { 703 // well then create a format tag 704 Element format_tag = config.createElement("format"); 705 current_node.appendChild(format_tag); 706 } 707 } 708 else 709 { 710 // look in <format> with no attributes 711 current_node_list = GSXML.getChildrenByTagName(current_node, "search"); 712 for (k = 0; k < current_node_list.getLength(); k++) 713 { 714 current_node = current_node_list.item(k); 715 // if current_node has no attributes then break 716 elem = (Element) current_node; 717 if (elem.hasAttribute("name") == false) 718 break; 719 } 720 } 721 722 current_node.replaceChild(config.importNode(format_statement, true), GSXML.getChildByTagName(current_node, "format")); 723 724 // Now convert config document to string for writing to file 725 String new_config = this.converter.getString(config); 726 727 new_config = StringUtils.replace(new_config, "<", "<"); 728 new_config = StringUtils.replace(new_config, ">", ">"); 729 new_config = StringUtils.replace(new_config, """, "\""); 730 731 // Write to file (not original! for now) 732 BufferedWriter writer = new BufferedWriter(new FileWriter(collection_config + ".new")); 733 writer.write(new_config); 734 writer.close(); 735 736 } 737 catch (Exception ex) 738 { 739 logger.error("There was an exception " + ex); 740 741 StringWriter sw = new StringWriter(); 742 PrintWriter pw = new PrintWriter(sw, true); 743 ex.printStackTrace(pw); 744 pw.flush(); 745 sw.flush(); 746 logger.error(sw.toString()); 747 } 748 749 } 750 } 751 else if (type.equals(GSXML.REQUEST_TYPE_SECURITY)) 752 { 753 String oid = request.getAttribute("oid"); 754 if (oid.contains(".")) 755 { 756 oid = oid.substring(0, oid.indexOf(".")); 757 } 758 759 ArrayList<String> groups = getPermittedGroups(oid); 760 761 Element groupList = this.doc.createElement(GSXML.GROUP_ELEM + GSXML.LIST_MODIFIER); 762 response.appendChild(groupList); 763 764 for (String groupName : groups) 765 { 766 Element group = this.doc.createElement(GSXML.GROUP_ELEM); 767 groupList.appendChild(group); 768 group.setAttribute(GSXML.NAME_ATT, groupName); 769 } 770 } 771 else if (type.equals(GSXML.REQUEST_TYPE_FORMAT)) 772 { 496 response.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_FORMAT); 773 497 if(_globalFormat != null) 774 498 { 775 response.appendChild(response.getOwnerDocument().importNode(_globalFormat, true)); 776 } 777 } 778 else 779 { // unknown type 780 return super.processMessage(request); 781 782 } 783 return response; 784 } 499 response.appendChild(this.doc.importNode(_globalFormat, true)); 500 } 501 return response; 502 } 503 // unknown type 504 return super.processMessage(request); 505 506 } 507 508 protected Element processSecurityRequest(Element request) { 509 Element response = this.doc.createElement(GSXML.RESPONSE_ELEM); 510 response.setAttribute(GSXML.FROM_ATT, this.cluster_name); 511 response.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_SECURITY); 512 513 String oid = request.getAttribute("oid"); 514 if (oid.contains(".")) 515 { 516 oid = oid.substring(0, oid.indexOf(".")); 517 } 518 519 ArrayList<String> groups = getPermittedGroups(oid); 520 521 Element groupList = this.doc.createElement(GSXML.GROUP_ELEM + GSXML.LIST_MODIFIER); 522 response.appendChild(groupList); 523 524 for (String groupName : groups) 525 { 526 Element group = this.doc.createElement(GSXML.GROUP_ELEM); 527 groupList.appendChild(group); 528 group.setAttribute(GSXML.NAME_ATT, groupName); 529 } 530 return response; 531 } 785 532 786 533 protected ArrayList<String> getPermittedGroups(String oid) … … 933 680 return null; 934 681 } 682 683 protected Element processFormatStringRequest(Element request) { 684 Element response = this.doc.createElement(GSXML.RESPONSE_ELEM); 685 response.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_FORMAT_STRING); 686 response.setAttribute(GSXML.FROM_ATT, this.cluster_name); 687 688 String subaction = request.getAttribute("subaction"); 689 String service = request.getAttribute("service"); 690 691 String classifier = null; 692 if (service.equals("ClassifierBrowse")) 693 { 694 classifier = request.getAttribute("classifier"); 695 } 696 697 // check for version file 698 String directory = new File(GSFile.collectionConfigFile(this.site_home, this.cluster_name)).getParent() + File.separator; 699 700 String version_filename = ""; 701 if (service.equals("ClassifierBrowse")) 702 version_filename = directory + "browse_" + classifier + "_format_statement_version.txt"; 703 else 704 version_filename = directory + "query_format_statement_version.txt"; 705 706 File version_file = new File(version_filename); 707 708 if (subaction.equals("update")) 709 { 710 Element format_element = (Element) GSXML.getChildByTagName(request, GSXML.FORMAT_STRING_ELEM); 711 //String format_string = GSXML.getNodeText(format_element); 712 Element format_statement = (Element) format_element.getFirstChild(); 713 714 String version_number = "1"; 715 BufferedWriter writer; 716 717 try 718 { 719 720 if (version_file.exists()) 721 { 722 // Read version 723 BufferedReader reader = new BufferedReader(new FileReader(version_filename)); 724 version_number = reader.readLine(); 725 int aInt = Integer.parseInt(version_number) + 1; 726 version_number = Integer.toString(aInt); 727 reader.close(); 728 } 729 else 730 { 731 // Create 732 version_file.createNewFile(); 733 writer = new BufferedWriter(new FileWriter(version_filename)); 734 writer.write(version_number); 735 writer.close(); 736 } 737 738 // Write version file 739 String format_statement_filename = ""; 740 741 if (service.equals("ClassifierBrowse")) 742 format_statement_filename = directory + "browse_" + classifier + "_format_statement_v" + version_number + ".txt"; 743 else 744 format_statement_filename = directory + "query_format_statement_v" + version_number + ".txt"; 745 746 // Write format statement 747 String format_string = this.converter.getString(format_statement); //GSXML.xmlNodeToString(format_statement); 748 writer = new BufferedWriter(new FileWriter(format_statement_filename)); 749 writer.write(format_string); 750 writer.close(); 751 752 // Update version number 753 writer = new BufferedWriter(new FileWriter(version_filename)); 754 writer.write(version_number); 755 writer.close(); 756 757 } 758 catch (IOException e) 759 { 760 logger.error("IO Exception " + e); 761 } 762 } 763 764 if (subaction.equals("saveDocument")) 765 { 766 Element format_element = (Element) GSXML.getChildByTagName(request, GSXML.FORMAT_STRING_ELEM); 767 //String format_string = GSXML.getNodeText(format_element); 768 // Get display tag 769 Element display_format = (Element) format_element.getFirstChild(); 770 771 String collection_config = directory + "collectionConfig.xml"; 772 Document config = this.converter.getDOM(new File(collection_config), "UTF-8"); 773 774 Node current_node = GSXML.getChildByTagName(config, "CollectionConfig"); 775 776 // Get display child 777 if (GSXML.getChildByTagName(current_node, "display") == null) 778 { 779 // well then create a format tag 780 Element display_tag = config.createElement("display"); 781 current_node = (Node) current_node.appendChild(display_tag); 782 } 783 else 784 { 785 current_node = GSXML.getChildByTagName(current_node, "display"); 786 } 787 788 if (GSXML.getChildByTagName(current_node, "format") == null) 789 { 790 // well then create a format tag 791 Element format_tag = config.createElement("format"); 792 current_node.appendChild(format_tag); 793 } 794 795 current_node.replaceChild(config.importNode(display_format, true), GSXML.getChildByTagName(current_node, "format")); 796 797 String new_config = this.converter.getString(config); 798 799 new_config = StringUtils.replace(new_config, "<", "<"); 800 new_config = StringUtils.replace(new_config, ">", ">"); 801 new_config = StringUtils.replace(new_config, """, "\""); 802 803 try 804 { 805 // Write to file (not original! for now) 806 BufferedWriter writer = new BufferedWriter(new FileWriter(collection_config + ".new")); 807 writer.write(new_config); 808 writer.close(); 809 } 810 catch (IOException e) 811 { 812 logger.error("IO Exception " + e); 813 } 814 } 815 816 if (subaction.equals("save")) 817 { 818 Element format_element = (Element) GSXML.getChildByTagName(request, GSXML.FORMAT_STRING_ELEM); 819 Element format_statement = (Element) format_element.getFirstChild(); 820 821 try 822 { 823 // open collectionConfig.xml and read in to w3 Document 824 String collection_config = directory + "collectionConfig.xml"; 825 Document config = this.converter.getDOM(new File(collection_config), "UTF-8"); 826 827 //String tag_name = ""; 828 int k; 829 int index; 830 Element elem; 831 // Try importing entire tree to this.doc so we can add and remove children at ease 832 //Node current_node = this.doc.importNode(GSXML.getChildByTagName(config, "CollectionConfig"),true); 833 Node current_node = GSXML.getChildByTagName(config, "CollectionConfig"); 834 NodeList current_node_list; 835 836 if (service.equals("ClassifierBrowse")) 837 { 838 //tag_name = "browse"; 839 // if CLX then need to look in <classifier> X then <format> 840 // default is <browse><format> 841 842 current_node = GSXML.getChildByTagName(current_node, "browse"); 843 844 // find CLX 845 if (classifier != null) 846 { 847 current_node_list = GSXML.getChildrenByTagName(current_node, "classifier"); 848 index = Integer.parseInt(classifier.substring(2)) - 1; 849 850 // index should be given by X-1 851 current_node = current_node_list.item(index); 852 // what if classifier does not have a format tag? 853 if (GSXML.getChildByTagName(current_node, "format") == null) 854 { 855 // well then create a format tag 856 Element format_tag = config.createElement("format"); 857 current_node.appendChild(format_tag); 858 } 859 } 860 else 861 { 862 // To support all classifiers, set classifier to null? There is the chance here that the format tag does not exist 863 if (GSXML.getChildByTagName(current_node, "format") == null) 864 { 865 // well then create a format tag 866 Element format_tag = config.createElement("format"); 867 current_node.appendChild(format_tag); 868 } 869 } 870 } 871 else if (service.equals("AllClassifierBrowse")) 872 { 873 current_node = GSXML.getChildByTagName(current_node, "browse"); 874 if (GSXML.getChildByTagName(current_node, "format") == null) 875 { 876 // well then create a format tag 877 Element format_tag = config.createElement("format"); 878 current_node.appendChild(format_tag); 879 } 880 } 881 else 882 { 883 // look in <format> with no attributes 884 current_node_list = GSXML.getChildrenByTagName(current_node, "search"); 885 for (k = 0; k < current_node_list.getLength(); k++) 886 { 887 current_node = current_node_list.item(k); 888 // if current_node has no attributes then break 889 elem = (Element) current_node; 890 if (elem.hasAttribute("name") == false) 891 break; 892 } 893 } 894 895 current_node.replaceChild(config.importNode(format_statement, true), GSXML.getChildByTagName(current_node, "format")); 896 897 // Now convert config document to string for writing to file 898 String new_config = this.converter.getString(config); 899 900 new_config = StringUtils.replace(new_config, "<", "<"); 901 new_config = StringUtils.replace(new_config, ">", ">"); 902 new_config = StringUtils.replace(new_config, """, "\""); 903 904 // Write to file (not original! for now) 905 BufferedWriter writer = new BufferedWriter(new FileWriter(collection_config + ".new")); 906 writer.write(new_config); 907 writer.close(); 908 909 } 910 catch (Exception ex) 911 { 912 logger.error("There was an exception " + ex); 913 914 StringWriter sw = new StringWriter(); 915 PrintWriter pw = new PrintWriter(sw, true); 916 ex.printStackTrace(pw); 917 pw.flush(); 918 sw.flush(); 919 logger.error(sw.toString()); 920 } 921 922 } 923 924 return response; 925 } 935 926 } -
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/collection/ServiceCluster.java
r25973 r26446 32 32 import org.greenstone.gsdl3.util.GSPath; 33 33 import org.greenstone.gsdl3.util.GSXML; 34 import org.greenstone.gsdl3.util.SimpleMacroResolver; 34 35 import org.greenstone.gsdl3.util.UserContext; 35 36 import org.greenstone.gsdl3.util.XMLConverter; … … 42 43 * Implements ModuleInterface. Contains a list of services provided by the cluster, along with metadata about the cluster itself. 43 44 * a collection is a special type of cluster 44 * @author <a href="mailto:[email protected]">Katherine Don</a>45 * @version $Revision$46 45 * @see ModuleInterface 47 46 */ … … 61 60 /** The name of the cluster - for a collection, this is the collection name */ 62 61 protected String cluster_name = null; 63 /** collection type : mg, mgpp or lucene */ 64 protected String col_type = ""; 65 /** database type : gdbm, jdbm or sqlite */ 66 protected String db_type = ""; 67 62 68 63 /** a reference to the message router */ 69 64 protected MessageRouter router = null; … … 85 80 /** XML converter for String to DOM and vice versa */ 86 81 protected XMLConverter converter = null; 82 /** a MacroResolver for resolving macros in displayItems */ 83 protected SimpleMacroResolver macro_resolver = null; 87 84 88 85 /** container doc for description elements */ … … 92 89 /** list of metadata - all metadata, regardless of language goes in here */ 93 90 protected Element metadata_list = null; 94 /** language specific stuff*/95 //protected Element lang_specific_metadata_list = null; 91 /** language specific display items */ 92 96 93 protected Element display_item_list = null; 94 /** default values for servlet params */ 95 protected Element library_param_list = null; 97 96 /** the element that will have any descriptions passed back in */ 98 97 protected Element description = null; 99 98 100 99 /** list of plugin */ 101 protected Element plugin_item_list = null;100 //protected Element plugin_item_list = null; 102 101 103 102 protected Element _globalFormat = null; … … 139 138 this.service_name_map = new HashMap<String, String>(); 140 139 this.converter = new XMLConverter(); 140 this.macro_resolver = new SimpleMacroResolver(); 141 141 this.doc = this.converter.newDOM(); 142 142 this.description = this.doc.createElement(GSXML.CLUSTER_ELEM); 143 143 this.display_item_list = this.doc.createElement(GSXML.DISPLAY_TEXT_ELEM + GSXML.LIST_MODIFIER); 144 144 this.metadata_list = this.doc.createElement(GSXML.METADATA_ELEM + GSXML.LIST_MODIFIER); 145 this.plugin_item_list = this.doc.createElement(GSXML.PLUGIN_ELEM + GSXML.LIST_MODIFIER); 145 this.library_param_list = this.doc.createElement("libraryParamList"); 146 this.service_list = this.doc.createElement(GSXML.SERVICE_ELEM + GSXML.LIST_MODIFIER); 147 //this.plugin_item_list = this.doc.createElement(GSXML.PLUGIN_ELEM + GSXML.LIST_MODIFIER); 146 148 } 147 149 … … 156 158 * parsed. This method will work with any subclass. 157 159 * 160 * This is called by ServiceCluster itself when asked to do a reconfigure 158 161 * @return true if configure successful, false otherwise. 159 162 */ … … 167 170 } 168 171 logger.info("configuring service cluster"); 172 macro_resolver.addMacro("_httpsite_", this.site_http_address); 169 173 // read the site configuration file 170 174 File config_file = new File(GSFile.siteConfigFile(this.site_home)); … … 187 191 Element sc = GSXML.getNamedElement(cluster_list, GSXML.CLUSTER_ELEM, GSXML.NAME_ATT, this.cluster_name); 188 192 193 // this is probably a reconfigure, so clear all previous info 194 clearServices(); 195 clearLocalData(); 189 196 return this.configure(sc); 190 197 } 191 198 199 /** this is called by configure(), but also by MR when it is loading up all the service clusters */ 192 200 public boolean configure(Element service_cluster_info) 193 201 { 194 202 configureLocalData(service_cluster_info); 203 // //get the plugin info 204 // Element import_list = (Element) GSXML.getChildByTagName(service_cluster_info, GSXML.IMPORT_ELEM); 205 // if (import_list != null) 206 // { 207 // Element plugin_list = (Element) GSXML.getChildByTagName(service_cluster_info, GSXML.PLUGIN_ELEM + GSXML.LIST_MODIFIER); 208 // if (plugin_list != null) 209 // { 210 // if (!addPlugins(plugin_list)) 211 // { 212 213 // logger.error("couldn't configure the plugins"); 214 // } 215 // } 216 // } 217 218 // do the service racks 219 // empty the service map in case this is a reconfigure 220 //clearServices(); 221 Element service_rack_list = (Element) GSXML.getChildByTagName(service_cluster_info, GSXML.SERVICE_CLASS_ELEM + GSXML.LIST_MODIFIER); 222 logger.error("cluster service rack list ="); 223 logger.error(GSXML.xmlNodeToString(service_rack_list)); 224 if (service_rack_list == null) 225 { 226 // is this an error? could you ever have a service cluster 227 // without service racks??? 228 logger.error(cluster_name+" has no service racks!!"); 229 } 230 else 231 { 232 233 if (!configureServiceRackList(service_rack_list, null)) 234 { 235 logger.error("couldn't configure "+cluster_name+" service racks!!"); 236 return false; 237 } 238 } 239 240 return true; 241 } 242 243 protected void configureLocalData(Element service_cluster_info) { 195 244 // get the metadata - for now just add it to the list 196 245 Element meta_list = (Element) GSXML.getChildByTagName(service_cluster_info, GSXML.METADATA_ELEM + GSXML.LIST_MODIFIER); … … 208 257 if (display_list != null) 209 258 { 259 resolveMacros(display_list); 210 260 if (!addDisplayItems(display_list)) 211 261 { … … 215 265 } 216 266 217 //get the plugin info 218 Element import_list = (Element) GSXML.getChildByTagName(service_cluster_info, GSXML.IMPORT_ELEM); 219 if (import_list != null) 220 { 221 Element plugin_list = (Element) GSXML.getChildByTagName(service_cluster_info, GSXML.PLUGIN_ELEM + GSXML.LIST_MODIFIER); 222 if (plugin_list != null) 223 { 224 if (!addPlugins(plugin_list)) 225 { 226 227 logger.error("couldn't configure the plugins"); 228 } 229 } 230 } 231 232 // do the service racks 233 // empty the service map in case this is a reconfigure 234 clearServices(); 235 Element service_rack_list = (Element) GSXML.getChildByTagName(service_cluster_info, GSXML.SERVICE_CLASS_ELEM + GSXML.LIST_MODIFIER); 236 if (service_rack_list == null) 237 { 238 // is this an error? could you ever have a service cluster 239 // without service racks??? 240 logger.error("cluster has no service racks!!"); 241 } 242 else 243 { 244 245 if (!configureServiceRackList(service_rack_list, null)) 246 { 247 logger.error("couldn't configure the service racks!!"); 248 return false; 249 } 250 } 251 252 return true; 253 } 254 267 // get the servlet params 268 Element param_list = (Element) GSXML.getChildByTagName(service_cluster_info, "libraryParamList"); 269 if (param_list != null) { 270 if (!addLibraryParams(param_list)) { 271 logger.error("couldn't configure the library param list"); 272 } 273 } 274 275 } 255 276 /** 256 277 * adds metadata from a metadataList into the metadata_list xml … … 271 292 return true; 272 293 } 273 294 /** adds an individual metadata element into the list */ 295 protected boolean addMetadata(String name, String value) { 296 return GSXML.addMetadata(this.doc, this.metadata_list, name, value); 297 } 298 299 /** in displayItemList, end up with the following for each named displayItem 300 <displayItem name=""> 301 <displayItem name="" lang="">value</displayItem> 302 <displayItem name="" lang="">value</displayItem> 303 </displayItem> 304 */ 274 305 protected boolean addDisplayItems(Element display_list) 275 306 { … … 305 336 } 306 337 307 protected boolean addPlugins(Element plugin_list) 308 { 309 if (plugin_list == null) 310 return false; 311 NodeList pluginNodes = plugin_list.getElementsByTagName(GSXML.PLUGIN_ELEM); 312 if (pluginNodes.getLength() > 0) 313 { 314 for (int k = 0; k < pluginNodes.getLength(); k++) 315 { 316 this.plugin_item_list.appendChild(this.doc.importNode(pluginNodes.item(k), true)); 317 } 318 } 319 338 // protected boolean addPlugins(Element plugin_list) 339 // { 340 // if (plugin_list == null) 341 // return false; 342 // NodeList pluginNodes = plugin_list.getElementsByTagName(GSXML.PLUGIN_ELEM); 343 // if (pluginNodes.getLength() > 0) 344 // { 345 // for (int k = 0; k < pluginNodes.getLength(); k++) 346 // { 347 // this.plugin_item_list.appendChild(this.doc.importNode(pluginNodes.item(k), true)); 348 // } 349 // } 350 351 // return true; 352 // } 353 protected boolean resolveMacros(Element display_list) 354 { 355 if (display_list == null) 356 return false; 357 NodeList displaynodes = display_list.getElementsByTagName(GSXML.DISPLAY_TEXT_ELEM); 358 if (displaynodes.getLength() > 0) 359 { 360 //String http_site = this.site_http_address; 361 //String http_collection = this.site_http_address + "/collect/" + this.cluster_name; 362 for (int k = 0; k < displaynodes.getLength(); k++) 363 { 364 Element d = (Element) displaynodes.item(k); 365 String text = GSXML.getNodeText(d); 366 text= macro_resolver.resolve(text); 367 //text = StringUtils.replace(text, "_httpsite_", http_site); 368 //text = StringUtils.replace(text, "_httpcollection_", http_collection); 369 GSXML.setNodeText(d, text); 370 } 371 } 320 372 return true; 321 373 } 322 374 375 /** 376 * adds library params from libraryParamList into library_param_list xml 377 */ 378 protected boolean addLibraryParams(Element param_list) 379 { 380 if (param_list == null) 381 return false; 382 NodeList paramnodes = param_list.getElementsByTagName(GSXML.PARAM_ELEM); 383 if (paramnodes.getLength() > 0) 384 { 385 for (int k = 0; k < paramnodes.getLength(); k++) 386 { 387 this.library_param_list.appendChild(this.doc.importNode(paramnodes.item(k), true)); 388 } 389 } 390 391 return true; 392 } 323 393 protected void clearServices() 324 394 { 395 cleanUp(); 325 396 service_map.clear(); 397 service_name_map.clear(); 326 398 this.service_list = this.doc.createElement(GSXML.SERVICE_ELEM + GSXML.LIST_MODIFIER); 327 399 } 328 400 401 protected void clearLocalData() { 402 this.description = this.doc.createElement(GSXML.CLUSTER_ELEM); 403 this.display_item_list = this.doc.createElement(GSXML.DISPLAY_TEXT_ELEM + GSXML.LIST_MODIFIER); 404 this.metadata_list = this.doc.createElement(GSXML.METADATA_ELEM + GSXML.LIST_MODIFIER); 405 this.library_param_list = this.doc.createElement("libraryParamList"); 406 407 } 329 408 /** 330 409 * creates and configures all the services - extra_info is some more xml … … 555 634 Element description = (Element) this.description.cloneNode(false); 556 635 // set collection type : mg, mgpp, lucene or solr 557 description.setAttribute(GSXML.TYPE_ATT, col_type);558 description.setAttribute(GSXML.DB_TYPE_ATT, db_type);636 //description.setAttribute(GSXML.TYPE_ATT, col_type); 637 //description.setAttribute(GSXML.DB_TYPE_ATT, db_type); 559 638 560 639 response.appendChild(description); … … 566 645 description.appendChild(this.service_list); 567 646 description.appendChild(this.metadata_list); 568 description.appendChild(this.plugin_item_list); 647 description.appendChild(this.library_param_list); 648 //description.appendChild(this.plugin_item_list); 569 649 return response; 570 650 } … … 586 666 else if (info.equals(GSXML.METADATA_ELEM + GSXML.LIST_MODIFIER)) 587 667 { 588 description.appendChild( metadata_list);668 description.appendChild(this.metadata_list); 589 669 } 590 670 else if (info.equals(GSXML.DISPLAY_TEXT_ELEM + GSXML.LIST_MODIFIER)) … … 592 672 addAllDisplayInfo(description, lang); 593 673 } 594 else if (info.equals( GSXML.PLUGIN_ELEM + GSXML.LIST_MODIFIER))674 else if (info.equals("libraryParamlist")) 595 675 { 596 description.appendChild(plugin_item_list);676 description.appendChild(this.library_param_list); 597 677 } 598 678 } … … 820 900 return addMetadata(metadata_list); 821 901 } 822 else if (subset.equals(GSXML.PLUGIN_ELEM + GSXML.LIST_MODIFIER))823 {824 this.plugin_item_list = this.doc.createElement(GSXML.PLUGIN_ELEM + GSXML.LIST_MODIFIER);825 Element import_list = (Element) GSXML.getChildByTagName(cluster_config_elem, GSXML.IMPORT_ELEM);826 if (import_list != null)827 {828 Element plugin_item_list = (Element) GSXML.getChildByTagName(cluster_config_elem, GSXML.PLUGIN_ELEM + GSXML.LIST_MODIFIER);829 return addPlugins(plugin_item_list);830 }831 else832 return false;833 }902 // else if (subset.equals(GSXML.PLUGIN_ELEM + GSXML.LIST_MODIFIER)) 903 // { 904 // this.plugin_item_list = this.doc.createElement(GSXML.PLUGIN_ELEM + GSXML.LIST_MODIFIER); 905 // Element import_list = (Element) GSXML.getChildByTagName(cluster_config_elem, GSXML.IMPORT_ELEM); 906 // if (import_list != null) 907 // { 908 // Element plugin_item_list = (Element) GSXML.getChildByTagName(cluster_config_elem, GSXML.PLUGIN_ELEM + GSXML.LIST_MODIFIER); 909 // return addPlugins(plugin_item_list); 910 // } 911 // else 912 // return false; 913 // } 834 914 else 835 915 { … … 847 927 { // for each key 848 928 Element m = (Element) items.item(i); 849 // find 929 // findthe child with the correct language 850 930 Element new_m = GSXML.getNamedElement(m, GSXML.DISPLAY_TEXT_ELEM, GSXML.LANG_ATT, lang); 851 931 if (new_m == null && lang != DEFAULT_LANG) -
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/collection/XMLCollection.java
r25465 r26446 48 48 49 49 //plugin stuff 50 Element import_list = (Element)GSXML.getChildByTagName(coll_config_xml, GSXML.IMPORT_ELEM);51 if (import_list != null)52 {53 Element plugin_list = (Element)GSXML.getChildByTagName(import_list, GSXML.PLUGIN_ELEM+GSXML.LIST_MODIFIER);54 addPlugins(plugin_list);55 }50 // Element import_list = (Element)GSXML.getChildByTagName(coll_config_xml, GSXML.IMPORT_ELEM); 51 // if (import_list != null) 52 // { 53 // Element plugin_list = (Element)GSXML.getChildByTagName(import_list, GSXML.PLUGIN_ELEM+GSXML.LIST_MODIFIER); 54 // addPlugins(plugin_list); 55 // } 56 56 57 57 // are we a private collection?? … … 100 100 description.appendChild(this.service_list); 101 101 description.appendChild(this.metadata_list); 102 description.appendChild(this. plugin_item_list);102 description.appendChild(this.library_param_list); 103 103 description.appendChild(this.document_list); 104 104 return response; … … 122 122 } else if (info.equals(GSXML.DOCUMENT_ELEM+GSXML.LIST_MODIFIER)) { 123 123 description.appendChild(this.document_list); 124 } else if (info.equals(GSXML.PLUGIN_ELEM+GSXML.LIST_MODIFIER)) { 125 description.appendChild(this.plugin_item_list); 124 // } else if (info.equals(GSXML.PLUGIN_ELEM+GSXML.LIST_MODIFIER)) { 125 // description.appendChild(this.plugin_item_list); 126 // } 127 } else if (info.equals("libraryParamlist")) { 128 129 description.appendChild(this.library_param_list); 126 130 } 127 131 128 132 } 129 133 }
Note:
See TracChangeset
for help on using the changeset viewer.