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/associatedObjectType"/>
<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:attributes>
<xrd:associations rule="include">

View File

@ -4,10 +4,12 @@
*/
package com.arsdigita.cms;
import com.arsdigita.cms.contenttypes.GenericAddress;
import com.arsdigita.dispatcher.DispatcherHelper;
import com.arsdigita.domain.DomainObject;
import com.arsdigita.domain.DomainObjectTraversalAdapter;
import com.arsdigita.domain.DomainObjectXMLRenderer;
import com.arsdigita.persistence.metadata.Property;
import com.arsdigita.xml.Element;
/**
@ -22,14 +24,12 @@ import com.arsdigita.xml.Element;
*
* @author quasi
*/
public class ContentItemXMLRenderer extends DomainObjectXMLRenderer {
public ContentItemXMLRenderer(Element root) {
super(root);
}
// This method will be called by DomainObjectTraversal.walk()
// It's purpose is to test for ContentBundle objects and if found, replace
// 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);
}
@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)) {
s_log.info("Specializing item");
try {
item = (ContentItem) DomainObjectFactory.newInstance(new OID(item.
getObjectType().getQualifiedName(),
item.
getID()));
item = (ContentItem) DomainObjectFactory.newInstance(new OID(item. getObjectType().getQualifiedName(), item.getID()));
} catch (DataObjectNotFoundException ex) {
throw new UncheckedWrapperException(
(String) GlobalizationUtil.globalize(
@ -133,8 +130,7 @@ public class SimpleXMLGenerator implements XMLGenerator {
XMLGenerator xitem = (XMLGenerator) item;
xitem.generateXML(state, parent, useContext);
} else if (className.equals(
"com.arsdigita.cms.UserDefinedContentItem")) {
} else if (className.equals("com.arsdigita.cms.UserDefinedContentItem")) {
s_log.info("Item is a user defined content item");
UserDefinedContentItem UDItem = (UserDefinedContentItem) item;
generateUDItemXML(UDItem, state, parent, useContext);
@ -145,8 +141,7 @@ public class SimpleXMLGenerator implements XMLGenerator {
// This is the preferred method
Element content = startElement(useContext);
ContentItemXMLRenderer renderer =
new ContentItemXMLRenderer(content);
ContentItemXMLRenderer renderer = new ContentItemXMLRenderer(content);
renderer.setWrapAttributes(true);
renderer.setWrapRoot(false);

View File

@ -45,10 +45,19 @@ import org.apache.log4j.Logger;
*/
public class DomainObjectXMLRenderer extends DomainObjectTraversal {
private static final Logger s_log = Logger.getLogger
(DomainObjectXMLRenderer.class);
private static final Logger s_log = Logger.getLogger(DomainObjectXMLRenderer.class);
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
@ -88,9 +97,9 @@ public class DomainObjectXMLRenderer extends DomainObjectTraversal {
DomainObjectXMLFormatter formatter,
String context) {
if (s_log.isDebugEnabled()) {
s_log.debug( "Registering formatter " +
formatter.getClass().getName() + " for type " + type +
" in context " + context );
s_log.debug("Registering formatter "
+ formatter.getClass().getName() + " for type " + type
+ " in context " + context);
}
registerFormatter(MetadataRoot.getMetadataRoot().getObjectType(type),
@ -121,8 +130,7 @@ public class DomainObjectXMLRenderer extends DomainObjectTraversal {
public static DomainObjectXMLFormatter getFormatter(
ObjectType type,
String context) {
return (DomainObjectXMLFormatter)s_formatters
.get(new AdapterKey(type, context));
return (DomainObjectXMLFormatter) s_formatters.get(new AdapterKey(type, context));
}
/**
@ -147,22 +155,6 @@ public class DomainObjectXMLRenderer extends DomainObjectTraversal {
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
* that outputs XML into the element passed into
@ -223,8 +215,8 @@ public class DomainObjectXMLRenderer extends DomainObjectTraversal {
String context,
DomainObjectTraversalAdapter adapter) {
if (s_log.isDebugEnabled()) {
s_log.debug("Traversing " + obj + " for context " + context + " " +
"using adapter " + adapter);
s_log.debug("Traversing " + obj + " for context " + context + " "
+ "using adapter " + adapter);
}
m_formatter = findFormatter(obj.getObjectType(), context);
@ -237,7 +229,6 @@ public class DomainObjectXMLRenderer extends DomainObjectTraversal {
super.walk(obj, context, adapter);
}
/**
* Determines XML output for root object.
* If set to true a separate element will
@ -281,7 +272,6 @@ public class DomainObjectXMLRenderer extends DomainObjectTraversal {
m_revisitFullObject = value;
}
public boolean isWrappingAttributes() {
return m_wrapAttributes;
}
@ -396,7 +386,6 @@ public class DomainObjectXMLRenderer extends DomainObjectTraversal {
}
}
protected void beginAssociation(DomainObject obj,
String path,
Property property) {
@ -429,18 +418,18 @@ public class DomainObjectXMLRenderer extends DomainObjectTraversal {
protected Element newElement(Element parent,
String name) {
return m_namespaceURI == null ?
parent.newChildElement(name) :
parent.newChildElement(m_namespacePrefix + ":" + name,
return m_namespaceURI == null
? parent.newChildElement(name)
: parent.newChildElement(m_namespacePrefix + ":" + name,
m_namespaceURI);
}
protected Element newElement(Element parent,
String name,
Element copy) {
return m_namespaceURI == null ?
parent.newChildElement(name, copy) :
parent.newChildElement(m_namespacePrefix + ":" + name,
return m_namespaceURI == null
? parent.newChildElement(name, copy)
: parent.newChildElement(m_namespacePrefix + ":" + name,
m_namespaceURI,
copy);
}