- Added some attributes to the date output in the XML (see #2092)
- Added missing text in search-paginator file of foundry-base git-svn-id: https://svn.libreccm.org/ccm/trunk@3112 8810af33-2d31-482b-a856-94f89814c4dfmaster
parent
c63f52f14e
commit
d3ac65f9e1
|
|
@ -18,6 +18,7 @@
|
||||||
*/
|
*/
|
||||||
package com.arsdigita.domain;
|
package com.arsdigita.domain;
|
||||||
|
|
||||||
|
import com.arsdigita.globalization.GlobalizationHelper;
|
||||||
import com.arsdigita.persistence.metadata.Property;
|
import com.arsdigita.persistence.metadata.Property;
|
||||||
import com.arsdigita.persistence.metadata.ObjectType;
|
import com.arsdigita.persistence.metadata.ObjectType;
|
||||||
import com.arsdigita.persistence.metadata.MetadataRoot;
|
import com.arsdigita.persistence.metadata.MetadataRoot;
|
||||||
|
|
@ -25,20 +26,23 @@ import com.arsdigita.xml.Element;
|
||||||
|
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import com.arsdigita.xml.XML;
|
import com.arsdigita.xml.XML;
|
||||||
|
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.text.FieldPosition;
|
|
||||||
import java.util.Stack;
|
import java.util.Stack;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An implementation of DomainObjectTraversal that generates an XML tree representing the DomainObject. The output
|
* An implementation of DomainObjectTraversal that generates an XML tree representing the
|
||||||
* format of the XML can be controlled using the various setWrapXXX methods detailed below.
|
* DomainObject. The output format of the XML can be controlled using the various setWrapXXX methods
|
||||||
|
* detailed below.
|
||||||
*
|
*
|
||||||
* @version $Id: DomainObjectXMLRenderer.java 2141 2011-01-16 12:17:15Z pboy $
|
* @version $Id: DomainObjectXMLRenderer.java 2141 2011-01-16 12:17:15Z pboy $
|
||||||
*/
|
*/
|
||||||
|
|
@ -61,9 +65,9 @@ public class DomainObjectXMLRenderer extends DomainObjectTraversal {
|
||||||
/**
|
/**
|
||||||
* Registers a traversal formatter for an object type in a given context.
|
* Registers a traversal formatter for an object type in a given context.
|
||||||
*
|
*
|
||||||
* @param type the object type whose items will be traversed
|
* @param type the object type whose items will be traversed
|
||||||
* @param formatter the formatter for controlling object traversal
|
* @param formatter the formatter for controlling object traversal
|
||||||
* @param context the context in which the formatter should be used
|
* @param context the context in which the formatter should be used
|
||||||
*/
|
*/
|
||||||
public static void registerFormatter(final ObjectType type,
|
public static void registerFormatter(final ObjectType type,
|
||||||
final DomainObjectXMLFormatter formatter,
|
final DomainObjectXMLFormatter formatter,
|
||||||
|
|
@ -74,7 +78,7 @@ public class DomainObjectXMLRenderer extends DomainObjectTraversal {
|
||||||
/**
|
/**
|
||||||
* Unregisteres a traversal formatter for an object type in a given context
|
* Unregisteres a traversal formatter for an object type in a given context
|
||||||
*
|
*
|
||||||
* @param type the object type whose items will be traversed
|
* @param type the object type whose items will be traversed
|
||||||
* @param context the context in which the formatter should be used
|
* @param context the context in which the formatter should be used
|
||||||
*/
|
*/
|
||||||
public static void unregisterFormatter(final ObjectType type, final String context) {
|
public static void unregisterFormatter(final ObjectType type, final String context) {
|
||||||
|
|
@ -84,17 +88,17 @@ public class DomainObjectXMLRenderer extends DomainObjectTraversal {
|
||||||
/**
|
/**
|
||||||
* Registers a traversal formatter for an object type in a given context.
|
* Registers a traversal formatter for an object type in a given context.
|
||||||
*
|
*
|
||||||
* @param type the object type whose items will be traversed
|
* @param type the object type whose items will be traversed
|
||||||
* @param formatter the formatter for controlling object traversal
|
* @param formatter the formatter for controlling object traversal
|
||||||
* @param context the context in which the formatter should be used
|
* @param context the context in which the formatter should be used
|
||||||
*/
|
*/
|
||||||
public static void registerFormatter(final String type,
|
public static void registerFormatter(final String type,
|
||||||
final DomainObjectXMLFormatter formatter,
|
final DomainObjectXMLFormatter formatter,
|
||||||
final String context) {
|
final 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),
|
||||||
|
|
@ -105,7 +109,7 @@ public class DomainObjectXMLRenderer extends DomainObjectTraversal {
|
||||||
/**
|
/**
|
||||||
* Unregisteres a traversal formatter for an object type in a given context
|
* Unregisteres a traversal formatter for an object type in a given context
|
||||||
*
|
*
|
||||||
* @param type the object type whose items will be traversed
|
* @param type the object type whose items will be traversed
|
||||||
* @param context the context in which the formatter should be used
|
* @param context the context in which the formatter should be used
|
||||||
*/
|
*/
|
||||||
public static void unregisterFormatter(final String type,
|
public static void unregisterFormatter(final String type,
|
||||||
|
|
@ -117,7 +121,7 @@ public class DomainObjectXMLRenderer extends DomainObjectTraversal {
|
||||||
/**
|
/**
|
||||||
* Retrieves the traversal formatter for an object type in a given context.
|
* Retrieves the traversal formatter for an object type in a given context.
|
||||||
*
|
*
|
||||||
* @param type the object type to lookup
|
* @param type the object type to lookup
|
||||||
* @param context the formatter context
|
* @param context the formatter context
|
||||||
*/
|
*/
|
||||||
public static DomainObjectXMLFormatter getFormatter(final ObjectType type, final String context) {
|
public static DomainObjectXMLFormatter getFormatter(final ObjectType type, final String context) {
|
||||||
|
|
@ -125,13 +129,14 @@ public class DomainObjectXMLRenderer extends DomainObjectTraversal {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the closest matching traversal formatter for an object type in a given context. The algorithm looks for
|
* Retrieves the closest matching traversal formatter for an object type in a given context. The
|
||||||
* an exact match, then considers the supertype, and the supertype's supertype. If no match could be found at all,
|
* algorithm looks for an exact match, then considers the supertype, and the supertype's
|
||||||
* returns null
|
* supertype. If no match could be found at all, returns null
|
||||||
*
|
*
|
||||||
* @param type the object type to search for
|
* @param type the object type to search for
|
||||||
* @param context the formatter context
|
* @param context the formatter context
|
||||||
* @return
|
*
|
||||||
|
* @return
|
||||||
*/
|
*/
|
||||||
public static DomainObjectXMLFormatter findFormatter(final ObjectType type, final String context) {
|
public static DomainObjectXMLFormatter findFormatter(final ObjectType type, final String context) {
|
||||||
DomainObjectXMLFormatter formatter = null;
|
DomainObjectXMLFormatter formatter = null;
|
||||||
|
|
@ -147,7 +152,8 @@ public class DomainObjectXMLRenderer extends DomainObjectTraversal {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new DomainObject XML renderer that outputs XML into the element passed into the constructor.
|
* Creates a new DomainObject XML renderer that outputs XML into the element passed into the
|
||||||
|
* constructor.
|
||||||
*
|
*
|
||||||
* @param root the XML element in which to output children
|
* @param root the XML element in which to output children
|
||||||
*/
|
*/
|
||||||
|
|
@ -161,12 +167,14 @@ public class DomainObjectXMLRenderer extends DomainObjectTraversal {
|
||||||
m_namespaceURI = uri;
|
m_namespaceURI = uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Object format(final DomainObject obj, final String path, final Property prop, final Object value) {
|
protected Object format(final DomainObject obj, final String path, final Property prop,
|
||||||
|
final Object value) {
|
||||||
if (m_formatter != null) {
|
if (m_formatter != null) {
|
||||||
final String propertyPath = appendToPath(path, prop.getName());
|
final String propertyPath = appendToPath(path, prop.getName());
|
||||||
Object rendered = m_formatter.format(obj, propertyPath, prop, value);
|
Object rendered = m_formatter.format(obj, propertyPath, 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) {
|
||||||
|
|
@ -181,8 +189,9 @@ public class DomainObjectXMLRenderer extends DomainObjectTraversal {
|
||||||
rendered = formatter.format(obj, propertyPath, prop, value);
|
rendered = formatter.format(obj, propertyPath, prop, value);
|
||||||
}
|
}
|
||||||
if (s_log.isDebugEnabled()) {
|
if (s_log.isDebugEnabled()) {
|
||||||
s_log.debug("FALLBACK supertype " + objectType + " formatter=" + formatter + " rendered="
|
s_log.debug("FALLBACK supertype " + objectType + " formatter=" + formatter
|
||||||
+ rendered);
|
+ " rendered="
|
||||||
|
+ rendered);
|
||||||
}
|
}
|
||||||
objectType = objectType.getSupertype();
|
objectType = objectType.getSupertype();
|
||||||
}
|
}
|
||||||
|
|
@ -196,10 +205,11 @@ public class DomainObjectXMLRenderer extends DomainObjectTraversal {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void walk(final DomainObject obj, final String context, final DomainObjectTraversalAdapter adapter) {
|
protected void walk(final DomainObject obj, final String context,
|
||||||
|
final 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);
|
||||||
|
|
@ -214,35 +224,37 @@ public class DomainObjectXMLRenderer extends DomainObjectTraversal {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines XML output for root object. If set to true a separate element will be output for the root object, if
|
* Determines XML output for root object. If set to true a separate element will be output for
|
||||||
* false, then the element passed into the constructor will be used.
|
* the root object, if false, then the element passed into the constructor will be used.
|
||||||
* @param value
|
*
|
||||||
|
* @param value
|
||||||
*/
|
*/
|
||||||
public void setWrapRoot(final boolean value) {
|
public void setWrapRoot(final boolean value) {
|
||||||
m_wrapRoot = value;
|
m_wrapRoot = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines XML output used for objects. If set to true, then a wrapper XML element will be generated for the
|
* Determines XML output used for objects. If set to true, then a wrapper XML element will be
|
||||||
* association, and then individual elements generated for each object. If false then no wrapper XML element will be
|
* generated for the association, and then individual elements generated for each object. If
|
||||||
* produced.
|
* false then no wrapper XML element will be produced.
|
||||||
* @param value
|
*
|
||||||
|
* @param value
|
||||||
*/
|
*/
|
||||||
public void setWrapObjects(final boolean value) {
|
public void setWrapObjects(final boolean value) {
|
||||||
m_wrapObjects = value;
|
m_wrapObjects = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines XML output used for scalar attributes. If set to true, then each attribute is output as a separate
|
* Determines XML output used for scalar attributes. If set to true, then each attribute is
|
||||||
* element, otherwise, attributes are output as simple attributes.
|
* output as a separate element, otherwise, attributes are output as simple attributes.
|
||||||
*/
|
*/
|
||||||
public void setWrapAttributes(final boolean value) {
|
public void setWrapAttributes(final boolean value) {
|
||||||
m_wrapAttributes = value;
|
m_wrapAttributes = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines XML output used for objects. If set to true, then repeated objects will generate full xml. If false
|
* Determines XML output used for objects. If set to true, then repeated objects will generate
|
||||||
* then only the OID will be printed.
|
* full xml. If false then only the OID will be printed.
|
||||||
*/
|
*/
|
||||||
public void setRevisitFullObject(final boolean value) {
|
public void setRevisitFullObject(final boolean value) {
|
||||||
m_revisitFullObject = value;
|
m_revisitFullObject = value;
|
||||||
|
|
@ -304,7 +316,8 @@ public class DomainObjectXMLRenderer extends DomainObjectTraversal {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void handleAttribute(final DomainObject obj, final String path, final Property property) {
|
protected void handleAttribute(final DomainObject obj, final String path,
|
||||||
|
final Property property) {
|
||||||
final String name = property.getName();
|
final String name = property.getName();
|
||||||
final Object value = obj.get(name);
|
final Object value = obj.get(name);
|
||||||
|
|
||||||
|
|
@ -327,24 +340,40 @@ public class DomainObjectXMLRenderer extends DomainObjectTraversal {
|
||||||
calDate.setTime(date);
|
calDate.setTime(date);
|
||||||
|
|
||||||
// locale-independent date output
|
// locale-independent date output
|
||||||
element.addAttribute("year", Integer.toString(calDate.get(Calendar.YEAR)));
|
element.addAttribute("year",
|
||||||
element.addAttribute("month", Integer.toString(calDate.get(Calendar.MONTH) + 1));
|
Integer.toString(calDate.get(Calendar.YEAR)));
|
||||||
element.addAttribute("day", Integer.toString(calDate.get(Calendar.DAY_OF_MONTH)));
|
element.addAttribute("month",
|
||||||
element.addAttribute("hour", Integer.toString(calDate.get(Calendar.HOUR_OF_DAY)));
|
Integer.toString(calDate.get(Calendar.MONTH) + 1));
|
||||||
element.addAttribute("minute", Integer.toString(calDate.get(Calendar.MINUTE)));
|
element.addAttribute("day",
|
||||||
element.addAttribute("second", Integer.toString(calDate.get(Calendar.SECOND)));
|
Integer.toString(calDate.get(Calendar.DAY_OF_MONTH)));
|
||||||
|
element.addAttribute("dayOfWeek",
|
||||||
|
Integer.toString(calDate.get(Calendar.DAY_OF_WEEK)));
|
||||||
|
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)));
|
||||||
|
|
||||||
// Quasimodo: BEGIN
|
// Quasimodo: BEGIN
|
||||||
// Add attributes for date and time
|
// Add attributes for date and time
|
||||||
final Locale negLocale = com.arsdigita.globalization.GlobalizationHelper.getNegotiatedLocale();
|
final Locale negLocale = GlobalizationHelper.getNegotiatedLocale();
|
||||||
final DateFormat dateFormatter = DateFormat.getDateInstance(DateFormat.MEDIUM, negLocale);
|
final DateFormat dateFormatter = DateFormat.getDateInstance(
|
||||||
final DateFormat longDateFormatter = DateFormat.getDateInstance(DateFormat.LONG, negLocale);
|
DateFormat.MEDIUM, negLocale);
|
||||||
final DateFormat timeFormatter = DateFormat.getTimeInstance(DateFormat.SHORT, negLocale);
|
final DateFormat longDateFormatter = DateFormat.getDateInstance(
|
||||||
|
DateFormat.LONG, negLocale);
|
||||||
|
final DateFormat timeFormatter = DateFormat.getTimeInstance(
|
||||||
|
DateFormat.SHORT, negLocale);
|
||||||
element.addAttribute("date", dateFormatter.format(date));
|
element.addAttribute("date", dateFormatter.format(date));
|
||||||
element.addAttribute("longDate", longDateFormatter.format(date));
|
element.addAttribute("longDate", longDateFormatter.format(date));
|
||||||
element.addAttribute("time", timeFormatter.format(date));
|
element.addAttribute("time", timeFormatter.format(date));
|
||||||
element.addAttribute("monthName", calDate.getDisplayName(Calendar.MONTH, Calendar.LONG,
|
element.addAttribute("monthName", calDate.getDisplayName(
|
||||||
negLocale));
|
Calendar.MONTH, Calendar.LONG, negLocale));
|
||||||
|
element.addAttribute("dayName", calDate.getDisplayName(Calendar.DAY_OF_WEEK,
|
||||||
|
Calendar.LONG,
|
||||||
|
negLocale));
|
||||||
|
element.addAttribute("dayNameShort", calDate.getDisplayName(
|
||||||
|
Calendar.DAY_OF_WEEK, Calendar.SHORT, negLocale));
|
||||||
// Quasimodo: END
|
// Quasimodo: END
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -370,7 +399,8 @@ public class DomainObjectXMLRenderer extends DomainObjectTraversal {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void beginAssociation(final DomainObject obj, final String path, final Property property) {
|
protected void beginAssociation(final DomainObject obj, final String path,
|
||||||
|
final Property property) {
|
||||||
if (m_wrapObjects) {
|
if (m_wrapObjects) {
|
||||||
final Element element = newElement(m_element, property.getName());
|
final Element element = newElement(m_element, property.getName());
|
||||||
m_elements.push(m_element);
|
m_elements.push(m_element);
|
||||||
|
|
@ -397,18 +427,17 @@ public class DomainObjectXMLRenderer extends DomainObjectTraversal {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Element newElement(final Element parent, final String name) {
|
protected Element newElement(final Element parent, final String name) {
|
||||||
if (m_namespaceURI == null) {
|
if (m_namespaceURI == null) {
|
||||||
return parent.newChildElement(name);
|
return parent.newChildElement(name);
|
||||||
} else {
|
} else {
|
||||||
final StringBuffer nameBuffer = new StringBuffer();
|
final StringBuffer nameBuffer = new StringBuffer();
|
||||||
nameBuffer.append(m_namespacePrefix);
|
nameBuffer.append(m_namespacePrefix);
|
||||||
nameBuffer.append(':');
|
nameBuffer.append(':');
|
||||||
nameBuffer.append(name);
|
nameBuffer.append(name);
|
||||||
|
|
||||||
return parent.newChildElement(name, m_namespaceURI);
|
return parent.newChildElement(name, m_namespaceURI);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// return m_namespaceURI == null
|
// return m_namespaceURI == null
|
||||||
// ? parent.newChildElement(name)
|
// ? parent.newChildElement(name)
|
||||||
// : parent.newChildElement(m_namespacePrefix + ":" + name,
|
// : parent.newChildElement(m_namespacePrefix + ":" + name,
|
||||||
|
|
@ -417,16 +446,16 @@ public class DomainObjectXMLRenderer extends DomainObjectTraversal {
|
||||||
|
|
||||||
protected Element newElement(final Element parent, final String name, final Element copy) {
|
protected Element newElement(final Element parent, final String name, final Element copy) {
|
||||||
if (m_namespaceURI == null) {
|
if (m_namespaceURI == null) {
|
||||||
return parent.newChildElement(name, copy);
|
return parent.newChildElement(name, copy);
|
||||||
} else {
|
} else {
|
||||||
final StringBuffer nameBuffer = new StringBuffer();
|
final StringBuffer nameBuffer = new StringBuffer();
|
||||||
nameBuffer.append(m_namespacePrefix);
|
nameBuffer.append(m_namespacePrefix);
|
||||||
nameBuffer.append(':');
|
nameBuffer.append(':');
|
||||||
nameBuffer.append(name);
|
nameBuffer.append(name);
|
||||||
|
|
||||||
return parent.newChildElement(name, m_namespaceURI, copy);
|
return parent.newChildElement(name, m_namespaceURI, 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,
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,10 @@
|
||||||
<translation lang="de"> von </translation>
|
<translation lang="de"> von </translation>
|
||||||
<translation lang="en"> from </translation>
|
<translation lang="en"> from </translation>
|
||||||
</text>
|
</text>
|
||||||
|
<text id="navbar/separator">
|
||||||
|
<translation lang="de"> </translation>
|
||||||
|
<translation lang="en"> </translation>
|
||||||
|
</text>
|
||||||
|
|
||||||
<text id="header/resultinfo/text/begin">
|
<text id="header/resultinfo/text/begin">
|
||||||
<translation lang="de"> Zeige Ergebnisse </translation>
|
<translation lang="de"> Zeige Ergebnisse </translation>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue