Project

General

Profile

Download (1.86 KB) Statistics
| Branch: | Tag: | Revision:
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 net.sf.json.JsonConfig;
13
import net.sf.json.processors.JsonValueProcessor;
14

    
15
import org.apache.log4j.Logger;
16
import org.joda.time.Partial;
17
import org.joda.time.format.ISODateTimeFormat;
18

    
19
import eu.etaxonomy.cdm.hibernate.PartialUserType;
20

    
21
/**
22
 * Partial time as four digit year, two digit month of year, and two digit day of month (yyyy-MM-dd).
23
 * @author a.kohlbecker
24
 * @since 20.01.2008
25
 * @version 1.0
26
 */
27
public class PartialJSONValueProcessor implements JsonValueProcessor {
28
	private static Logger logger = Logger.getLogger(PartialJSONValueProcessor.class);
29

    
30
	
31
	/* (non-Javadoc)
32
	 * @see net.sf.json.processors.JsonValueProcessor#processArrayValue(java.lang.Object, net.sf.json.JsonConfig)
33
	 */
34
	public Object processArrayValue(Object object, JsonConfig jsonConfig) {
35
		if(object == null){
36
			return "";
37
		}
38
		Partial partial = (Partial) object;
39
		if (logger.isDebugEnabled()) {
40
			logger.debug("processArrayValue of joda.time.DateTime: " + PartialUserType.partialToString(partial));
41
		}
42
        return partial.toString(ISODateTimeFormat.date());
43
	}
44

    
45
	/* (non-Javadoc)
46
	 * @see net.sf.json.processors.JsonValueProcessor#processObjectValue(java.lang.String, java.lang.Object, net.sf.json.JsonConfig)
47
	 */
48
	public Object processObjectValue(String key, Object object, JsonConfig jsonConfig) {
49
		if(object == null){
50
			return "";
51
		}
52
		Partial partial = (Partial) object;
53
		if (logger.isDebugEnabled()) {
54
			logger.debug("processObjectValue of joda.time.DateTime: " + PartialUserType.partialToString(partial));
55
		}
56
		return partial.toString(ISODateTimeFormat.date());
57
	}
58
}
(8-8/10)