2 * Copyright (C) 2009 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.cdm
.remote
.json
.processor
.value
;
12 import java
.util
.Objects
;
14 import eu
.etaxonomy
.cdm
.api
.service
.l10n
.TermRepresentation_L10n
;
15 import eu
.etaxonomy
.cdm
.api
.service
.name
.TypeDesignationSet
;
16 import eu
.etaxonomy
.cdm
.model
.common
.LanguageString
;
17 import eu
.etaxonomy
.cdm
.model
.name
.TypeDesignationStatusBase
;
18 import eu
.etaxonomy
.cdm
.ref
.TypedEntityReference
;
19 import net
.sf
.json
.JSONObject
;
20 import net
.sf
.json
.JsonConfig
;
21 import net
.sf
.json
.processors
.JsonValueProcessor
;
24 * @author a.kohlbecker
28 public class MapJSONValueProcessor
implements JsonValueProcessor
{
32 public Object
processArrayValue(Object value
, JsonConfig jsonConfig
) {
34 if(value
instanceof TypeDesignationSet
){
35 TypeDesignationSet map
= (TypeDesignationSet
)value
;
36 JSONObject json
= new JSONObject();
37 for(TypeDesignationStatusBase
<?
> key
: map
.keySet()){
38 TermRepresentation_L10n term_L10n
= new TermRepresentation_L10n(key
, false);
39 String label
= Objects
.toString(term_L10n
.getLabel(), "NULL");
40 json
.element(label
, map
.get(key
), jsonConfig
);
43 } else if(value
instanceof Map
){
44 Map
<?
,?
> map
= (Map
<?
,?
>)value
;
46 JSONObject json
= new JSONObject();
47 if(map
.keySet().iterator().next() instanceof TypedEntityReference
){
48 for(Object key
: map
.keySet()){
49 json
.element(key
.toString(), map
.get(key
), jsonConfig
);
52 for (Object val
: map
.values()){
53 if(val
instanceof LanguageString
){
54 json
.element(((LanguageString
)val
).getLanguageLabel(), val
, jsonConfig
);
56 return JSONObject
.fromObject(value
, jsonConfig
);
63 return JSONObject
.fromObject(value
, jsonConfig
);
67 * @see net.sf.json.processors.JsonValueProcessor#processObjectValue(java.lang.String, java.lang.Object, net.sf.json.JsonConfig)
70 public Object
processObjectValue(String key
, Object value
,
71 JsonConfig jsonConfig
) {
72 return processArrayValue(value
, jsonConfig
);