Class EncodingSchemeUtils

java.lang.Object
org.opencastproject.metadata.dublincore.EncodingSchemeUtils

public final class EncodingSchemeUtils extends Object
Utility class to facilitate the work with DCMI encoding schemes.
  • Method Details

    • encodeDate

      public static DublinCoreValue encodeDate(Date date, Precision precision)
      Encode a date with the given precision into a Dublin Core string value, using the recommended W3C-DTF scheme. The UTC timezone is used for all precisions from Precision.Minute to Precision.Fraction. For years, months and days the local timezone is used instead to ensure that the given date enters the DublinCore as is. If UTC was used it may happen that you get the previous or next day, month or year respectively

      The language of the returned value is DublinCore.LANGUAGE_UNDEFINED.

      See http://www.w3.org/TR/NOTE-datetime for more information about W3C-DTF.

      Parameters:
      date - the date to encode
      precision - the precision to use
    • formatDate

      public static String formatDate(Date date, Precision precision)
    • encodePeriod

      public static DublinCoreValue encodePeriod(DCMIPeriod period, Precision precision)
      Encode a period with the given precision into a Dublin Core string value using the recommended DCMI Period scheme. For the usage of the UTC timezone please refer to encodeDate(Date, Precision) for further information.

      One of the dates may be null to create an open interval.

      The language of the returned value is DublinCore.LANGUAGE_UNDEFINED.

      See http://dublincore.org/documents/dcmi-period/ for more information about DCMI Period.

      Parameters:
      period - the period
      precision - the precision
    • encodeDuration

      public static DublinCoreValue encodeDuration(long duration)
      Encode a duration measured in milliseconds into a Dublin Core string using the DublinCore.ENC_SCHEME_ISO8601 encoding scheme PTnHnMnS.

      The language of the returned value is DublinCore.LANGUAGE_UNDEFINED.

      See ISO8601 Durations for details.

      Parameters:
      duration - the duration in milliseconds
    • decodeDuration

      public static Long decodeDuration(String value)
      Decode a string encoded in the ISO8601 encoding scheme.

      Also supports the REPLAY legacy format hh:mm:ss.

      See ISO8601 Durations for details.

      Parameters:
      value - the ISO encoded string
      Returns:
      the duration in milliseconds or null, if the value cannot be parsed
    • decodeDuration

      public static Long decodeDuration(DublinCoreValue value)
      Decode a string encoded in the ISO8601 encoding scheme.
      Parameters:
      value - the Dublin Core value
      Returns:
      the duration in milliseconds or null, if the value cannot be parsed or is in a different encoding scheme
    • decodeMandatoryDuration

      public static Long decodeMandatoryDuration(String value)
    • decodeDate

      public static Date decodeDate(DublinCoreValue value)
      Tries to decode the given value as a W3C-DTF encoded date. If decoding fails, null is returned.
      Returns:
      the date or null if decoding fails
    • decodeDate

      public static Date decodeDate(String value)
      Tries to decode the given value as a W3C-DTF encoded date. If decoding fails, null is returned.
      Returns:
      the date or null if decoding fails
    • decodeMandatoryDate

      public static Date decodeMandatoryDate(DublinCoreValue value)
      Like decodeDate(String), but throws an IllegalArgumentException if the value cannot be decoded.
      Parameters:
      value - the value
      Returns:
      the date
      Throws:
      IllegalArgumentException - if the value cannot be decoded
    • decodeMandatoryDate

      public static Date decodeMandatoryDate(String value)
      Like decodeDate(String), but throws an IllegalArgumentException if the value cannot be decoded.
      Returns:
      the date
      Throws:
      IllegalArgumentException - if the value cannot be decoded
    • decodePeriod

      public static DCMIPeriod decodePeriod(DublinCoreValue value)
      Tries to decode a string in the DCMI period format, using W3C-DTF for the encoding of the individual dates. If parsing fails at any point, null will be returned.
      Returns:
      the period or null if decoding fails
    • decodePeriod

      public static DCMIPeriod decodePeriod(String value)
      Tries to decode a string in the DCMI period format, using W3C-DTF for the encoding of the individual dates. If parsing fails at any point, null will be returned.
      Returns:
      the period or null if decoding fails
    • decodeMandatoryPeriod

      public static DCMIPeriod decodeMandatoryPeriod(DublinCoreValue value)
      Like decodePeriod(String), but throws an IllegalArgumentException if the value cannot be decoded.
      Returns:
      the period
      Throws:
      IllegalArgumentException - if the value cannot be decoded
    • decodeMandatoryPeriod

      public static DCMIPeriod decodeMandatoryPeriod(String value)
      Like decodePeriod(DublinCoreValue), but throws an IllegalArgumentException if the value cannot be decoded.
      Returns:
      the period
      Throws:
      IllegalArgumentException - if the value cannot be decoded
    • decodeTemporal

      public static Temporal decodeTemporal(DublinCoreValue value)
      Tries to decode the value to a temporal object. For now, supported types are Date, DCMIPeriod and Long for a duration.
      Parameters:
      value - the value to decode
      Returns:
      a temporal object of the said types or null if decoding fails
    • decodeMandatoryTemporal

      public static Temporal decodeMandatoryTemporal(DublinCoreValue value)
      Like decodeTemporal(DublinCoreValue), but throws an IllegalArgumentException if the value cannot be decoded.
      Returns:
      the temporal object of type Date or DCMIPeriod
      Throws:
      IllegalArgumentException - if the value cannot be decoded