Author: apevec Date: 2005-12-08 01:18:16 +0100 (Thu, 08 Dec 2005) New Revision: 1040 Modified: trunk/ccm-cms/src/WEB-INF/resources/cms-item-adapters.xml trunk/ccm-core/src/com/arsdigita/domain/DomainObjectXMLRenderer.java trunk/ccm-core/src/com/arsdigita/domain/SimpleDomainObjectXMLFormatter.java trunk/ccm-core/src/com/arsdigita/domain/xml/TraversalHandler.java trunk/ccm-forum/src/com/arsdigita/forum/ui/MessageXMLFormatter.java Log: Implement fallback to supertype formatters, otherwise only formatters directly attached to the most specific type are used. Also don't attach empty formatters to the type i.e. no formats defined in traversal config XML. Experimental: use FullDateFormatter from Fabrice for /object/auditing/*Date Modified: trunk/ccm-cms/src/WEB-INF/resources/cms-item-adapters.xml =================================================================== --- trunk/ccm-cms/src/WEB-INF/resources/cms-item-adapters.xml 2005-12-07 21:44:44 UTC (rev 1039) +++ trunk/ccm-cms/src/WEB-INF/resources/cms-item-adapters.xml 2005-12-08 00:18:16 UTC (rev 1040) @@ -32,9 +32,16 @@ </xrd:adapter> <xrd:adapter objectType="com.arsdigita.cms.ContentPage" extends="com.arsdigita.cms.ContentItem" traversalClass="com.arsdigita.cms.contenttypes.ContentItemTraversalAdapter"> + <xrd:attributes rule="exclude"> + <xrd:property name="/object/auditing/id"/> + </xrd:attributes> <xrd:associations rule="include"> <xrd:property name="/object/auditing"/> </xrd:associations> + <xrd:formatter property="/object/auditing/creationDate" + class="com.arsdigita.xml.formatters.FullDateFormatter"/> + <xrd:formatter property="/object/auditing/lastModifiedDate" + class="com.arsdigita.xml.formatters.FullDateFormatter"/> </xrd:adapter> <!-- Adds a text asset --> Modified: trunk/ccm-core/src/com/arsdigita/domain/DomainObjectXMLRenderer.java =================================================================== --- trunk/ccm-core/src/com/arsdigita/domain/DomainObjectXMLRenderer.java 2005-12-07 21:44:44 UTC (rev 1039) +++ trunk/ccm-core/src/com/arsdigita/domain/DomainObjectXMLRenderer.java 2005-12-08 00:18:16 UTC (rev 1040) @@ -86,7 +86,7 @@ String context) { if( s_log.isDebugEnabled() ) { s_log.debug( "Registering formatter " + - formatter.getClass().getName() + " for type " + type + + formatter + " for type " + type + " in context " + context ); } @@ -136,6 +136,9 @@ DomainObjectXMLFormatter formatter = null; while (formatter == null && type != null) { formatter = getFormatter(type, context); + if (s_log.isDebugEnabled()) { + s_log.debug("getFormatter("+type+","+context+")="+formatter); + } type = type.getSupertype(); } return formatter; @@ -155,6 +158,7 @@ private String m_namespacePrefix; private DomainObjectXMLFormatter m_formatter; + private String m_context; /** * Creates a new DomainObject XML renderer @@ -179,10 +183,35 @@ Property prop, Object value) { if (m_formatter != null) { - return m_formatter.format(obj, - appendToPath(path, prop.getName()), + String propertyPath = appendToPath(path, prop.getName()); + String rendered = m_formatter.format(obj, + propertyPath, prop, value); + if (s_log.isDebugEnabled()) { + s_log.debug("FORMAT "+obj+" m_formatter="+m_formatter+" rendered="+rendered); + } + if (rendered == null) { + // try supertype formatters + ObjectType objectType = obj.getObjectType().getSupertype(); + DomainObjectXMLFormatter formatter = m_formatter; + while (rendered == null && formatter != null && objectType != null) { + formatter = findFormatter(objectType, m_context); + if (formatter != null) { + rendered = formatter.format(obj, propertyPath, prop, value); + } else { + rendered = null; + } + if (s_log.isDebugEnabled()) { + s_log.debug("FALLBACK supertype "+objectType+" formatter="+formatter+" rendered="+rendered); + } + objectType = objectType.getSupertype(); + } + } + if (rendered != null) { + return rendered; + } // else fallback to default below } + s_log.debug("DEFAULT XML.format"); return XML.format(value); } @@ -195,6 +224,7 @@ } m_formatter = findFormatter(obj.getObjectType(), context); + m_context = context; if (s_log.isDebugEnabled()) { s_log.debug("Found formatter " + m_formatter); @@ -371,6 +401,6 @@ parent.newChildElement(name, copy) : parent.newChildElement(m_namespacePrefix + ":" + name, m_namespaceURI, - copy); + copy); } } Modified: trunk/ccm-core/src/com/arsdigita/domain/SimpleDomainObjectXMLFormatter.java =================================================================== --- trunk/ccm-core/src/com/arsdigita/domain/SimpleDomainObjectXMLFormatter.java 2005-12-07 21:44:44 UTC (rev 1039) +++ trunk/ccm-core/src/com/arsdigita/domain/SimpleDomainObjectXMLFormatter.java 2005-12-08 00:18:16 UTC (rev 1040) @@ -50,14 +50,9 @@ Object value) { Formatter formatter = (Formatter)m_formatters.get(path); if (formatter == null) { - if (s_log.isDebugEnabled()) { - s_log.debug("No formatter for " + path + - " for object "+obj+ - " and property "+prop+ - " and value "+value+ - " using default"); - } - return XML.format(value); + // don't fallback to default here + // let the upper layer (XMLRenderer) try super types + return null; } if (s_log.isDebugEnabled()) { s_log.debug("Processing property " + path + @@ -68,5 +63,9 @@ } return formatter.format(value); } + + public boolean isEmpty() { + return m_formatters.isEmpty(); + } } Modified: trunk/ccm-core/src/com/arsdigita/domain/xml/TraversalHandler.java =================================================================== --- trunk/ccm-core/src/com/arsdigita/domain/xml/TraversalHandler.java 2005-12-07 21:44:44 UTC (rev 1039) +++ trunk/ccm-core/src/com/arsdigita/domain/xml/TraversalHandler.java 2005-12-08 00:18:16 UTC (rev 1040) @@ -221,10 +221,12 @@ (m_objectType, m_adapter, m_typeContext == null ? m_context : m_typeContext); - registerFormatter + if (!m_formatters.isEmpty()) { + registerFormatter (m_objectType, m_formatters, m_typeContext == null ? m_context : m_typeContext); + } m_objectType = null; m_adapter = null; m_typeContext = null; Modified: trunk/ccm-forum/src/com/arsdigita/forum/ui/MessageXMLFormatter.java =================================================================== --- trunk/ccm-forum/src/com/arsdigita/forum/ui/MessageXMLFormatter.java 2005-12-07 21:44:44 UTC (rev 1039) +++ trunk/ccm-forum/src/com/arsdigita/forum/ui/MessageXMLFormatter.java 2005-12-08 00:18:16 UTC (rev 1040) @@ -38,4 +38,9 @@ } return super.format(obj, path, prop, value); } + + public boolean isEmpty() { + return false; + } + } |