1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.localization.internal; |
21 |
|
|
22 |
|
import java.util.Locale; |
23 |
|
import java.util.Map; |
24 |
|
import java.util.concurrent.ConcurrentHashMap; |
25 |
|
|
26 |
|
import org.xwiki.localization.LocaleUtils; |
27 |
|
import org.xwiki.localization.Translation; |
28 |
|
|
29 |
|
|
30 |
|
@link@link |
31 |
|
|
32 |
|
@version |
33 |
|
@since |
34 |
|
|
|
|
| 78.6% |
Uncovered Elements: 9 (42) |
Complexity: 13 |
Complexity Density: 0.54 |
|
35 |
|
public abstract class AbstractCachedTranslationBundle extends AbstractTranslationBundle |
36 |
|
{ |
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
protected Map<Locale, LocalizedTranslationBundle> bundleCache = |
41 |
|
new ConcurrentHashMap<Locale, LocalizedTranslationBundle>(); |
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
46 |
216 |
protected AbstractCachedTranslationBundle()... |
47 |
|
{ |
48 |
|
} |
49 |
|
|
50 |
|
|
51 |
|
@param |
52 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
53 |
0 |
public AbstractCachedTranslationBundle(String id)... |
54 |
|
{ |
55 |
0 |
super(id); |
56 |
|
} |
57 |
|
|
58 |
|
|
59 |
|
@param |
60 |
|
@param |
61 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
62 |
0 |
public AbstractCachedTranslationBundle(String id, int priority)... |
63 |
|
{ |
64 |
0 |
super(id, priority); |
65 |
|
} |
66 |
|
|
67 |
|
|
68 |
|
@param |
69 |
|
@return |
70 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
71 |
1384037 |
private LocalizedTranslationBundle getLocalizedBundle(Locale locale)... |
72 |
|
{ |
73 |
1384038 |
LocalizedTranslationBundle bundle = this.bundleCache.get(locale); |
74 |
1384034 |
if (bundle == null) { |
75 |
440 |
bundle = getSynchLocalizedBundle(locale); |
76 |
|
} |
77 |
|
|
78 |
1384037 |
return bundle; |
79 |
|
} |
80 |
|
|
81 |
|
|
82 |
|
@param |
83 |
|
@return |
84 |
|
|
|
|
| 75% |
Uncovered Elements: 3 (12) |
Complexity: 4 |
Complexity Density: 0.5 |
|
85 |
440 |
private synchronized LocalizedTranslationBundle getSynchLocalizedBundle(Locale locale)... |
86 |
|
{ |
87 |
440 |
LocalizedTranslationBundle bundle = this.bundleCache.get(locale); |
88 |
|
|
89 |
440 |
if (bundle == null) { |
90 |
440 |
try { |
91 |
440 |
bundle = createBundle(locale); |
92 |
440 |
if (bundle != null) { |
93 |
440 |
this.bundleCache.put(locale, bundle); |
94 |
|
} |
95 |
|
} catch (Exception e) { |
96 |
0 |
this.logger.error("Failed to get localization bundle", e); |
97 |
|
} |
98 |
|
} |
99 |
|
|
100 |
440 |
return bundle; |
101 |
|
} |
102 |
|
|
|
|
| 87.5% |
Uncovered Elements: 2 (16) |
Complexity: 4 |
Complexity Density: 0.4 |
|
103 |
1384035 |
@Override... |
104 |
|
public Translation getTranslation(String key, Locale locale) |
105 |
|
{ |
106 |
1384036 |
Translation translation; |
107 |
|
|
108 |
1384037 |
LocalizedTranslationBundle bundle = getLocalizedBundle(locale); |
109 |
1384033 |
if (bundle != null) { |
110 |
1384035 |
translation = bundle.getTranslation(key); |
111 |
1384037 |
if (translation == null) { |
112 |
1228519 |
Locale parentLocale = LocaleUtils.getParentLocale(locale); |
113 |
1228524 |
if (parentLocale != null) { |
114 |
462920 |
translation = getTranslation(key, parentLocale); |
115 |
|
} |
116 |
|
} |
117 |
|
} else { |
118 |
0 |
translation = null; |
119 |
|
} |
120 |
|
|
121 |
1384041 |
return translation; |
122 |
|
} |
123 |
|
|
124 |
|
|
125 |
|
@param |
126 |
|
@return |
127 |
|
|
128 |
|
protected abstract LocalizedTranslationBundle createBundle(Locale locale) throws Exception; |
129 |
|
} |