Java Code Examples for javax.xml.datatype.XMLGregorianCalendar#toXMLFormat()

The following examples show how to use javax.xml.datatype.XMLGregorianCalendar#toXMLFormat() . 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
Source File: RuntimeBuiltinLeafInfoImpl.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
public String print(XMLGregorianCalendar cal) {
    XMLSerializer xs = XMLSerializer.getInstance();

    QName type = xs.getSchemaType();
    if (type != null) {
        try {
            checkXmlGregorianCalendarFieldRef(type, cal);
            String format = xmlGregorianCalendarFormatString.get(type);
            if (format != null) {
                return format(format, cal);
            }
        } catch (javax.xml.bind.MarshalException e) {
            // see issue 649
            xs.handleEvent(new ValidationEventImpl(ValidationEvent.WARNING, e.getMessage(),
                xs.getCurrentLocation(null) ));
            return "";
        }
    }
    return cal.toXMLFormat();
}
 
Example 2
Source File: RuntimeBuiltinLeafInfoImpl.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
public String print(XMLGregorianCalendar cal) {
    XMLSerializer xs = XMLSerializer.getInstance();

    QName type = xs.getSchemaType();
    if (type != null) {
        try {
            checkXmlGregorianCalendarFieldRef(type, cal);
            String format = xmlGregorianCalendarFormatString.get(type);
            if (format != null) {
                return format(format, cal);
            }
        } catch (javax.xml.bind.MarshalException e) {
            // see issue 649
            xs.handleEvent(new ValidationEventImpl(ValidationEvent.WARNING, e.getMessage(),
                xs.getCurrentLocation(null) ));
            return "";
        }
    }
    return cal.toXMLFormat();
}
 
Example 3
Source File: RuntimeBuiltinLeafInfoImpl.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public String print(XMLGregorianCalendar cal) {
    XMLSerializer xs = XMLSerializer.getInstance();

    QName type = xs.getSchemaType();
    if (type != null) {
        try {
            checkXmlGregorianCalendarFieldRef(type, cal);
            String format = xmlGregorianCalendarFormatString.get(type);
            if (format != null) {
                return format(format, cal);
            }
        } catch (javax.xml.bind.MarshalException e) {
            // see issue 649
            xs.handleEvent(new ValidationEventImpl(ValidationEvent.WARNING, e.getMessage(),
                xs.getCurrentLocation(null) ));
            return "";
        }
    }
    return cal.toXMLFormat();
}
 
Example 4
Source File: RuntimeBuiltinLeafInfoImpl.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public String print(XMLGregorianCalendar cal) {
    XMLSerializer xs = XMLSerializer.getInstance();

    QName type = xs.getSchemaType();
    if (type != null) {
        try {
            checkXmlGregorianCalendarFieldRef(type, cal);
            String format = xmlGregorianCalendarFormatString.get(type);
            if (format != null) {
                return format(format, cal);
            }
        } catch (javax.xml.bind.MarshalException e) {
            // see issue 649
            xs.handleEvent(new ValidationEventImpl(ValidationEvent.WARNING, e.getMessage(),
                xs.getCurrentLocation(null) ));
            return "";
        }
    }
    return cal.toXMLFormat();
}
 
Example 5
Source File: RuntimeBuiltinLeafInfoImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public String print(XMLGregorianCalendar cal) {
    XMLSerializer xs = XMLSerializer.getInstance();

    QName type = xs.getSchemaType();
    if (type != null) {
        try {
            checkXmlGregorianCalendarFieldRef(type, cal);
            String format = xmlGregorianCalendarFormatString.get(type);
            if (format != null) {
                return format(format, cal);
            }
        } catch (javax.xml.bind.MarshalException e) {
            // see issue 649
            xs.handleEvent(new ValidationEventImpl(ValidationEvent.WARNING, e.getMessage(),
                xs.getCurrentLocation(null) ));
            return "";
        }
    }
    return cal.toXMLFormat();
}
 
Example 6
Source File: RuntimeBuiltinLeafInfoImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public String print(XMLGregorianCalendar cal) {
    XMLSerializer xs = XMLSerializer.getInstance();

    QName type = xs.getSchemaType();
    if (type != null) {
        try {
            checkXmlGregorianCalendarFieldRef(type, cal);
            String format = xmlGregorianCalendarFormatString.get(type);
            if (format != null) {
                return format(format, cal);
            }
        } catch (javax.xml.bind.MarshalException e) {
            // see issue 649
            xs.handleEvent(new ValidationEventImpl(ValidationEvent.WARNING, e.getMessage(),
                xs.getCurrentLocation(null) ));
            return "";
        }
    }
    return cal.toXMLFormat();
}
 
Example 7
Source File: RuntimeBuiltinLeafInfoImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public String print(XMLGregorianCalendar cal) {
    XMLSerializer xs = XMLSerializer.getInstance();

    QName type = xs.getSchemaType();
    if (type != null) {
        try {
            checkXmlGregorianCalendarFieldRef(type, cal);
            String format = xmlGregorianCalendarFormatString.get(type);
            if (format != null) {
                return format(format, cal);
            }
        } catch (javax.xml.bind.MarshalException e) {
            // see issue 649
            xs.handleEvent(new ValidationEventImpl(ValidationEvent.WARNING, e.getMessage(),
                xs.getCurrentLocation(null) ));
            return "";
        }
    }
    return cal.toXMLFormat();
}
 
Example 8
Source File: RuntimeBuiltinLeafInfoImpl.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public String print(XMLGregorianCalendar cal) {
    XMLSerializer xs = XMLSerializer.getInstance();

    QName type = xs.getSchemaType();
    if (type != null) {
        try {
            checkXmlGregorianCalendarFieldRef(type, cal);
            String format = xmlGregorianCalendarFormatString.get(type);
            if (format != null) {
                return format(format, cal);
            }
        } catch (javax.xml.bind.MarshalException e) {
            // see issue 649
            xs.handleEvent(new ValidationEventImpl(ValidationEvent.WARNING, e.getMessage(),
                xs.getCurrentLocation(null) ));
            return "";
        }
    }
    return cal.toXMLFormat();
}
 
Example 9
Source File: XAdESSignatureBuilder.java    From dss with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Creates SigningTime DOM object element like :
 *
 * <pre>
 * 	{@code
 * 		<SigningTime>2013-11-23T11:22:52Z</SigningTime>
 * 	}
 * </pre>
 */
private void incorporateSigningTime() {
	final Date signingDate = params.bLevel().getSigningDate();
	final XMLGregorianCalendar xmlGregorianCalendar = DomUtils.createXMLGregorianCalendar(signingDate);
	final String xmlSigningTime = xmlGregorianCalendar.toXMLFormat();

	final Element signingTimeDom = DomUtils.createElementNS(documentDom, getXadesNamespace(), getCurrentXAdESElements().getElementSigningTime());
	signedSignaturePropertiesDom.appendChild(signingTimeDom);
	final Text textNode = documentDom.createTextNode(xmlSigningTime);
	signingTimeDom.appendChild(textNode);
}
 
Example 10
Source File: SqlTimestampMarshall.java    From anno4j with 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 11
Source File: StringUtil.java    From yawl with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static String longToDateTime(long time) {
    GregorianCalendar gregCal = new GregorianCalendar();
    gregCal.setTimeInMillis(time);
    try {
        XMLGregorianCalendar cal =
                DatatypeFactory.newInstance().newXMLGregorianCalendar(gregCal);
        return cal.toXMLFormat();
    } catch (DatatypeConfigurationException dce) {
        return null;
    }
}
 
Example 12
Source File: XMLGregorianCalendarTest.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void testIt() {

		final XMLGregorianCalendar calendar = getDatatypeFactory()
				.newXMLGregorianCalendar();

		calendar.setDay(15);
		calendar.setTimezone(120);
		final String gDayString = calendar.toXMLFormat();
		logger.debug(gDayString);
	}
 
Example 13
Source File: CalendarUtilTest.java    From hsac-fitnesse-fixtures with Apache License 2.0 5 votes vote down vote up
/**
 * Test BuildXMLGregorianCalendar.
 */
@Test
public void testBuildXMLGregorianCalendar() {
    Calendar today = Calendar.getInstance();
    XMLGregorianCalendar cal = calendarUtil.buildXMLGregorianCalendar();
    assertTrue(cal.getYear() == today.get(Calendar.YEAR));
    assertTrue(cal.getMonth() == today.get(Calendar.MONTH) + 1);
    assertTrue(cal.getDay() == today.get(Calendar.DAY_OF_MONTH));

    String dateString = cal.toXMLFormat();
    XMLGregorianCalendar calFromString = calendarUtil.buildXMLGregorianCalendar(dateString);
    assertEquals(cal, calFromString);
}
 
Example 14
Source File: NotificationServiceImpl.java    From OpenESPI-Common-java with Apache License 2.0 5 votes vote down vote up
@Override
public void notify(Subscription subscription,
		XMLGregorianCalendar startDate, XMLGregorianCalendar endDate) {
	
	String thirdPartyNotificationURI = subscription
			.getApplicationInformation().getThirdPartyNotifyUri();
	String separator = "?";
	String subscriptionURI = subscription.getApplicationInformation()
			.getDataCustodianResourceEndpoint()
			+ "/Batch/Subscription/"
			+ subscription.getId();
	
	if (startDate != null) {
		subscriptionURI = subscriptionURI + separator + "published-min="
				+ startDate.toXMLFormat();
		separator = "&";
	}
	
	if (endDate != null) {
		subscriptionURI = subscriptionURI + separator + "published-max="
				+ endDate.toXMLFormat();
	}

	BatchList batchList = new BatchList();
	batchList.getResources().add(subscriptionURI);
	notifyInternal(thirdPartyNotificationURI, batchList);
}
 
Example 15
Source File: ExportFilterTests.java    From OpenESPI-DataCustodian-java with Apache License 2.0 5 votes vote down vote up
private String getXMLTime(int millis) throws DatatypeConfigurationException {
	DatatypeFactory datatypeFactory = DatatypeFactory.newInstance();
	GregorianCalendar cal = getGregorianCalendar(millis);
	XMLGregorianCalendar xmlGregorianCalendar = datatypeFactory
			.newXMLGregorianCalendar(cal);
	xmlGregorianCalendar.setFractionalSecond(null);
	return xmlGregorianCalendar.toXMLFormat();
}
 
Example 16
Source File: ExportServiceTests.java    From OpenESPI-DataCustodian-java with Apache License 2.0 5 votes vote down vote up
private String getXMLTime(int millis) throws DatatypeConfigurationException {
	DatatypeFactory datatypeFactory = DatatypeFactory.newInstance();
	GregorianCalendar cal = getGregorianCalendar(millis);
	XMLGregorianCalendar xmlGregorianCalendar = datatypeFactory
			.newXMLGregorianCalendar(cal);
	xmlGregorianCalendar.setFractionalSecond(null);
	return xmlGregorianCalendar.toXMLFormat();
}
 
Example 17
Source File: ParseDate.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
protected Value evaluate(ValueFactory valueFactory, Value arg1, Value arg2) throws ValueExprEvaluationException {
	if (!(arg1 instanceof Literal) || !(arg2 instanceof Literal)) {
		throw new ValueExprEvaluationException("Both arguments must be literals");
	}
	Literal value = (Literal) arg1;
	Literal format = (Literal) arg2;

	FieldAwareGregorianCalendar cal = new FieldAwareGregorianCalendar();

	SimpleDateFormat formatter = new SimpleDateFormat(format.getLabel());
	formatter.setCalendar(cal);
	try {
		formatter.parse(value.getLabel());
	} catch (ParseException e) {
		throw new ValueExprEvaluationException(e);
	}

	XMLGregorianCalendar xmlCal = datatypeFactory.newXMLGregorianCalendar(cal);
	if (!cal.isDateSet()) {
		xmlCal.setYear(DatatypeConstants.FIELD_UNDEFINED);
		xmlCal.setMonth(DatatypeConstants.FIELD_UNDEFINED);
		xmlCal.setDay(DatatypeConstants.FIELD_UNDEFINED);
	}
	if (!cal.isTimeSet()) {
		xmlCal.setHour(DatatypeConstants.FIELD_UNDEFINED);
		xmlCal.setMinute(DatatypeConstants.FIELD_UNDEFINED);
		xmlCal.setSecond(DatatypeConstants.FIELD_UNDEFINED);
	}
	if (!cal.isMillisecondSet()) {
		xmlCal.setMillisecond(DatatypeConstants.FIELD_UNDEFINED);
	}

	String dateValue = xmlCal.toXMLFormat();
	QName dateType = xmlCal.getXMLSchemaType();
	if (!cal.isTimezoneSet()) {
		int len = dateValue.length();
		if (dateValue.endsWith("Z")) {
			dateValue = dateValue.substring(0, len - 1);
		} else if (dateValue.charAt(len - 6) == '+' || dateValue.charAt(len - 6) == '-') {
			dateValue = dateValue.substring(0, len - 6);
		}
	}

	return valueFactory.createLiteral(dateValue, XMLDatatypeUtil.qnameToURI(dateType));
}
 
Example 18
Source File: CalendarMemLiteral.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public CalendarMemLiteral(Object creator, XMLGregorianCalendar calendar) {
	this(creator, calendar.toXMLFormat(), calendar);
}
 
Example 19
Source File: CalendarLiteral.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Creates a literal for the specified calendar using a datatype appropriate for the value indicated by
 * {@link XMLGregorianCalendar#getXMLSchemaType()}.
 */
protected CalendarLiteral(XMLGregorianCalendar calendar) {
	super(calendar.toXMLFormat(), XMLDatatypeUtil.qnameToURI(calendar.getXMLSchemaType()));
	this.calendar = calendar;
}
 
Example 20
Source File: CalendarConverter.java    From semweb4j with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/** 
	 * return all normalized to UTC. 
	 * @param cal should be a GregorianCalendar 
	 * */
	public static String encodeCalendar_toXSDDateTime(Calendar cal) {

		// convert cal to UTC
		GregorianCalendar utcCalendar = new GregorianCalendar(TimeZone
				.getTimeZone("UTC"));
		utcCalendar.setTimeInMillis(cal.getTimeInMillis());

		XMLGregorianCalendar xmlCalendar = dtFactory.newXMLGregorianCalendar(utcCalendar);
		xmlCalendar = xmlCalendar.normalize();
		return xmlCalendar.toXMLFormat();
		
//		// TODO get rid of Jena dependency
//		XSDDateTime x = new XSDDateTime(utcCalendar);
//
//		StringBuffer buff = new StringBuffer();
//
//		int years = x.getYears();
//		buff.append(years);
//		buff.append("-");
//
//		if (x.getMonths() < 10)
//			buff.append("0");
//		buff.append(x.getMonths());
//		buff.append("-");
//
//		if (x.getDays() < 10)
//			buff.append("0");
//		buff.append(x.getDays());
//		buff.append("T");
//
//		if (x.getHours() < 10)
//			buff.append("0");
//		buff.append(x.getHours());
//
//		buff.append(":");
//		if (x.getMinutes() < 10)
//			buff.append("0");
//		buff.append(x.getMinutes());
//
//		buff.append(":");
//		if (x.getFullSeconds() < 10)
//			buff.append("0");
//		buff.append(x.getFullSeconds());
//
//		// TODO append milliseconds
//		// double milliseconds = ((double) x.getSeconds() - (double)
//		// x.getFullSeconds());
//
//		buff.append("Z");
//		return buff.toString();

	}