1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.rendering.internal.macro.chart.source; |
21 |
|
|
22 |
|
import java.text.DateFormat; |
23 |
|
import java.text.SimpleDateFormat; |
24 |
|
import java.util.Locale; |
25 |
|
import java.util.TimeZone; |
26 |
|
|
27 |
|
import org.apache.commons.lang3.LocaleUtils; |
28 |
|
import org.xwiki.rendering.macro.MacroExecutionException; |
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
@version |
36 |
|
@since |
37 |
|
|
|
|
| 84.2% |
Uncovered Elements: 6 (38) |
Complexity: 12 |
Complexity Density: 0.52 |
|
38 |
|
public class LocaleConfiguration extends AbstractConfigurator |
39 |
|
{ |
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
public static final String LOCALE_PARAM = "locale"; |
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
public static final String DATEFORMAT_PARAM = "date_format"; |
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
private Locale locale = Locale.getDefault(); |
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
private TimeZone timeZone = TimeZone.getDefault(); |
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
private DateFormat dateFormat = DateFormat.getInstance(); |
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
|
68 |
|
private String dateFormatString; |
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
@param |
74 |
|
@param |
75 |
|
@return |
76 |
|
@throws |
77 |
|
|
|
|
| 79.2% |
Uncovered Elements: 5 (24) |
Complexity: 6 |
Complexity Density: 0.38 |
|
78 |
144 |
public boolean setParameter(String key, String value) throws MacroExecutionException... |
79 |
|
{ |
80 |
144 |
boolean claimed = true; |
81 |
|
|
82 |
144 |
if (LOCALE_PARAM.equals(key)) { |
83 |
2 |
boolean valid = true; |
84 |
2 |
Locale l; |
85 |
2 |
try { |
86 |
2 |
l = LocaleUtils.toLocale(value); |
87 |
2 |
if (!LocaleUtils.isAvailableLocale(l)) { |
88 |
0 |
valid = false; |
89 |
|
} else { |
90 |
2 |
this.locale = l; |
91 |
|
} |
92 |
|
} catch (IllegalArgumentException e) { |
93 |
0 |
valid = false; |
94 |
|
} |
95 |
2 |
if (!valid) { |
96 |
0 |
throw new MacroExecutionException(String.format("Invalid locale string [%s].", value)); |
97 |
|
} |
98 |
142 |
} else if (DATEFORMAT_PARAM.equals(key)) { |
99 |
5 |
this.dateFormatString = value; |
100 |
|
} else { |
101 |
137 |
claimed = false; |
102 |
|
} |
103 |
|
|
104 |
144 |
return claimed; |
105 |
|
} |
106 |
|
|
|
|
| 83.3% |
Uncovered Elements: 1 (6) |
Complexity: 3 |
Complexity Density: 0.75 |
|
107 |
21 |
@Override... |
108 |
|
public void validateParameters() throws MacroExecutionException |
109 |
|
{ |
110 |
21 |
try { |
111 |
21 |
if (dateFormatString != null) { |
112 |
5 |
dateFormat = new SimpleDateFormat(dateFormatString, locale); |
113 |
|
} |
114 |
|
} catch (IllegalArgumentException e) { |
115 |
0 |
throw new MacroExecutionException(String.format("Invalid date format [%s].", dateFormatString)); |
116 |
|
} |
117 |
|
} |
118 |
|
|
119 |
|
|
120 |
|
@return |
121 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
122 |
58 |
public DateFormat getDateFormat()... |
123 |
|
{ |
124 |
58 |
return dateFormat; |
125 |
|
} |
126 |
|
|
127 |
|
|
128 |
|
@return |
129 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
130 |
122 |
public Locale getLocale()... |
131 |
|
{ |
132 |
122 |
return locale; |
133 |
|
} |
134 |
|
|
135 |
|
|
136 |
|
@return |
137 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
138 |
119 |
public TimeZone getTimeZone()... |
139 |
|
{ |
140 |
119 |
return timeZone; |
141 |
|
} |
142 |
|
} |