Mercurial > dive4elements > gnv-client
annotate gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/ressource/RessourceFactory.java @ 355:fce70ff3486b
Forget to check in pom.xml
gnv-artifacts/trunk@428 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Tue, 15 Dec 2009 14:35:41 +0000 |
parents | 1c427acb6c76 |
children | 9a828e5a2390 |
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.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
|
9 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
|
10 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
|
11 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
|
12 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
|
13 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
|
14 import java.util.List; |
123
8cc96c9cc962
Added some missing RessourceValues
Tim Englich <tim.englich@intevation.de>
parents:
121
diff
changeset
|
15 import java.util.MissingResourceException; |
117
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
16 import java.util.ResourceBundle; |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
17 |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
18 import org.apache.log4j.Logger; |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
19 |
118
5ebc059064a6
Adding Languagetransfer to the ArtifactDatabase to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents:
117
diff
changeset
|
20 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
|
21 |
117
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
22 /** |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
23 * @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
|
24 * |
117
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
25 */ |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
26 public class RessourceFactory { |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
27 |
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 * the logger, used to log exceptions and additonaly information |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
30 */ |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
31 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
|
32 |
117
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
33 /** |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
34 * The singleton Instance of this Factory. |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
35 */ |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
36 private static RessourceFactory instance = null; |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
37 |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
38 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
|
39 |
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
|
40 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
|
41 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
|
42 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
|
43 |
117
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
44 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
|
45 |
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
|
46 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
|
47 |
117
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
48 /** |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
49 * Basic-Constructor of this Class |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
50 */ |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
51 private RessourceFactory() { |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
52 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
|
53 ressourceDir = System.getProperty(RESSOURCE_BASE_ID, DEFAULT_DIR); |
117
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
54 } |
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 * 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
|
58 * |
117
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
59 * @return an singleton Instance of this Class |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
60 */ |
171
7fb9441dd8af
Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents:
123
diff
changeset
|
61 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
|
62 if (instance == null) { |
117
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
63 instance = new RessourceFactory(); |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
64 } |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
65 return instance; |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
66 } |
171
7fb9441dd8af
Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents:
123
diff
changeset
|
67 |
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
|
68 |
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 * 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
|
71 * 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
|
72 * |
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 * @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
|
74 */ |
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 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
|
76 |
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 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
|
78 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
|
79 |
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 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
|
81 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
|
82 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
|
83 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
|
84 |
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 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
|
86 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
|
87 ); |
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 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
|
90 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
|
91 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
|
92 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
|
93 |
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 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
|
95 |
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 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
|
97 // 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
|
98 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
|
99 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
|
100 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
|
101 } |
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 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
|
104 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
|
105 // 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
|
106 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
|
107 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
|
108 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
|
109 } |
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 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
|
111 // 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
|
112 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
|
113 } |
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 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
|
117 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
|
118 ); |
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 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
|
121 } |
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 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
|
123 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
|
124 } |
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 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
|
126 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
|
127 } |
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 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
|
130 } |
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 |
117
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
133 /** |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
134 * 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
|
135 * |
7fb9441dd8af
Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents:
123
diff
changeset
|
136 * @param locale |
7fb9441dd8af
Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents:
123
diff
changeset
|
137 * The choosen locale |
7fb9441dd8af
Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents:
123
diff
changeset
|
138 * @param key |
7fb9441dd8af
Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents:
123
diff
changeset
|
139 * the key |
7fb9441dd8af
Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents:
123
diff
changeset
|
140 * @param defaultValue |
7fb9441dd8af
Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents:
123
diff
changeset
|
141 * the Value that should be returned. |
117
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
142 * @return the translated Value |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
143 */ |
171
7fb9441dd8af
Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents:
123
diff
changeset
|
144 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
|
145 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
|
146 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
|
147 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
|
148 } |
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 |
331
1c427acb6c76
Added subtitles to charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
324
diff
changeset
|
150 return getRessource(preferredLocales[0].getLocale(), key, defaultValue); |
1c427acb6c76
Added subtitles to charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
324
diff
changeset
|
151 } |
1c427acb6c76
Added subtitles to charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
324
diff
changeset
|
152 |
1c427acb6c76
Added subtitles to charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
324
diff
changeset
|
153 |
1c427acb6c76
Added subtitles to charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
324
diff
changeset
|
154 public String getRessource(Locale locale, String key, String defaultVal) { |
1c427acb6c76
Added subtitles to charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
324
diff
changeset
|
155 if (key == null || locale == null) |
1c427acb6c76
Added subtitles to charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
324
diff
changeset
|
156 return defaultVal; |
1c427acb6c76
Added subtitles to charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
324
diff
changeset
|
157 |
117
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
158 try { |
331
1c427acb6c76
Added subtitles to charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
324
diff
changeset
|
159 ResourceBundle rb = ResourceBundle.getBundle( |
1c427acb6c76
Added subtitles to charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
324
diff
changeset
|
160 ressourceDir + "/" + ressourceName, |
1c427acb6c76
Added subtitles to charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
324
diff
changeset
|
161 locale |
1c427acb6c76
Added subtitles to charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
324
diff
changeset
|
162 ); |
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
|
163 |
117
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
164 return rb.getString(key); |
331
1c427acb6c76
Added subtitles to charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
324
diff
changeset
|
165 } |
1c427acb6c76
Added subtitles to charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
324
diff
changeset
|
166 catch (MissingResourceException mre) { |
1c427acb6c76
Added subtitles to charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
324
diff
changeset
|
167 log.warn("No resource bundle: " + locale.toString(), mre); |
1c427acb6c76
Added subtitles to charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
324
diff
changeset
|
168 return defaultVal; |
117
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
169 } |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
170 } |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
171 } |