Java Code Examples for org.eclipse.rdf4j.model.vocabulary.XMLSchema#YEARMONTHDURATION

The following examples show how to use org.eclipse.rdf4j.model.vocabulary.XMLSchema#YEARMONTHDURATION . 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: XMLDatatypeMathUtil.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private static IRI getDatatypeForDuration(Duration duration) {
	// Could not be implemented with Duration.getXMLSchemaType that is too strict ("P1Y" is considered invalid)

	boolean yearSet = duration.isSet(DatatypeConstants.YEARS);
	boolean monthSet = duration.isSet(DatatypeConstants.MONTHS);
	boolean daySet = duration.isSet(DatatypeConstants.DAYS);
	boolean hourSet = duration.isSet(DatatypeConstants.HOURS);
	boolean minuteSet = duration.isSet(DatatypeConstants.MINUTES);
	boolean secondSet = duration.isSet(DatatypeConstants.SECONDS);

	if (!yearSet && !monthSet) {
		return XMLSchema.DAYTIMEDURATION;
	}
	if (!daySet && !hourSet && !minuteSet && !secondSet) {
		return XMLSchema.YEARMONTHDURATION;
	}
	return XMLSchema.DURATION;
}
 
Example 2
Source File: XMLDatatypeUtil.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Maps a datatype QName from the javax.xml.namespace package to an XML Schema 1.0 URI for the corresponding
 * datatype. This method recognizes the XML Schema qname mentioned in {@link DatatypeConstants}.
 *
 * Note that Java 8 / 11 do not have constants for XML Schema 1.1 datatypes like xsd:dateTimeStamp.
 *
 * @param qname One of the XML Schema qnames from {@link DatatypeConstants}.
 * @return A URI for the specified datatype.
 * @throws IllegalArgumentException If the supplied qname was not recognized by this method.
 * @see DatatypeConstants
 */
public static IRI qnameToURI(QName qname) {
	if (DatatypeConstants.DATETIME.equals(qname)) {
		return XMLSchema.DATETIME;
	} else if (DatatypeConstants.DATE.equals(qname)) {
		return XMLSchema.DATE;
	} else if (DatatypeConstants.TIME.equals(qname)) {
		return XMLSchema.TIME;
	} else if (DatatypeConstants.GYEARMONTH.equals(qname)) {
		return XMLSchema.GYEARMONTH;
	} else if (DatatypeConstants.GMONTHDAY.equals(qname)) {
		return XMLSchema.GMONTHDAY;
	} else if (DatatypeConstants.GYEAR.equals(qname)) {
		return XMLSchema.GYEAR;
	} else if (DatatypeConstants.GMONTH.equals(qname)) {
		return XMLSchema.GMONTH;
	} else if (DatatypeConstants.GDAY.equals(qname)) {
		return XMLSchema.GDAY;
	} else if (DatatypeConstants.DURATION.equals(qname)) {
		return XMLSchema.DURATION;
	} else if (DatatypeConstants.DURATION_DAYTIME.equals(qname)) {
		return XMLSchema.DAYTIMEDURATION;
	} else if (DatatypeConstants.DURATION_YEARMONTH.equals(qname)) {
		return XMLSchema.YEARMONTHDURATION;
	} else {
		throw new IllegalArgumentException("QName cannot be mapped to an XML Schema URI: " + qname.toString());
	}
}