- Timestamp:
- 2010-03-15T10:57:35+13:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/OAIPMH.java
r16871 r21782 61 61 protected String site_name = ""; 62 62 protected String coll_name = ""; 63 protected Element coll_config_xml = null; 64 63 65 64 /** constructor */ 66 65 public OAIPMH() { … … 72 71 this.coll_db.closeDatabase(); 73 72 } 74 /** configure this service */ 73 /** configure this service 74 info is the OAIPMH service rack from collectionConfig.xml, and 75 extra_info is buildConfig.xml */ 75 76 public boolean configure(Element info, Element extra_info) { 76 77 if (!super.configure(info, extra_info)){ … … 80 81 81 82 //get the names from ServiceRack.java 82 site_name = this.router.getSiteName(); 83 coll_name = this.cluster_name; 84 //get the collection-specific configurations from collectionConfig.xml 85 coll_config_xml = OAIXML.getCollectionConfigXML(site_name, coll_name); 83 this.site_name = this.router.getSiteName(); 84 this.coll_name = this.cluster_name; 86 85 87 86 logger.info("Configuring OAIPMH..."); 88 // this call passes the indexStem in of ServiceRack element in buildConfig.xml to the super class. 87 89 88 this.config_info = info; 90 89 91 // the index stem is either specified in the buildConfig.xml file or uses the collection name 92 Element index_stem_elem = (Element) GSXML.getChildByTagName(info, GSXML.INDEX_STEM_ELEM); 93 String index_stem = null; 94 if (index_stem_elem != null) { 95 index_stem = index_stem_elem.getAttribute(GSXML.NAME_ATT); 96 } 90 // the index stem is either specified in the buildConfig.xml file (extra_info) or uses the collection name 91 Element metadata_list = (Element) GSXML.getChildByTagName(extra_info, GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER); 92 String index_stem = ""; 93 String infodb_type = ""; 94 if (metadata_list != null) { 95 96 Element index_stem_elem = (Element) GSXML.getNamedElement(metadata_list, GSXML.METADATA_ELEM, GSXML.NAME_ATT, "indexStem"); 97 98 if (index_stem_elem != null) { 99 index_stem = GSXML.getNodeText(index_stem_elem); 100 } 101 102 Element infodb_type_elem = (Element) GSXML.getNamedElement(metadata_list, GSXML.METADATA_ELEM, GSXML.NAME_ATT, "infodbType"); 103 if (infodb_type_elem != null) { 104 infodb_type = GSXML.getNodeText(infodb_type_elem); 105 } 106 107 } 108 97 109 if (index_stem == null || index_stem.equals("")) { 98 110 index_stem = this.cluster_name; 99 111 } 100 101 // find out what kind of database we have 102 Element database_type_elem = (Element) GSXML.getChildByTagName(info, GSXML.DATABASE_TYPE_ELEM); 103 String database_type = null; 104 if (database_type_elem != null) { 105 database_type = database_type_elem.getAttribute(GSXML.NAME_ATT); 106 } 107 if (database_type == null || database_type.equals("")) { 108 database_type = "gdbm"; // the default 109 } 110 coll_db = new SimpleCollectionDatabase(database_type); 112 if (infodb_type == null || infodb_type.equals("")) { 113 infodb_type = "gdbm"; // the default 114 } 115 116 coll_db = new SimpleCollectionDatabase(infodb_type); 111 117 if (coll_db == null) { 112 logger.error("Couldn't create the collection database of type "+ database_type);118 logger.error("Couldn't create the collection database of type "+infodb_type); 113 119 return false; 114 120 } 115 121 116 122 // Open database for querying 117 String coll_db_file = GSFile.collectionDatabaseFile(this.site_home, this.cluster_name, index_stem, database_type);123 String coll_db_file = GSFile.collectionDatabaseFile(this.site_home, this.cluster_name, index_stem, infodb_type); 118 124 if (!this.coll_db.openDatabase(coll_db_file, SimpleCollectionDatabase.READ)) { 119 125 logger.error("Could not open collection database!"); … … 395 401 return OAIXML.getResponse(OAIXML.createErrorElement(OAIXML.CANNOT_DISSEMINATE_FORMAT, "")); 396 402 } 397 // Another way of doing the same job!398 // HashMap prefix_map = OAIXML.getChildrenMapByTagName(coll_config_xml, OAIXML.METADATA_PREFIX);399 // if(!prefix_map.contains(prefix)) {400 // logger.error("metadata prefix is not supported.");401 // return OAIXML.getResponse(OAIXML.createErrorElement(OAIXML.CANNOT_DISSEMINATE_FORMAT, ""));402 // }403 403 404 404 //get a list of identifiers (it contains a list of strings) … … 452 452 */ 453 453 private Element getMetadataFormatElement(String prefix) { 454 Element oai = (Element)GSXML.getChildByTagName(this.coll_config_xml, OAIXML.OAI); 455 Element list_meta_format = (Element)GSXML.getChildByTagName(oai, OAIXML.LIST_METADATA_FORMATS); 454 Element list_meta_format = (Element)GSXML.getChildByTagName(this.config_info, OAIXML.LIST_METADATA_FORMATS); 456 455 Element metadata_format = GSXML.getNamedElement(list_meta_format, OAIXML.METADATA_FORMAT, OAIXML.METADATA_PREFIX, prefix); 457 456 return metadata_format; … … 537 536 } 538 537 539 NodeList meta_list = getMetadataFormatList( this.coll_config_xml);538 NodeList meta_list = getMetadataFormatList(); 540 539 if (meta_list == null || meta_list.getLength() == 0) { 541 540 logger.error("No metadata format is present in collectionConfig.xml"); … … 569 568 * Currently, it will only contain one metadata format: oai_dc 570 569 */ 571 protected NodeList getMetadataFormatList(Element coll_config_xml) { 572 Element oai_elem = (Element)GSXML.getChildByTagName(coll_config_xml, OAIXML.OAI); 573 Element list_meta_formats = (Element)GSXML.getChildByTagName(oai_elem, OAIXML.LIST_METADATA_FORMATS); 570 protected NodeList getMetadataFormatList() { 571 Element list_meta_formats = (Element)GSXML.getChildByTagName(this.config_info, OAIXML.LIST_METADATA_FORMATS); 574 572 return GSXML.getChildrenByTagName(list_meta_formats, OAIXML.METADATA_FORMAT); 575 573 } … … 684 682 } 685 683 if(key.equals(second_name)) { 686 684 String meta_value = info.getInfo(key); 687 685 name_value[0] = first_name; 688 689 686 name_value[1] = meta_value; 687 return name_value; 690 688 } 691 689 } … … 698 696 for(int i=0; i<metadata_names.length; i++) { 699 697 String[] name_value = getMetadata(info, metadata_names[i]); 700 if(name_value != null) { 698 if(name_value != null) { 701 699 map.put(name_value[0], name_value[1]); 702 700 empty_map = false;
Note:
See TracChangeset
for help on using the changeset viewer.