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.render; |
35 |
|
|
36 |
|
import java.io.IOException; |
37 |
|
import java.util.Locale; |
38 |
|
|
39 |
|
import javax.servlet.ServletException; |
40 |
|
import javax.servlet.http.HttpServletRequest; |
41 |
|
import javax.servlet.http.HttpServletResponse; |
42 |
|
|
43 |
|
import org.springframework.beans.BeansException; |
44 |
|
import org.springframework.beans.factory.config.BeanFactoryPostProcessor; |
45 |
|
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; |
46 |
|
import org.springframework.beans.factory.support.BeanDefinitionRegistry; |
47 |
|
import org.springframework.context.ApplicationContext; |
48 |
|
import org.springframework.util.Assert; |
49 |
|
import org.springframework.web.context.ConfigurableWebApplicationContext; |
50 |
|
import org.springframework.web.context.WebApplicationContext; |
51 |
|
import org.springframework.web.servlet.DispatcherServlet; |
52 |
|
import org.springframework.web.servlet.HandlerAdapter; |
53 |
|
import org.springframework.web.servlet.HandlerExecutionChain; |
54 |
|
import org.springframework.web.servlet.HandlerInterceptor; |
55 |
|
import org.springframework.web.servlet.LocaleResolver; |
56 |
|
import org.springframework.web.servlet.ModelAndView; |
57 |
|
import org.springframework.web.servlet.View; |
58 |
|
|
59 |
|
import info.magnolia.context.MgnlContext; |
60 |
|
import info.magnolia.module.blossom.context.MagnoliaLocaleResolver; |
61 |
|
import info.magnolia.module.blossom.dialog.DialogExporter; |
62 |
|
import info.magnolia.module.blossom.dispatcher.BlossomDispatcher; |
63 |
|
import info.magnolia.module.blossom.dispatcher.BlossomDispatcherAwareBeanPostProcessor; |
64 |
|
import info.magnolia.module.blossom.dispatcher.BlossomDispatcherInitializedEvent; |
65 |
|
import info.magnolia.module.blossom.support.BeanFactoryUtils; |
66 |
|
import info.magnolia.module.blossom.support.ForwardRequestWrapper; |
67 |
|
import info.magnolia.module.blossom.support.IncludeRequestWrapper; |
68 |
|
import info.magnolia.module.blossom.template.TemplateExporter; |
69 |
|
import info.magnolia.module.blossom.urimapping.AnnotatedVirtualURIMappingExporter; |
70 |
|
import info.magnolia.module.blossom.urimapping.VirtualURIMappingExporter; |
71 |
|
|
72 |
|
|
73 |
|
|
74 |
|
|
75 |
|
|
76 |
|
@since |
77 |
|
|
|
|
| 23.9% |
Uncovered Elements: 67 (88) |
Complexity: 22 |
Complexity Density: 0.39 |
|
78 |
|
public class BlossomDispatcherServlet extends DispatcherServlet implements BlossomDispatcher, BeanFactoryPostProcessor { |
79 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
80 |
3 |
public BlossomDispatcherServlet() {... |
81 |
3 |
super(); |
82 |
|
} |
83 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
84 |
0 |
public BlossomDispatcherServlet(WebApplicationContext webApplicationContext) {... |
85 |
0 |
super(webApplicationContext); |
86 |
|
} |
87 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
88 |
12 |
@Override... |
89 |
|
protected Object getDefaultStrategy(ApplicationContext context, Class strategyInterface) throws BeansException { |
90 |
12 |
if (strategyInterface.equals(LocaleResolver.class)) { |
91 |
3 |
return super.createDefaultStrategy(context, MagnoliaLocaleResolver.class); |
92 |
|
} |
93 |
9 |
return super.getDefaultStrategy(context, strategyInterface); |
94 |
|
} |
95 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
96 |
3 |
@Override... |
97 |
|
protected void postProcessWebApplicationContext(ConfigurableWebApplicationContext wac) { |
98 |
3 |
wac.addBeanFactoryPostProcessor(this); |
99 |
|
} |
100 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
|
101 |
3 |
@Override... |
102 |
|
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { |
103 |
|
|
104 |
3 |
Assert.isInstanceOf(BeanDefinitionRegistry.class, beanFactory); |
105 |
|
|
106 |
3 |
BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory; |
107 |
|
|
108 |
3 |
beanFactory.addBeanPostProcessor(new BlossomDispatcherAwareBeanPostProcessor(this)); |
109 |
|
|
110 |
3 |
BeanFactoryUtils.registerBeanIfMissing(beanFactory, registry, TemplateExporter.class); |
111 |
3 |
BeanFactoryUtils.registerBeanIfMissing(beanFactory, registry, DialogExporter.class); |
112 |
3 |
BeanFactoryUtils.registerBeanIfMissing(beanFactory, registry, AnnotatedVirtualURIMappingExporter.class); |
113 |
3 |
BeanFactoryUtils.registerBeanIfMissing(beanFactory, registry, VirtualURIMappingExporter.class); |
114 |
|
} |
115 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
116 |
3 |
@Override... |
117 |
|
protected void onRefresh(ApplicationContext context) { |
118 |
3 |
super.onRefresh(context); |
119 |
3 |
context.publishEvent(new BlossomDispatcherInitializedEvent(this)); |
120 |
|
} |
121 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
|
122 |
0 |
@Override... |
123 |
|
public void forward(String path, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { |
124 |
|
|
125 |
0 |
String contextPath = request.getContextPath(); |
126 |
|
|
127 |
0 |
ForwardRequestWrapper forwardRequestWrapper = new ForwardRequestWrapper(request, contextPath + path, contextPath, path, null); |
128 |
|
|
129 |
0 |
MgnlContext.push(forwardRequestWrapper, response); |
130 |
0 |
try { |
131 |
0 |
super.service(forwardRequestWrapper, response); |
132 |
|
} finally { |
133 |
0 |
forwardRequestWrapper.restore(); |
134 |
0 |
MgnlContext.pop(); |
135 |
|
} |
136 |
|
} |
137 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
|
138 |
0 |
@Override... |
139 |
|
public void include(String path, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { |
140 |
|
|
141 |
0 |
String contextPath = request.getContextPath(); |
142 |
|
|
143 |
0 |
IncludeRequestWrapper includeRequestWrapper = new IncludeRequestWrapper(request, contextPath + path, contextPath, path, null, request.getQueryString()); |
144 |
|
|
145 |
0 |
MgnlContext.push(includeRequestWrapper, response); |
146 |
0 |
try { |
147 |
0 |
super.service(includeRequestWrapper, response); |
148 |
|
} finally { |
149 |
0 |
includeRequestWrapper.restore(); |
150 |
0 |
MgnlContext.pop(); |
151 |
|
} |
152 |
|
} |
153 |
|
|
|
|
| 0% |
Uncovered Elements: 48 (48) |
Complexity: 13 |
Complexity Density: 0.46 |
|
154 |
0 |
@Override... |
155 |
|
public ModelAndView executeChain(HandlerExecutionChain mappedHandler, HttpServletRequest request, HttpServletResponse response) throws Exception { |
156 |
|
|
157 |
|
|
158 |
|
|
159 |
|
|
160 |
0 |
HandlerInterceptor[] interceptors = mappedHandler.getInterceptors(); |
161 |
0 |
if (interceptors != null) { |
162 |
0 |
for (int i = 0; i < interceptors.length; i++) { |
163 |
0 |
HandlerInterceptor interceptor = interceptors[i]; |
164 |
0 |
if (!interceptor.preHandle(request, response, mappedHandler.getHandler())) { |
165 |
0 |
return null; |
166 |
|
} |
167 |
|
} |
168 |
|
} |
169 |
|
|
170 |
|
|
171 |
0 |
HandlerAdapter ha = getHandlerAdapter(mappedHandler.getHandler()); |
172 |
0 |
ModelAndView mv = ha.handle(request, response, mappedHandler.getHandler()); |
173 |
|
|
174 |
|
|
175 |
0 |
if (mv != null && !mv.hasView()) { |
176 |
0 |
mv.setViewName(getDefaultViewName(request)); |
177 |
|
} |
178 |
|
|
179 |
|
|
180 |
0 |
if (interceptors != null) { |
181 |
0 |
for (int i = interceptors.length - 1; i >= 0; i--) { |
182 |
0 |
HandlerInterceptor interceptor = interceptors[i]; |
183 |
0 |
interceptor.postHandle(request, response, mappedHandler.getHandler(), mv); |
184 |
|
} |
185 |
|
} |
186 |
|
|
187 |
0 |
if (mv != null && !mv.wasCleared()) { |
188 |
|
|
189 |
|
|
190 |
|
|
191 |
0 |
LocaleResolver localeResolver = (LocaleResolver) request.getAttribute(LOCALE_RESOLVER_ATTRIBUTE); |
192 |
|
|
193 |
|
|
194 |
0 |
Locale locale = localeResolver.resolveLocale(request); |
195 |
0 |
response.setLocale(locale); |
196 |
|
|
197 |
0 |
View view; |
198 |
0 |
if (mv.isReference()) { |
199 |
|
|
200 |
0 |
view = resolveViewName(mv.getViewName(), mv.getModel(), locale, request); |
201 |
0 |
if (view == null) { |
202 |
0 |
throw new ServletException( |
203 |
|
"Could not resolve view with name '" + mv.getViewName() + "' in servlet with name '" + |
204 |
|
getServletName() + "'"); |
205 |
|
} |
206 |
|
} |
207 |
|
else { |
208 |
|
|
209 |
0 |
view = mv.getView(); |
210 |
0 |
if (view == null) { |
211 |
0 |
throw new ServletException("ModelAndView [" + mv + "] neither contains a view name nor a " + |
212 |
|
"View object in servlet with name '" + getServletName() + "'"); |
213 |
|
} |
214 |
|
} |
215 |
|
|
216 |
0 |
mv.setView(view); |
217 |
|
} |
218 |
|
|
219 |
0 |
return mv; |
220 |
|
} |
221 |
|
} |