Project

General

Profile

Download (1.64 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
package eu.etaxonomy.cdm.remote.json.processor.value;
10

    
11
import org.apache.logging.log4j.LogManager;
12
import org.apache.logging.log4j.Logger;
13
import org.joda.time.Partial;
14
import org.joda.time.format.ISODateTimeFormat;
15

    
16
import eu.etaxonomy.cdm.hibernate.PartialUserType;
17
import net.sf.json.JsonConfig;
18
import net.sf.json.processors.JsonValueProcessor;
19

    
20
/**
21
 * Partial time as four digit year, two digit month of year, and two digit day of month (yyyy-MM-dd).
22
 *
23
 * @author a.kohlbecker
24
 * @since 20.01.2008
25
 */
26
public class PartialJSONValueProcessor implements JsonValueProcessor {
27

    
28
    private static Logger logger = LogManager.getLogger(PartialJSONValueProcessor.class);
29

    
30
	@Override
31
    public Object processArrayValue(Object object, JsonConfig jsonConfig) {
32
		if(object == null){
33
			return "";
34
		}
35
		Partial partial = (Partial) object;
36
		if (logger.isDebugEnabled()) {
37
			logger.debug("processArrayValue of joda.time.DateTime: " + PartialUserType.partialToString(partial));
38
		}
39
        return partial.toString(ISODateTimeFormat.date());
40
	}
41

    
42
	@Override
43
    public Object processObjectValue(String key, Object object, JsonConfig jsonConfig) {
44
		if(object == null){
45
			return "";
46
		}
47
		Partial partial = (Partial) object;
48
		if (logger.isDebugEnabled()) {
49
			logger.debug("processObjectValue of joda.time.DateTime: " + PartialUserType.partialToString(partial));
50
		}
51
		return partial.toString(ISODateTimeFormat.date());
52
	}
53
}
(8-8/10)