Package org.apache.sis.internal.xml
Class XmlUtilities
java.lang.Object
org.apache.sis.internal.system.SystemListener
org.apache.sis.internal.xml.XmlUtilities
- All Implemented Interfaces:
EventListener
Utilities methods related to XML.
- Since:
- 0.3
- Version:
- 1.3
- Author:
- Martin Desruisseaux (Geomatys)
-
Method Summary
Modifier and TypeMethodDescriptionprotected voidInvoked when the classpath changed.static DatatypeFactoryReturns the factory for creatingjavax.xml.datatypeobjects.static DatetoDate(Context context, XMLGregorianCalendar xml) Converts the given XML Gregorian calendar to a date.static TemporaltoTemporal(Context context, XMLGregorianCalendar xml) Converts the given XML Gregorian calendar to a temporal object.static XMLGregorianCalendarConverts the given temporal object to a XML Gregorian calendar.static XMLGregorianCalendarConverts the given date to a XML Gregorian calendar using the locale and timezone from the current marshalling context.static booleantrimTime(XMLGregorianCalendar gc, boolean force) Trims the time components of the given calendar if their values are zero, or leaves them unchanged otherwise (except for milliseconds).Methods inherited from class org.apache.sis.internal.system.SystemListener
add, databaseChanged, fireClasspathChanged, remove
-
Method Details
-
classpathChanged
protected void classpathChanged()Invoked when the classpath changed. This method resets thefactorytonullin order to force the search for a new instance.- Specified by:
classpathChangedin classSystemListener
-
getDatatypeFactory
Returns the factory for creatingjavax.xml.datatypeobjects.- Returns:
- the factory (never
null). - Throws:
DatatypeConfigurationException- if the factory cannot be created.
-
trimTime
Trims the time components of the given calendar if their values are zero, or leaves them unchanged otherwise (except for milliseconds). More specifically:- If the
forceargument isfalse, then:- If every time components (hour, minute, seconds and milliseconds) are zero, set
them to
FIELD_UNDEFINEDin order to prevent them from being formatted at XML marshalling time. Then returnstrue. - Otherwise returns
false. But before doing so, still set the milliseconds toFIELD_UNDEFINEDif its value was 0.
- If every time components (hour, minute, seconds and milliseconds) are zero, set
them to
- Otherwise (if the
forceargument isfalse), then the temporal part is set toFIELD_UNDEFINEDunconditionally and this method returnstrue.
Date, in which case we don't know if the time is really 0 or just unspecified. This method should be invoked only when we want to assume that a time of zero means "unspecified".This method will be deprecated after we implemented ISO 19108 in SIS.
- Parameters:
gc- the date to modify in-place.force-truefor forcing the temporal components to be removed without any check.- Returns:
trueif the time part has been completely removed,falseotherwise.
- If the
-
toXML
public static XMLGregorianCalendar toXML(Context context, Temporal date) throws DatatypeConfigurationException Converts the given temporal object to a XML Gregorian calendar. The returned calendar may have undefined fields (including undefined time zone) if the corresponding information was not provided in the given temporal object.If the returned date has a time, then it usually has millisecond accuracy. Caller may want to clear the millisecond field if it is equal to zero.
- Parameters:
context- the current (un)marshalling context, ornullif none.date- the date to convert to a XML calendar, ornull.- Returns:
- the XML calendar, or
nullifdatewas null. - Throws:
DatatypeConfigurationException- if the factory cannot be created.
-
toXML
public static XMLGregorianCalendar toXML(Context context, Date date) throws DatatypeConfigurationException Converts the given date to a XML Gregorian calendar using the locale and timezone from the current marshalling context. The returned date has millisecond accuracy. Caller may want to clear the millisecond field if it is equal to zero.- Parameters:
context- the current (un)marshalling context, ornullif none.date- the date to convert to a XML calendar, ornull.- Returns:
- the XML calendar, or
nullifdatewas null. - Throws:
DatatypeConfigurationException- if the factory cannot be created.
-
toTemporal
Converts the given XML Gregorian calendar to a temporal object. The temporal object may beLocalDate,LocalTime,LocalDateTime,OffsetDateTime,YearorYearMonthdepending on which fields are defined in the given calendar.- Parameters:
context- the current (un)marshalling context, ornullif none.xml- the XML calendar to convert to a temporal object, ornull.- Returns:
- the temporal object, or
nullifxmlis null or has too many undefined fields.
-
toDate
Converts the given XML Gregorian calendar to a date.- Parameters:
context- the current (un)marshalling context, ornullif none.xml- the XML calendar to convert to a date, ornull.- Returns:
- the date, or
nullifxmlwas null.
-