comparison artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/TypeConverter.java @ 7403:99312d2b4a20

Removed dc:to-date(). Added 'date' type for <dc:convert> instead.
author Sascha L. Teichmann <teichmann@intevation.de>
date Mon, 21 Oct 2013 17:43:01 +0200
parents af13ceeba52a
children c2acc840963b
comparison
equal deleted inserted replaced
7402:93ae1aa8ade9 7403:99312d2b4a20
6 * documentation coming with Dive4Elements River for details. 6 * documentation coming with Dive4Elements River for details.
7 */ 7 */
8 8
9 package org.dive4elements.river.artifacts.datacage.templating; 9 package org.dive4elements.river.artifacts.datacage.templating;
10 10
11 import java.util.Date;
12
13 import org.apache.log4j.Logger;
14
11 public class TypeConverter 15 public class TypeConverter
12 { 16 {
17 private static Logger log = Logger.getLogger(TypeConverter.class);
18
13 private TypeConverter() { 19 private TypeConverter() {
14 } 20 }
15 21
16 public static Object convert(Object object, String type) { 22 public static Object convert(Object object, String type) {
17 23
18 if (type == null) { 24 if (type == null) {
19 return object; 25 return object;
20 } 26 }
21 27
22 if ("Integer".equals(type)) { 28 type = type.toLowerCase();
29
30 if ("integer".equals(type)) {
23 return Integer.valueOf(object.toString()); 31 return Integer.valueOf(object.toString());
24 } 32 }
25 33
26 if ("Double".equals(type)) { 34 if ("double".equals(type)) {
27 return Double.valueOf(object.toString()); 35 return Double.valueOf(object.toString());
28 } 36 }
29 37
30 if ("String".equals(type)) { 38 if ("string".equals(type)) {
31 return object.toString(); 39 return object.toString();
40 }
41
42 if ("date".equals(type)) {
43 if (object instanceof Date) {
44 return object;
45 }
46 try {
47 return new Date((long)Double.parseDouble(object.toString()));
48 }
49 catch (NumberFormatException nfe) {
50 log.warn(nfe);
51 return null;
52 }
32 } 53 }
33 54
34 // TODO: Add more types 55 // TODO: Add more types
35 56
36 return object; 57 return object;

http://dive4elements.wald.intevation.org