95600657ca74f717be42192dd8641c10623f8bfd
[cdmlib.git] / cdmlib-remote / src / main / java / eu / etaxonomy / cdm / remote / json / processor / value / CalendarJSONValueProcessor.java
1 /**
2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
8 */
9
10 package eu.etaxonomy.cdm.remote.json.processor.value;
11
12 import java.text.SimpleDateFormat;
13 import java.util.Calendar;
14
15 import net.sf.json.JsonConfig;
16 import net.sf.json.processors.JsonValueProcessor;
17
18 import org.apache.logging.log4j.LogManager;import org.apache.logging.log4j.Logger;
19
20
21
22 /**
23 * @author a.kohlbecker
24 * @since 20.01.2009
25 * @version 1.0
26 */
27 public class CalendarJSONValueProcessor implements JsonValueProcessor {
28 private static Logger logger = LogManager.getLogger(DateTimeJSONValueProcessor.class);
29
30 private static SimpleDateFormat iso8601Format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssz");
31
32 /* (non-Javadoc)
33 * @see net.sf.json.processors.JsonValueProcessor#processArrayValue(java.lang.Object, net.sf.json.JsonConfig)
34 */
35 public Object processArrayValue(Object object, JsonConfig jsonConfig) {
36 if(object == null){
37 return "";
38 }
39 Calendar calendar = (Calendar) object;
40 if (logger.isDebugEnabled()) {
41 logger.debug("processArrayValue of java.util.Calendar: " + CalendarJSONValueProcessor.iso8601Format.format(calendar.getTime()));
42 }
43 return CalendarJSONValueProcessor.iso8601Format.format(calendar.getTime());
44 }
45
46 /* (non-Javadoc)
47 * @see net.sf.json.processors.JsonValueProcessor#processObjectValue(java.lang.String, java.lang.Object, net.sf.json.JsonConfig)
48 */
49 public Object processObjectValue(String key, Object object, JsonConfig jsonConfig) {
50 if(object == null){
51 return "";
52 }
53 Calendar dateTime = (Calendar) object;
54 if (logger.isDebugEnabled()) {
55 logger.debug("processObjectValue of java.util.Calendar: " + CalendarJSONValueProcessor.iso8601Format.format(dateTime.getTime()));
56 }
57 return CalendarJSONValueProcessor.iso8601Format.format(dateTime.getTime());
58 }
59 }