Mercurial > dive4elements > gnv-client
annotate gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/ressource/RessourceFactory.java @ 1145:dfe1ac687c7f tip
added tags
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:16:15 +0200 |
parents | f953c9a559d8 |
children |
rev | line source |
---|---|
1115
f953c9a559d8
Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
1 /* |
f953c9a559d8
Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
2 * Copyright (c) 2010 by Intevation GmbH |
f953c9a559d8
Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
3 * |
f953c9a559d8
Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
4 * This program is free software under the LGPL (>=v2.1) |
f953c9a559d8
Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
5 * Read the file LGPL.txt coming with the software for details |
f953c9a559d8
Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
6 * or visit http://www.gnu.org/licenses/ if it does not exist. |
f953c9a559d8
Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
7 */ |
f953c9a559d8
Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
8 |
117
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
9 package de.intevation.gnv.artifacts.ressource; |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
10 |
779
b1f5f2a8840f
Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
11 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
|
12 |
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.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
|
14 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
|
15 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
|
16 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
|
17 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
|
18 |
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
|
19 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
|
20 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
|
21 import java.util.Locale; |
123
8cc96c9cc962
Added some missing RessourceValues
Tim Englich <tim.englich@intevation.de>
parents:
121
diff
changeset
|
22 import java.util.MissingResourceException; |
117
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
23 import java.util.ResourceBundle; |
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 import org.apache.log4j.Logger; |
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 /** |
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
|
28 * @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
|
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 public class RessourceFactory { |
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 /** |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
34 * the logger, used to log exceptions and additonaly information |
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 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
|
37 |
117
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 * The singleton Instance of this Factory. |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
40 */ |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
41 private static RessourceFactory instance = null; |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
42 |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
43 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
|
44 |
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
|
45 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
|
46 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
|
47 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
|
48 |
117
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
49 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
|
50 |
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
|
51 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
|
52 |
117
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 * Basic-Constructor of this Class |
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 private RessourceFactory() { |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
57 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
|
58 ressourceDir = System.getProperty(RESSOURCE_BASE_ID, DEFAULT_DIR); |
117
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
59 } |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
60 |
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 * 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
|
63 * |
117
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
64 * @return an singleton Instance of this Class |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
65 */ |
171
7fb9441dd8af
Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents:
123
diff
changeset
|
66 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
|
67 if (instance == null) { |
117
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
68 instance = new RessourceFactory(); |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
69 } |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
70 return instance; |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
71 } |
171
7fb9441dd8af
Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents:
123
diff
changeset
|
72 |
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
|
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 /** |
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 * 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
|
76 * 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
|
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 * @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
|
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 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
|
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 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
|
83 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
|
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 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
|
86 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
|
87 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
|
88 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
|
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 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
|
91 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
|
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 |
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 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
|
95 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
|
96 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
|
97 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
|
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 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
|
100 |
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 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
|
102 // 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
|
103 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
|
104 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
|
105 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
|
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 |
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 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
|
109 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
|
110 // 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
|
111 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
|
112 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
|
113 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
|
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 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
|
116 // 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
|
117 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
|
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 |
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 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
|
122 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
|
123 ); |
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 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
|
126 } |
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 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
|
128 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
|
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 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
|
131 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
|
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 |
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
|
134 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
|
135 } |
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
|
136 |
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
|
137 |
117
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
138 /** |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
139 * 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
|
140 * |
792
9b9bf42b7928
Added and repaired JavaDoc in artifacts package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
141 * @param preferredLocales |
9b9bf42b7928
Added and repaired JavaDoc in artifacts package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
142 * @param key the key |
9b9bf42b7928
Added and repaired JavaDoc in artifacts package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
143 * @param defaultValue the Value that should be returned. |
117
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
144 * @return the translated Value |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
145 */ |
171
7fb9441dd8af
Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents:
123
diff
changeset
|
146 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
|
147 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
|
148 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
|
149 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
|
150 } |
6b9a07f758cf
Move resources to a place where maven puts them into final package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
118
diff
changeset
|
151 |
331
1c427acb6c76
Added subtitles to charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
324
diff
changeset
|
152 return getRessource(preferredLocales[0].getLocale(), key, defaultValue); |
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 |
1c427acb6c76
Added subtitles to charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
324
diff
changeset
|
155 |
792
9b9bf42b7928
Added and repaired JavaDoc in artifacts package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
156 /** |
9b9bf42b7928
Added and repaired JavaDoc in artifacts package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
157 * 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
|
158 * |
792
9b9bf42b7928
Added and repaired JavaDoc in artifacts package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
159 * @param locale |
9b9bf42b7928
Added and repaired JavaDoc in artifacts package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
160 * @param key |
9b9bf42b7928
Added and repaired JavaDoc in artifacts package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
161 * @param defaultVal |
9b9bf42b7928
Added and repaired JavaDoc in artifacts package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
162 * @return language specific string. |
9b9bf42b7928
Added and repaired JavaDoc in artifacts package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
163 */ |
331
1c427acb6c76
Added subtitles to charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
324
diff
changeset
|
164 public String getRessource(Locale locale, String key, String defaultVal) { |
1c427acb6c76
Added subtitles to charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
324
diff
changeset
|
165 if (key == null || locale == null) |
1c427acb6c76
Added subtitles to charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
324
diff
changeset
|
166 return defaultVal; |
1c427acb6c76
Added subtitles to charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
324
diff
changeset
|
167 |
117
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
168 try { |
331
1c427acb6c76
Added subtitles to charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
324
diff
changeset
|
169 ResourceBundle rb = ResourceBundle.getBundle( |
1c427acb6c76
Added subtitles to charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
324
diff
changeset
|
170 ressourceDir + "/" + ressourceName, |
1c427acb6c76
Added subtitles to charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
324
diff
changeset
|
171 locale |
1c427acb6c76
Added subtitles to charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
324
diff
changeset
|
172 ); |
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
|
173 |
117
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
174 return rb.getString(key); |
331
1c427acb6c76
Added subtitles to charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
324
diff
changeset
|
175 } |
1c427acb6c76
Added subtitles to charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
324
diff
changeset
|
176 catch (MissingResourceException mre) { |
1c427acb6c76
Added subtitles to charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
324
diff
changeset
|
177 log.warn("No resource bundle: " + locale.toString(), mre); |
1c427acb6c76
Added subtitles to charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
324
diff
changeset
|
178 return defaultVal; |
117
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
179 } |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
180 } |
ef157bd2fa92
LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
181 } |
836
05bf8534a35a
Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
803
diff
changeset
|
182 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |