[Geoserver-devel] [jira] Created: (GEOS-311) Date-Attributes in requests and responses should have xs:dateTime / xs:date format

Date-Attributes in requests and responses should have xs:dateTime / xs:date format
-----------------------------------------------------------------------------------

         Key: GEOS-311
         URL: http://jira.codehaus.org/browse/GEOS-311
     Project: GeoServer
        Type: Bug
  Components: WFS
    Reporter: Holger Lang
Assigned to: Chris Holmes
     Fix For: 1.2.5
Attachments: DefaultAttributeType.java

Hi,

I think date attributes in wfs-requests and wfs-responses should have xs:date or xs:dateTime format. In the moment, the format, that is send and demanded from GeoServer is something like "Thu Feb 10 00:00:00 CET 2005".

The easiest way to fix this bug seems to me, to write a subclass of Date that overrides the method toString() and use this class in the class Temporal in org.geotools.feature.DefaultAttributeType.java instead of Date.
But I don't know if it is a good idea, to do the fix at that place, because I don't know, where else the class Temporal is needed...

For parsing an instance of Date into a String with the xs:dateTime format and accordingly parsing a String with xs:dateTime format into an instance of Date, I propose to use the class org.jibx.runtime.Utility that is part of the jar-file jibx-run.jar from the JiBX project (see http://www.jibx.org).

Here is an fix attempt:

    public static class Temporal extends DefaultAttributeType {

        public Temporal(String name, boolean nillable, int fieldLength,
            Object defaultValue) {
            super(name, DateTime.class, nillable, fieldLength, defaultValue);
        }

        public Object parse(Object value) throws IllegalArgumentException {
            if (value == null) {
                return value;
            }

            if (type.isAssignableFrom(value.getClass())) {
                return value;
            }

            if (value instanceof Number) {
                return new DateTime(((Number) value).longValue());
            }

            if (value instanceof java.util.Calendar) {
                return new DateTime(((java.util.Calendar) value).getTimeInMillis());
            }

            if (value instanceof java.util.Date) {
                return new DateTime(((Date) value).getTime());
            }

            try {

                return new DateTime(Utility.parseDateTime(value.toString()));

            } catch (JiBXException je) {
                throw new IllegalArgumentException("unable to parse " + value
                    + " as Date");
            }
        }
        
        public Object duplicate(Object o) throws IllegalAttributeException {
            if (o == null)
                return null;
            if (o instanceof Date) {
                Date d = (Date) o;

                return new DateTime(d.getTime());
            }
            throw new IllegalAttributeException("Cannot duplicate " + o.getClass().getName());
        }

         public class DateTime extends Date{

             private final Logger LOGGER = Logger.getLogger(
            "org.vfny.geoserver.global");

            public DateTime() {
                super();
            }

            public DateTime(long time) {
                super(time);
            }
            public String toString() {
                try {
                    return Utility.serializeDateTime(this);
                } catch (JiBXException je) {
                    LOGGER.fine("Could not parse DateTime to String:" + je);
                }
                return null;
            }
        }
    }

Best regards,
Holger

--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://jira.codehaus.org/secure/Administrators.jspa
-
If you want more information on JIRA, or have a bug to report see:
   http://www.atlassian.com/software/jira

     [ http://jira.codehaus.org/browse/GEOS-311?page=all ]
     
dblasby reopened GEOS-311:
--------------------------

This fix kills cite tests because its parsing a PostGIS Date (ie. day-month-year) into a "DateTime". When it goes to convert this to XML, its turns into a date-and-time "2002-12-02T08:00:00".

Date-Attributes in requests and responses should have xs:dateTime / xs:date format
-----------------------------------------------------------------------------------

         Key: GEOS-311
         URL: http://jira.codehaus.org/browse/GEOS-311
     Project: GeoServer
        Type: Bug
  Components: WFS
    Reporter: Holger Lang
    Assignee: Chris Holmes
     Fix For: 1.3-rc1
Attachments: DateUtil.class, DefaultAttributeType.java, TemporalAttributeType$DateTime.class, TemporalAttributeType.class, jibx-run.jar

Hi,
I think date attributes in wfs-requests and wfs-responses should have xs:date or xs:dateTime format. In the moment, the format, that is send and demanded from GeoServer is something like "Thu Feb 10 00:00:00 CET 2005".
The easiest way to fix this bug seems to me, to write a subclass of Date that overrides the method toString() and use this class in the class Temporal in org.geotools.feature.DefaultAttributeType.java instead of Date.
But I don't know if it is a good idea, to do the fix at that place, because I don't know, where else the class Temporal is needed...
For parsing an instance of Date into a String with the xs:dateTime format and accordingly parsing a String with xs:dateTime format into an instance of Date, I propose to use the class org.jibx.runtime.Utility that is part of the jar-file jibx-run.jar from the JiBX project (see http://www.jibx.org).
Here is an fix attempt:
    public static class Temporal extends DefaultAttributeType {
        public Temporal(String name, boolean nillable, int fieldLength,
            Object defaultValue) {
            super(name, DateTime.class, nillable, fieldLength, defaultValue);
        }
        public Object parse(Object value) throws IllegalArgumentException {
            if (value == null) {
                return value;
            }
            if (type.isAssignableFrom(value.getClass())) {
                return value;
            }
            if (value instanceof Number) {
                return new DateTime(((Number) value).longValue());
            }
            if (value instanceof java.util.Calendar) {
                return new DateTime(((java.util.Calendar) value).getTimeInMillis());
            }
            if (value instanceof java.util.Date) {
                return new DateTime(((Date) value).getTime());
            }
            try {
                return new DateTime(Utility.parseDateTime(value.toString()));
            } catch (JiBXException je) {
                throw new IllegalArgumentException("unable to parse " + value
                    + " as Date");
            }
        }
        
        public Object duplicate(Object o) throws IllegalAttributeException {
            if (o == null)
                return null;
            if (o instanceof Date) {
                Date d = (Date) o;
                return new DateTime(d.getTime());
            }
            throw new IllegalAttributeException("Cannot duplicate " + o.getClass().getName());
        }
         public class DateTime extends Date{
             private final Logger LOGGER = Logger.getLogger(
            "org.vfny.geoserver.global");
            public DateTime() {
                super();
            }
            public DateTime(long time) {
                super(time);
            }
            public String toString() {
                try {
                    return Utility.serializeDateTime(this);
                } catch (JiBXException je) {
                    LOGGER.fine("Could not parse DateTime to String:" + je);
                }
                return null;
            }
        }
    }
Best regards,
Holger

--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira