1
2
3
4
5
6
7 package nl.mineleni.cbsviewer.util;
8
9 import java.util.Enumeration;
10 import java.util.MissingResourceException;
11 import java.util.PropertyResourceBundle;
12 import java.util.ResourceBundle;
13
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
16
17
18
19
20
21
22
23 public class LabelsBundle extends ResourceBundle {
24
25
26 private static final Logger LOGGER = LoggerFactory
27 .getLogger(LabelsBundle.class);
28
29
30 private PropertyResourceBundle resBundle;
31
32
33
34
35
36 public LabelsBundle() {
37 try {
38 this.resBundle = (PropertyResourceBundle) PropertyResourceBundle
39 .getBundle(
40 "LabelsBundle",
41 ResourceBundle.Control
42 .getControl(ResourceBundle.Control.FORMAT_PROPERTIES));
43 } catch (final NullPointerException e) {
44 LOGGER.error("baseName of control is null.", e);
45 } catch (final MissingResourceException e) {
46 LOGGER.error(
47 "De resourcebundel (LabelsBundle.properties) is niet gevonden",
48 e);
49 } catch (final IllegalArgumentException e) {
50 LOGGER.error(
51 "ResourceBundle.Control heeft geen locale kunnen achterhalen.",
52 e);
53 }
54 }
55
56
57
58
59
60
61
62 public String getOpenLayersLangBundle() {
63 final StringBuilder sb = new StringBuilder(
64 "\n/* <![CDATA[ */ OpenLayers.Lang.nl = OpenLayers.Util.extend({");
65 for (final Enumeration<String> keys = this.getKeys(); keys
66 .hasMoreElements();) {
67 final String key = keys.nextElement();
68 if (LOGGER.isDebugEnabled()) {
69 sb.append("\n");
70 }
71 sb.append("'");
72 sb.append(key);
73 sb.append("'");
74 sb.append(":'");
75 sb.append(this.getString(key).replaceAll("\\{[0-9]\\}*", "\\$$0"));
76 sb.append("',");
77 }
78 sb.deleteCharAt(sb.length() - 1);
79 sb.append("}, OpenLayers.Lang.nl);/* ]]> */");
80 return sb.toString();
81 }
82
83 @Override
84 public Enumeration<String> getKeys() {
85 return this.resBundle.getKeys();
86 }
87
88 @Override
89 protected Object handleGetObject(final String key) {
90 return this.resBundle.handleGetObject(key);
91 }
92 }