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.urimapping; |
35 |
|
|
36 |
|
import java.lang.reflect.Method; |
37 |
|
import javax.servlet.http.HttpServletRequest; |
38 |
|
|
39 |
|
import info.magnolia.cms.beans.config.VirtualURIMapping; |
40 |
|
import info.magnolia.context.MgnlContext; |
41 |
|
import info.magnolia.module.blossom.support.MethodInvocationUtils; |
42 |
|
import info.magnolia.module.blossom.support.ParameterResolver; |
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
@since |
49 |
|
|
|
|
| 88.2% |
Uncovered Elements: 4 (34) |
Complexity: 9 |
Complexity Density: 0.45 |
|
50 |
|
public class VirtualURIMappingAdapter implements VirtualURIMapping { |
51 |
|
|
52 |
|
private Object targetObject; |
53 |
|
private Method targetMethod; |
54 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
55 |
4 |
public VirtualURIMappingAdapter(Object targetObject, Method targetMethod) {... |
56 |
4 |
this.targetObject = targetObject; |
57 |
4 |
this.targetMethod = targetMethod; |
58 |
|
} |
59 |
|
|
|
|
| 88.9% |
Uncovered Elements: 2 (18) |
Complexity: 4 |
Complexity Density: 0.33 |
|
60 |
22 |
@Override... |
61 |
|
public MappingResult mapURI(String uri) { |
62 |
|
|
63 |
22 |
Object result = MethodInvocationUtils.invoke(targetMethod, targetObject, getVirtualURIMappingParameters(uri)); |
64 |
|
|
65 |
22 |
if (result == null) { |
66 |
18 |
return null; |
67 |
|
} |
68 |
|
|
69 |
4 |
if (result instanceof VirtualURIMapping.MappingResult) { |
70 |
2 |
return (VirtualURIMapping.MappingResult) result; |
71 |
|
} |
72 |
|
|
73 |
2 |
if (result instanceof String) { |
74 |
2 |
String resultString = (String) result; |
75 |
2 |
VirtualURIMapping.MappingResult mappingResult = new VirtualURIMapping.MappingResult(); |
76 |
2 |
mappingResult.setLevel(resultString.length()); |
77 |
2 |
mappingResult.setToURI(resultString); |
78 |
2 |
return mappingResult; |
79 |
|
} |
80 |
|
|
81 |
0 |
throw new IllegalArgumentException("VirtualURIMapping must return either String or MappingResult"); |
82 |
|
} |
83 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
84 |
22 |
private ParameterResolver getVirtualURIMappingParameters(final String uri) {... |
85 |
22 |
return new ParameterResolver() { |
86 |
|
|
|
|
| 77.8% |
Uncovered Elements: 2 (9) |
Complexity: 3 |
Complexity Density: 0.6 |
|
87 |
33 |
@Override... |
88 |
|
public Object resolveParameter(Class<?> parameterType) { |
89 |
33 |
if (parameterType.equals(String.class)) { |
90 |
22 |
return uri; |
91 |
|
} |
92 |
11 |
if (parameterType.equals(HttpServletRequest.class)) { |
93 |
11 |
return MgnlContext.getWebContext().getRequest(); |
94 |
|
} |
95 |
0 |
return super.resolveParameter(parameterType); |
96 |
|
} |
97 |
|
}; |
98 |
|
} |
99 |
|
} |