annotate gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/ressource/RessourceFactory.java @ 779:b1f5f2a8840f

Ordered imports. Removed needless imports. Removed empty headers. gnv-artifacts/trunk@854 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 29 Mar 2010 08:51:20 +0000
parents 9a828e5a2390
children c4156275c1e1
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.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
7 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
8 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
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;
779
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
11
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
12 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
13 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
14 import java.util.Locale;
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
ef157bd2fa92 LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
20 /**
ef157bd2fa92 LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
21 * @author Tim Englich <tim.englich@intevation.de>
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 331
diff changeset
22 *
117
ef157bd2fa92 LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
23 */
ef157bd2fa92 LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
24 public class RessourceFactory {
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 /**
ef157bd2fa92 LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
27 * the logger, used to log exceptions and additonaly information
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 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
30
117
ef157bd2fa92 LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
31 /**
ef157bd2fa92 LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
32 * The singleton Instance of this Factory.
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 private static RessourceFactory instance = null;
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 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
37
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
38 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
39 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
40 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
41
117
ef157bd2fa92 LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
42 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
43
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
44 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
45
117
ef157bd2fa92 LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
46 /**
ef157bd2fa92 LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
47 * Basic-Constructor of this Class
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 private RessourceFactory() {
ef157bd2fa92 LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
50 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
51 ressourceDir = System.getProperty(RESSOURCE_BASE_ID, DEFAULT_DIR);
117
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 /**
ef157bd2fa92 LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
55 * 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
56 *
117
ef157bd2fa92 LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
57 * @return an singleton Instance of this Class
ef157bd2fa92 LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
58 */
171
7fb9441dd8af Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents: 123
diff changeset
59 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
60 if (instance == null) {
117
ef157bd2fa92 LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
61 instance = new RessourceFactory();
ef157bd2fa92 LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
62 }
ef157bd2fa92 LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
63 return instance;
ef157bd2fa92 LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
64 }
171
7fb9441dd8af Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents: 123
diff changeset
65
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
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 /**
7b4e2f80cba2 New method in 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 * 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
69 * 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
70 *
7b4e2f80cba2 New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 171
diff changeset
71 * @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
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 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
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 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
76 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
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 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
79 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
80 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
81 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
82
7b4e2f80cba2 New method in 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 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
84 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
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
7b4e2f80cba2 New method in 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 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
88 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
89 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
90 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
91
7b4e2f80cba2 New method in 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 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
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 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
95 // 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
96 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
97 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
98 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
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
7b4e2f80cba2 New method in 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 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
102 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
103 // 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
104 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
105 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
106 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
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 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
109 // 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
110 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
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
7b4e2f80cba2 New method in 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 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
115 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
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
7b4e2f80cba2 New method in 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 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
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 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
121 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
122 }
7b4e2f80cba2 New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 171
diff changeset
123 catch (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
124 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
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
7b4e2f80cba2 New method in 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 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
128 }
7b4e2f80cba2 New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 171
diff changeset
129
7b4e2f80cba2 New method in RessourceFactory to read locales supported by the server. Added config file for supported locales.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 171
diff changeset
130
117
ef157bd2fa92 LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
131 /**
ef157bd2fa92 LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
132 * 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
133 *
171
7fb9441dd8af Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents: 123
diff changeset
134 * @param locale
7fb9441dd8af Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents: 123
diff changeset
135 * The choosen locale
7fb9441dd8af Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents: 123
diff changeset
136 * @param key
7fb9441dd8af Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents: 123
diff changeset
137 * the key
7fb9441dd8af Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents: 123
diff changeset
138 * @param defaultValue
7fb9441dd8af Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents: 123
diff changeset
139 * the Value that should be returned.
117
ef157bd2fa92 LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
140 * @return the translated Value
ef157bd2fa92 LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
141 */
171
7fb9441dd8af Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents: 123
diff changeset
142 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
143 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
144 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
145 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
146 }
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
331
1c427acb6c76 Added subtitles to charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 324
diff changeset
148 return getRessource(preferredLocales[0].getLocale(), key, defaultValue);
1c427acb6c76 Added subtitles to charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 324
diff changeset
149 }
1c427acb6c76 Added subtitles to charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 324
diff changeset
150
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 public String getRessource(Locale locale, String key, String defaultVal) {
1c427acb6c76 Added subtitles to charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 324
diff changeset
153 if (key == null || locale == null)
1c427acb6c76 Added subtitles to charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 324
diff changeset
154 return defaultVal;
1c427acb6c76 Added subtitles to charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 324
diff changeset
155
117
ef157bd2fa92 LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
156 try {
331
1c427acb6c76 Added subtitles to charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 324
diff changeset
157 ResourceBundle rb = ResourceBundle.getBundle(
1c427acb6c76 Added subtitles to charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 324
diff changeset
158 ressourceDir + "/" + ressourceName,
1c427acb6c76 Added subtitles to charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 324
diff changeset
159 locale
1c427acb6c76 Added subtitles to charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 324
diff changeset
160 );
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
161
117
ef157bd2fa92 LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
162 return rb.getString(key);
331
1c427acb6c76 Added subtitles to charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 324
diff changeset
163 }
1c427acb6c76 Added subtitles to charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 324
diff changeset
164 catch (MissingResourceException mre) {
1c427acb6c76 Added subtitles to charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 324
diff changeset
165 log.warn("No resource bundle: " + locale.toString(), mre);
1c427acb6c76 Added subtitles to charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 324
diff changeset
166 return defaultVal;
117
ef157bd2fa92 LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
167 }
ef157bd2fa92 LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
168 }
ef157bd2fa92 LanguageSupport integrated
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
169 }

http://dive4elements.wald.intevation.org