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.web; |
35 |
|
|
36 |
|
import info.magnolia.cms.core.AggregationState; |
37 |
|
import info.magnolia.cms.core.Content; |
38 |
|
import info.magnolia.cms.security.MgnlUser; |
39 |
|
import info.magnolia.cms.security.User; |
40 |
|
import info.magnolia.context.Context; |
41 |
|
import info.magnolia.context.MgnlContext; |
42 |
|
import info.magnolia.context.WebContext; |
43 |
|
import info.magnolia.module.blossom.template.BlossomAreaDefinition; |
44 |
|
import info.magnolia.module.blossom.template.BlossomTemplateDefinition; |
45 |
|
import info.magnolia.objectfactory.Components; |
46 |
|
import info.magnolia.rendering.context.RenderingContext; |
47 |
|
import info.magnolia.rendering.template.AreaDefinition; |
48 |
|
import info.magnolia.rendering.template.TemplateDefinition; |
49 |
|
|
50 |
|
import java.util.HashSet; |
51 |
|
import java.util.Set; |
52 |
|
|
53 |
|
import javax.jcr.Node; |
54 |
|
|
55 |
|
import org.springframework.core.MethodParameter; |
56 |
|
import org.springframework.web.bind.support.WebDataBinderFactory; |
57 |
|
import org.springframework.web.context.request.NativeWebRequest; |
58 |
|
import org.springframework.web.method.support.HandlerMethodArgumentResolver; |
59 |
|
import org.springframework.web.method.support.ModelAndViewContainer; |
60 |
|
|
61 |
|
|
62 |
|
@link@link |
63 |
|
@link@link@link |
64 |
|
|
65 |
|
@link |
66 |
|
|
67 |
|
@since |
68 |
|
|
|
|
| 88% |
Uncovered Elements: 11 (92) |
Complexity: 22 |
Complexity Density: 0.42 |
|
69 |
|
public class BlossomHandlerMethodArgumentResolver implements HandlerMethodArgumentResolver { |
70 |
|
|
71 |
|
private Set<Class<?>> supportedParameterTypes = new HashSet<Class<?>>(); |
72 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
|
73 |
7 |
public BlossomHandlerMethodArgumentResolver() {... |
74 |
7 |
supportedParameterTypes.add(Node.class); |
75 |
7 |
supportedParameterTypes.add(Content.class); |
76 |
7 |
supportedParameterTypes.add(TemplateDefinition.class); |
77 |
7 |
supportedParameterTypes.add(BlossomTemplateDefinition.class); |
78 |
7 |
supportedParameterTypes.add(AreaDefinition.class); |
79 |
7 |
supportedParameterTypes.add(BlossomAreaDefinition.class); |
80 |
7 |
supportedParameterTypes.add(AggregationState.class); |
81 |
7 |
supportedParameterTypes.add(WebContext.class); |
82 |
7 |
supportedParameterTypes.add(Context.class); |
83 |
7 |
supportedParameterTypes.add(User.class); |
84 |
7 |
supportedParameterTypes.add(MgnlUser.class); |
85 |
|
} |
86 |
|
|
|
|
| 83.3% |
Uncovered Elements: 1 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
87 |
13 |
@Override... |
88 |
|
public boolean supportsParameter(MethodParameter parameter) { |
89 |
13 |
for (Class<?> supportedParameterType : supportedParameterTypes) { |
90 |
68 |
if (parameter.getParameterType().isAssignableFrom(supportedParameterType)) { |
91 |
13 |
return true; |
92 |
|
} |
93 |
|
} |
94 |
0 |
return false; |
95 |
|
} |
96 |
|
|
|
|
| 85.2% |
Uncovered Elements: 9 (61) |
Complexity: 16 |
Complexity Density: 0.52 |
|
97 |
13 |
@Override... |
98 |
|
public Object resolveArgument(MethodParameter methodParameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception { |
99 |
|
|
100 |
13 |
if (methodParameter.getParameterType().isAssignableFrom(Node.class)) { |
101 |
2 |
RenderingContext renderingContext = Components.getComponent(RenderingContext.class); |
102 |
2 |
if (hasSubsequentParametersOfType(methodParameter, Node.class)) { |
103 |
1 |
return renderingContext.getMainContent(); |
104 |
|
} |
105 |
1 |
Node currentContent = renderingContext.getCurrentContent(); |
106 |
1 |
return currentContent != null ? currentContent : renderingContext.getMainContent(); |
107 |
|
} |
108 |
11 |
if (methodParameter.getParameterType().isAssignableFrom(Content.class)) { |
109 |
4 |
AggregationState aggregationState = MgnlContext.getAggregationState(); |
110 |
4 |
if (hasSubsequentParametersOfType(methodParameter, Content.class)) { |
111 |
1 |
return aggregationState.getMainContent(); |
112 |
|
} |
113 |
3 |
Content currentContent = aggregationState.getCurrentContent(); |
114 |
3 |
return currentContent != null ? currentContent : aggregationState.getMainContent(); |
115 |
|
} |
116 |
7 |
if (methodParameter.getParameterType().isAssignableFrom(TemplateDefinition.class)) { |
117 |
1 |
return Components.getComponent(RenderingContext.class).getRenderableDefinition(); |
118 |
|
} |
119 |
6 |
if (methodParameter.getParameterType().isAssignableFrom(BlossomTemplateDefinition.class)) { |
120 |
1 |
return Components.getComponent(RenderingContext.class).getRenderableDefinition(); |
121 |
|
} |
122 |
5 |
if (methodParameter.getParameterType().isAssignableFrom(AreaDefinition.class)) { |
123 |
0 |
return Components.getComponent(RenderingContext.class).getRenderableDefinition(); |
124 |
|
} |
125 |
5 |
if (methodParameter.getParameterType().isAssignableFrom(BlossomAreaDefinition.class)) { |
126 |
0 |
return Components.getComponent(RenderingContext.class).getRenderableDefinition(); |
127 |
|
} |
128 |
5 |
if (methodParameter.getParameterType().isAssignableFrom(AggregationState.class)) { |
129 |
1 |
return MgnlContext.getAggregationState(); |
130 |
|
} |
131 |
4 |
if (methodParameter.getParameterType().isAssignableFrom(WebContext.class)) { |
132 |
2 |
return MgnlContext.getWebContext(); |
133 |
|
} |
134 |
2 |
if (methodParameter.getParameterType().isAssignableFrom(Context.class)) { |
135 |
0 |
return MgnlContext.getInstance(); |
136 |
|
} |
137 |
2 |
if (methodParameter.getParameterType().isAssignableFrom(User.class)) { |
138 |
1 |
return MgnlContext.getUser(); |
139 |
|
} |
140 |
1 |
if (methodParameter.getParameterType().isAssignableFrom(MgnlUser.class)) { |
141 |
1 |
return MgnlContext.getUser(); |
142 |
|
} |
143 |
|
|
144 |
0 |
return null; |
145 |
|
} |
146 |
|
|
|
|
| 90% |
Uncovered Elements: 1 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
147 |
6 |
private boolean hasSubsequentParametersOfType(MethodParameter methodParameter, Class<?> clazz) {... |
148 |
6 |
Class<?>[] parameterTypes = methodParameter.getMethod().getParameterTypes(); |
149 |
6 |
for (int i = methodParameter.getParameterIndex() + 1; i < parameterTypes.length; i++) { |
150 |
2 |
Class<?> parameterType = parameterTypes[i]; |
151 |
2 |
if (parameterType.equals(clazz)) { |
152 |
2 |
return true; |
153 |
|
} |
154 |
|
} |
155 |
4 |
return false; |
156 |
|
} |
157 |
|
} |