From: <ap...@vh...> - 2006-02-28 12:09:15
|
Author: apevec Date: 2006-02-28 13:08:54 +0100 (Tue, 28 Feb 2006) New Revision: 1099 Modified: trunk/ccm-core/src/com/arsdigita/domain/DomainObjectXMLRenderer.java Log: Experimental: locale-independent Date output adds Date elements year, month, day, hour, minute and second as attributes of the date XML element This is backward compatible with existing XSL templates, new attributes are ignored and human-readable XML text is still there. Of course, styling needs to be modified to take advantage of new attributes. Modified: trunk/ccm-core/src/com/arsdigita/domain/DomainObjectXMLRenderer.java =================================================================== --- trunk/ccm-core/src/com/arsdigita/domain/DomainObjectXMLRenderer.java 2006-02-28 12:00:22 UTC (rev 1098) +++ trunk/ccm-core/src/com/arsdigita/domain/DomainObjectXMLRenderer.java 2006-02-28 12:08:54 UTC (rev 1099) @@ -22,6 +22,9 @@ import com.arsdigita.persistence.metadata.ObjectType; import com.arsdigita.persistence.metadata.MetadataRoot; import com.arsdigita.xml.Element; + +import java.util.Calendar; +import java.util.Date; import java.util.HashMap; import java.util.Map; import com.arsdigita.xml.XML; @@ -338,6 +341,18 @@ if (m_wrapAttributes) { Element element = newElement(m_element, name); element.setText(format(obj, path, property, value)); + // locale-independent date output + if (value instanceof Date) { + Date date = (Date) value; + Calendar calDate = Calendar.getInstance(); + calDate.setTime(date); + element.addAttribute("year", Integer.toString(calDate.get(Calendar.YEAR))); + element.addAttribute("month", Integer.toString(calDate.get(1+Calendar.MONTH))); + element.addAttribute("day", Integer.toString(calDate.get(Calendar.DAY_OF_MONTH))); + element.addAttribute("hour", Integer.toString(calDate.get(Calendar.HOUR_OF_DAY))); + element.addAttribute("minute", Integer.toString(calDate.get(Calendar.MINUTE))); + element.addAttribute("second", Integer.toString(calDate.get(Calendar.SECOND))); + } } else { m_element.addAttribute(property.getName(), format(obj, path, property, value)); |