Project

General

Profile

Download (2.78 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.Representation;
24
import eu.etaxonomy.cdm.model.common.TermBase;
25
import eu.etaxonomy.cdm.remote.l10n.LocaleContext;
26

    
27
/**
28
 * @author a.kohlbecker
29
 *
30
 */
31
public class TermBaseBeanProcessor extends AbstractCdmBeanProcessor<TermBase> {
32

    
33
	public static final Logger logger = Logger.getLogger(TermBaseBeanProcessor.class);
34

    
35
	private static final List<String> IGNORE_LIST = Arrays.asList(new String[]{"representations"});
36

    
37
	private boolean replaceRepresentations = false;
38
	
39
	public boolean isReplaceRepresentations() {
40
		return replaceRepresentations;
41
	}
42

    
43
	public void setReplaceRepresentations(boolean replace) {
44
		this.replaceRepresentations = replace;
45
	}
46

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

    
55
	/* (non-Javadoc)
56
	 * @see eu.etaxonomy.cdm.remote.json.processor.AbstractCdmBeanProcessor#processBeanSecondStep(eu.etaxonomy.cdm.model.common.CdmBase, net.sf.json.JSONObject, net.sf.json.JsonConfig)
57
	 */
58
	@Override
59
	public JSONObject processBeanSecondStep(TermBase bean, JSONObject json,	JsonConfig jsonConfig) {
60
		
61
		TermBase term = (TermBase)bean;
62
		Representation representation;
63
		List<Language> languages = LocaleContext.getLanguages();
64
		if(Hibernate.isInitialized(term.getRepresentations())){
65
			
66
			representation = term.getPreferredRepresentation(languages);
67
			if(representation != null){
68
				if(representation.getText() != null && !representation.getText().isEmpty()){
69
					json.element("representation_L10n", representation.getText());
70
				} else if (representation.getLabel() != null && !representation.getLabel().isEmpty()) {
71
					json.element("representation_L10n", representation.getLabel());
72
				} else {
73
					json.element("representation_L10n", representation.getAbbreviatedLabel());
74
				}
75
			}
76
			if(!replaceRepresentations){
77
				json.element("representations", term.getRepresentations(), jsonConfig);
78
			}
79
		} else {
80
			logger.debug("representations of term not initialized  " + term.getUuid().toString());
81
		}
82
		return json;
83
	}
84
	
85
}
(16-16/18)