1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package com.xpn.xwiki.plugin.charts.params; |
21 |
|
|
22 |
|
import java.text.DateFormat; |
23 |
|
import java.text.SimpleDateFormat; |
24 |
|
import java.util.HashMap; |
25 |
|
import java.util.Locale; |
26 |
|
import java.util.Map; |
27 |
|
|
28 |
|
import com.xpn.xwiki.plugin.charts.exceptions.InvalidArgumentException; |
29 |
|
import com.xpn.xwiki.plugin.charts.exceptions.MissingArgumentException; |
30 |
|
import com.xpn.xwiki.plugin.charts.exceptions.ParamException; |
31 |
|
|
|
|
| 0% |
Uncovered Elements: 74 (74) |
Complexity: 20 |
Complexity Density: 0.43 |
|
32 |
|
public class DateFormatChartParam extends LocaleChartParam |
33 |
|
{ |
34 |
|
public static final String TYPE = "type"; |
35 |
|
|
36 |
|
public static final String DATE = "date"; |
37 |
|
|
38 |
|
public static final String TIME = "time"; |
39 |
|
|
40 |
|
public static final String DATETIME = "datetime"; |
41 |
|
|
42 |
|
public static final String CUSTOM = "custom"; |
43 |
|
|
44 |
|
public static final String DATE_STYLE = "date_style"; |
45 |
|
|
46 |
|
public static final String TIME_STYLE = "time_style"; |
47 |
|
|
48 |
|
public static final String SHORT = "short"; |
49 |
|
|
50 |
|
public static final String MEDIUM = "medium"; |
51 |
|
|
52 |
|
public static final String LONG = "long"; |
53 |
|
|
54 |
|
public static final String FULL = "full"; |
55 |
|
|
56 |
|
public static final String PATTERN = "pattern"; |
57 |
|
|
58 |
|
private Map styleChoices; |
59 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
60 |
0 |
public DateFormatChartParam(String name)... |
61 |
|
{ |
62 |
0 |
super(name); |
63 |
0 |
init(); |
64 |
|
} |
65 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
66 |
0 |
public DateFormatChartParam(String name, boolean optional)... |
67 |
|
{ |
68 |
0 |
super(name, optional); |
69 |
0 |
init(); |
70 |
|
} |
71 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
72 |
0 |
public void init()... |
73 |
|
{ |
74 |
0 |
styleChoices = new HashMap(4); |
75 |
0 |
styleChoices.put(SHORT, DateFormat.SHORT); |
76 |
0 |
styleChoices.put(MEDIUM, DateFormat.MEDIUM); |
77 |
0 |
styleChoices.put(LONG, DateFormat.LONG); |
78 |
0 |
styleChoices.put(FULL, DateFormat.FULL); |
79 |
|
} |
80 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
81 |
0 |
@Override... |
82 |
|
public Class getType() |
83 |
|
{ |
84 |
0 |
return DateFormat.class; |
85 |
|
} |
86 |
|
|
|
|
| 0% |
Uncovered Elements: 59 (59) |
Complexity: 16 |
Complexity Density: 0.43 |
|
87 |
0 |
@Override... |
88 |
|
public Object convert(String value) throws ParamException |
89 |
|
{ |
90 |
0 |
Map map = parseMap(value); |
91 |
|
|
92 |
0 |
Integer dateStyle, timeStyle; |
93 |
0 |
try { |
94 |
0 |
dateStyle = (Integer) getChoiceArg(map, DATE_STYLE, styleChoices); |
95 |
|
} catch (MissingArgumentException e) { |
96 |
0 |
dateStyle = null; |
97 |
|
} |
98 |
0 |
try { |
99 |
0 |
timeStyle = (Integer) getChoiceArg(map, TIME_STYLE, styleChoices); |
100 |
|
} catch (MissingArgumentException e) { |
101 |
0 |
timeStyle = null; |
102 |
|
} |
103 |
|
|
104 |
0 |
Locale locale; |
105 |
0 |
try { |
106 |
0 |
locale = (Locale) super.convert(value); |
107 |
|
} catch (MissingArgumentException e) { |
108 |
0 |
locale = null; |
109 |
|
} |
110 |
|
|
111 |
0 |
String type = getStringArg(map, TYPE); |
112 |
|
|
113 |
0 |
if (type.equals(DATE)) { |
114 |
0 |
if (dateStyle != null) { |
115 |
0 |
if (locale != null) { |
116 |
0 |
return DateFormat.getDateInstance(dateStyle.intValue(), locale); |
117 |
|
} else { |
118 |
0 |
return DateFormat.getDateInstance(dateStyle.intValue()); |
119 |
|
} |
120 |
|
} else { |
121 |
0 |
return DateFormat.getDateInstance(); |
122 |
|
} |
123 |
0 |
} else if (type.equals(TIME)) { |
124 |
0 |
if (timeStyle != null) { |
125 |
0 |
if (locale != null) { |
126 |
0 |
return DateFormat.getTimeInstance(timeStyle.intValue(), locale); |
127 |
|
} else { |
128 |
0 |
return DateFormat.getTimeInstance(timeStyle.intValue()); |
129 |
|
} |
130 |
|
} else { |
131 |
0 |
return DateFormat.getDateInstance(); |
132 |
|
} |
133 |
0 |
} else if (type.equals(DATETIME)) { |
134 |
0 |
if (dateStyle != null && timeStyle != null) { |
135 |
0 |
if (locale != null) { |
136 |
0 |
return DateFormat.getDateTimeInstance(dateStyle.intValue(), timeStyle.intValue(), locale); |
137 |
|
} else { |
138 |
0 |
return DateFormat.getDateTimeInstance(dateStyle.intValue(), timeStyle.intValue()); |
139 |
|
} |
140 |
|
} else { |
141 |
0 |
return DateFormat.getDateTimeInstance(); |
142 |
|
} |
143 |
0 |
} else if (type.equals(CUSTOM)) { |
144 |
0 |
String pattern = getStringArg(map, PATTERN); |
145 |
0 |
if (locale != null) { |
146 |
0 |
return new SimpleDateFormat(pattern, locale); |
147 |
|
} else { |
148 |
0 |
return new SimpleDateFormat(pattern); |
149 |
|
} |
150 |
|
} else { |
151 |
0 |
throw new InvalidArgumentException("Invalid value for parameter " + getName() |
152 |
|
+ ": Unexpected value for type argument: " + type); |
153 |
|
} |
154 |
|
} |
155 |
|
} |