Changeset 24440 for main/trunk
- Timestamp:
- 2011-08-20T21:42:11+12:00 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/core/OAIReceptionist.java
r23944 r24440 287 287 return getMessage(list_sets_elem); 288 288 } 289 private Element createResumptionTokenElement(int total_size, int cursor, int so_far_sent, boolean set_expiration) {289 private Element createResumptionTokenElement(int total_size, int cursor, int so_far_sent, boolean set_expiration, String metadata_prefix) { 290 290 Element token = OAIXML.createElement(OAIXML.RESUMPTION_TOKEN); 291 291 token.setAttribute(OAIXML.COMPLETE_LIST_SIZE, "" + total_size); … … 305 305 //data provider has to offer 306 306 //Here, we make use of the uniqueness of the system time 307 GSXML.setNodeText(token, OAIXML.GS3OAI + System.currentTimeMillis() + ":" + so_far_sent); 307 String tokenValue = OAIXML.GS3OAI + System.currentTimeMillis() + ":" + so_far_sent; 308 if(!metadata_prefix.equals("")) { 309 tokenValue = tokenValue + ":" + metadata_prefix; 310 } 311 GSXML.setNodeText(token, tokenValue); 308 312 } 309 313 return token; 310 314 } 315 316 private Element createResumptionTokenElement(int total_size, int cursor, int so_far_sent, boolean set_expiration) { 317 return createResumptionTokenElement(total_size, cursor, so_far_sent, set_expiration, ""); // empty metadata_prefix 318 } 319 311 320 /** if the param_map contains strings other than those in valid_strs, return false; 312 321 * otherwise true. … … 622 631 //} 623 632 token = (String)param_map.get(OAIXML.RESUMPTION_TOKEN); 624 logger.info("has resumptionToken " + token);633 logger.info("has resumptionToken: " + token); 625 634 if(OAIXML.containsToken(token) == false) { 626 635 return getMessage(OAIXML.createErrorElement(OAIXML.BAD_RESUMPTION_TOKEN, "")); … … 632 641 // such that GS2's oaiserver will validate properly. 633 642 if (!param_map.containsKey(OAIXML.METADATA_PREFIX)) { 634 // it must have a metadataPrefix 635 /** Here I disagree with the OAI specification: even if a resumptionToken is 636 * included in the request, the metadataPrefix is a must argument. Otherwise 637 * how would we know what metadataPrefix the harvester requested in his last request? 638 */ 639 logger.error("no metadataPrefix"); 640 return getMessage(OAIXML.createErrorElement(OAIXML.BAD_ARGUMENT, "")); 641 } 642 643 if(!token.equals("")) { // resumptiontoken 644 int lastIndex = token.lastIndexOf(":"); 645 if(lastIndex != token.indexOf(":")) { // if a meta_prefix is suffixed to the usual token, 646 // put that in the map and remove it from the end of the stored token 647 String meta_prefix = token.substring(lastIndex+1); 648 param_map.put(OAIXML.METADATA_PREFIX, meta_prefix); 649 token = token.substring(0, lastIndex); 650 param_map.put(OAIXML.RESUMPTION_TOKEN, token); 651 652 // Add to request <param name="metadataPrefix" value="oai_dc"/> 653 // need to add metaprefix as param to request, else a request 654 // for subsequent records when working with resumption tokens will fail 655 Element paramEl = req.getOwnerDocument().createElement(OAIXML.PARAM); 656 paramEl.setAttribute(OAIXML.NAME, OAIXML.METADATA_PREFIX); 657 paramEl.setAttribute(OAIXML.VALUE, meta_prefix); 658 req.appendChild(paramEl); 659 } 660 } else { // no metadata_prefix 661 662 // it must have a metadataPrefix 663 /** Here I disagree with the OAI specification: even if a resumptionToken is 664 * included in the request, the metadataPrefix is a must argument. Otherwise 665 * how would we know what metadataPrefix the harvester requested in his last request? 666 */ 667 logger.error("no metadataPrefix"); 668 return getMessage(OAIXML.createErrorElement(OAIXML.BAD_ARGUMENT, "")); 669 } 670 } 671 643 672 //Now that we got a prefix, check and see if it's supported by this repository 644 673 String prefix_value = (String)param_map.get(OAIXML.METADATA_PREFIX); 645 674 if (containsMetadataPrefix(prefix_value) == false) { 646 logger.error("requested prefix is not found in OAIConfig.xml"); 647 return getMessage(OAIXML.createErrorElement(OAIXML.CANNOT_DISSEMINATE_FORMAT, "")); 648 } 675 logger.error("requested prefix is not found in OAIConfig.xml"); 676 return getMessage(OAIXML.createErrorElement(OAIXML.CANNOT_DISSEMINATE_FORMAT, "")); 677 } 678 649 679 650 680 //Now that all validation has been done, I hope, we can send request to the message router … … 678 708 Element e = converter.nodeToElement(n); 679 709 result = collectAll(result, e, verb, OAIXML.RECORD); 680 710 681 711 //clear the content of the old request element 682 712 msg.removeChild(req); … … 717 747 getRecords(list_records, record_list, 0, resume_after); 718 748 //An incomplete list is sent; append a resumptionToken element 719 Element token_elem = createResumptionTokenElement(num_records, 0, resume_after, true );749 Element token_elem = createResumptionTokenElement(num_records, 0, resume_after, true, (String)param_map.get(OAIXML.METADATA_PREFIX)); 720 750 //store this token 721 751 OAIXML.addToken(token_elem); … … 738 768 getRecords(list_records, record_list, cursor, num_records); 739 769 //An incomplete list is sent; append a resumptionToken element 740 token_elem = createResumptionTokenElement(num_records, cursor, -1, false); 741 list_records.appendChild(token_elem); 770 token_elem = createResumptionTokenElement(num_records, cursor, -1, false, (String)param_map.get(OAIXML.METADATA_PREFIX)); 771 list_records.appendChild(token_elem); 772 742 773 } else { 743 774 //No, we are not. 744 775 //append required records to list_records (list is incomplete) 745 776 getRecords(list_records, record_list, cursor, cursor + resume_after); 746 token_elem = createResumptionTokenElement(num_records, cursor, cursor + resume_after, true );777 token_elem = createResumptionTokenElement(num_records, cursor, cursor + resume_after, true, (String)param_map.get(OAIXML.METADATA_PREFIX)); 747 778 //store this token 748 779 OAIXML.addToken(token_elem);
Note:
See TracChangeset
for help on using the changeset viewer.