Mercurial > dive4elements > gnv-client
annotate gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/ressource/RessourceFactory.java @ 835:2423cefe7d39
Removed trailing whitespace.
gnv-artifacts/trunk@936 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Sat, 17 Apr 2010 09:35:24 +0000 |
parents | feae2f9d6c6f |
children | 05bf8534a35a |
rev | line source |
---|---|
117
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.gnv.artifacts.ressource; |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
2 |
779
b1f5f2a8840f
Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
3 import de.intevation.artifacts.PreferredLocale; |
b1f5f2a8840f
Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
4 |
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
|
5 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
|
6 import java.io.FileNotFoundException; |
779
b1f5f2a8840f
Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
7 import java.io.IOException; |
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
|
8 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
|
9 import java.io.InputStreamReader; |
779
b1f5f2a8840f
Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
10 |
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
|
11 import java.util.ArrayList; |
779
b1f5f2a8840f
Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
12 import java.util.List; |
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
|
13 import java.util.Locale; |
123
8cc96c9cc962
Added some missing RessourceValues
Tim Englich <tim.englich@intevation.de>
parents:
121
diff
changeset
|
14 import java.util.MissingResourceException; |
117
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
15 import java.util.ResourceBundle; |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
16 |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
17 import org.apache.log4j.Logger; |
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 /** |
780
c4156275c1e1
Bring @author javadoc tags in form '@author <a href="john.doe@example.com">John Doe</a>'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
779
diff
changeset
|
20 * @author <a href="mailto:tim.englich@intevation.de">Tim Englich</a> |
778
9a828e5a2390
Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
331
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 public class RessourceFactory { |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
24 |
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 * the logger, used to log exceptions and additonaly information |
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 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
|
29 |
117
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 * The singleton Instance of this Factory. |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
32 */ |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
33 private static RessourceFactory instance = null; |
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 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
|
36 |
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
|
37 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
|
38 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
|
39 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
|
40 |
117
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
41 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
|
42 |
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
|
43 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
|
44 |
117
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
45 /** |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
46 * Basic-Constructor of this Class |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
47 */ |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
48 private RessourceFactory() { |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
49 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
|
50 ressourceDir = System.getProperty(RESSOURCE_BASE_ID, DEFAULT_DIR); |
117
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 |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
53 /** |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
54 * This Method provides an singleton Instance of this Class. |
778
9a828e5a2390
Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
331
diff
changeset
|
55 * |
117
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
56 * @return an singleton Instance of this Class |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
57 */ |
171
7fb9441dd8af
Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents:
123
diff
changeset
|
58 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
|
59 if (instance == null) { |
117
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
60 instance = new RessourceFactory(); |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
61 } |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
62 return instance; |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
63 } |
171
7fb9441dd8af
Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents:
123
diff
changeset
|
64 |
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
|
65 |
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
|
66 /** |
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
|
67 * 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
|
68 * 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
|
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 * @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
|
71 */ |
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 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
|
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 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
|
75 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
|
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 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
|
78 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
|
79 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
|
80 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
|
81 |
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 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
|
83 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
|
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 |
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 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
|
87 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
|
88 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
|
89 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
|
90 |
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 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
|
92 |
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 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
|
94 // 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
|
95 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
|
96 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
|
97 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
|
98 } |
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 |
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 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
|
101 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
|
102 // 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
|
103 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
|
104 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
|
105 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
|
106 } |
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 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
|
108 // 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
|
109 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
|
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 } |
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 |
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 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
|
114 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
|
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 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
|
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 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
|
120 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
|
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 (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
|
123 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
|
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 |
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 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
|
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 |
117
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
130 /** |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
131 * Deliveres the translated Value for an Key to an given Language |
778
9a828e5a2390
Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
331
diff
changeset
|
132 * |
792
9b9bf42b7928
Added and repaired JavaDoc in artifacts package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
133 * @param preferredLocales |
9b9bf42b7928
Added and repaired JavaDoc in artifacts package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
134 * @param key the key |
9b9bf42b7928
Added and repaired JavaDoc in artifacts package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
135 * @param defaultValue the Value that should be returned. |
117
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
136 * @return the translated Value |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
137 */ |
171
7fb9441dd8af
Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents:
123
diff
changeset
|
138 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
|
139 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
|
140 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
|
141 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
|
142 } |
6b9a07f758cf
Move resources to a place where maven puts them into final package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
118
diff
changeset
|
143 |
331
1c427acb6c76
Added subtitles to charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
324
diff
changeset
|
144 return getRessource(preferredLocales[0].getLocale(), key, defaultValue); |
1c427acb6c76
Added subtitles to charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
324
diff
changeset
|
145 } |
1c427acb6c76
Added subtitles to charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
324
diff
changeset
|
146 |
1c427acb6c76
Added subtitles to charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
324
diff
changeset
|
147 |
792
9b9bf42b7928
Added and repaired JavaDoc in artifacts package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
148 /** |
9b9bf42b7928
Added and repaired JavaDoc in artifacts package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
149 * Deliveres the language specific value for the given <code>key</code> |
803
feae2f9d6c6f
Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
792
diff
changeset
|
150 * |
792
9b9bf42b7928
Added and repaired JavaDoc in artifacts package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
151 * @param locale |
9b9bf42b7928
Added and repaired JavaDoc in artifacts package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
152 * @param key |
9b9bf42b7928
Added and repaired JavaDoc in artifacts package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
153 * @param defaultVal |
9b9bf42b7928
Added and repaired JavaDoc in artifacts package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
154 * @return language specific string. |
9b9bf42b7928
Added and repaired JavaDoc in artifacts package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
155 */ |
331
1c427acb6c76
Added subtitles to charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
324
diff
changeset
|
156 public String getRessource(Locale locale, String key, String defaultVal) { |
1c427acb6c76
Added subtitles to charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
324
diff
changeset
|
157 if (key == null || locale == null) |
1c427acb6c76
Added subtitles to charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
324
diff
changeset
|
158 return defaultVal; |
1c427acb6c76
Added subtitles to charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
324
diff
changeset
|
159 |
117
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
160 try { |
331
1c427acb6c76
Added subtitles to charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
324
diff
changeset
|
161 ResourceBundle rb = ResourceBundle.getBundle( |
1c427acb6c76
Added subtitles to charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
324
diff
changeset
|
162 ressourceDir + "/" + ressourceName, |
1c427acb6c76
Added subtitles to charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
324
diff
changeset
|
163 locale |
1c427acb6c76
Added subtitles to charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
324
diff
changeset
|
164 ); |
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
|
165 |
117
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
166 return rb.getString(key); |
331
1c427acb6c76
Added subtitles to charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
324
diff
changeset
|
167 } |
1c427acb6c76
Added subtitles to charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
324
diff
changeset
|
168 catch (MissingResourceException mre) { |
1c427acb6c76
Added subtitles to charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
324
diff
changeset
|
169 log.warn("No resource bundle: " + locale.toString(), mre); |
1c427acb6c76
Added subtitles to charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
324
diff
changeset
|
170 return defaultVal; |
117
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
171 } |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
172 } |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
173 } |
792
9b9bf42b7928
Added and repaired JavaDoc in artifacts package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
174 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |