Changeset 24007 for main/branches/64_bit_Greenstone/greenstone3/src/java/org/greenstone/gsdl3/util/OAIXML.java
- Timestamp:
- 2011-05-09T14:37:04+12:00 (13 years ago)
- Location:
- main/branches/64_bit_Greenstone/greenstone3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/branches/64_bit_Greenstone/greenstone3
- Property svn:mergeinfo changed
-
main/branches/64_bit_Greenstone/greenstone3/src/java/org/greenstone/gsdl3/util/OAIXML.java
r22085 r24007 112 112 public static final String OAI = "OAI"; 113 113 public static final String OAI_DASH_PMH = "OAI-PMH"; 114 public static final String OAI_LASTMODIFIED = "oailastmodified"; 114 115 public static final String OAIPMH = "OAIPMH"; 115 116 public static final String OAI_RESUMPTION_TOKENS = "OAIResumptionTokens"; … … 161 162 //stores the date format "yyyy-MM-ddTHH:mm:ssZ" 162 163 public static String granularity = ""; 164 165 // http://www.openarchives.org/OAI/openarchivesprotocol.html#DatestampsRequests 166 // specifies that all repositories must support YYYY-MM-DD (yyyy-MM-dd in Java) 167 // this would be in addition to the other (optional) granularity of above that 168 // a repository may additionally choose to support. 169 public static final String default_granularity = "yyyy-MM-dd"; 170 163 171 //this value is overriden in getOAIConfigXML() 164 172 public static long token_expiration = 7200; … … 232 240 Element token_elem = (Element)tokens.item(i); 233 241 String expire_str = token_elem.getAttribute(EXPIRATION_DATE); 234 long datestamp = getTime(expire_str); 242 long datestamp = getTime(expire_str); // expire_str is in milliseconds 235 243 if(datestamp < System.currentTimeMillis()) { 236 244 resumption_token_elem.removeChild(token_elem); … … 312 320 //initialize the granu_str which might be used by other methods (eg, getDate()) 313 321 granularity = GSXML.getNodeText(granu_elem).trim(); 322 314 323 //change "yyyy-MM-ddTHH:mm:ssZ" to "yyyy-MM-dd'T'HH:mm:ss'Z'" 315 324 granularity = granularity.replaceAll("T", "'T'"); … … 352 361 353 362 public static long getTokenExpiration() { 354 return token_expiration*1000; 363 return token_expiration*1000; // in milliseconds 355 364 } 356 365 … … 462 471 date = sdf.parse(pattern); 463 472 } catch(Exception e) { 464 logger.error("invalid date format: " + pattern); 465 return null; 473 if(!default_granularity.equals(granularity)) { // try validating against default granularity 474 try { 475 date = null; 476 sdf = null; 477 sdf = new SimpleDateFormat(default_granularity); 478 date = sdf.parse(pattern); 479 } catch(Exception ex) { 480 logger.error("invalid date format: " + pattern); 481 return null; 482 } 483 } else { 484 logger.error("invalid date format: " + pattern); 485 return null; 486 } 466 487 } 467 488 return date; … … 481 502 date = sdf.parse(pattern); 482 503 } catch(Exception e) { 483 logger.error("invalid date format: " + pattern); 484 return -1; 504 if(!default_granularity.equals(granularity)) { // try validating against default granularity 505 try { 506 date = null; 507 sdf = null; 508 sdf = new SimpleDateFormat(default_granularity); 509 date = sdf.parse(pattern); 510 } catch(Exception ex) { 511 logger.error("invalid date format: " + pattern); 512 return -1; 513 } 514 } else { 515 logger.error("invalid date format: " + pattern); 516 return -1; 517 } 485 518 } 486 519 return date.getTime(); … … 488 521 /** get the string representation of a time from a long value(long type) 489 522 */ 490 public static String getTime(long seconds) {491 Date date = new Date( seconds);523 public static String getTime(long milliseconds) { 524 Date date = new Date(milliseconds); 492 525 SimpleDateFormat sdf = new SimpleDateFormat(granularity); 493 526 return sdf.format(date); … … 504 537 oai.setAttribute("xmlns", "http://www.openarchives.org/OAI/2.0/"); 505 538 oai.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); 506 oai.setAttribute("xsi:schemaLocation", "http://www.openarchives.org/OAI/2.0 \n http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd");539 oai.setAttribute("xsi:schemaLocation", "http://www.openarchives.org/OAI/2.0/ \n http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd"); 507 540 } else { 508 541 oai.setAttribute("xmlns", "http://www.openarchives.com/OAI/1.1/OAI_" + verb);
Note:
See TracChangeset
for help on using the changeset viewer.