Project

General

Profile

Download (1.89 KB) Statistics
| Branch: | Tag: | Revision:
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 java.util.Map;
12

    
13
import net.sf.json.JSONObject;
14
import net.sf.json.JsonConfig;
15
import net.sf.json.processors.JsonValueProcessor;
16
import eu.etaxonomy.cdm.model.common.LanguageString;
17

    
18
/**
19
 * @author a.kohlbecker
20
 * @since 23.06.2010
21
 *
22
 */
23
public class MapJSONValueProcessor implements JsonValueProcessor {
24

    
25
	
26

    
27
	/* (non-Javadoc)
28
	 * @see net.sf.json.processors.JsonValueProcessor#processArrayValue(java.lang.Object, net.sf.json.JsonConfig)
29
	 */
30
	@SuppressWarnings("unchecked")
31
	@Override
32
	public Object processArrayValue(Object value, JsonConfig jsonConfig) {
33
		if(value instanceof Map){ // TODO move type check into vlaue processor matcher
34
			Map map= (Map)value;
35
			if( ! map.isEmpty()){
36
				
37
				//Map<String, LanguageString> returnMap = new HashMap<String, LanguageString>(map.size());
38
				JSONObject json = new JSONObject();
39
				for (Object val : map.values()){
40
					if(val instanceof LanguageString){
41
						//returnMap.put(((LanguageString)val).getLanguageLabel(), (LanguageString) val);
42
						json.element(((LanguageString)val).getLanguageLabel(), val, jsonConfig);
43
					} else {
44
						return JSONObject.fromObject(value, jsonConfig);
45
					}
46
						
47
				}
48
				return json;
49
			}
50
		}
51
		return JSONObject.fromObject(value, jsonConfig);
52
	}
53

    
54
	/* (non-Javadoc)
55
	 * @see net.sf.json.processors.JsonValueProcessor#processObjectValue(java.lang.String, java.lang.Object, net.sf.json.JsonConfig)
56
	 */
57
	@Override
58
	public Object processObjectValue(String key, Object value,
59
			JsonConfig jsonConfig) {
60
		return processArrayValue(value, jsonConfig);
61
	}
62

    
63
}
(5-5/8)