Ignore:
Timestamp:
2011-05-09T14:37:04+12:00 (13 years ago)
Author:
sjm84
Message:

Updating this branch to match the latest Greenstone3 changes

Location:
main/branches/64_bit_Greenstone/greenstone3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/branches/64_bit_Greenstone/greenstone3

  • main/branches/64_bit_Greenstone/greenstone3/src/java/org/greenstone/gsdl3/util/OAIXML.java

    r22085 r24007  
    112112    public static final String OAI = "OAI";
    113113    public static final String OAI_DASH_PMH = "OAI-PMH";
     114    public static final String OAI_LASTMODIFIED = "oailastmodified";
    114115    public static final String OAIPMH = "OAIPMH";
    115116    public static final String OAI_RESUMPTION_TOKENS = "OAIResumptionTokens";
     
    161162    //stores the date format "yyyy-MM-ddTHH:mm:ssZ"
    162163    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
    163171    //this value is overriden in getOAIConfigXML()
    164172    public static long token_expiration = 7200;
     
    232240        Element token_elem = (Element)tokens.item(i);
    233241        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
    235243        if(datestamp < System.currentTimeMillis()) {
    236244          resumption_token_elem.removeChild(token_elem);
     
    312320      //initialize the granu_str which might be used by other methods (eg, getDate())
    313321      granularity = GSXML.getNodeText(granu_elem).trim();
     322
    314323      //change "yyyy-MM-ddTHH:mm:ssZ" to "yyyy-MM-dd'T'HH:mm:ss'Z'"
    315324      granularity = granularity.replaceAll("T", "'T'");
     
    352361   
    353362    public static long getTokenExpiration() {
    354       return token_expiration*1000;
     363    return token_expiration*1000; // in milliseconds
    355364    }
    356365
     
    462471        date = sdf.parse(pattern);
    463472      } 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      }
    466487      }
    467488      return date;
     
    481502        date = sdf.parse(pattern);
    482503      } 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      }       
    485518      }
    486519      return date.getTime();
     
    488521    /** get the string representation of a time from a long value(long type)
    489522     */
    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);
    492525      SimpleDateFormat sdf = new SimpleDateFormat(granularity);
    493526      return sdf.format(date);
     
    504537        oai.setAttribute("xmlns", "http://www.openarchives.org/OAI/2.0/");
    505538        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");
    507540      } else {
    508541        oai.setAttribute("xmlns", "http://www.openarchives.com/OAI/1.1/OAI_" + verb);
Note: See TracChangeset for help on using the changeset viewer.