Java Code Examples for javax.xml.bind.DatatypeConverter#parseDate()

The following examples show how to use javax.xml.bind.DatatypeConverter#parseDate() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
public static Date parseXsdDateToDate(String value) throws DataConversionException {
    Date result = null;
    String valueType = Date.class.getName();
    
    try {
        Calendar calendar = DatatypeConverter.parseDate(value);
        result = calendar.getTime();    
    } catch(Exception e) {
        if (result != null) valueType = result.getClass().getName();
        logger.fatal("Unable to parse xsd:date to "+valueType+".",e);
        throw new DataConversionException("Unable to parse xsd:date to "+valueType+".", e);
    }
    
    return result;
}
 
Example 2
Source Project: secure-data-service   File: DateSchema.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Object convert(Object value) {
    try {
        DatatypeConverter.parseDate((String) value);
    } catch (Exception ex) {
        LOG.error(ex.getMessage(), ex);
        LOG.error("Failed to parse date", ex);
        throw new EntityValidationException(ex, "irrelevant", "doesn't matter", new ArrayList<ValidationError>());
    }
    return value;
}
 
Example 3
/** @deprecated */
@Deprecated
public static Calendar getNotOnOrAfterConditions(Element stsResponse) {
   return DatatypeConverter.parseDate(stsResponse.getElementsByTagNameNS("*", "Conditions").item(0).getAttributes().getNamedItem("NotOnOrAfter").getTextContent());
}
 
Example 4
/** @deprecated */
@Deprecated
public static Calendar getNotOnOrAfterConditions(Element stsResponse) {
   return DatatypeConverter.parseDate(stsResponse.getElementsByTagNameNS("*", "Conditions").item(0).getAttributes().getNamedItem("NotOnOrAfter").getTextContent());
}
 
Example 5
/** @deprecated */
@Deprecated
public static Calendar getNotOnOrAfterConditions(Element stsResponse) {
   return DatatypeConverter.parseDate(stsResponse.getElementsByTagNameNS("*", "Conditions").item(0).getAttributes().getNamedItem("NotOnOrAfter").getTextContent());
}
 
Example 6
/** @deprecated */
@Deprecated
public static Calendar getNotOnOrAfterConditions(Element stsResponse) {
   return DatatypeConverter.parseDate(stsResponse.getElementsByTagNameNS("*", "Conditions").item(0).getAttributes().getNamedItem("NotOnOrAfter").getTextContent());
}
 
Example 7
public static Calendar getNotOnOrAfterConditions(Element stsResponse) {
   return DatatypeConverter.parseDate(stsResponse.getElementsByTagName("Conditions").item(0).getAttributes().getNamedItem("NotOnOrAfter").getTextContent());
}
 
Example 8
/** @deprecated */
@Deprecated
public static Calendar getNotOnOrAfterConditions(Element stsResponse) {
   return DatatypeConverter.parseDate(stsResponse.getElementsByTagNameNS("*", "Conditions").item(0).getAttributes().getNamedItem("NotOnOrAfter").getTextContent());
}
 
Example 9
Source Project: java-client-api   File: ValueConverter.java    License: Apache License 2.0 4 votes vote down vote up
static public Object convertToJava(String type, String value) {
  if ("xs:anySimpleType".equals(type))
    return DatatypeConverter.parseAnySimpleType(value);
  if ("xs:base64Binary".equals(type))
    return DatatypeConverter.parseBase64Binary(value);
  if ("xs:boolean".equals(type)) return StringToBoolean(value);
  if ("xs:byte".equals(type))
    return DatatypeConverter.parseByte(value);
  if ("xs:date".equals(type))
    return DatatypeConverter.parseDate(value);
  if ("xs:dateTime".equals(type))
    return DatatypeConverter.parseDateTime(value);
  if ("xs:dayTimeDuration".equals(type))
    return Utilities.getDatatypeFactory().newDurationDayTime(value);
  if ("xs:decimal".equals(type))
    return DatatypeConverter.parseDecimal(value);
  if ("xs:double".equals(type)) return StringToDouble(value);
  if ("xs:duration".equals(type))
    return Utilities.getDatatypeFactory().newDuration(value);
  if ("xs:float".equals(type)) return StringToFloat(value);
  if ("xs:int".equals(type)) return StringToInteger(value);
  if ("xs:integer".equals(type))
    return DatatypeConverter.parseInteger(value);
  if ("xs:long".equals(type)) return StringToLong(value);
  if ("xs:short".equals(type))
    return DatatypeConverter.parseShort(value);
  if ("xs:string".equals(type))
    return DatatypeConverter.parseString(value);
  if ("xs:time".equals(type))
    return DatatypeConverter.parseTime(value);
  if ("xs:unsignedInt".equals(type))
    return DatatypeConverter.parseUnsignedInt(value);
  if ("xs:unsignedLong".equals(type)) {
    BigInteger bi = DatatypeConverter.parseInteger(value);
    if (bi.compareTo(MAX_UNSIGNED_LONG) < 0) {
      return bi.longValue();
    } else {
      return bi;
    }
  } if ("xs:unsignedShort".equals(type))
    return DatatypeConverter.parseUnsignedShort(value);
  if ("xs:yearMonthDuration".equals(type))
    return Utilities.getDatatypeFactory().newDurationYearMonth(value);
  return value;
}
 
Example 10
Source Project: java-client-api   File: XsValueImpl.java    License: Apache License 2.0 4 votes vote down vote up
public DateValImpl(String value) {
    this(DatatypeConverter.parseDate(value));
}
 
Example 11
Source Project: ews-java-api   File: TimeChangeTest.java    License: MIT License 4 votes vote down vote up
private String testDate(String value) {
  Calendar cal = DatatypeConverter.parseDate(value);
  cal.setTimeZone(TimeZone.getTimeZone("UTC"));
  String XSDate = EwsUtilities.dateTimeToXSDate(cal.getTime());
  return XSDate;
}
 
Example 12
Source Project: vraptor4   File: CalendarGsonConverter.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Calendar deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
	return DatatypeConverter.parseDate(json.getAsString());
}
 
Example 13
/**
 * Gets the not on or after conditions.
 *
 * @param stsResponse the sts response
 * @return the not on or after conditions
 */
public static Calendar getNotOnOrAfterConditions(Element stsResponse) {
    return DatatypeConverter.parseDate(stsResponse.getElementsByTagName(SAML_CONDITIONS).item(0).getAttributes().getNamedItem(SAML_NOTONORAFTER).getTextContent());
}
 
Example 14
/**
 * Gets the not on or after conditions.
 *
 * @param stsResponse the sts response
 * @return the not on or after conditions
 */
public static Calendar getNotOnOrAfterConditions(Element stsResponse) {
    return DatatypeConverter.parseDate(stsResponse.getElementsByTagName(SAML_CONDITIONS).item(0).getAttributes().getNamedItem(SAML_NOTONORAFTER).getTextContent());
}