Changeset 27672 for main/trunk
- Timestamp:
- 2013-06-20T14:02:39+12:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/core/OAIReceptionist.java
r25635 r27672 26 26 /** Instead of a config_params object, only a site_name is needed by oai receptionist. */ 27 27 protected String site_name = null; 28 /** The unique repository identifier */ 29 protected String repository_id = null; 30 28 31 /** container Document to create XML Nodes for requests sent to message router 29 32 * Not used for response … … 43 46 protected ModuleInterface mr = null; 44 47 48 49 // Some of the data/responses will not change while the servlet is running, so 50 // we can cache them 51 52 /** A list of all the collections available to this OAI server */ 53 protected NodeList collection_list = null; 54 55 /** The identify response */ 56 protected Element identify_response = null; 57 45 58 public OAIReceptionist() { 46 59 this.converter = new XMLConverter(); … … 74 87 resume_after = getResumeAfter(); 75 88 89 repository_id = getRepositoryId(); 90 collection_list = getOAICollectionList(); 91 76 92 //clear out expired resumption tokens stored in OAIResumptionToken.xml 77 93 OAIXML.init(); … … 190 206 return -1; 191 207 } 208 private String getRepositoryId() { 209 Element ri = (Element)GSXML.getChildByTagName(oai_config, OAIXML.REPOSITORY_ID); 210 if (ri != null) { 211 return GSXML.getNodeText(ri); 212 } 213 return ""; 214 } 192 215 /** method to compose a set element 193 216 */ … … 198 221 Element list_sets_elem = OAIXML.createElement(OAIXML.LIST_SETS); 199 222 200 //ask the message router for a list of oai collections 201 NodeList oai_coll = getOAICollectionList(); 202 int oai_coll_size = oai_coll.getLength(); 223 int oai_coll_size = collection_list.getLength(); 203 224 if (oai_coll_size == 0) { 204 225 return getMessage(list_sets_elem); … … 229 250 //no resumeptionToken stored in OAIConfig.xml. 230 251 //As long as the verb is 'ListSets', we ignore the rest of the parameters 231 getSets(list_sets_elem, oai_coll, 0, oai_coll_size);252 getSets(list_sets_elem, collection_list, 0, oai_coll_size); 232 253 return getMessage(list_sets_elem); 233 254 } 234 255 235 256 //append required sets to list_sets_elem (may be a complete or incomplete list) 236 getSets(list_sets_elem, oai_coll, 0, smaller);257 getSets(list_sets_elem, collection_list, 0, smaller); 237 258 238 259 if(oai_coll_size > resume_after) { … … 272 293 //Yes, we are. 273 294 //append required sets to list_sets_elem (list is complete) 274 getSets(list_sets_elem, oai_coll, cursor, oai_coll_size);295 getSets(list_sets_elem, collection_list, cursor, oai_coll_size); 275 296 //An incomplete list is sent; append a resumptionToken element 276 297 token_elem = createResumptionTokenElement(oai_coll_size, cursor, -1, false); … … 279 300 //No, we are not. 280 301 //append required sets to list_sets_elem (list is incomplete) 281 getSets(list_sets_elem, oai_coll, cursor, cursor + resume_after);302 getSets(list_sets_elem, collection_list, cursor, cursor + resume_after); 282 303 token_elem = createResumptionTokenElement(oai_coll_size, cursor, cursor + resume_after, true); 283 304 //store this token … … 377 398 378 399 //ask the message router for a list of oai collections 379 NodeList oai_coll =getOAICollectionList();380 int oai_coll_size = oai_coll.getLength();400 //NodeList oai_coll = collection_list; //getOAICollectionList(); 401 int oai_coll_size = collection_list.getLength(); 381 402 if (oai_coll_size == 0) { 382 403 logger.info("returned oai collection list is empty"); … … 396 417 397 418 for(int i=0; i<oai_coll_size; i++) { 398 if(set_spec_str.equals(((Element) oai_coll.item(i)).getAttribute(OAIXML.NAME))) {419 if(set_spec_str.equals(((Element)collection_list.item(i)).getAttribute(OAIXML.NAME))) { 399 420 set_supported = true; 400 421 } … … 452 473 } 453 474 } 454 String full_name = ((Element) oai_coll.item(i)).getAttribute(OAIXML.NAME);475 String full_name = ((Element)collection_list.item(i)).getAttribute(OAIXML.NAME); 455 476 coll_name = full_name.substring(full_name.indexOf(":") + 1); 456 477 req.setAttribute(OAIXML.TO, coll_name + "/" + verb); … … 589 610 590 611 //ask the message router for a list of oai collections 591 NodeList oai_coll = getOAICollectionList();592 int oai_coll_size = oai_coll.getLength();612 //NodeList oai_coll = getOAICollectionList(); 613 int oai_coll_size = collection_list.getLength(); 593 614 if (oai_coll_size == 0) { 594 615 logger.info("returned oai collection list is empty"); … … 610 631 611 632 for(int i=0; i<oai_coll_size; i++) { 612 if(set_spec_str.equals(((Element) oai_coll.item(i)).getAttribute(OAIXML.NAME))) {633 if(set_spec_str.equals(((Element)collection_list.item(i)).getAttribute(OAIXML.NAME))) { 613 634 set_supported = true; 614 635 } … … 701 722 } 702 723 } 703 String full_name = ((Element) oai_coll.item(i)).getAttribute(OAIXML.NAME);724 String full_name = ((Element)collection_list.item(i)).getAttribute(OAIXML.NAME); 704 725 coll_name = full_name.substring(full_name.indexOf(":") + 1); 705 726 req.setAttribute(OAIXML.TO, coll_name + "/" + verb); … … 832 853 //this is requesting metadata formats for the whole repository 833 854 //read the oaiConfig.xml file, return the metadata formats specified there. 834 Element oai_config = OAIXML.getOAIConfigXML(); 835 if (oai_config == null) { 836 return getMessage(OAIXML.createErrorElement(OAIXML.ERROR, OAIXML.SERVICE_UNAVAILABLE)); 837 } else { 838 Element format_list = (Element)GSXML.getChildByTagName(oai_config, OAIXML.LIST_METADATA_FORMATS); 839 if(format_list == null) { 840 logger.error("OAIConfig.xml must contain the supported metadata formats"); 841 return getMessage(list_metadata_formats); 855 Element format_list = (Element)GSXML.getChildByTagName(oai_config, OAIXML.LIST_METADATA_FORMATS); 856 if(format_list == null) { 857 logger.error("OAIConfig.xml must contain the supported metadata formats"); 858 return getMessage(list_metadata_formats); 859 } 860 NodeList formats = format_list.getElementsByTagName(OAIXML.METADATA_FORMAT); 861 for(int i=0; i<formats.getLength(); i++) { 862 Element meta_fmt = OAIXML.createElement(OAIXML.METADATA_FORMAT); 863 Element first_meta_format = (Element)formats.item(i); 864 //the element also contains mappings, but we don't want them 865 meta_fmt.appendChild(meta_fmt.getOwnerDocument().importNode(GSXML.getChildByTagName(first_meta_format, OAIXML.METADATA_PREFIX), true)); 866 meta_fmt.appendChild(meta_fmt.getOwnerDocument().importNode(GSXML.getChildByTagName(first_meta_format, OAIXML.SCHEMA), true)); 867 meta_fmt.appendChild(meta_fmt.getOwnerDocument().importNode(GSXML.getChildByTagName(first_meta_format, OAIXML.METADATA_NAMESPACE), true)); 868 list_metadata_formats.appendChild(meta_fmt); 842 869 } 843 NodeList formats = format_list.getElementsByTagName(OAIXML.METADATA_FORMAT); 844 for(int i=0; i<formats.getLength(); i++) { 845 Element meta_fmt = OAIXML.createElement(OAIXML.METADATA_FORMAT); 846 Element first_meta_format = (Element)formats.item(i); 847 //the element also contains mappings, but we don't want them 848 meta_fmt.appendChild(meta_fmt.getOwnerDocument().importNode(GSXML.getChildByTagName(first_meta_format, OAIXML.METADATA_PREFIX), true)); 849 meta_fmt.appendChild(meta_fmt.getOwnerDocument().importNode(GSXML.getChildByTagName(first_meta_format, OAIXML.SCHEMA), true)); 850 meta_fmt.appendChild(meta_fmt.getOwnerDocument().importNode(GSXML.getChildByTagName(first_meta_format, OAIXML.METADATA_NAMESPACE), true)); 851 list_metadata_formats.appendChild(meta_fmt); 852 } 853 return getMessage(list_metadata_formats); 854 } 870 return getMessage(list_metadata_formats); 855 871 856 } else if (params.getLength() > 1) { 872 873 } 874 875 if (params.getLength() > 1) { 857 876 //Bad argument. Can't be more than one parameters for ListMetadataFormats verb 858 877 return getMessage(OAIXML.createErrorElement(OAIXML.BAD_ARGUMENT, "")); 859 } else { 860 // This is a request for the metadata of a particular item with an identifier 878 } 879 880 // This is a request for the metadata of a particular item with an identifier 861 881 /**the request xml is in the form: <request> 862 882 * <param name=.../> … … 904 924 return converter.nodeToElement(result_node); 905 925 } 906 } 907 908 } 926 927 928 } 929 930 909 931 private void appendParam(Element req, String name, String value) { 910 932 Element param = req.getOwnerDocument().createElement(OAIXML.PARAM); … … 913 935 req.appendChild(param); 914 936 } 915 private void copyElement(Element identify, String tag_name) { 916 Element from_repository_name = (Element)GSXML.getChildByTagName(oai_config, tag_name); 917 if(from_repository_name != null) { 918 Element this_repository_name = OAIXML.createElement(tag_name); 919 GSXML.setNodeText(this_repository_name, GSXML.getNodeText(from_repository_name)); 920 identify.appendChild(this_repository_name); 921 } 922 } 937 private void copyNamedElementfromConfig(Element to_elem, String element_name) { 938 Element original_element = (Element)GSXML.getChildByTagName(oai_config, element_name); 939 if(original_element != null) { 940 copyNode(to_elem, original_element); 941 } 942 } 943 944 private void copyNode(Element to_elem, Node original_element) { 945 to_elem.appendChild(to_elem.getOwnerDocument().importNode(original_element, true)); 946 947 } 948 923 949 private Element doIdentify() { 924 950 //The validation for this verb has been done in OAIServer.validate(). So no bother here. 925 951 logger.info(""); 952 if (this.identify_response != null) { 953 // we have already created it 954 return getMessage(this.identify_response); 955 } 926 956 927 957 Element identify = OAIXML.createElement(OAIXML.IDENTIFY); 928 958 //do the repository name 929 copy Element(identify, OAIXML.REPOSITORY_NAME);959 copyNamedElementfromConfig(identify, OAIXML.REPOSITORY_NAME); 930 960 //do the baseurl 931 copy Element(identify, OAIXML.BASE_URL);961 copyNamedElementfromConfig(identify, OAIXML.BASE_URL); 932 962 //do the protocol version 933 copy Element(identify, OAIXML.PROTOCOL_VERSION);963 copyNamedElementfromConfig(identify, OAIXML.PROTOCOL_VERSION); 934 964 935 965 //There can be more than one admin email according to the OAI specification … … 941 971 } 942 972 for (int i=0; i<num_admin; i++) { 943 copy Element(identify, OAIXML.ADMIN_EMAIL);973 copyNode(identify, admin_emails.item(i)); 944 974 } 945 975 … … 947 977 //send request to mr to search through the earliest datestamp amongst all oai collections in the repository. 948 978 //ask the message router for a list of oai collections 949 NodeList oai_coll = getOAICollectionList();950 long earliestDatestamp = getEarliestDateStamp( oai_coll);979 //NodeList oai_coll = getOAICollectionList(); 980 long earliestDatestamp = getEarliestDateStamp(collection_list); 951 981 String earliestDatestamp_str = OAIXML.getTime(earliestDatestamp); 952 982 Element earliestDatestamp_elem = OAIXML.createElement(OAIXML.EARLIEST_DATESTAMP); … … 955 985 956 986 //do the deletedRecord 957 copy Element(identify, OAIXML.DELETED_RECORD);987 copyNamedElementfromConfig(identify, OAIXML.DELETED_RECORD); 958 988 //do the granularity 959 copyElement(identify, OAIXML.GRANULARITY); 960 989 copyNamedElementfromConfig(identify, OAIXML.GRANULARITY); 990 991 // output the oai identifier 992 Element description = OAIXML.createElement(OAIXML.DESCRIPTION); 993 identify.appendChild(description); 994 Element oaiIdentifier = OAIXML.createOAIIdentifierXML(repository_id, "lucene-jdbm-demo", "ec159e"); 995 description.appendChild(oaiIdentifier); 996 997 // if there are any oaiInfo metadata, add them in too. 998 Element info = (Element)GSXML.getChildByTagName(oai_config, OAIXML.OAI_INFO); 999 if (info != null) { 1000 NodeList meta = GSXML.getChildrenByTagName(info, OAIXML.INFO_METADATA); 1001 if (meta != null && meta.getLength() > 0) { 1002 Element gsdl = OAIXML.createGSDLElement(); 1003 description.appendChild(gsdl); 1004 for (int m = 0; m<meta.getLength(); m++) { 1005 copyNode(gsdl, meta.item(m)); 1006 } 1007 1008 } 1009 } 1010 this.identify_response = identify; 961 1011 return getMessage(identify); 962 1012 }
Note:
See TracChangeset
for help on using the changeset viewer.