DLESE Tools
v1.6.0

org.dlese.dpc.oai
Class OAIUtils

java.lang.Object
  extended by org.dlese.dpc.oai.OAIUtils

public final class OAIUtils
extends Object

Contains utility methods used in OAI.

Version:
$Id: OAIUtils.java,v 1.11 2009/03/20 23:33:53 jweather Exp $
Author:
John Weatherley

Constructor Summary
OAIUtils()
           
 
Method Summary
static String decode(String msg)
          Decode an identifier or resumption token.
static String encode(String msg)
          Encode an identifier or resumption token.
static Date getDateFromDatestamp(String datestamp)
          Converts an ISO8601 UTC datestamp String of the form yyyy-MM-ddTHH:mm:ssZ or the short form yyyy-MM-dd to a Java Date.
static Date getDateFromDatestamp(String datestamp, long increment)
          Converts an ISO8601 UTC datastamp String of the form yyyy-MM-ddTHH:mm:ssZ or the short form yyyy-MM-dd to a Java Date.
static String getDatestampFromDate(Date date)
          Gets an ISO8601 UTC datestamp string of the form yyyy-MM-ddTHH:mm:ssZ from a Date.
static String getHarvestedDirBaseURLPath(String basePath, String baseURL)
          Creates an appropriate directory path where harvested file(s) are saved similar to wget paths based on the URI.
static String getHarvestedDirPath(String basePath, String setname, String prefix, String baseURL)
          Creates an appropriate directory path where harvested file(s) are saved based on the baseURL, format and set.
static long getLongFromDatestamp(String datestamp)
          Converts an ISO8601 UTC datastamp String of the form yyyy-MM-ddTHH:mm:ssZ to a long.
static long getLongFromDatestamp(String datestamp, long increment)
          Converts an ISO8601 UTC datastamp String of the form yyyy-MM-ddTHH:mm:ssZ to a long.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OAIUtils

public OAIUtils()
Method Detail

getDatestampFromDate

public static final String getDatestampFromDate(Date date)
Gets an ISO8601 UTC datestamp string of the form yyyy-MM-ddTHH:mm:ssZ from a Date.

Parameters:
date - The Date
Returns:
The corresponding datestamp String in UTC timezone
See Also:
getDateFromDatestamp(java.lang.String)

getDateFromDatestamp

public static final Date getDateFromDatestamp(String datestamp)
                                       throws ParseException
Converts an ISO8601 UTC datestamp String of the form yyyy-MM-ddTHH:mm:ssZ or the short form yyyy-MM-dd to a Java Date. See ISO8601 and OAI date info for more info. If the short form yyyy-MM-dd is given, this method adds the String t01:00:00z to it to produce an ISO8601 compliant date time.

Parameters:
datestamp - A datestamp in UTC format.
Returns:
The dateFromDatestamp value
Throws:
ParseException - If unable to interpret the datestamp.

getDateFromDatestamp

public static final Date getDateFromDatestamp(String datestamp,
                                              long increment)
                                       throws ParseException
Converts an ISO8601 UTC datastamp String of the form yyyy-MM-ddTHH:mm:ssZ or the short form yyyy-MM-dd to a Java Date. See ISO8601 and OAI date info for more info. If the short form yyyy-MM-dd is given, this method adds the String t01:00:00z to it to produce an ISO8601 compliant date time.

Parameters:
datestamp - A datestamp in UTC format.
increment - Number of seconds to increment the date, positive or negative, or 0 to leave unchanged.
Returns:
The dateFromDatestamp value
Throws:
ParseException - If unable to interpret the datestamp.

getLongFromDatestamp

public static final long getLongFromDatestamp(String datestamp)
                                       throws ParseException
Converts an ISO8601 UTC datastamp String of the form yyyy-MM-ddTHH:mm:ssZ to a long. See ISO8601 and OAI date info for more info.

Parameters:
datestamp - A datestamp in UTC format.
Returns:
The longFromDatestamp value
Throws:
ParseException - If unable to interpret the datestamp.

getLongFromDatestamp

public static final long getLongFromDatestamp(String datestamp,
                                              long increment)
                                       throws ParseException
Converts an ISO8601 UTC datastamp String of the form yyyy-MM-ddTHH:mm:ssZ to a long. See ISO8601 and OAI date info for more info.

Parameters:
datestamp - A datestamp in UTC format.
increment - Number of seconds to increment the date, positive or negative, or 0 to leave unchanged.
Returns:
The longFromDatestamp value
Throws:
ParseException - If unable to interpret the datestamp.

getHarvestedDirBaseURLPath

public static String getHarvestedDirBaseURLPath(String basePath,
                                                String baseURL)
Creates an appropriate directory path where harvested file(s) are saved similar to wget paths based on the URI.

Parameters:
basePath - The base output directory.
baseURL - The baseURL of the OAI data provider.
Returns:
The path where the harvested files are saved.

getHarvestedDirPath

public static String getHarvestedDirPath(String basePath,
                                         String setname,
                                         String prefix,
                                         String baseURL)
Creates an appropriate directory path where harvested file(s) are saved based on the baseURL, format and set. The set name is encoded for file system compliance.

Parameters:
basePath - The base output directory.
setname - The OAI setSpec harvested, or null if none.
prefix - The metadataPrefix (format) harvested.
baseURL - The baseURL of the OAI data provider.
Returns:
The path where the harvested files are saved.

encode

public static String encode(String msg)
                     throws Exception
Encode an identifier or resumption token. Can also be used to encode chars for use in file names.

See section 3.1.1.3 in http://www.openarchives.org/OAI/2.0/openarchivesprotocol.htm

Parameters:
msg - A String to encode.
Returns:
Encoded String
Throws:
Exception - If error

decode

public static String decode(String msg)
                     throws Exception
Decode an identifier or resumption token.

See section 3.1.1.3 in http://www.openarchives.org/OAI/2.0/openarchivesprotocol.htm

Parameters:
msg - Message to decode
Returns:
Decoded String
Throws:
Exception - If unable to decode.

DLESE Tools
v1.6.0