1
|
/**
|
2
|
* Copyright (C) 2007 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
|
|
10
|
package eu.etaxonomy.cdm.model.common;
|
11
|
|
12
|
|
13
|
import org.apache.log4j.Logger;
|
14
|
import org.springframework.stereotype.Component;
|
15
|
import au.com.bytecode.opencsv.CSVWriter;
|
16
|
|
17
|
import java.util.*;
|
18
|
|
19
|
import javax.persistence.*;
|
20
|
|
21
|
/**
|
22
|
* list of languages according to current internet best practices as given by IANA
|
23
|
* or ISO codes. http://www.ietf.org/rfc/rfc4646.txt
|
24
|
* http://www.loc.gov/standards/iso639-2/php/English_list.php
|
25
|
* @author m.doering
|
26
|
* @version 1.0
|
27
|
* @created 08-Nov-2007 13:06:31
|
28
|
*/
|
29
|
@Entity
|
30
|
@Component
|
31
|
public class Language extends DefinedTermBase {
|
32
|
static Logger logger = Logger.getLogger(Language.class);
|
33
|
|
34
|
private static final UUID uuidChinese = UUID.fromString("a9fc2782-5b2a-466f-b9c3-64d9ca6614c4");
|
35
|
public static final UUID uuidEnglish = UUID.fromString("e9f8cdb7-6819-44e8-95d3-e2d0690c3523");
|
36
|
private static final UUID uuidSpanish = UUID.fromString("511d8125-f5e6-445d-aee2-6327375238be");
|
37
|
private static final UUID uuidHindi = UUID.fromString("0a1d9d1d-135d-4575-b172-669b51673c39");
|
38
|
private static final UUID uuidArabic = UUID.fromString("4d3ec2eb-536f-4aab-81c5-34e37a3edbba");
|
39
|
private static final UUID uuidRussian = UUID.fromString("64ea9354-cbf8-40de-9f6e-387d24896f50");
|
40
|
private static final UUID uuidPortuguese = UUID.fromString("c2c08339-2405-4d7d-bd25-cbe01fb7ce09");
|
41
|
private static final UUID uuidJapanese = UUID.fromString("6778c7fb-c195-4dc1-ae3f-164201314e51");
|
42
|
private static final UUID uuidGerman = UUID.fromString("d1131746-e58b-4e80-a865-f5182c9c3073");
|
43
|
private static final UUID uuidFrench = UUID.fromString("7759a1d8-a5ea-454a-8c93-1dcfaae8cc21");
|
44
|
private static final UUID uuidItalian = UUID.fromString("fecbf0c7-fea9-465b-8a16-950517c5c0c4");
|
45
|
private static final UUID uuidDutch = UUID.fromString("9965d79a-acf9-4921-a2c0-863b8c16c056");
|
46
|
private static final UUID uuidPolish = UUID.fromString("3fdca387-f1b0-4ec1-808f-1bc3dc482194");
|
47
|
|
48
|
public static Language NewInstance(){
|
49
|
return new Language();
|
50
|
}
|
51
|
|
52
|
public static Language NewInstance(UUID uuid){
|
53
|
return new Language(uuid);
|
54
|
}
|
55
|
|
56
|
|
57
|
private char[] iso639_1 = new char[2];
|
58
|
private char[] iso639_2 = new char[3];
|
59
|
|
60
|
|
61
|
public Language() {
|
62
|
super();
|
63
|
}
|
64
|
public Language(UUID uuid) {
|
65
|
super();
|
66
|
this.setUuid(uuid);
|
67
|
}
|
68
|
public Language(char[] iso639_1, char[] iso639_2, String englishLabel, String frenchLabel) {
|
69
|
super();
|
70
|
this.iso639_1=iso639_1;
|
71
|
this.iso639_2=iso639_2;
|
72
|
this.addRepresentation(new Representation(englishLabel, String.valueOf(iso639_2), Language.ENGLISH()));
|
73
|
this.addRepresentation(new Representation(frenchLabel, String.valueOf(iso639_2), Language.FRENCH()));
|
74
|
}
|
75
|
public Language(String text, String label, Language lang) {
|
76
|
super();
|
77
|
this.addRepresentation(new Representation(text,label,lang));
|
78
|
}
|
79
|
public Language(String label, String text) {
|
80
|
this(label,text, DEFAULT());
|
81
|
}
|
82
|
|
83
|
public static final Language getByUuid(UUID uuid){
|
84
|
return (Language)findByUuid(uuid);
|
85
|
}
|
86
|
|
87
|
|
88
|
public static final Language DEFAULT(){
|
89
|
return ENGLISH();
|
90
|
}
|
91
|
|
92
|
|
93
|
public static final Language CHINESE(){
|
94
|
return getByUuid(uuidChinese);
|
95
|
}
|
96
|
|
97
|
public static final Language ENGLISH(){
|
98
|
return getByUuid(uuidEnglish);
|
99
|
}
|
100
|
|
101
|
public static final Language SPANISH(){
|
102
|
return getByUuid(uuidSpanish);
|
103
|
}
|
104
|
|
105
|
public static final Language HINDI(){
|
106
|
return getByUuid(uuidHindi);
|
107
|
}
|
108
|
|
109
|
public static final Language ARABIC(){
|
110
|
return getByUuid(uuidArabic);
|
111
|
}
|
112
|
|
113
|
public static final Language RUSSIAN(){
|
114
|
return getByUuid(uuidRussian);
|
115
|
}
|
116
|
|
117
|
public static final Language PORTUGUESE(){
|
118
|
return getByUuid(uuidPortuguese);
|
119
|
}
|
120
|
|
121
|
public static final Language JAPANESE(){
|
122
|
return getByUuid(uuidJapanese);
|
123
|
}
|
124
|
|
125
|
public static final Language GERMAN(){
|
126
|
return getByUuid(uuidGerman);
|
127
|
}
|
128
|
|
129
|
public static final Language FRENCH(){
|
130
|
return getByUuid(uuidFrench);
|
131
|
}
|
132
|
|
133
|
public static final Language ITALIAN(){
|
134
|
return getByUuid(uuidItalian);
|
135
|
}
|
136
|
|
137
|
public static final Language DUTCH(){
|
138
|
return getByUuid(uuidDutch);
|
139
|
}
|
140
|
|
141
|
public static final Language POLISH(){
|
142
|
return getByUuid(uuidPolish);
|
143
|
}
|
144
|
|
145
|
@Override
|
146
|
public ILoadableTerm readCsvLine(List csvLine) {
|
147
|
ILoadableTerm result;
|
148
|
if ( UUID.fromString(csvLine.get(0).toString()).equals(DEFAULT().getUuid()) && this != DEFAULT() ){
|
149
|
result = DEFAULT();
|
150
|
result.readCsvLine(csvLine);
|
151
|
}else{
|
152
|
// read UUID, URI, english label+description
|
153
|
List<String> csvLineString = csvLine;
|
154
|
result = this;
|
155
|
super.readCsvLine(csvLine);
|
156
|
// iso codes extra
|
157
|
this.iso639_1=csvLineString.get(4).trim().toCharArray();
|
158
|
this.iso639_2=csvLineString.get(5).trim().toCharArray();
|
159
|
}
|
160
|
return result;
|
161
|
}
|
162
|
|
163
|
public void writeCsvLine(CSVWriter writer) {
|
164
|
String [] line = new String[6];
|
165
|
line[0] = getUuid().toString();
|
166
|
line[1] = getUri();
|
167
|
line[2] = getLabel(Language.ENGLISH());
|
168
|
line[3] = getDescription(Language.ENGLISH());
|
169
|
line[4] = String.valueOf(this.iso639_1);
|
170
|
line[5] = String.valueOf(this.iso639_2);
|
171
|
writer.writeNext(line);
|
172
|
}
|
173
|
|
174
|
}
|