Changeset 28987 for main/trunk
- Timestamp:
- 2014-04-17T13:17:33+12:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/core/OAIReceptionist.java
r28966 r28987 47 47 /** The unique repository identifier */ 48 48 protected String repository_id = null; 49 50 /** a converter class to parse XML and create Docs */ 51 protected XMLConverter converter=null; 52 49 53 50 /** the configure file of this receptionist passed from the oai servlet. */ 54 51 protected Element oai_config = null; … … 78 75 /** store the super coll elements for convenience */ 79 76 HashMap<String, Element> super_coll_data = null; 77 /** store the metadata formats ??????*/ 80 78 /** The identify response */ 81 79 protected Element identify_response = null; … … 86 84 87 85 public OAIReceptionist() { 88 this.converter = new XMLConverter(); 86 89 87 } 90 88 … … 199 197 200 198 // go through and store a list of collection names for convenience 201 // also create a 'to' attribute 199 // also create a 'to' attribute for the next request to the MR, which 200 // is a ListSets request to each collection 202 201 Node child = this.collection_list.getFirstChild(); 203 202 if (child == null) { … … 239 238 // send to MR 240 239 msg_node = mr.process(message); 241 logger.error( this.converter.getPrettyString(msg_node));240 logger.error(XMLConverter.getPrettyString(msg_node)); 242 241 NodeList response_list = ((Element)msg_node).getElementsByTagName(GSXML.RESPONSE_ELEM); 243 242 for (int c=0; c<response_list.getLength(); c++) { … … 267 266 this.super_coll_map.put(set_spec, subcolls); 268 267 // the first time a supercoll is mentioned, add into the set list 269 logger.error("finding the set info "+ this.converter.getPrettyString(this.super_coll_data.get(set_spec)));268 logger.error("finding the set info "+XMLConverter.getPrettyString(this.super_coll_data.get(set_spec))); 270 269 listsets_element.appendChild(GSXML.duplicateWithNewName(listsets_doc, this.super_coll_data.get(set_spec), OAIXML.SET, true)); 271 270 } … … 295 294 296 295 Element response = (Element) this.mr.process(mr_request_message); 297 logger.error("configure response = "+ this.converter.getPrettyString(response));296 logger.error("configure response = "+XMLConverter.getPrettyString(response)); 298 297 } 299 298 /** process using strings - just calls process using Elements */ 300 299 public String process(String xml_in) { 301 300 302 Node message_node = this.converter.getDOM(xml_in);301 Node message_node = XMLConverter.getDOM(xml_in); 303 302 Node page = process(message_node); 304 return this.converter.getString(page);303 return XMLConverter.getString(page); 305 304 } 306 305 … … 322 321 323 322 Element message = GSXML.nodeToElement(message_node); 324 logger.error( this.converter.getString(message));323 logger.error(XMLConverter.getString(message)); 325 324 326 325 // check that its a correct message tag … … 593 592 Element result = (Element)mr.process(mr_msg); 594 593 logger.error(verb+ " result for coll "+current_coll); 595 logger.error( this.converter.getPrettyString(result));594 logger.error(XMLConverter.getPrettyString(result)); 596 595 if (result == null) { 597 596 logger.info("message router returns null"); … … 725 724 } 726 725 727 728 // method exclusively used by doListRecords/doListIdentifiers729 private void getRecords(Element verb_elem, NodeList list, int start_point, int end_point) {730 for (int i=start_point; i<end_point; i++) {731 verb_elem.appendChild(verb_elem.getOwnerDocument().importNode(list.item(i), true));732 }733 }734 726 private Element collectAll(Element result, Element msg, String verb, String elem_name) { 735 727 if(result == null) { … … 763 755 //if the verb is ListMetadataFormats, there could be only one parameter: identifier 764 756 //, or there is no parameter; otherwise it is an error 765 //logger.info("" + this.converter.getString(msg));757 //logger.info("" + XMLConverter.getString(msg)); 766 758 767 759 NodeList params = GSXML.getChildrenByTagName(req, GSXML.PARAM_ELEM); … … 777 769 778 770 Element list_metadata_formats = lmf_doc.createElement(OAIXML.LIST_METADATA_FORMATS); 779 780 Element format_list = (Element)GSXML.getChildByTagName(oai_config, OAIXML.LIST_METADATA_FORMATS);781 if (format_list == null) {782 logger.error("OAIConfig.xml must contain the supported metadata formats");783 // TODO this is internal error, what to do???784 return getMessage(lmf_doc, list_metadata_formats);785 } 786 NodeList formats = format_list.getElementsByTagName(OAIXML.METADATA_FORMAT); 771 // get all the formats out of oai_config 772 NodeList formats = oai_config.getElementsByTagName(OAIXML.METADATA_FORMAT); 773 if (formats.getLength() ==0) { 774 logger.error("OAIConfig.xml must contain the supported metadata formats"); 775 // TODO this is internal error, what to do??? 776 return getMessage(lmf_doc, list_metadata_formats); 777 } 778 787 779 for(int i=0; i<formats.getLength(); i++) { 788 780 Element meta_fmt = lmf_doc.createElement(OAIXML.METADATA_FORMAT); … … 794 786 list_metadata_formats.appendChild(meta_fmt); 795 787 } 796 returngetMessage(lmf_doc, list_metadata_formats);797 788 this.listmetadataformats_response = getMessage(lmf_doc, list_metadata_formats); 789 return this.listmetadataformats_response; 798 790 799 791 } … … 820 812 identifier = param.getAttribute(GSXML.VALUE_ATT); 821 813 // the identifier is in the form: <coll_name>:<OID> 822 // so it must contain at least two ':' characters823 String[] strs = identifier.split(":");824 if(strs == null || strs.length < 2) {825 // the OID may also contain ':'814 // so it must contain at least one ':' characters 815 // (the oid itself may contain : chars) 816 String[] strs = identifier.split(":", 2); 817 if(strs.length != 2) { 826 818 logger.error("identifier is not in the form coll:id" + identifier); 827 819 return OAIXML.createErrorMessage(OAIXML.ID_DOES_NOT_EXIST, ""); … … 830 822 // send request to message router 831 823 // get the names 832 strs = splitNames(identifier);833 if(strs == null || strs.length < 2) {834 logger.error("identifier is not in the form coll:id" + identifier);835 return OAIXML.createErrorMessage(OAIXML.ID_DOES_NOT_EXIST, "");836 }837 //String name_of_site = strs[0];838 824 String coll_name = strs[0]; 839 825 String oid = strs[1]; 840 826 841 //re-organize the request element842 // reset the 'to' attribute827 Document msg_doc = XMLConverter.newDOM(); 828 Element message = msg_doc.createElement(GSXML.MESSAGE_ELEM); 843 829 String verb = req.getAttribute(GSXML.TO_ATT); 844 req.setAttribute(GSXML.TO_ATT, coll_name + "/" + verb); 845 // reset the identifier element 846 param.setAttribute(GSXML.NAME_ATT, OAIXML.OID); 847 param.setAttribute(GSXML.VALUE_ATT, oid); 848 849 // TODO is this the best way to do this???? should we create a new request??? 850 Element message = req.getOwnerDocument().createElement(GSXML.MESSAGE_ELEM); 851 message.appendChild(req); 830 String new_to = coll_name + "/" + verb; 831 Element request = GSXML.createBasicRequest(msg_doc, "oai???", new_to, null); 832 message.appendChild(request); 833 // add the id param 834 GSXML.addParameterToList(request, OAIXML.OID, oid); 835 852 836 //Now send the request to the message router to process 853 837 Node result_node = mr.process(message); … … 861 845 Element original_element = (Element)GSXML.getChildByTagName(oai_config, element_name); 862 846 if(original_element != null) { 863 copyNode(to_elem, original_element); 864 } 865 } 866 867 private void copyNode(Element to_elem, Node original_element) { 868 to_elem.appendChild(to_elem.getOwnerDocument().importNode(original_element, true)); 869 870 } 847 GSXML.copyNode(to_elem, original_element); 848 } 849 } 850 871 851 872 852 private Element doIdentify() { … … 894 874 } 895 875 for (int i=0; i<num_admin; i++) { 896 copyNode(identify, admin_emails.item(i));876 GSXML.copyNode(identify, admin_emails.item(i)); 897 877 } 898 878 … … 927 907 description.appendChild(gsdl); 928 908 for (int m = 0; m<meta.getLength(); m++) { 929 copyNode(gsdl, meta.item(m));909 GSXML.copyNode(gsdl, meta.item(m)); 930 910 } 931 911 … … 934 914 this.identify_response = identify; 935 915 return getMessage(doc, identify); 936 }937 //split setSpec (site_name:coll_name) into an array of strings938 //It has already been checked that the set_spec contains at least one ':'939 private String[] splitSetSpec(String set_spec) {940 logger.info(set_spec);941 String[] strs = new String[2];942 int colon_index = set_spec.indexOf(":");943 strs[0] = set_spec.substring(0, colon_index);944 strs[1] = set_spec.substring(colon_index + 1);945 return strs;946 916 } 947 917 /** split the identifier into <collection + OID> as an array 948 918 It has already been checked that the 'identifier' contains at least one ':' 949 919 */ 950 private String[] splitNames(String identifier) {951 logger.info(identifier);952 String [] strs = new String[2];953 int first_colon = identifier.indexOf(":");954 if(first_colon == -1) {955 return null;956 }957 strs[0] = identifier.substring(0, first_colon);958 strs[1] = identifier.substring(first_colon + 1);959 return strs;960 }920 // private String[] splitNames(String identifier) { 921 // logger.info(identifier); 922 // String [] strs = new String[2]; 923 // int first_colon = identifier.indexOf(":"); 924 // if(first_colon == -1) { 925 // return null; 926 // } 927 // strs[0] = identifier.substring(0, first_colon); 928 // strs[1] = identifier.substring(first_colon + 1); 929 // return strs; 930 // } 961 931 /** validate if the specified metadata prefix value is supported by the repository 962 932 * by checking it in the OAIConfig.xml … … 1007 977 1008 978 // get the names 1009 String[] strs = splitNames(identifier);979 String[] strs = identifier.split(":", 2); 1010 980 if(strs == null || strs.length < 2) { 1011 981 logger.error("identifier is not in the form coll:id" + identifier);
Note:
See TracChangeset
for help on using the changeset viewer.