Project

General

Profile

Revision 2f4f765e

ID2f4f765e29050881d9e7af45d73b00c3e15dafdd
Parent e25cc9dd
Child 4b24820e

Added by Andreas Müller about 1 year ago

add preferred languages to DesciptionElementFormatterBase

View differences:

cdmlib-model/src/main/java/eu/etaxonomy/cdm/format/description/CategoricalDataFormatter.java
8 8
*/
9 9
package eu.etaxonomy.cdm.format.description;
10 10

  
11
import java.util.ArrayList;
12 11
import java.util.List;
13 12

  
14 13
import eu.etaxonomy.cdm.common.CdmUtils;
......
30 29
    }
31 30

  
32 31
    @Override
33
    public String doFormat(CategoricalData catData) {
34

  
32
    protected String doFormat(CategoricalData catData, List<Language> preferredLanguages) {
35 33
        List<StateData> stateDatas = catData.getStateData();
36
         //TODO add as method argument
37
        List<Language> preferredLanguages = new ArrayList<>();
38
        preferredLanguages.add(Language.DEFAULT());
39 34
        String stateDataText = getStateDatasText(stateDatas, preferredLanguages);
40 35
        return stateDataText;
41 36
    }
cdmlib-model/src/main/java/eu/etaxonomy/cdm/format/description/DesciptionElementFormatterBase.java
8 8
*/
9 9
package eu.etaxonomy.cdm.format.description;
10 10

  
11
import java.util.ArrayList;
11 12
import java.util.List;
12 13

  
13 14
import eu.etaxonomy.cdm.format.DefaultCdmFormatter;
......
47 48

  
48 49
    @Override
49 50
    public String format(Object object) {
51
        List<Language> preferredLanguages = new ArrayList<>();
52
        preferredLanguages.add(Language.DEFAULT());
53
        return format(object, preferredLanguages);
54
    }
55

  
56
    public String format(Object object, List<Language> preferredLanguages) {
50 57
        if (! (object instanceof ICdmBase)){
51 58
            throw new IllegalArgumentException("object is not of type ICdmBase");
52 59
        }
......
55 62
            throw new IllegalArgumentException("object is not of type " + clazz.getSimpleName());
56 63
        }
57 64
        T descEl = CdmBase.deproxy(object, clazz);
58

  
59
        return doFormat(descEl);
65
        if (preferredLanguages == null || preferredLanguages.isEmpty()){
66
            preferredLanguages = new ArrayList<>();
67
            preferredLanguages.add(Language.DEFAULT());
68
        }
69
        return doFormat(descEl, preferredLanguages);
60 70
    }
61 71

  
62
    protected abstract String doFormat(T descEl);
72
    /**
73
     * To be implemented by subclasses. The caller must guarantee that preferredLanguages
74
     * is neither <code>null</code> nor empty.
75
     */
76
    protected abstract String doFormat(T descEl, List<Language> preferredLanguages);
63 77

  
64 78

  
65 79
    protected String getLabel(DefinedTermBase<?> term, List<Language> preferredLanguages) {
cdmlib-model/src/main/java/eu/etaxonomy/cdm/format/description/QuantitativeDataFormatter.java
9 9
package eu.etaxonomy.cdm.format.description;
10 10

  
11 11
import java.math.BigDecimal;
12
import java.util.List;
12 13

  
13 14
import eu.etaxonomy.cdm.common.CdmUtils;
15
import eu.etaxonomy.cdm.model.common.Language;
14 16
import eu.etaxonomy.cdm.model.description.MeasurementUnit;
15 17
import eu.etaxonomy.cdm.model.description.QuantitativeData;
16 18

  
......
30 32
    }
31 33

  
32 34
    @Override
33
    public String doFormat(QuantitativeData quantData) {
35
    protected String doFormat(QuantitativeData quantData, List<Language> preferredLanguages) {
34 36

  
35 37
        String result = "";
36 38

  

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)