1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
package info.magnolia.module.blossom.multipart; |
35 |
|
|
36 |
|
import java.lang.reflect.InvocationTargetException; |
37 |
|
import java.lang.reflect.Method; |
38 |
|
import java.util.Map; |
39 |
|
import javax.servlet.http.HttpServletRequest; |
40 |
|
|
41 |
|
import org.springframework.util.Assert; |
42 |
|
import org.springframework.web.multipart.MultipartFile; |
43 |
|
import org.springframework.web.multipart.support.AbstractMultipartHttpServletRequest; |
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
@see |
52 |
|
@see |
53 |
|
@since |
54 |
|
|
|
|
| 89.3% |
Uncovered Elements: 3 (28) |
Complexity: 11 |
Complexity Density: 0.61 |
|
55 |
|
public abstract class CompatibleAbstractMultipartHttpServletRequest extends AbstractMultipartHttpServletRequest { |
56 |
|
|
57 |
|
private static Method setter; |
58 |
|
private static Class<?> multiValueType; |
59 |
|
private static Method populateMethod; |
60 |
|
|
|
|
| 87.5% |
Uncovered Elements: 1 (8) |
Complexity: 4 |
Complexity Density: 0.67 |
|
61 |
1 |
static {... |
62 |
1 |
setter = getDeclaredMethodIfAvailable(AbstractMultipartHttpServletRequest.class, "setMultipartFiles", Map.class); |
63 |
1 |
if (setter == null) { |
64 |
1 |
try { |
65 |
1 |
multiValueType = Class.forName("org.springframework.util.LinkedMultiValueMap"); |
66 |
1 |
populateMethod = getDeclaredMethod(multiValueType, "setAll", Map.class); |
67 |
1 |
setter = getDeclaredMethod(AbstractMultipartHttpServletRequest.class, "setMultipartFiles", Class.forName("org.springframework.util.MultiValueMap")); |
68 |
|
} catch (ClassNotFoundException e) { |
69 |
|
|
70 |
|
} catch (NoSuchMethodException e) { |
71 |
|
|
72 |
|
} |
73 |
|
} |
74 |
|
} |
75 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
76 |
1 |
protected CompatibleAbstractMultipartHttpServletRequest(HttpServletRequest request) {... |
77 |
1 |
super(request); |
78 |
|
} |
79 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
80 |
1 |
protected void setSingleValueMultipartFiles(Map<String, MultipartFile> multipartFiles) throws InvocationTargetException, InstantiationException, IllegalAccessException {... |
81 |
1 |
Assert.notNull(setter, "No usable method found for setting multipartFiles in AbstractMultipartHttpServletRequest"); |
82 |
1 |
setter.invoke(this, convertMapIfNecessary(multipartFiles)); |
83 |
|
} |
84 |
|
|
|
|
| 71.4% |
Uncovered Elements: 2 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
85 |
1 |
private Object convertMapIfNecessary(Map<String, MultipartFile> multipartFiles) throws IllegalAccessException, InstantiationException, InvocationTargetException {... |
86 |
|
|
87 |
|
|
88 |
1 |
if (multiValueType == null) { |
89 |
0 |
return multipartFiles; |
90 |
|
} |
91 |
|
|
92 |
|
|
93 |
1 |
Object multiValueMap = multiValueType.newInstance(); |
94 |
1 |
populateMethod.invoke(multiValueMap, multipartFiles); |
95 |
1 |
return multiValueMap; |
96 |
|
} |
97 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
98 |
1 |
private static Method getDeclaredMethodIfAvailable(Class<?> clazz, String name, Class... parameterTypes) {... |
99 |
1 |
try { |
100 |
1 |
return getDeclaredMethod(clazz, name, parameterTypes); |
101 |
|
} catch (NoSuchMethodException e) { |
102 |
1 |
return null; |
103 |
|
} |
104 |
|
} |
105 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
106 |
3 |
private static Method getDeclaredMethod(Class<?> clazz, String name, Class... parameterTypes) throws NoSuchMethodException {... |
107 |
3 |
return clazz.getDeclaredMethod(name, parameterTypes); |
108 |
|
} |
109 |
|
} |