javax.xml.bind.DatatypeConverter#parseDateTime ( )源码实例Demo

下面列出了javax.xml.bind.DatatypeConverter#parseDateTime ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: jandy   文件: TravisApiTest.java
@Test
public void testGetBuild() throws Exception {
  long buildId = 79083233;
  server.expect(requestTo("https://api.travis-ci.org/builds/"+buildId))
          .andExpect(method(HttpMethod.GET))
          .andExpect(header(HttpHeaders.ACCEPT, "application/vnd.travis-ci.2+json"))
          .andRespond(withSuccess(output, MediaType.APPLICATION_JSON_UTF8));

  TResult result = client.getBuild(79083233);

  System.out.println(result);

  Calendar calendar = DatatypeConverter.parseDateTime((String)result.getBuild().getStartedAt());
  PrettyTime p = new PrettyTime(Locale.ENGLISH);

  System.out.println(p.format(calendar));
  
  assertThat(result.getBuild().getCommitId(), is(result.getCommit().getId()));
  assertThat(result.getCommit().getId(), is(22542817L));
  assertThat(result.getCommit().getMessage(), is("add depedency of icu4j"));
  assertThat(result.getCommit().getCommitterName(), is("JCooky"));
}
 
源代码2 项目: development   文件: AssertionContentVerifier.java
/**
 * Verify that the NotOnOrAfter attribute in any bearer
 * <SubjectConfirmationData> has not passed, subject to allowable clock skew
 * between the providers
 * 
 * @throws AssertionValidationException
 */
void verifyAssertionExpirationDate(Node nodeAssertion,
        Node nodeConfirmationData) throws AssertionValidationException {

    Calendar expirationDate = DatatypeConverter.parseDateTime(XMLConverter
            .getStringAttValue(nodeConfirmationData,
                    SamlXmlTags.ATTRIBUTE_NOT_ON_OR_AFTER));
    if (now.equals(expirationDate) || now.after(expirationDate)) {
        String assertionId = XMLConverter.getStringAttValue(nodeAssertion,
                SamlXmlTags.ATTRIBUTE_ID);
        AssertionValidationException exception = new AssertionValidationException(
                String.format("Assertion (id=%s) expired", assertionId),
                AssertionValidationException.ReasonEnum.ASSERTION_EXPIRED,
                new String[] { assertionId });
        throw exception;
    }
}
 
源代码3 项目: java-client-api   文件: BitemporalTest.java
@Test
public void a_testCreate() throws Exception {
  String contents = "<test>" +
    "<system-start></system-start>" +
    "<system-end></system-end>" +
    "<valid-start>2014-08-19T00:00:00Z</valid-start>" +
    "<valid-end>2014-08-19T00:00:01Z</valid-end>" +
    "</test>";
  TemporalDescriptor desc = docMgr.create(docMgr.newDocumentUriTemplate("xml"),
    null, new StringHandle(contents), null, null, temporalCollection);
  assertNotNull("Missing TemporalDescriptor from create", desc);
  assertNotNull(desc.getUri());
  assertTrue(desc.getUri().endsWith(".xml"));
  String lastWriteTimestamp = desc.getTemporalSystemTime();
  Calendar lastWriteTime = DatatypeConverter.parseDateTime(lastWriteTimestamp);
  assertNotNull(lastWriteTime);
}
 
源代码4 项目: java-client-api   文件: TestBiTemporal.java
@Test
// Test LSQT Query using temporalLsqtQuery. Do the query as REST reader
public void testLsqtQuery() throws Exception {

  ConnectedRESTQA.updateTemporalCollectionForLSQT(dbName,
      temporalLsqtCollectionName, true);

  // Read documents based on document URI and ALN Contains. We are just
  // looking for count of documents to be correct
  String docId = "javaSingleJSONDoc.json";

  Calendar insertTime = DatatypeConverter
      .parseDateTime("2005-01-01T00:00:01");
  insertJSONSingleDocument(temporalLsqtCollectionName, docId, null, null,
      insertTime);

  Calendar updateTime = DatatypeConverter
      .parseDateTime("2010-01-01T00:00:01");
  updateJSONSingleDocument(temporalLsqtCollectionName, docId, null,
      updateTime);

  Thread.sleep(2000);

  validateLSQTQueryData(readerClient);
}
 
源代码5 项目: semanticMDR   文件: PermissibleValueImpl.java
@Override
public Calendar getPermissibleValueBeginDate() {
	RDFNode permissibleValueBeginDate = getPropertyValue(mdrDatabase
			.getVocabulary().permissibleValueBeginDate);
	return DatatypeConverter.parseDateTime(permissibleValueBeginDate
			.asLiteral().getLexicalForm());
}
 
源代码6 项目: semanticMDR   文件: ValueMeaningImpl.java
@Override
public Calendar getValueMeaningBeginDate() {
	RDFNode valueMeaningBeginDate = getPropertyValue(mdrDatabase
			.getVocabulary().valueMeaningBeginDate);
	return DatatypeConverter.parseDateTime(valueMeaningBeginDate
			.asLiteral().getLexicalForm());
}
 
源代码7 项目: semanticMDR   文件: AdministrationRecordImpl.java
@Override
public Calendar getEffectiveDate() {
	RDFNode effectiveDate = getPropertyValue(mdrDatabase.getVocabulary().effectiveDate);
	if (effectiveDate == null) {
		logger.debug("AdministrationRecord does not have effectiveDate");
		return null;
	}
	return DatatypeConverter.parseDateTime(effectiveDate.asLiteral()
			.getLexicalForm());
}
 
源代码8 项目: yawl   文件: YTimerParameters.java
public boolean parseYTimerType(Element eTimerTypeValue) throws IllegalArgumentException {
    XNode node = new XNodeParser(true).parse(eTimerTypeValue);
    if (node == null) throw new IllegalArgumentException("Invalid YTimerType XML");

    String triggerStr = node.getChildText("trigger");
    if (triggerStr == null) throw new IllegalArgumentException("Missing 'trigger' parameter");

    // throws IllegalArgumentException if triggerStr is not a valid Trigger
    YWorkItemTimer.Trigger trigger = YWorkItemTimer.Trigger.valueOf(triggerStr);

    String expiry = node.getChildText("expiry");
    if (expiry == null) throw new IllegalArgumentException("Missing 'expiry' parameter");

    setWorkDaysOnly(node.getChild("workdays") != null);

    if (expiry.startsWith("P")) {         // duration types start with P
        Duration duration = StringUtil.strToDuration(expiry);
        if (duration == null) throw new IllegalArgumentException("Malformed duration value");
        set(trigger, duration);
        return true;
    }

    try {                                 // test for xsd datetime
        Calendar calendar = DatatypeConverter.parseDateTime(expiry);
        set(trigger, calendar.getTime());
        return true;
    }
    catch (IllegalArgumentException pe) {
        // do nothing here - trickle down
    }

    long time = StringUtil.strToLong(expiry, -1);           // test for long
    if (time < 0) throw new IllegalArgumentException("Malformed expiry value");
    set(trigger, new Date(time));
    return true;
}
 
public static Date parseXsdDateTimeToDate(String value) throws DataConversionException {
    Date result = null;
    String valueType = Date.class.getName();
    
    try {
        Calendar calendar = DatatypeConverter.parseDateTime(value);
        result = calendar.getTime();    
    } catch(Exception e) {
        if (result != null) valueType = result.getClass().getName();
        logger.fatal("Unable to parse xsd:dateTime to "+valueType+".",e);
        throw new DataConversionException("Unable to parse xsd:dateTime to "+valueType+".", e);
    }
    
    return result;
}
 
源代码10 项目: java-client-api   文件: ValueConverter.java
static public Date StringToDate(String value) {
  if (value == null || value.length() == 0) {
    return null;
  }
  try {
    Calendar cal = DatatypeConverter.parseDateTime(value);
    return cal.getTime();
  } catch(Exception e) {
    throw new IllegalArgumentException("Could not convert to Date: "+value, e);
  }
}
 
源代码11 项目: java-client-api   文件: TestBiTemporal.java
@Test
// Test LSQT Query using temporalLsqtQuery. Do the query as REST admin
public void testLsqtQueryAsAdmin() throws Exception {

  ConnectedRESTQA.updateTemporalCollectionForLSQT(dbName,
      temporalLsqtCollectionName, true);

  // Read documents based on document URI and ALN Contains. We are just
  // looking for count of documents to be correct
  String docId = "javaSingleJSONDoc.json";

  Calendar insertTime = DatatypeConverter
      .parseDateTime("2005-01-01T00:00:01");

  JacksonDatabindHandle<ObjectNode> handle = getJSONDocumentHandle(
      "2001-01-01T00:00:00", "2011-12-31T23:59:59", "999 Skyway Park - JSON",
      docId);

  JSONDocumentManager docMgr = writerClient.newJSONDocumentManager();
  docMgr.setMetadataCategories(Metadata.ALL);

  // put meta-data
  DocumentMetadataHandle mh = setMetadata(false);
  docMgr.write(docId, mh, handle, null, null, temporalLsqtCollectionName,
      insertTime);

  Calendar updateTime = DatatypeConverter
      .parseDateTime("2010-01-01T00:00:01");
  docMgr.write(docId, mh, handle, null, null, temporalLsqtCollectionName,
      updateTime);

  Thread.sleep(2000);

  validateLSQTQueryData(writerClient);
}
 
源代码12 项目: semanticMDR   文件: ValueMeaningImpl.java
@Override
public Calendar getValueMeaningEndDate() {
	RDFNode valueMeaningEndDate = getPropertyValue(mdrDatabase
			.getVocabulary().valueMeaningEndDate);
	if (valueMeaningEndDate == null) {
		logger.debug("ValueMeaning does not have endDate");
		return null;
	}
	return DatatypeConverter.parseDateTime(valueMeaningEndDate.asLiteral()
			.getLexicalForm());
}
 
源代码13 项目: zephyr   文件: IsoDateFormatValidator.java
@Override
public boolean isValid(String value) {
    try {
        /*	initial formats we're concerned about
YYYY-MM-DDTHH:MM:SSZ
YYYY-MM-DDTHH:MM:SS.SSSZ
*/
        DatatypeConverter.parseDateTime(value);
        return true;
    } catch (IllegalArgumentException iae) {
        return false;
    }
}
 
源代码14 项目: xml-avro   文件: DatumBuilder.java
private static long parseDateTime(String text) {
    Calendar c = DatatypeConverter.parseDateTime(text);
    c.setTimeZone(defaultTimeZone);
    return c.getTimeInMillis();
}
 
源代码15 项目: OpenEstate-IO   文件: ImmobiliareItUtils.java
public static boolean isValidDateUpdatedType(Calendar value) {
    final Calendar min = DatatypeConverter.parseDateTime("2000-12-31T00:00:00");
    return value != null && !value.before(min);
}
 
源代码16 项目: java-client-api   文件: ValueConverter.java
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;
}
 
源代码17 项目: vraptor4   文件: CalendarConverter.java
@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
	String value = reader.getValue();
	return DatatypeConverter.parseDateTime(value);
}
 
源代码18 项目: java-client-api   文件: TestBiTempMetaValues.java
@Test
/*
 * Test bitemporal protections - NOWIPE With transaction.
 */
public void testProtectWipe() throws Exception {

  System.out.println("Inside testProtectWipe");
  ConnectedRESTQA.updateTemporalCollectionForLSQT(dbName,
      temporalLsqtCollectionName, true);

  Calendar insertTime = DatatypeConverter.parseDateTime("2005-01-01T00:00:01");
  Calendar updateTime = DatatypeConverter.parseDateTime("2005-01-01T00:00:11");

  String docId = "javaSingleJSONDoc.json";
  JacksonDatabindHandle<ObjectNode> handle = getJSONDocumentHandle("2001-01-01T00:00:00",
      "2011-12-31T23:59:59",
      "999 Skyway Park - JSON",
      docId
      );

  JSONDocumentManager docMgr = writerClient.newJSONDocumentManager();

  docMgr.write(docId, null, handle, null, null, temporalLsqtCollectionName, insertTime);
  Thread.sleep(5000);

  // Protect document for 60 sec. Use Duration.
  docMgr.protect(docId, temporalLsqtCollectionName, ProtectionLevel.NOWIPE, DatatypeFactory.newInstance().newDuration("PT60S"));
  JacksonDatabindHandle<ObjectNode> handleUpd = getJSONDocumentHandle(
      "2003-01-01T00:00:00", "2012-12-31T23:59:59",
      "1999 Skyway Park - Updated - JSON", docId);
  docMgr.write(docId, null, handleUpd, null, null, temporalLsqtCollectionName, updateTime);
  StringBuilder str = new StringBuilder();
  try {
    docMgr.wipe(docId, temporalLsqtCollectionName);
  } catch (Exception ex) {
    str.append(ex.getMessage());
    System.out.println("Exception when delete within 60 sec is " + str.toString());
  }

  assertTrue("Did not receive Expected Exception, Expecting TEMPORAL-PROTECTED, received " + str.toString(), str.toString().contains("TEMPORAL-PROTECTED"));
  JSONDocumentManager jsonDocMgr = writerClient.newJSONDocumentManager();
  DocumentPage readResults = jsonDocMgr.read(docId);
  String content = jsonDocMgr.read(docId, new StringHandle()).get();
  assertTrue("Wrong number of results", content.contains("1999 Skyway Park - Updated - JSON"));

  // Sleep for 60 secs and try to delete the same docId.
  Thread.sleep(60000);
  Transaction t1 = writerClient.openTransaction();
  // TODO replace get with search and verify the system end time for the
  // document \
  // temporal document will not be deleted from DB and using get will only
  // return the latest docuemnt.
  docMgr.wipe(docId, t1, temporalLsqtCollectionName);
  Thread.sleep(5000);
  t1.commit();

  readResults = jsonDocMgr.read(docId);
  System.out.println("Number of results = " + readResults.size());
  assertEquals("Wrong number of results", 0, readResults.size());
}
 
源代码19 项目: java-client-api   文件: TestSandBox.java
@Test
/*
 * Test bitemporal protections - NOUPDATE With transaction.
 */
public void testProtectUpdateInTransaction() throws Exception {

  System.out.println("Inside testProtectUpdateInTransaction");
  ConnectedRESTQA.updateTemporalCollectionForLSQT(dbName,
      temporalLsqtCollectionName, true);

  Calendar insertTime = DatatypeConverter
      .parseDateTime("2005-01-01T00:00:01");
  Calendar updateTime = DatatypeConverter
      .parseDateTime("2005-01-01T00:00:11");

  String docId = "javaSingleJSONDoc.json";
  JacksonDatabindHandle<ObjectNode> handle = getJSONDocumentHandle(
      "2001-01-01T00:00:00", "2011-12-31T23:59:59", "999 Skyway Park - JSON",
      docId);

  JSONDocumentManager docMgr = writerClient.newJSONDocumentManager();
  Transaction t1 = writerClient.openTransaction();
  Transaction t2 = null;
  docMgr.write("javaSingleJSONDocV1.json", docId, null, handle, null, t1,
      temporalLsqtCollectionName, insertTime);

  // Protect document for 30 sec from delete and update. Use Duration.
  docMgr.protect(docId, temporalLsqtCollectionName, ProtectionLevel.NOUPDATE,
      DatatypeFactory.newInstance().newDuration("PT30S"), t1);
  JacksonDatabindHandle<ObjectNode> handleUpd = getJSONDocumentHandle(
      "2003-01-01T00:00:00", "2008-12-31T23:59:59",
      "1999 Skyway Park - Updated - JSON", docId);
  StringBuilder str = new StringBuilder();
  try {
    docMgr.write(docId, null, handleUpd, null, t1,
        temporalLsqtCollectionName, updateTime);
  } catch (Exception ex) {
    str.append(ex.getMessage());
    System.out.println("Exception when update within 30 sec is "
        + str.toString());
  }
  assertTrue(
      "Doc should not be updated",
      str.toString().contains(
          "The document javaSingleJSONDoc.json is protected noUpdate"));
  try {
    // Sleep for 40 secs and try to update the same docId.
    Thread.sleep(40000);
    docMgr.write(docId, null, handleUpd, null, t1,
        temporalLsqtCollectionName, updateTime);
    Thread.sleep(5000);

    JSONDocumentManager jsonDocMgr = writerClient.newJSONDocumentManager();
    DocumentPage readResults = jsonDocMgr.read(t1, docId);
    System.out.println("Number of results = " + readResults.size());
    assertEquals("Wrong number of results", 1, readResults.size());

    QueryManager queryMgr = writerClient.newQueryManager();

    StructuredQueryBuilder sqb = queryMgr.newStructuredQueryBuilder();
    StructuredQueryDefinition termQuery = sqb
        .collection(temporalLsqtCollectionName);
    t1.commit();

    long start = 1;
    t2 = writerClient.openTransaction();
    DocumentPage termQueryResults = docMgr.search(termQuery, start, t2);
    System.out.println("Number of results = "
        + termQueryResults.getTotalSize());
    assertEquals("Wrong number of results", 4,
        termQueryResults.getTotalSize());
  } catch (Exception e) {
    System.out.println("Exception when update within 30 sec is "
        + e.getMessage());
  } finally {
    if (t2 != null)
      t2.rollback();
    writerClient.release();
  }
}
 
源代码20 项目: java-client-api   文件: TestBiTempMetaValues.java
@Ignore
/*
 * Test bitemporal protections - NOUPDATE With different transactions. Write
 * doc in T1. Protect in T2. Update doc in T1 within 30 sec duration. TODO
 * Wait for Git #542
 */
public void testProtectUpdateInDiffTransactions() throws Exception {

  System.out.println("Inside testProtectUpdateInDiffTransactions");
  ConnectedRESTQA.updateTemporalCollectionForLSQT(dbName,
      temporalLsqtCollectionName, true);

  Calendar insertTime = DatatypeConverter.parseDateTime("2005-01-01T00:00:01");
  Calendar updateTime = DatatypeConverter.parseDateTime("2005-01-01T00:00:11");
  Transaction t1 = writerClient.openTransaction();
  Transaction t2 = writerClient.openTransaction();

  String docId = "javaSingleJSONDoc.json";
  JacksonDatabindHandle<ObjectNode> handle = getJSONDocumentHandle("2001-01-01T00:00:00",
      "2011-12-31T23:59:59",
      "999 Skyway Park - JSON",
      docId
      );

  JSONDocumentManager docMgr = writerClient.newJSONDocumentManager();

  docMgr.write("javaSingleJSONDocV1.json", docId, null, handle, null, t1, temporalLsqtCollectionName, insertTime);

  // Protect document for 30 sec from delete and update. Use Duration. Use T2
  docMgr.protect(docId, temporalLsqtCollectionName, ProtectionLevel.NOUPDATE, DatatypeFactory.newInstance().newDuration("PT30S"), t2);
  JacksonDatabindHandle<ObjectNode> handleUpd = getJSONDocumentHandle(
      "2003-01-01T00:00:00", "2008-12-31T23:59:59",
      "1999 Skyway Park - Updated - JSON", docId);

  StringBuilder str = new StringBuilder();
  try {
    // Use t1 to write
    docMgr.write(docId, null, handleUpd, null, t1, temporalLsqtCollectionName, updateTime);
  } catch (Exception ex) {
    str.append(ex.getMessage());
    System.out.println("Exception when update within 30 sec is " + str.toString());
  }
  // TODO Yet to know what exception message will be. #542
  // assertTrue("Doc should not be updated",
  // str.toString().contains("The document javaSingleJSONDoc.json is protected noUpdate"));

  // Sleep for 40 secs and try to update the same docId.
  Thread.sleep(40000);
  docMgr.write(docId, null, handleUpd, null, t1, temporalLsqtCollectionName, updateTime);
  Thread.sleep(5000);

  JSONDocumentManager jsonDocMgr = writerClient.newJSONDocumentManager();
  DocumentPage readResults = jsonDocMgr.read(t1, docId);
  System.out.println("Number of results = " + readResults.size());
  assertEquals("Wrong number of results", 1, readResults.size());

  QueryManager queryMgr = writerClient.newQueryManager();

  StructuredQueryBuilder sqb = queryMgr.newStructuredQueryBuilder();
  StructuredQueryDefinition termQuery = sqb.collection(temporalLsqtCollectionName);

  long start = 1;
  DocumentPage termQueryResults = docMgr.search(termQuery, start, t1);
  System.out
      .println("Number of results = " + termQueryResults.getTotalSize());
  assertEquals("Wrong number of results", 4, termQueryResults.getTotalSize());
  t1.rollback();
  t2.rollback();
}