Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
JThequeResourceBundle |
|
| 1.0;1 |
1 | package org.jtheque.core.managers.language; | |
2 | ||
3 | import org.springframework.context.support.ReloadableResourceBundleMessageSource; | |
4 | ||
5 | import javax.annotation.PostConstruct; | |
6 | import java.util.ArrayList; | |
7 | import java.util.Arrays; | |
8 | import java.util.Collection; | |
9 | ||
10 | /* | |
11 | * This file is part of JTheque. | |
12 | * | |
13 | * JTheque is free software: you can redistribute it and/or modify | |
14 | * it under the terms of the GNU General Public License as published by | |
15 | * the Free Software Foundation, either version 3 of the License. | |
16 | * | |
17 | * JTheque is distributed in the hope that it will be useful, | |
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 | * GNU General Public License for more details. | |
21 | * | |
22 | * You should have received a copy of the GNU General Public License | |
23 | * along with JTheque. If not, see <http://www.gnu.org/licenses/>. | |
24 | */ | |
25 | ||
26 | /** | |
27 | * An editable resource bundle implementation. | |
28 | * | |
29 | * @author Baptiste Wicht | |
30 | */ | |
31 | 0 | public final class JThequeResourceBundle extends ReloadableResourceBundleMessageSource implements EditableResourceBundle { |
32 | private String[] coreBaseNames; | |
33 | ||
34 | 0 | private final Collection<String> baseNames = new ArrayList<String>(10); |
35 | ||
36 | /** | |
37 | * Init the JTheque resource bundle. | |
38 | */ | |
39 | @PostConstruct | |
40 | public void init() { | |
41 | 0 | baseNames.addAll(Arrays.asList(coreBaseNames)); |
42 | ||
43 | 0 | refresh(); |
44 | 0 | } |
45 | ||
46 | @Override | |
47 | public void addBaseName(String baseName) { | |
48 | 0 | baseNames.add(baseName); |
49 | ||
50 | 0 | refresh(); |
51 | 0 | } |
52 | ||
53 | @Override | |
54 | public void removeBaseName(String baseName) { | |
55 | 0 | baseNames.remove(baseName); |
56 | ||
57 | 0 | refresh(); |
58 | 0 | } |
59 | ||
60 | /** | |
61 | * Refresh the resource bundle. | |
62 | */ | |
63 | private void refresh() { | |
64 | 0 | setBasenames(baseNames.toArray(new String[baseNames.size()])); |
65 | 0 | } |
66 | ||
67 | /** | |
68 | * Set the base names of the core. | |
69 | * | |
70 | * @param coreBaseNames An array of all the base names of the core. | |
71 | */ | |
72 | public void setCoreBaseNames(String[] coreBaseNames) { | |
73 | 0 | this.coreBaseNames = Arrays.copyOf(coreBaseNames, coreBaseNames.length); |
74 | 0 | } |
75 | } |