| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
package org.itracker.core.resources; |
| 20 |
|
|
| 21 |
|
import java.util.Collections; |
| 22 |
|
import java.util.Enumeration; |
| 23 |
|
import java.util.HashMap; |
| 24 |
|
import java.util.List; |
| 25 |
|
import java.util.Locale; |
| 26 |
|
import java.util.MissingResourceException; |
| 27 |
|
import java.util.ResourceBundle; |
| 28 |
|
import java.util.Set; |
| 29 |
|
import java.util.TreeSet; |
| 30 |
|
|
| 31 |
|
import org.apache.log4j.Logger; |
| 32 |
|
import org.itracker.model.Language; |
| 33 |
|
import org.itracker.services.exceptions.ITrackerDirtyResourceException; |
| 34 |
|
|
|
|
|
| 0% |
Uncovered Elements: 146 (146) |
Complexity: 46 |
Complexity Density: 0.55 |
|
| 35 |
|
public class ITrackerResourceBundle extends ResourceBundle { |
| 36 |
|
|
| 37 |
|
private static final Logger log = Logger |
| 38 |
|
.getLogger(ITrackerResourceBundle.class); |
| 39 |
|
private final HashMap<String, Object> data = new HashMap<String, Object>(); |
| 40 |
|
|
| 41 |
|
|
| 42 |
|
|
| 43 |
|
private Object[][] dataArray = null; |
| 44 |
|
private ResourceBundle propertiesBundle; |
| 45 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 46 |
0
|
static ResourceBundle loadBundle() {... |
| 47 |
0
|
return new ITrackerResourceBundle(); |
| 48 |
|
} |
| 49 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 50 |
0
|
static ResourceBundle loadBundle(Locale locale) {... |
| 51 |
0
|
return new ITrackerResourceBundle(locale); |
| 52 |
|
} |
| 53 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 54 |
0
|
static ResourceBundle loadBundle(Locale locale, Object[][] data) {... |
| 55 |
0
|
return new ITrackerResourceBundle(locale, data); |
| 56 |
|
} |
| 57 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 58 |
0
|
static ResourceBundle loadBundle(Locale locale, List<Language> items) {... |
| 59 |
0
|
return new ITrackerResourceBundle(locale, items); |
| 60 |
|
} |
| 61 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 62 |
0
|
private ITrackerResourceBundle() {... |
| 63 |
0
|
super.setParent(ResourceBundle.getBundle( |
| 64 |
|
ITrackerResources.RESOURCE_BUNDLE_NAME, new Locale( |
| 65 |
|
ITrackerResources.getDefaultLocale()))); |
| 66 |
|
} |
| 67 |
|
|
| 68 |
|
|
| 69 |
|
@param |
| 70 |
|
|
|
|
|
| 0% |
Uncovered Elements: 16 (16) |
Complexity: 5 |
Complexity Density: 0.62 |
|
| 71 |
0
|
private ITrackerResourceBundle(Locale locale) {... |
| 72 |
0
|
if (null == locale) { |
| 73 |
0
|
locale = ITrackerResources.getLocale(ITrackerResources |
| 74 |
|
.getDefaultLocale()); |
| 75 |
|
} |
| 76 |
0
|
this.propertiesBundle = ResourceBundle.getBundle( |
| 77 |
|
ITrackerResources.RESOURCE_BUNDLE_NAME, locale); |
| 78 |
|
|
| 79 |
0
|
if (!locale.equals(ITrackerResources |
| 80 |
|
.getLocale(ITrackerResources.BASE_LOCALE))) { |
| 81 |
0
|
if (locale.getCountry().length() > 0) { |
| 82 |
0
|
setParent(ITrackerResources.getBundle(new Locale(locale |
| 83 |
|
.getLanguage()))); |
| 84 |
0
|
} else if (locale.getLanguage().length() > 0) { |
| 85 |
0
|
setParent(ITrackerResources.getBundle(ITrackerResources |
| 86 |
|
.getLocale(ITrackerResources.BASE_LOCALE))); |
| 87 |
|
} |
| 88 |
|
} |
| 89 |
|
|
| 90 |
|
} |
| 91 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 92 |
0
|
public static ResourceBundle getBundle() {... |
| 93 |
0
|
return ITrackerResources.getBundle(); |
| 94 |
|
} |
| 95 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 96 |
0
|
public static ResourceBundle getBundle(Locale locale) {... |
| 97 |
0
|
return ITrackerResources.getBundle(locale); |
| 98 |
|
} |
| 99 |
|
|
| 100 |
|
|
| 101 |
|
@param |
| 102 |
|
@param |
| 103 |
|
@deprecated |
| 104 |
|
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 105 |
0
|
public ITrackerResourceBundle(Locale locale, Object[][] data) {... |
| 106 |
0
|
this(locale); |
| 107 |
0
|
setContents(data); |
| 108 |
|
} |
| 109 |
|
|
| 110 |
|
|
| 111 |
|
@param |
| 112 |
|
@param |
| 113 |
|
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 114 |
0
|
private ITrackerResourceBundle(Locale locale, List<Language> items) {... |
| 115 |
0
|
this(locale); |
| 116 |
0
|
setContents(items); |
| 117 |
|
} |
| 118 |
|
|
| 119 |
|
|
| 120 |
|
|
| 121 |
|
@return |
| 122 |
|
@deprecated |
| 123 |
|
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 3 |
Complexity Density: 0.33 |
|
| 124 |
0
|
public Object[][] getContents() {... |
| 125 |
|
|
| 126 |
0
|
if (dataArray == null) { |
| 127 |
0
|
int i = 0; |
| 128 |
0
|
Object[][] newData = new Object[2][data.size()]; |
| 129 |
0
|
Enumeration<String> keys = getKeys(); |
| 130 |
0
|
while (keys.hasMoreElements()) { |
| 131 |
0
|
newData[0][i] = keys.nextElement(); |
| 132 |
0
|
newData[1][i] = data.get(newData[0][i]); |
| 133 |
|
} |
| 134 |
|
|
| 135 |
0
|
this.dataArray = newData; |
| 136 |
|
} |
| 137 |
|
|
| 138 |
0
|
return dataArray.clone(); |
| 139 |
|
} |
| 140 |
|
|
| 141 |
|
|
| 142 |
|
@deprecated |
| 143 |
|
@param |
| 144 |
|
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
| 145 |
0
|
public void setContents(List<Language> content) {... |
| 146 |
0
|
if (content != null) { |
| 147 |
0
|
synchronized (data) { |
| 148 |
0
|
data.clear(); |
| 149 |
0
|
this.dataArray = null; |
| 150 |
0
|
for (int i = 0; i < content.size(); i++) { |
| 151 |
0
|
data.put(content.get(i).getResourceKey(), content.get(i) |
| 152 |
|
.getResourceValue()); |
| 153 |
|
} |
| 154 |
|
} |
| 155 |
|
} |
| 156 |
|
} |
| 157 |
|
|
| 158 |
|
|
| 159 |
|
@deprecated |
| 160 |
|
@param |
| 161 |
|
|
| 162 |
|
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 5 |
Complexity Density: 0.83 |
|
| 163 |
0
|
private void setContents(Object[][] content) {... |
| 164 |
0
|
if (content != null && content.length == 2 |
| 165 |
|
&& content[0].length == content[1].length) { |
| 166 |
0
|
synchronized (data) { |
| 167 |
0
|
data.clear(); |
| 168 |
0
|
this.dataArray = null; |
| 169 |
0
|
for (int i = 0; i < content[0].length; i++) { |
| 170 |
0
|
data.put((String) content[0][i], content[1][i]); |
| 171 |
|
} |
| 172 |
|
} |
| 173 |
|
} |
| 174 |
|
} |
| 175 |
|
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 3 |
Complexity Density: 0.75 |
|
| 176 |
0
|
@Override... |
| 177 |
|
public Locale getLocale() { |
| 178 |
0
|
Locale l = super.getLocale(); |
| 179 |
0
|
if (null == l && null != propertiesBundle) { |
| 180 |
0
|
l = propertiesBundle.getLocale(); |
| 181 |
|
} |
| 182 |
0
|
return l; |
| 183 |
|
} |
| 184 |
|
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 185 |
0
|
public boolean isDirty(String key) {... |
| 186 |
0
|
try { |
| 187 |
0
|
handleGetObject(key); |
| 188 |
|
} catch (ITrackerDirtyResourceException exception) { |
| 189 |
0
|
return true; |
| 190 |
|
} |
| 191 |
0
|
return false; |
| 192 |
|
} |
| 193 |
|
|
| 194 |
|
|
| 195 |
|
|
| 196 |
|
|
| 197 |
|
|
| 198 |
|
|
| 199 |
|
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 200 |
0
|
public void updateValue(String key, String value) {... |
| 201 |
0
|
synchronized (data) { |
| 202 |
0
|
data.put(key, value); |
| 203 |
0
|
this.dataArray = null; |
| 204 |
|
} |
| 205 |
|
} |
| 206 |
|
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 207 |
0
|
public void updateValue(Language model) {... |
| 208 |
0
|
if (model != null) { |
| 209 |
0
|
synchronized (data) { |
| 210 |
0
|
data.put(model.getResourceKey(), model.getResourceValue()); |
| 211 |
0
|
this.dataArray = null; |
| 212 |
|
} |
| 213 |
|
} |
| 214 |
|
} |
| 215 |
|
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
| 216 |
0
|
public void removeValue(String key, boolean markDirty) {... |
| 217 |
0
|
if (key != null) { |
| 218 |
0
|
synchronized (data) { |
| 219 |
0
|
if (markDirty) { |
| 220 |
0
|
data.put(key, new DirtyKey() { |
| 221 |
|
}); |
| 222 |
|
} else { |
| 223 |
0
|
data.remove(key); |
| 224 |
|
} |
| 225 |
0
|
this.dataArray = null; |
| 226 |
|
} |
| 227 |
|
} |
| 228 |
|
} |
| 229 |
|
|
| 230 |
|
|
| 231 |
|
|
| 232 |
|
|
| 233 |
|
|
|
|
|
| 0% |
Uncovered Elements: 15 (15) |
Complexity: 5 |
Complexity Density: 0.56 |
|
| 234 |
0
|
public final Object handleGetObject(String key) {... |
| 235 |
0
|
Object value = data.get(key); |
| 236 |
0
|
if (value instanceof DirtyKey) { |
| 237 |
0
|
throw new ITrackerDirtyResourceException( |
| 238 |
|
"The requested key has been marked dirty.", |
| 239 |
|
"ITrackerResourceBundle_" + getLocale(), key); |
| 240 |
|
} |
| 241 |
0
|
if (null == value) { |
| 242 |
0
|
try { |
| 243 |
0
|
value = propertiesBundle.getObject(key); |
| 244 |
|
|
| 245 |
|
|
| 246 |
|
|
| 247 |
|
} catch (MissingResourceException e) { |
| 248 |
0
|
if (log.isDebugEnabled()) { |
| 249 |
0
|
log.debug("handleGetObject: " + key, e); |
| 250 |
|
} |
| 251 |
|
} |
| 252 |
|
} |
| 253 |
0
|
return value; |
| 254 |
|
} |
| 255 |
|
|
| 256 |
|
|
| 257 |
|
|
| 258 |
|
|
| 259 |
|
|
| 260 |
|
|
|
|
|
| 0% |
Uncovered Elements: 22 (22) |
Complexity: 5 |
Complexity Density: 0.36 |
|
| 261 |
0
|
public Enumeration<String> getKeys() {... |
| 262 |
0
|
Set<String> set = new TreeSet<String>(data.keySet()); |
| 263 |
0
|
if (null != parent) { |
| 264 |
0
|
Enumeration<String> keys = parent.getKeys(); |
| 265 |
0
|
String key; |
| 266 |
0
|
while (keys.hasMoreElements()) { |
| 267 |
0
|
key = keys.nextElement(); |
| 268 |
0
|
set.add(key); |
| 269 |
|
} |
| 270 |
|
} |
| 271 |
0
|
if (null != propertiesBundle) { |
| 272 |
0
|
Enumeration<String> keys = propertiesBundle.getKeys(); |
| 273 |
0
|
String key; |
| 274 |
0
|
while (keys.hasMoreElements()) { |
| 275 |
0
|
key = keys.nextElement(); |
| 276 |
0
|
set.add(key); |
| 277 |
|
} |
| 278 |
|
} |
| 279 |
0
|
return Collections.enumeration(set); |
| 280 |
|
} |
| 281 |
|
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
| 282 |
|
public static interface DirtyKey { |
| 283 |
|
} |
| 284 |
|
} |