GenericAddress

Bei der Ausgabe von GenericAddress und abgeleiteten CTs wird nun neben dem ISO-Country-Code auch das Land in übersetzter Form ausgegeben.

git-svn-id: https://svn.libreccm.org/ccm/trunk@623 8810af33-2d31-482b-a856-94f89814c4df
master
quasi 2010-11-18 19:14:57 +00:00
parent d02a207bba
commit 7bf1e264fa
4 changed files with 131 additions and 127 deletions

View File

@ -23,7 +23,7 @@
<xrd:property name="/object/type/displayName"/> <xrd:property name="/object/type/displayName"/>
<xrd:property name="/object/type/associatedObjectType"/> <xrd:property name="/object/type/associatedObjectType"/>
<xrd:property name="/object/type/className"/> <xrd:property name="/object/type/className"/>
<xrd:property name="/object/type/isInternal"/> <xrd:property name="/object/type/mode"/>
<xrd:property name="/object/type/itemFormID"/> <xrd:property name="/object/type/itemFormID"/>
</xrd:attributes> </xrd:attributes>
<xrd:associations rule="include"> <xrd:associations rule="include">

View File

@ -4,10 +4,12 @@
*/ */
package com.arsdigita.cms; package com.arsdigita.cms;
import com.arsdigita.cms.contenttypes.GenericAddress;
import com.arsdigita.dispatcher.DispatcherHelper; import com.arsdigita.dispatcher.DispatcherHelper;
import com.arsdigita.domain.DomainObject; import com.arsdigita.domain.DomainObject;
import com.arsdigita.domain.DomainObjectTraversalAdapter; import com.arsdigita.domain.DomainObjectTraversalAdapter;
import com.arsdigita.domain.DomainObjectXMLRenderer; import com.arsdigita.domain.DomainObjectXMLRenderer;
import com.arsdigita.persistence.metadata.Property;
import com.arsdigita.xml.Element; import com.arsdigita.xml.Element;
/** /**
@ -22,14 +24,12 @@ import com.arsdigita.xml.Element;
* *
* @author quasi * @author quasi
*/ */
public class ContentItemXMLRenderer extends DomainObjectXMLRenderer { public class ContentItemXMLRenderer extends DomainObjectXMLRenderer {
public ContentItemXMLRenderer(Element root) { public ContentItemXMLRenderer(Element root) {
super(root); super(root);
} }
// This method will be called by DomainObjectTraversal.walk() // This method will be called by DomainObjectTraversal.walk()
// It's purpose is to test for ContentBundle objects and if found, replace // It's purpose is to test for ContentBundle objects and if found, replace
// that object with the negotiated version of the content item. // that object with the negotiated version of the content item.
@ -50,4 +50,24 @@ public class ContentItemXMLRenderer extends DomainObjectXMLRenderer {
super.walk(adapter, nObj, path, context, linkObject); super.walk(adapter, nObj, path, context, linkObject);
} }
@Override
protected void handleAttribute(DomainObject obj,
String path,
Property property) {
String name = property.getName();
if (obj instanceof GenericAddress) {
if (name.equals("isoCountryCode")) {
super.handleAttribute(obj, path, property);
Element element = newElement(m_element, "country");
element.setText(GenericAddress.getCountryNameFromIsoCode(((GenericAddress) obj).getIsoCountryCode()));
return;
}
}
super.handleAttribute(obj, path, property);
}
} }

View File

@ -115,10 +115,7 @@ public class SimpleXMLGenerator implements XMLGenerator {
if (!item.getClass().getName().equals(className)) { if (!item.getClass().getName().equals(className)) {
s_log.info("Specializing item"); s_log.info("Specializing item");
try { try {
item = (ContentItem) DomainObjectFactory.newInstance(new OID(item. item = (ContentItem) DomainObjectFactory.newInstance(new OID(item. getObjectType().getQualifiedName(), item.getID()));
getObjectType().getQualifiedName(),
item.
getID()));
} catch (DataObjectNotFoundException ex) { } catch (DataObjectNotFoundException ex) {
throw new UncheckedWrapperException( throw new UncheckedWrapperException(
(String) GlobalizationUtil.globalize( (String) GlobalizationUtil.globalize(
@ -133,8 +130,7 @@ public class SimpleXMLGenerator implements XMLGenerator {
XMLGenerator xitem = (XMLGenerator) item; XMLGenerator xitem = (XMLGenerator) item;
xitem.generateXML(state, parent, useContext); xitem.generateXML(state, parent, useContext);
} else if (className.equals( } else if (className.equals("com.arsdigita.cms.UserDefinedContentItem")) {
"com.arsdigita.cms.UserDefinedContentItem")) {
s_log.info("Item is a user defined content item"); s_log.info("Item is a user defined content item");
UserDefinedContentItem UDItem = (UserDefinedContentItem) item; UserDefinedContentItem UDItem = (UserDefinedContentItem) item;
generateUDItemXML(UDItem, state, parent, useContext); generateUDItemXML(UDItem, state, parent, useContext);
@ -145,8 +141,7 @@ public class SimpleXMLGenerator implements XMLGenerator {
// This is the preferred method // This is the preferred method
Element content = startElement(useContext); Element content = startElement(useContext);
ContentItemXMLRenderer renderer = ContentItemXMLRenderer renderer = new ContentItemXMLRenderer(content);
new ContentItemXMLRenderer(content);
renderer.setWrapAttributes(true); renderer.setWrapAttributes(true);
renderer.setWrapRoot(false); renderer.setWrapRoot(false);

View File

@ -45,10 +45,19 @@ import org.apache.log4j.Logger;
*/ */
public class DomainObjectXMLRenderer extends DomainObjectTraversal { public class DomainObjectXMLRenderer extends DomainObjectTraversal {
private static final Logger s_log = Logger.getLogger private static final Logger s_log = Logger.getLogger(DomainObjectXMLRenderer.class);
(DomainObjectXMLRenderer.class);
private static Map s_formatters = new HashMap(); private static Map s_formatters = new HashMap();
private Stack m_elements = new Stack();
protected Element m_element;
private boolean m_wrapRoot = false;
private boolean m_wrapObjects = false;
private boolean m_wrapAttributes = false;
private boolean m_revisitFullObject = false;
private Map m_objectElements;
private String m_namespaceURI;
private String m_namespacePrefix;
private DomainObjectXMLFormatter m_formatter;
private String m_context;
/** /**
* Registers a traversal formatter for an object type in a given * Registers a traversal formatter for an object type in a given
@ -87,10 +96,10 @@ public class DomainObjectXMLRenderer extends DomainObjectTraversal {
public static void registerFormatter(String type, public static void registerFormatter(String type,
DomainObjectXMLFormatter formatter, DomainObjectXMLFormatter formatter,
String context) { String context) {
if( s_log.isDebugEnabled() ) { if (s_log.isDebugEnabled()) {
s_log.debug( "Registering formatter " + s_log.debug("Registering formatter "
formatter.getClass().getName() + " for type " + type + + formatter.getClass().getName() + " for type " + type
" in context " + context ); + " in context " + context);
} }
registerFormatter(MetadataRoot.getMetadataRoot().getObjectType(type), registerFormatter(MetadataRoot.getMetadataRoot().getObjectType(type),
@ -121,8 +130,7 @@ public class DomainObjectXMLRenderer extends DomainObjectTraversal {
public static DomainObjectXMLFormatter getFormatter( public static DomainObjectXMLFormatter getFormatter(
ObjectType type, ObjectType type,
String context) { String context) {
return (DomainObjectXMLFormatter)s_formatters return (DomainObjectXMLFormatter) s_formatters.get(new AdapterKey(type, context));
.get(new AdapterKey(type, context));
} }
/** /**
@ -140,29 +148,13 @@ public class DomainObjectXMLRenderer extends DomainObjectTraversal {
while (formatter == null && type != null) { while (formatter == null && type != null) {
formatter = getFormatter(type, context); formatter = getFormatter(type, context);
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
s_log.debug("getFormatter("+type+","+context+")="+formatter); s_log.debug("getFormatter(" + type + "," + context + ")=" + formatter);
} }
type = type.getSupertype(); type = type.getSupertype();
} }
return formatter; return formatter;
} }
private Stack m_elements = new Stack();
private Element m_element;
private boolean m_wrapRoot = false;
private boolean m_wrapObjects = false;
private boolean m_wrapAttributes = false;
private boolean m_revisitFullObject = false;
private Map m_objectElements;
private String m_namespaceURI;
private String m_namespacePrefix;
private DomainObjectXMLFormatter m_formatter;
private String m_context;
/** /**
* Creates a new DomainObject XML renderer * Creates a new DomainObject XML renderer
* that outputs XML into the element passed into * that outputs XML into the element passed into
@ -191,7 +183,7 @@ public class DomainObjectXMLRenderer extends DomainObjectTraversal {
propertyPath, propertyPath,
prop, value); prop, value);
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
s_log.debug("FORMAT "+obj+" m_formatter="+m_formatter+" rendered="+rendered); s_log.debug("FORMAT " + obj + " m_formatter=" + m_formatter + " rendered=" + rendered);
} }
if (rendered == null) { if (rendered == null) {
// try supertype formatters // try supertype formatters
@ -205,7 +197,7 @@ public class DomainObjectXMLRenderer extends DomainObjectTraversal {
rendered = null; rendered = null;
} }
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
s_log.debug("FALLBACK supertype "+objectType+" formatter="+formatter+" rendered="+rendered); s_log.debug("FALLBACK supertype " + objectType + " formatter=" + formatter + " rendered=" + rendered);
} }
objectType = objectType.getSupertype(); objectType = objectType.getSupertype();
} }
@ -223,8 +215,8 @@ public class DomainObjectXMLRenderer extends DomainObjectTraversal {
String context, String context,
DomainObjectTraversalAdapter adapter) { DomainObjectTraversalAdapter adapter) {
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
s_log.debug("Traversing " + obj + " for context " + context + " " + s_log.debug("Traversing " + obj + " for context " + context + " "
"using adapter " + adapter); + "using adapter " + adapter);
} }
m_formatter = findFormatter(obj.getObjectType(), context); m_formatter = findFormatter(obj.getObjectType(), context);
@ -237,7 +229,6 @@ public class DomainObjectXMLRenderer extends DomainObjectTraversal {
super.walk(obj, context, adapter); super.walk(obj, context, adapter);
} }
/** /**
* Determines XML output for root object. * Determines XML output for root object.
* If set to true a separate element will * If set to true a separate element will
@ -281,7 +272,6 @@ public class DomainObjectXMLRenderer extends DomainObjectTraversal {
m_revisitFullObject = value; m_revisitFullObject = value;
} }
public boolean isWrappingAttributes() { public boolean isWrappingAttributes() {
return m_wrapAttributes; return m_wrapAttributes;
} }
@ -312,7 +302,7 @@ public class DomainObjectXMLRenderer extends DomainObjectTraversal {
protected void endObject(DomainObject obj, protected void endObject(DomainObject obj,
String path) { String path) {
if (m_wrapRoot || !path.equals("/object")) { if (m_wrapRoot || !path.equals("/object")) {
m_element = (Element)m_elements.pop(); m_element = (Element) m_elements.pop();
} }
} }
@ -322,7 +312,7 @@ public class DomainObjectXMLRenderer extends DomainObjectTraversal {
if (m_revisitFullObject) { if (m_revisitFullObject) {
priorElement = (Element) m_objectElements.get(obj.getOID()); priorElement = (Element) m_objectElements.get(obj.getOID());
} }
if (priorElement != null && (m_elements.search(priorElement)==-1)) { if (priorElement != null && (m_elements.search(priorElement) == -1)) {
String name = m_wrapObjects ? "object" : nameFromPath(path); String name = m_wrapObjects ? "object" : nameFromPath(path);
Element element = newElement(m_element, name, priorElement); Element element = newElement(m_element, name, priorElement);
} else { } else {
@ -342,11 +332,11 @@ public class DomainObjectXMLRenderer extends DomainObjectTraversal {
if (m_wrapAttributes) { if (m_wrapAttributes) {
Object formattedValue = format(obj, path, property, value); Object formattedValue = format(obj, path, property, value);
if (formattedValue instanceof Element) { if (formattedValue instanceof Element) {
m_element.addContent((Element)formattedValue); m_element.addContent((Element) formattedValue);
} else { } else {
Element element = newElement(m_element, name); Element element = newElement(m_element, name);
element.setText((String)format(obj, path, property, value)); element.setText((String) format(obj, path, property, value));
// locale-independent date output // locale-independent date output
if (value instanceof Date) { if (value instanceof Date) {
@ -354,7 +344,7 @@ public class DomainObjectXMLRenderer extends DomainObjectTraversal {
Calendar calDate = Calendar.getInstance(); Calendar calDate = Calendar.getInstance();
calDate.setTime(date); calDate.setTime(date);
element.addAttribute("year", Integer.toString(calDate.get(Calendar.YEAR))); element.addAttribute("year", Integer.toString(calDate.get(Calendar.YEAR)));
element.addAttribute("month", Integer.toString(calDate.get(Calendar.MONTH)+1)); element.addAttribute("month", Integer.toString(calDate.get(Calendar.MONTH) + 1));
element.addAttribute("day", Integer.toString(calDate.get(Calendar.DAY_OF_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("hour", Integer.toString(calDate.get(Calendar.HOUR_OF_DAY)));
element.addAttribute("minute", Integer.toString(calDate.get(Calendar.MINUTE))); element.addAttribute("minute", Integer.toString(calDate.get(Calendar.MINUTE)));
@ -373,7 +363,7 @@ public class DomainObjectXMLRenderer extends DomainObjectTraversal {
} }
} else { } else {
m_element.addAttribute(property.getName(), m_element.addAttribute(property.getName(),
(String)format(obj, path, property, value)); (String) format(obj, path, property, value));
} }
} }
} }
@ -392,11 +382,10 @@ public class DomainObjectXMLRenderer extends DomainObjectTraversal {
String path, String path,
Property property) { Property property) {
if (m_wrapObjects) { if (m_wrapObjects) {
m_element = (Element)m_elements.pop(); m_element = (Element) m_elements.pop();
} }
} }
protected void beginAssociation(DomainObject obj, protected void beginAssociation(DomainObject obj,
String path, String path,
Property property) { Property property) {
@ -411,7 +400,7 @@ public class DomainObjectXMLRenderer extends DomainObjectTraversal {
String path, String path,
Property property) { Property property) {
if (m_wrapObjects) { if (m_wrapObjects) {
m_element = (Element)m_elements.pop(); m_element = (Element) m_elements.pop();
} }
} }
@ -429,18 +418,18 @@ public class DomainObjectXMLRenderer extends DomainObjectTraversal {
protected Element newElement(Element parent, protected Element newElement(Element parent,
String name) { String name) {
return m_namespaceURI == null ? return m_namespaceURI == null
parent.newChildElement(name) : ? parent.newChildElement(name)
parent.newChildElement(m_namespacePrefix + ":" + name, : parent.newChildElement(m_namespacePrefix + ":" + name,
m_namespaceURI); m_namespaceURI);
} }
protected Element newElement(Element parent, protected Element newElement(Element parent,
String name, String name,
Element copy) { Element copy) {
return m_namespaceURI == null ? return m_namespaceURI == null
parent.newChildElement(name, copy) : ? parent.newChildElement(name, copy)
parent.newChildElement(m_namespacePrefix + ":" + name, : parent.newChildElement(m_namespacePrefix + ":" + name,
m_namespaceURI, m_namespaceURI,
copy); copy);
} }