1
|
/**
|
2
|
* Copyright (C) 2013 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.bean;
|
10
|
|
11
|
import java.util.List;
|
12
|
|
13
|
import net.sf.json.JSONObject;
|
14
|
import net.sf.json.JsonConfig;
|
15
|
|
16
|
import org.hibernate.Hibernate;
|
17
|
|
18
|
import eu.etaxonomy.cdm.model.common.Language;
|
19
|
import eu.etaxonomy.cdm.model.common.LanguageString;
|
20
|
import eu.etaxonomy.cdm.model.common.MultilanguageTextHelper;
|
21
|
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
|
22
|
import eu.etaxonomy.cdm.model.description.TextData;
|
23
|
import eu.etaxonomy.cdm.remote.l10n.LocaleContext;
|
24
|
|
25
|
|
26
|
/**
|
27
|
*
|
28
|
*
|
29
|
* @author a.kohlbecker
|
30
|
* @date Dec 4, 2013
|
31
|
*
|
32
|
*/
|
33
|
public class DescriptionElementBeanProcessor extends AbstractModifiableThingBeanProcessor<DescriptionElementBase> {
|
34
|
|
35
|
@Override
|
36
|
public JSONObject processBeanSecondStep(DescriptionElementBase bean, JSONObject json, JsonConfig jsonConfig) {
|
37
|
|
38
|
List<Language> languages = LocaleContext.getLanguages();
|
39
|
|
40
|
// --- general processing for all DescriptionElement types
|
41
|
if(Hibernate.isInitialized(bean.getModifyingText())){
|
42
|
LanguageString modifyingText = MultilanguageTextHelper.getPreferredLanguageString(bean.getModifyingText(), languages);
|
43
|
if(modifyingText != null){
|
44
|
json.element("modifyingText_l10n", modifyingText.getText());
|
45
|
}
|
46
|
if(!isReplaceMultilanguageText()){
|
47
|
json.element("modifyingText", bean.getModifyingText().values(), jsonConfig);
|
48
|
}
|
49
|
}
|
50
|
|
51
|
// --- special processing for specific types
|
52
|
if(TextData.class.isAssignableFrom(bean.getClass())){
|
53
|
TextData textdata = (TextData) bean;
|
54
|
LanguageString languageString;
|
55
|
//textdata.getSources().iterator().next()
|
56
|
if(Hibernate.isInitialized(textdata.getMultilanguageText())){
|
57
|
languageString = MultilanguageTextHelper.getPreferredLanguageString(textdata.getMultilanguageText(), languages);
|
58
|
if(languageString != null){
|
59
|
json.element("multilanguageText_L10n", languageString, jsonConfig);
|
60
|
}
|
61
|
if(!isReplaceMultilanguageText()){
|
62
|
json.element("multilanguageText", textdata.getMultilanguageText().values(), jsonConfig);
|
63
|
}
|
64
|
}
|
65
|
}
|
66
|
return json;
|
67
|
}
|
68
|
|
69
|
|
70
|
}
|