Mercurial > dive4elements > gnv-client
annotate gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/ressource/RessourceFactory.java @ 313:7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
gnv-artifacts/trunk@371 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 26 Nov 2009 08:40:15 +0000 |
parents | 7fb9441dd8af |
children | e6e172a4915e |
rev | line source |
---|---|
117
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
1 /** |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
2 * |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
3 */ |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
4 package de.intevation.gnv.artifacts.ressource; |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
5 |
313
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
6 import java.io.BufferedReader; |
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
7 import java.io.File; |
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
8 import java.io.FileInputStream; |
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
9 import java.io.FileNotFoundException; |
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
10 import java.io.InputStream; |
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
11 import java.io.InputStreamReader; |
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
12 import java.io.IOException; |
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
13 import java.util.ArrayList; |
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
14 import java.util.Locale; |
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
15 import java.util.List; |
123
8cc96c9cc962
Added some missing RessourceValues
Tim Englich <tim.englich@intevation.de>
parents:
121
diff
changeset
|
16 import java.util.MissingResourceException; |
117
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
17 import java.util.ResourceBundle; |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
18 |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
19 import org.apache.log4j.Logger; |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
20 |
118
5ebc059064a6
Adding Languagetransfer to the ArtifactDatabase to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents:
117
diff
changeset
|
21 import de.intevation.artifacts.PreferredLocale; |
5ebc059064a6
Adding Languagetransfer to the ArtifactDatabase to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents:
117
diff
changeset
|
22 |
117
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
23 /** |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
24 * @author Tim Englich <tim.englich@intevation.de> |
171
7fb9441dd8af
Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents:
123
diff
changeset
|
25 * |
117
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
26 */ |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
27 public class RessourceFactory { |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
28 |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
29 /** |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
30 * the logger, used to log exceptions and additonaly information |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
31 */ |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
32 private static Logger log = Logger.getLogger(RessourceFactory.class); |
171
7fb9441dd8af
Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents:
123
diff
changeset
|
33 |
117
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
34 /** |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
35 * The singleton Instance of this Factory. |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
36 */ |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
37 private static RessourceFactory instance = null; |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
38 |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
39 private static String RESSOURCE_BASE_ID = "artifact.ressource.dir"; |
171
7fb9441dd8af
Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents:
123
diff
changeset
|
40 |
313
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
41 private static String ressourceName = "artifactMessages"; |
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
42 private static String DEFAULT_DIR = "lang"; |
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
43 private static String LANG_CONFIG_FILE = "lang.conf"; |
171
7fb9441dd8af
Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents:
123
diff
changeset
|
44 |
117
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
45 private String ressourceDir = null; |
118
5ebc059064a6
Adding Languagetransfer to the ArtifactDatabase to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents:
117
diff
changeset
|
46 |
313
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
47 private Locale[] locales = null; |
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
48 |
117
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
49 /** |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
50 * Basic-Constructor of this Class |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
51 */ |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
52 private RessourceFactory() { |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
53 super(); |
121
6b9a07f758cf
Move resources to a place where maven puts them into final package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
118
diff
changeset
|
54 ressourceDir = System.getProperty(RESSOURCE_BASE_ID, DEFAULT_DIR); |
117
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
55 } |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
56 |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
57 /** |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
58 * This Method provides an singleton Instance of this Class. |
171
7fb9441dd8af
Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents:
123
diff
changeset
|
59 * |
117
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
60 * @return an singleton Instance of this Class |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
61 */ |
171
7fb9441dd8af
Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents:
123
diff
changeset
|
62 public static synchronized RessourceFactory getInstance() { |
7fb9441dd8af
Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents:
123
diff
changeset
|
63 if (instance == null) { |
117
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
64 instance = new RessourceFactory(); |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
65 } |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
66 return instance; |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
67 } |
171
7fb9441dd8af
Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents:
123
diff
changeset
|
68 |
313
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
69 |
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
70 /** |
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
71 * This method reads locales, configured in LANG_CONFIG_FILE, from |
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
72 * filesystem and returns them as array. |
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
73 * |
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
74 * @return Array of locales supported by the the server. |
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
75 */ |
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
76 public Locale[] getLocales() { |
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
77 |
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
78 if (locales != null) |
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
79 return locales; |
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
80 |
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
81 log.debug("Supported locales have not been read - read now."); |
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
82 try { |
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
83 String config = "/" + ressourceDir + "/" + LANG_CONFIG_FILE; |
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
84 InputStream in = RessourceFactory.class.getResourceAsStream(config); |
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
85 |
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
86 BufferedReader reader = new BufferedReader( |
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
87 new InputStreamReader(in) |
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
88 ); |
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
89 |
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
90 String line = null; |
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
91 String country = null; |
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
92 String language = null; |
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
93 int idx = -1; |
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
94 |
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
95 List tmpLocales = new ArrayList(); |
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
96 |
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
97 while((line = reader.readLine()) != null) { |
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
98 // validate if defined locale has a valid length |
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
99 if (line.length() != 2 && line.length() != 5) { |
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
100 log.warn("Illegal locale definition found."); |
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
101 continue; |
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
102 } |
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
103 |
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
104 idx = line.indexOf("_"); |
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
105 if (idx > 0) { |
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
106 // found locale containing language and country code |
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
107 language = line.substring(0, idx); |
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
108 country = line.substring(idx+1); |
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
109 tmpLocales.add(new Locale(language, country)); |
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
110 } |
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
111 else { |
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
112 // found locale containing languagey code only |
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
113 tmpLocales.add(new Locale(line)); |
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
114 } |
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
115 } |
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
116 |
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
117 locales = (Locale[]) tmpLocales.toArray( |
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
118 new Locale[tmpLocales.size()] |
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
119 ); |
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
120 |
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
121 return locales; |
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
122 } |
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
123 catch (FileNotFoundException fnfe) { |
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
124 log.warn("File not found: " + LANG_CONFIG_FILE, fnfe); |
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
125 } |
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
126 catch (IOException ioe) { |
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
127 log.warn(ioe.getLocalizedMessage(), ioe); |
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
128 } |
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
129 |
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
130 return null; |
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
131 } |
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
132 |
7b4e2f80cba2
New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
171
diff
changeset
|
133 |
117
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
134 /** |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
135 * Deliveres the translated Value for an Key to an given Language |
171
7fb9441dd8af
Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents:
123
diff
changeset
|
136 * |
7fb9441dd8af
Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents:
123
diff
changeset
|
137 * @param locale |
7fb9441dd8af
Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents:
123
diff
changeset
|
138 * The choosen locale |
7fb9441dd8af
Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents:
123
diff
changeset
|
139 * @param key |
7fb9441dd8af
Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents:
123
diff
changeset
|
140 * the key |
7fb9441dd8af
Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents:
123
diff
changeset
|
141 * @param defaultValue |
7fb9441dd8af
Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents:
123
diff
changeset
|
142 * the Value that should be returned. |
117
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
143 * @return the translated Value |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
144 */ |
171
7fb9441dd8af
Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents:
123
diff
changeset
|
145 public String getRessource(PreferredLocale[] preferredLocales, String key, |
7fb9441dd8af
Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents:
123
diff
changeset
|
146 String defaultValue) { |
121
6b9a07f758cf
Move resources to a place where maven puts them into final package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
118
diff
changeset
|
147 if (key == null || preferredLocales.length == 0) { |
6b9a07f758cf
Move resources to a place where maven puts them into final package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
118
diff
changeset
|
148 return defaultValue; |
6b9a07f758cf
Move resources to a place where maven puts them into final package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
118
diff
changeset
|
149 } |
6b9a07f758cf
Move resources to a place where maven puts them into final package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
118
diff
changeset
|
150 |
117
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
151 try { |
171
7fb9441dd8af
Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents:
123
diff
changeset
|
152 ResourceBundle rb = ResourceBundle.getBundle(ressourceDir + "/" |
7fb9441dd8af
Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents:
123
diff
changeset
|
153 + ressourceName, |
7fb9441dd8af
Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents:
123
diff
changeset
|
154 preferredLocales[0].getLocale()); |
121
6b9a07f758cf
Move resources to a place where maven puts them into final package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
118
diff
changeset
|
155 |
117
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
156 return rb.getString(key); |
171
7fb9441dd8af
Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents:
123
diff
changeset
|
157 } catch (MissingResourceException mre) { |
121
6b9a07f758cf
Move resources to a place where maven puts them into final package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
118
diff
changeset
|
158 log.warn(mre.getLocalizedMessage()); |
117
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
159 return defaultValue; |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
160 } |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
161 } |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
162 } |