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
|
import javax.xml.bind.annotation.XmlAccessType;
|
21
|
import javax.xml.bind.annotation.XmlAccessorType;
|
22
|
import javax.xml.bind.annotation.XmlAttribute;
|
23
|
import javax.xml.bind.annotation.XmlRootElement;
|
24
|
import javax.xml.bind.annotation.XmlType;
|
25
|
|
26
|
/**
|
27
|
* list of languages according to current internet best practices as given by IANA
|
28
|
* or ISO codes. http://www.ietf.org/rfc/rfc4646.txt
|
29
|
* http://www.loc.gov/standards/iso639-2/php/English_list.php
|
30
|
* @author m.doering
|
31
|
* @version 1.0
|
32
|
* @created 08-Nov-2007 13:06:31
|
33
|
*/
|
34
|
@XmlAccessorType(XmlAccessType.FIELD)
|
35
|
@XmlType(name = "Language")
|
36
|
@XmlRootElement(name = "Language")
|
37
|
@Entity
|
38
|
@Component
|
39
|
public class Language extends DefinedTermBase {
|
40
|
static Logger logger = Logger.getLogger(Language.class);
|
41
|
|
42
|
private static final UUID uuidChinese = UUID.fromString("a9fc2782-5b2a-466f-b9c3-64d9ca6614c4");
|
43
|
public static final UUID uuidEnglish = UUID.fromString("e9f8cdb7-6819-44e8-95d3-e2d0690c3523");
|
44
|
private static final UUID uuidSpanish = UUID.fromString("511d8125-f5e6-445d-aee2-6327375238be");
|
45
|
private static final UUID uuidHindi = UUID.fromString("0a1d9d1d-135d-4575-b172-669b51673c39");
|
46
|
private static final UUID uuidArabic = UUID.fromString("4d3ec2eb-536f-4aab-81c5-34e37a3edbba");
|
47
|
private static final UUID uuidRussian = UUID.fromString("64ea9354-cbf8-40de-9f6e-387d24896f50");
|
48
|
private static final UUID uuidPortuguese = UUID.fromString("c2c08339-2405-4d7d-bd25-cbe01fb7ce09");
|
49
|
private static final UUID uuidJapanese = UUID.fromString("6778c7fb-c195-4dc1-ae3f-164201314e51");
|
50
|
private static final UUID uuidGerman = UUID.fromString("d1131746-e58b-4e80-a865-f5182c9c3073");
|
51
|
private static final UUID uuidFrench = UUID.fromString("7759a1d8-a5ea-454a-8c93-1dcfaae8cc21");
|
52
|
private static final UUID uuidItalian = UUID.fromString("fecbf0c7-fea9-465b-8a16-950517c5c0c4");
|
53
|
private static final UUID uuidDutch = UUID.fromString("9965d79a-acf9-4921-a2c0-863b8c16c056");
|
54
|
private static final UUID uuidPolish = UUID.fromString("3fdca387-f1b0-4ec1-808f-1bc3dc482194");
|
55
|
private static final UUID uuidLatin = UUID.fromString("160a5b6c-87f5-4422-9bda-78cd404c179e");
|
56
|
|
57
|
public static Language NewInstance(){
|
58
|
return new Language();
|
59
|
}
|
60
|
|
61
|
public static Language NewInstance(UUID uuid){
|
62
|
return new Language(uuid);
|
63
|
}
|
64
|
|
65
|
@XmlAttribute(name = "iso639_1")
|
66
|
private char[] iso639_1 = new char[2];
|
67
|
@XmlAttribute(name = "iso639_2")
|
68
|
private char[] iso639_2 = new char[3];
|
69
|
|
70
|
public Language() {
|
71
|
super();
|
72
|
}
|
73
|
public Language(UUID uuid) {
|
74
|
super();
|
75
|
this.setUuid(uuid);
|
76
|
}
|
77
|
public Language(char[] iso639_1, char[] iso639_2, String englishLabel, String frenchLabel) throws Exception {
|
78
|
super();
|
79
|
if(iso639_1.length > 2){
|
80
|
logger.warn("iso639_1 too long: "+iso639_1.toString());
|
81
|
}
|
82
|
if(iso639_2.length > 3){
|
83
|
logger.warn("iso639_2 too long: "+iso639_2.toString());
|
84
|
}
|
85
|
this.iso639_1=iso639_1;
|
86
|
this.iso639_2=iso639_2;
|
87
|
String textEnglish = englishLabel;
|
88
|
String textFrench = englishLabel;
|
89
|
String label = String.valueOf(iso639_2);
|
90
|
String labelAbbrev = null;
|
91
|
this.addRepresentation(new Representation(textEnglish, label, labelAbbrev, Language.ENGLISH()));
|
92
|
this.addRepresentation(new Representation(textFrench, label, labelAbbrev, Language.FRENCH()));
|
93
|
}
|
94
|
public Language(String text, String label, String labelAbbrev, Language lang) {
|
95
|
super();
|
96
|
this.addRepresentation(new Representation(text,label,labelAbbrev, lang));
|
97
|
}
|
98
|
public Language(String label, String text, String labelAbbrev) {
|
99
|
this(label,text,labelAbbrev, DEFAULT());
|
100
|
}
|
101
|
|
102
|
public static final Language getByUuid(UUID uuid){
|
103
|
return (Language)findByUuid(uuid);
|
104
|
}
|
105
|
|
106
|
|
107
|
public static final Language DEFAULT(){
|
108
|
return ENGLISH();
|
109
|
}
|
110
|
|
111
|
|
112
|
public static final Language CHINESE(){
|
113
|
return getByUuid(uuidChinese);
|
114
|
}
|
115
|
|
116
|
public static final Language ENGLISH(){
|
117
|
return getByUuid(uuidEnglish);
|
118
|
}
|
119
|
|
120
|
public static final Language SPANISH(){
|
121
|
return getByUuid(uuidSpanish);
|
122
|
}
|
123
|
|
124
|
public static final Language HINDI(){
|
125
|
return getByUuid(uuidHindi);
|
126
|
}
|
127
|
|
128
|
public static final Language ARABIC(){
|
129
|
return getByUuid(uuidArabic);
|
130
|
}
|
131
|
|
132
|
public static final Language RUSSIAN(){
|
133
|
return getByUuid(uuidRussian);
|
134
|
}
|
135
|
|
136
|
public static final Language PORTUGUESE(){
|
137
|
return getByUuid(uuidPortuguese);
|
138
|
}
|
139
|
|
140
|
public static final Language JAPANESE(){
|
141
|
return getByUuid(uuidJapanese);
|
142
|
}
|
143
|
|
144
|
public static final Language GERMAN(){
|
145
|
return getByUuid(uuidGerman);
|
146
|
}
|
147
|
|
148
|
public static final Language FRENCH(){
|
149
|
return getByUuid(uuidFrench);
|
150
|
}
|
151
|
|
152
|
public static final Language ITALIAN(){
|
153
|
return getByUuid(uuidItalian);
|
154
|
}
|
155
|
|
156
|
public static final Language DUTCH(){
|
157
|
return getByUuid(uuidDutch);
|
158
|
}
|
159
|
|
160
|
public static final Language POLISH(){
|
161
|
return getByUuid(uuidPolish);
|
162
|
}
|
163
|
|
164
|
public static final Language LATIN(){
|
165
|
return getByUuid(uuidLatin);
|
166
|
}
|
167
|
|
168
|
/**
|
169
|
* Get the according iso639-1 alpha-2 language code
|
170
|
* http://www.loc.gov/standards/iso639-2/
|
171
|
*
|
172
|
* @return the iso639 alpha-2 language code or null if not available
|
173
|
*/
|
174
|
//TODO create userDefinedType ?
|
175
|
@Column(length=2)
|
176
|
public String getIso639_1() {
|
177
|
|
178
|
return String.valueOf(iso639_1);
|
179
|
}
|
180
|
|
181
|
public void setIso639_1(String iso639_1) {
|
182
|
iso639_1 = iso639_1.trim();
|
183
|
if(iso639_1.length() > 2){
|
184
|
logger.warn("Iso639-1: "+iso639_1+" too long");
|
185
|
}
|
186
|
this.iso639_1 = iso639_1.toCharArray();
|
187
|
}
|
188
|
|
189
|
/**
|
190
|
* Get the according iso639-2 alpha-3 language code
|
191
|
* http://www.loc.gov/standards/iso639-2/
|
192
|
*
|
193
|
* @return the iso639 alpha-3 language code or null if not available
|
194
|
*/
|
195
|
//TODO create userDefinedType ?
|
196
|
@Column(length=3)
|
197
|
public String getIso639_2() {
|
198
|
return String.valueOf(iso639_2);
|
199
|
}
|
200
|
|
201
|
public void setIso639_2(String iso639_2) {
|
202
|
iso639_2 = iso639_2.trim();
|
203
|
if(iso639_2.length() > 3 ){
|
204
|
logger.warn("Iso639-2: "+iso639_2+" too long");
|
205
|
}
|
206
|
this.iso639_2 = iso639_2.toCharArray();
|
207
|
}
|
208
|
|
209
|
@Override
|
210
|
public ILoadableTerm readCsvLine(List csvLine) {
|
211
|
ILoadableTerm result;
|
212
|
if ( UUID.fromString(csvLine.get(0).toString()).equals(DEFAULT().getUuid()) && this != DEFAULT() ){
|
213
|
result = DEFAULT();
|
214
|
result.readCsvLine(csvLine);
|
215
|
}else{
|
216
|
// read UUID, URI, english label+description
|
217
|
List<String> csvLineString = csvLine;
|
218
|
result = this;
|
219
|
super.readCsvLine(csvLine);
|
220
|
// iso codes extra
|
221
|
this.iso639_1=csvLineString.get(5).trim().toCharArray();
|
222
|
this.iso639_2=csvLineString.get(4).trim().toCharArray();
|
223
|
if(iso639_1.length > 2){
|
224
|
logger.warn("Iso639-1: "+iso639_1.toString()+" from "+csvLine.get(3)+" ,"+csvLine.get(2)+" too long");
|
225
|
}
|
226
|
if(iso639_2.length > 3 ){
|
227
|
logger.warn("Iso639-2: "+iso639_2.toString()+" from "+csvLine.get(3)+" ,"+csvLine.get(2)+" too long");
|
228
|
}
|
229
|
}
|
230
|
return result;
|
231
|
}
|
232
|
|
233
|
@Override
|
234
|
public void writeCsvLine(CSVWriter writer) {
|
235
|
String [] line = new String[6];
|
236
|
line[0] = getUuid().toString();
|
237
|
line[1] = getUri();
|
238
|
line[2] = getLabel(Language.ENGLISH());
|
239
|
line[3] = getDescription(Language.ENGLISH());
|
240
|
line[4] = String.valueOf(this.iso639_1);
|
241
|
line[5] = String.valueOf(this.iso639_2);
|
242
|
writer.writeNext(line);
|
243
|
}
|
244
|
|
245
|
/* (non-Javadoc)
|
246
|
* @see eu.etaxonomy.cdm.model.common.TermBase#toString()
|
247
|
*/
|
248
|
@Override
|
249
|
public String toString() {
|
250
|
if (this.getLabel() != null){
|
251
|
return this.getLabel();
|
252
|
}else{
|
253
|
return super.toString();
|
254
|
}
|
255
|
}
|
256
|
|
257
|
|
258
|
|
259
|
}
|