Project

General

Profile

Download (2.55 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id: TaxonBeanProcessor.java 5561 2009-04-07 12:25:33Z a.kohlbecker $
2
/**
3
 * Copyright (C) 2009 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.util.Arrays;
14
import java.util.List;
15

    
16
import net.sf.json.JSONObject;
17
import net.sf.json.JsonConfig;
18

    
19
import org.apache.log4j.Logger;
20
import org.hibernate.Hibernate;
21

    
22
import eu.etaxonomy.cdm.model.common.Language;
23
import eu.etaxonomy.cdm.model.common.LanguageString;
24
import eu.etaxonomy.cdm.model.common.MultilanguageTextHelper;
25
import eu.etaxonomy.cdm.model.common.Representation;
26
import eu.etaxonomy.cdm.model.common.TermBase;
27
import eu.etaxonomy.cdm.model.description.TextData;
28
import eu.etaxonomy.cdm.remote.l10n.LocaleContext;
29

    
30
/**
31
 * @author a.kohlbecker
32
 *
33
 */
34
public class TextDataBeanProcessor extends AbstractCdmBeanProcessor<TextData> {
35

    
36
	public static final Logger logger = Logger.getLogger(TextDataBeanProcessor.class);
37

    
38
	private static final List<String> IGNORE_LIST = Arrays.asList(new String[]{"multilanguageText"});
39

    
40
	private boolean replaceMultilanguageText = false;
41
	
42
	public boolean isReplaceMultilanguageText() {
43
		return replaceMultilanguageText;
44
	}
45

    
46
	public void setReplaceMultilanguageText(boolean replace) {
47
		this.replaceMultilanguageText = replace;
48
	}
49

    
50
	/* (non-Javadoc)
51
	 * @see eu.etaxonomy.cdm.remote.json.processor.AbstractCdmBeanProcessor#getIgnorePropNames()
52
	 */
53
	@Override
54
	public List<String> getIgnorePropNames() {
55
		return IGNORE_LIST;
56
	}
57

    
58
	/* (non-Javadoc)
59
	 * @see eu.etaxonomy.cdm.remote.json.processor.AbstractCdmBeanProcessor#processBeanSecondStep(eu.etaxonomy.cdm.model.common.CdmBase, net.sf.json.JSONObject, net.sf.json.JsonConfig)
60
	 */
61
	@Override
62
	public JSONObject processBeanSecondStep(TextData bean, JSONObject json,	JsonConfig jsonConfig) {
63
		
64
		TextData textdata = (TextData)bean;
65
		LanguageString languageString;
66
		List<Language> languages = LocaleContext.getLanguages();
67
		//textdata.getSources().iterator().next()
68
		languageString = MultilanguageTextHelper.getPreferredLanguageString(textdata.getMultilanguageText(), languages);
69
		if(languageString != null){
70
			json.element("multilanguageText_L10n", languageString, jsonConfig);
71
		}
72
		if(!replaceMultilanguageText){
73
			json.element("multilanguageText", textdata.getMultilanguageText(), jsonConfig);
74
		}
75
		return json;
76
	}
77
	
78
}
(23-23/24)