Java Code Examples for javax.xml.datatype.XMLGregorianCalendar

The following examples show how to use javax.xml.datatype.XMLGregorianCalendar. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: keycloak   Source File: AssertionUtil.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Verify whether the assertion has expired. You can add in a clock skew to adapt to conditions where in the IDP and
 * SP are
 * out of sync.
 *
 * @param assertion
 * @param clockSkewInMilis in miliseconds
 *
 * @return
 *
 * @throws ConfigurationException
 */
public static boolean hasExpired(SAML11AssertionType assertion, long clockSkewInMilis) throws ConfigurationException {
    boolean expiry = false;

    // Check for validity of assertion
    SAML11ConditionsType conditionsType = assertion.getConditions();
    if (conditionsType != null) {
        XMLGregorianCalendar now = XMLTimeUtil.getIssueInstant();
        XMLGregorianCalendar notBefore = conditionsType.getNotBefore();
        XMLGregorianCalendar updatedNotBefore = XMLTimeUtil.subtract(notBefore, clockSkewInMilis);
        XMLGregorianCalendar notOnOrAfter = conditionsType.getNotOnOrAfter();
        XMLGregorianCalendar updatedOnOrAfter = XMLTimeUtil.add(notOnOrAfter, clockSkewInMilis);

        logger.trace("Now=" + now.toXMLFormat() + " ::notBefore=" + notBefore.toXMLFormat() + " ::notOnOrAfter=" + notOnOrAfter);

        expiry = !XMLTimeUtil.isValid(now, updatedNotBefore, updatedOnOrAfter);
        if (expiry) {
            logger.samlAssertionExpired(assertion.getID());
        }
    }

    // TODO: if conditions do not exist, assume the assertion to be everlasting?
    return expiry;
}
 
Example 2
Source Project: jadira   Source File: TestCloner.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testBasicWithPortable() throws DatatypeConfigurationException {

    GregorianCalendar cal = new GregorianCalendar();
    cal.add(Calendar.YEAR, 10);
    XMLGregorianCalendar xmlCal = DatatypeFactory.newInstance().newXMLGregorianCalendar((GregorianCalendar) cal);
    cal.add(Calendar.MONTH, 3);

    DeepCopyHolder source = new DeepCopyHolder();
    source.value = new IdHolder();
    source.value.setId("A Sample Value to Copy");
    source.timestamp = new Timestamp(System.currentTimeMillis() + 10000000);
    source.calendar = cal;
    source.xmlCalendar = xmlCal;

    BasicCloner cloner = new BasicCloner(new PortableCloneStrategy());
    cloner.initialiseFor(IdHolder.class);
    DeepCopyHolder dest = cloner.clone(source);
    
    Assert.assertEquals(source.value, dest.value);
    Assert.assertNotSame(source.value, dest.value);
    Assert.assertEquals(source.timestamp, dest.timestamp);
    Assert.assertNotSame(source.timestamp, dest.timestamp);
    Assert.assertEquals(source.calendar, dest.calendar);
    Assert.assertNotSame(source.calendar, dest.calendar);
    Assert.assertEquals(source.xmlCalendar, dest.xmlCalendar);
    Assert.assertNotSame(source.xmlCalendar, dest.xmlCalendar);
}
 
Example 3
/**
 * Returns an XMLGregorianCalendar representing the current date and time
 */
protected static XMLGregorianCalendar getCurrentDateTime() {
	XMLGregorianCalendar now = null;
	try {
		DatatypeFactory dataFactory = DatatypeFactory.newInstance();
		now = dataFactory.newXMLGregorianCalendar(new GregorianCalendar());
	} catch (DatatypeConfigurationException e) {
		System.err.println("unable to construct the date/time object");
		e.printStackTrace();
	}
	return now;
}
 
Example 4
Source Project: proarc   Source File: FoxmlUtils.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static XMLGregorianCalendar createXmlDate(Date d) {
    try {
        DatatypeFactory xmlDataFactory = DatatypeFactory.newInstance();
        GregorianCalendar gcNow = new GregorianCalendar();
        gcNow.setTime(d);
        return xmlDataFactory.newXMLGregorianCalendar(gcNow);
    } catch (DatatypeConfigurationException ex) {
        throw new IllegalStateException(ex);
    }
}
 
Example 5
Source Project: jdmn   Source File: DefaultSignavioDateLib.java    License: Apache License 2.0 5 votes vote down vote up
public XMLGregorianCalendar dayAdd(XMLGregorianCalendar dateTime, BigDecimal daysToAdd) {
    XMLGregorianCalendar result = (XMLGregorianCalendar) dateTime.clone();
    int days = daysToAdd.intValue();
    boolean isPositive = days > 0;
    Duration duration;
    duration = DATA_TYPE_FACTORY.newDurationDayTime(
            isPositive, daysToAdd.abs().intValue(), 0, 0, 0);
    result.add(duration);
    return result;
}
 
Example 6
/**
 * <p>Indicates whether parameter <code>obj</code> is "equal to" this one.</p>
 *
 * @param obj to compare.
 *
 * @return <code>true</code> when <code>compare(this,(XMLGregorianCalendar)obj) == EQUAL.</code>.
 */
public boolean equals(Object obj) {

    if (obj == null || !(obj instanceof XMLGregorianCalendar)) {
        return false;
    }
    return compare((XMLGregorianCalendar) obj) == DatatypeConstants.EQUAL;
}
 
Example 7
Source Project: hsac-fitnesse-fixtures   Source File: CalendarUtilTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Test AddMonths into winterTime.
 * Result should be moths +2 and a one hour shift to the left.
 *
 */
@Test
public void testAddMonthsIntoWinterTime() {
    XMLGregorianCalendar cal = calendarUtil.buildXMLGregorianCalendar();
    cal.setMonth(10);
    cal.setDay(1);
    cal.setHour(0);
    cal.setMinute(0);
    cal.setSecond(0);
    cal.setMillisecond(0);
    XMLGregorianCalendar result = calendarUtil.addMonths(cal, 2);
    assertEquals(12, result.getMonth());
}
 
Example 8
public static XMLGregorianCalendar getSystemServicesVersionFromFile(File file) throws IntegrationModuleException {
   Object var1 = null;

   byte[] xml;
   try {
      xml = FileUtils.readFileToByteArray(file);
   } catch (IOException var3) {
      throw new IntegrationModuleException(I18nHelper.getLabel("error.get.system.services.failed"));
   }

   XMLGregorianCalendar version = null;
   version = getVersionNewXml(xml);
   return version;
}
 
Example 9
Source Project: anno4j   Source File: SqlTimestampMarshall.java    License: Apache License 2.0 5 votes vote down vote up
public Literal serialize(Timestamp object) {
	GregorianCalendar gc = new GregorianCalendar(0, 0, 0);
	gc.setTime(object);
	XMLGregorianCalendar xgc = factory.newXMLGregorianCalendar(gc);
	BigDecimal fraction = BigDecimal.valueOf(object.getNanos(), 9);
	xgc.setFractionalSecond(fraction);
	String label = xgc.toXMLFormat();
	return vf.createLiteral(label, datatype);
}
 
Example 10
public XMLGregorianCalendar getCurrentXMLGregorianCalendar() {
    XMLGregorianCalendar xgcal = null;
    try {
        GregorianCalendar gcal = new GregorianCalendar();
        gcal.setTimeInMillis(System.currentTimeMillis());
        xgcal = DatatypeFactory.newInstance().newXMLGregorianCalendar(gcal);
    } catch (DatatypeConfigurationException ex) {
        LOG.error("Error creating a xml gregorian calendat!! ", ex);
    }
    return xgcal;
}
 
Example 11
public void setLastUpdated(XMLGregorianCalendar value) {
   this.lastUpdated = value;
}
 
Example 12
Source Project: openjdk-8-source   Source File: DateTimeDV.java    License: GNU General Public License v2.0 4 votes vote down vote up
protected XMLGregorianCalendar getXMLGregorianCalendar(DateTimeData date) {
    return datatypeFactory.newXMLGregorianCalendar(BigInteger.valueOf(date.unNormYear), date.unNormMonth,
            date.unNormDay, date.unNormHour, date.unNormMinute,
            (int)date.unNormSecond, date.unNormSecond != 0 ? getFractionalSecondsAsBigDecimal(date) : null,
            date.hasTimeZone() ? (date.timezoneHr * 60 + date.timezoneMin) : DatatypeConstants.FIELD_UNDEFINED);
}
 
Example 13
public XMLGregorianCalendar getStartDate() {
    return startDate;
}
 
Example 14
/**
 *
 *  <p>Implements Step B from http://www.w3.org/TR/xmlschema-2/#dateTime-order </p>
 * @param P calendar instance with normalized timezone offset or
 *          having same timezone as Q
 * @param Q calendar instance with normalized timezone offset or
 *          having same timezone as P
 *
 * @return result of comparing P and Q, value of
 *   {@link DatatypeConstants#EQUAL},
 *   {@link DatatypeConstants#LESSER},
 *   {@link DatatypeConstants#GREATER} or
 *   {@link DatatypeConstants#INDETERMINATE}.
 */
private static int internalCompare(XMLGregorianCalendar P,
                                   XMLGregorianCalendar Q) {

    int result;

    // compare Year.
    if (P.getEon() == Q.getEon()) {

        // Eon field is only equal when null.
        // optimized case for comparing year not requiring eon field.
        result = compareField(P.getYear(), Q.getYear());
        if (result != DatatypeConstants.EQUAL) {
            return result;
        }
    } else {
        result = compareField(P.getEonAndYear(), Q.getEonAndYear());
        if (result != DatatypeConstants.EQUAL) {
            return result;
        }
    }

    result = compareField(P.getMonth(), Q.getMonth());
    if (result != DatatypeConstants.EQUAL) {
        return result;
    }

    result = compareField(P.getDay(), Q.getDay());
    if (result != DatatypeConstants.EQUAL) {
        return result;
    }

    result = compareField(P.getHour(), Q.getHour());
    if (result != DatatypeConstants.EQUAL) {
        return result;
    }

    result = compareField(P.getMinute(), Q.getMinute());
    if (result != DatatypeConstants.EQUAL) {
        return result;
    }
    result = compareField(P.getSecond(), Q.getSecond());
    if (result != DatatypeConstants.EQUAL) {
        return result;
    }

    result = compareField(P.getFractionalSecond(), Q.getFractionalSecond());
    return result;
}
 
Example 15
public void setMinute(Calendar source, XMLGregorianCalendar target) {
	target.setMinute(source.get(Calendar.MINUTE));
}
 
Example 16
Source Project: openjdk-8   Source File: DateDV.java    License: GNU General Public License v2.0 4 votes vote down vote up
protected XMLGregorianCalendar getXMLGregorianCalendar(DateTimeData date) {
    return datatypeFactory.newXMLGregorianCalendar(date.unNormYear, date.unNormMonth,
            date.unNormDay, DatatypeConstants.FIELD_UNDEFINED, DatatypeConstants.FIELD_UNDEFINED,
            DatatypeConstants.FIELD_UNDEFINED, DatatypeConstants.FIELD_UNDEFINED,
            date.hasTimeZone() ? (date.timezoneHr * 60 + date.timezoneMin) : DatatypeConstants.FIELD_UNDEFINED);
}
 
Example 17
public XMLGregorianCalendar getLastUpdated() {
   return this.lastUpdated;
}
 
Example 18
Source Project: ldp4j   Source File: ObjectUtilTest.java    License: Apache License 2.0 4 votes vote down vote up
@Test
public void testXMLGregorianCalendarSupport() throws Exception {
	verifyTypeSupport(javax.xml.datatype.XMLGregorianCalendar.class);
}
 
Example 19
public void setDeliveryDate(XMLGregorianCalendar value) {
   this.deliveryDate = value;
}
 
Example 20
public void setDeceased(XMLGregorianCalendar value) {
   this.deceased = value;
}
 
Example 21
public void setRequested(XMLGregorianCalendar value) {
   this.requested = value;
}
 
Example 22
Source Project: jdmn   Source File: DefaultDateTimeType.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Boolean dateTimeGreaterThan(XMLGregorianCalendar first, XMLGregorianCalendar second) {
    return xmlCalendarGreaterThan(first, second);
}
 
Example 23
public XMLGregorianCalendar getCurrentDateTime() {
   return this.currentDateTime;
}
 
Example 24
Source Project: caravan   Source File: ListTypes.java    License: Apache License 2.0 4 votes vote down vote up
public void setDateTimeType(List<XMLGregorianCalendar> value) {
    this.dateTimeType = value;
}
 
Example 25
public void setDateTime(XMLGregorianCalendar value) {
   this.dateTime = value;
}
 
Example 26
Source Project: anno4j   Source File: XMLGregorianCalendarMarshall.java    License: Apache License 2.0 4 votes vote down vote up
public Literal serialize(XMLGregorianCalendar object) {
	return vf.createLiteral(object);
}
 
Example 27
Source Project: hsac-fitnesse-fixtures   Source File: CalendarUtil.java    License: Apache License 2.0 3 votes vote down vote up
/**
 * Add Days to a Gregorian Calendar.
 * 
 * @param cal The XMLGregorianCalendar source
 * @param amount The amount of days. Can be a negative Integer to substract.
 * @return A XMLGregorianCalendar with the new Date
 */
public XMLGregorianCalendar addDays(final XMLGregorianCalendar cal, final int amount) {
    XMLGregorianCalendar to = buildXMLGregorianCalendarDate(cal);
    // Add amount of months
    to.add(addDays(amount));
    return to;
}
 
Example 28
@Test
public void convert_date_to_XMLGregorianCalendar()
		throws DatatypeConfigurationException {

	GregorianCalendar gCalendar = new GregorianCalendar();

	XMLGregorianCalendar xmlGregorianCalendar = DatatypeFactory
			.newInstance().newXMLGregorianCalendar(gCalendar);

	logger.info(xmlGregorianCalendar);

	assertNotNull(xmlGregorianCalendar);
}
 
Example 29
/**
 * Obtient la valeur de la propriété time.
 * 
 * @return
 *     possible object is
 *     {@link XMLGregorianCalendar }
 *     
 */
public XMLGregorianCalendar getTime() {
    return time;
}
 
Example 30
Source Project: icure-backend   Source File: ContentType.java    License: GNU General Public License v2.0 2 votes vote down vote up
/**
 * Sets the value of the time property.
 * 
 * @param value
 *     allowed object is
 *     {@link XMLGregorianCalendar }
 *     
 */
public void setTime(XMLGregorianCalendar value) {
    this.time = value;
}