1
|
/**
|
2
|
* Copyright (C) 2009 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.log4j.Logger;
|
12
|
|
13
|
import eu.etaxonomy.cdm.api.service.l10n.KeyTerm_L10n;
|
14
|
import eu.etaxonomy.cdm.model.taxon.TaxonNodeStatus;
|
15
|
import eu.etaxonomy.cdm.model.term.IKeyTerm;
|
16
|
import net.sf.json.JSONNull;
|
17
|
import net.sf.json.JSONObject;
|
18
|
import net.sf.json.JsonConfig;
|
19
|
import net.sf.json.processors.JsonValueProcessor;
|
20
|
|
21
|
/**
|
22
|
* @author a.kohlbecker
|
23
|
*/
|
24
|
public class KeyTermValueProcessor implements JsonValueProcessor {
|
25
|
|
26
|
public static final Logger logger = Logger.getLogger(KeyTermValueProcessor.class);
|
27
|
|
28
|
@Override
|
29
|
public Object processArrayValue(Object value, JsonConfig jsonConfig) {
|
30
|
// TODO Auto-generated method stub
|
31
|
return null;
|
32
|
}
|
33
|
|
34
|
@Override
|
35
|
public Object processObjectValue(String key, Object value, JsonConfig jsonConfig) {
|
36
|
|
37
|
if(value == null) {
|
38
|
return JSONNull.getInstance();
|
39
|
}
|
40
|
IKeyTerm term = (IKeyTerm)value;
|
41
|
|
42
|
JSONObject json = new JSONObject();
|
43
|
if(term.getClass().isEnum()) {
|
44
|
json.element("name", term); // will be serialized as enum.name()
|
45
|
}
|
46
|
KeyTerm_L10n<?> status_L10n = new KeyTerm_L10n<>(term);
|
47
|
json.element("message_L10n", status_L10n.localizedLabel());
|
48
|
if(term instanceof TaxonNodeStatus) {
|
49
|
json.element("symbol", ((TaxonNodeStatus)term).getSymbol());
|
50
|
}
|
51
|
return json;
|
52
|
}
|
53
|
}
|