Project

General

Profile

« Previous | Next » 

Revision 02a7041f

Added by Andreas Kohlbecker about 14 years ago

fixing problem with content negotiation in views & oai-pmh controller for references

View differences:

cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/json/processor/CalendarJSONValueProcessor.java
1
// $Id$
2
/**
3
* Copyright (C) 2007 EDIT
4
* European Distributed Institute of Taxonomy 
5
* http://www.e-taxonomy.eu
6
* 
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10

  
11
package eu.etaxonomy.cdm.remote.json.processor;
12

  
13
import java.text.DateFormat;
14
import java.text.SimpleDateFormat;
15
import java.util.Calendar;
16

  
17
import net.sf.json.JsonConfig;
18
import net.sf.json.processors.JsonValueProcessor;
19

  
20
import org.apache.log4j.Logger;
21

  
22

  
23
/**
24
 * @author a.kohlbecker
25
 * @created 20.01.2009
26
 * @version 1.0
27
 */
28
public class CalendarJSONValueProcessor implements JsonValueProcessor {
29
	private static Logger logger = Logger.getLogger(DateTimeJSONValueProcessor.class);
30

  
31
	private static SimpleDateFormat iso8601Format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssz");
32
	
33
	/* (non-Javadoc)
34
	 * @see net.sf.json.processors.JsonValueProcessor#processArrayValue(java.lang.Object, net.sf.json.JsonConfig)
35
	 */
36
	public Object processArrayValue(Object object, JsonConfig jsonConfig) {
37
		if(object == null){
38
			return "";
39
		}
40
		Calendar calendar = (Calendar) object;
41
		if (logger.isDebugEnabled()) {
42
			logger.debug("processArrayValue of java.util.Calendar: " + CalendarJSONValueProcessor.iso8601Format.format(calendar.getTime()));
43
		}
44
        return CalendarJSONValueProcessor.iso8601Format.format(calendar.getTime());
45
	}
46

  
47
	/* (non-Javadoc)
48
	 * @see net.sf.json.processors.JsonValueProcessor#processObjectValue(java.lang.String, java.lang.Object, net.sf.json.JsonConfig)
49
	 */
50
	public Object processObjectValue(String key, Object object, JsonConfig jsonConfig) {
51
		if(object == null){
52
			return "";
53
		}
54
		Calendar dateTime = (Calendar) object;
55
		if (logger.isDebugEnabled()) {
56
			logger.debug("processObjectValue of java.util.Calendar: " + CalendarJSONValueProcessor.iso8601Format.format(dateTime.getTime()));
57
		}
58
        return CalendarJSONValueProcessor.iso8601Format.format(dateTime.getTime());
59
	}
60
}
1
// $Id$
2
/**
3
* Copyright (C) 2007 EDIT
4
* European Distributed Institute of Taxonomy 
5
* http://www.e-taxonomy.eu
6
* 
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10

  
11
package eu.etaxonomy.cdm.remote.json.processor;
12

  
13
import java.text.DateFormat;
14
import java.text.SimpleDateFormat;
15
import java.util.Calendar;
16

  
17
import net.sf.json.JsonConfig;
18
import net.sf.json.processors.JsonValueProcessor;
19

  
20
import org.apache.log4j.Logger;
21

  
22

  
23
/**
24
 * @author a.kohlbecker
25
 * @created 20.01.2009
26
 * @version 1.0
27
 */
28
public class CalendarJSONValueProcessor implements JsonValueProcessor {
29
	private static Logger logger = Logger.getLogger(DateTimeJSONValueProcessor.class);
30

  
31
	private static SimpleDateFormat iso8601Format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssz");
32
	
33
	/* (non-Javadoc)
34
	 * @see net.sf.json.processors.JsonValueProcessor#processArrayValue(java.lang.Object, net.sf.json.JsonConfig)
35
	 */
36
	public Object processArrayValue(Object object, JsonConfig jsonConfig) {
37
		if(object == null){
38
			return "";
39
		}
40
		Calendar calendar = (Calendar) object;
41
		if (logger.isDebugEnabled()) {
42
			logger.debug("processArrayValue of java.util.Calendar: " + CalendarJSONValueProcessor.iso8601Format.format(calendar.getTime()));
43
		}
44
        return CalendarJSONValueProcessor.iso8601Format.format(calendar.getTime());
45
	}
46

  
47
	/* (non-Javadoc)
48
	 * @see net.sf.json.processors.JsonValueProcessor#processObjectValue(java.lang.String, java.lang.Object, net.sf.json.JsonConfig)
49
	 */
50
	public Object processObjectValue(String key, Object object, JsonConfig jsonConfig) {
51
		if(object == null){
52
			return "";
53
		}
54
		Calendar dateTime = (Calendar) object;
55
		if (logger.isDebugEnabled()) {
56
			logger.debug("processObjectValue of java.util.Calendar: " + CalendarJSONValueProcessor.iso8601Format.format(dateTime.getTime()));
57
		}
58
        return CalendarJSONValueProcessor.iso8601Format.format(dateTime.getTime());
59
	}
60
}

Also available in: Unified diff