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.preexecution; |
35 |
|
|
36 |
|
import java.io.IOException; |
37 |
|
import javax.jcr.Node; |
38 |
|
import javax.jcr.RepositoryException; |
39 |
|
import javax.jcr.Session; |
40 |
|
import javax.servlet.FilterChain; |
41 |
|
import javax.servlet.FilterConfig; |
42 |
|
import javax.servlet.ServletException; |
43 |
|
import javax.servlet.http.HttpServletRequest; |
44 |
|
import javax.servlet.http.HttpServletResponse; |
45 |
|
|
46 |
|
import org.slf4j.Logger; |
47 |
|
import org.slf4j.LoggerFactory; |
48 |
|
import org.springframework.core.NestedIOException; |
49 |
|
import org.springframework.web.servlet.ModelAndView; |
50 |
|
|
51 |
|
import info.magnolia.cms.core.AggregationState; |
52 |
|
import info.magnolia.cms.filters.OncePerRequestAbstractMgnlFilter; |
53 |
|
import info.magnolia.context.MgnlContext; |
54 |
|
import info.magnolia.jcr.util.NodeTypes; |
55 |
|
import info.magnolia.objectfactory.Components; |
56 |
|
import info.magnolia.rendering.engine.RenderingEngine; |
57 |
|
import info.magnolia.rendering.engine.ResponseOutputProvider; |
58 |
|
import info.magnolia.repository.RepositoryConstants; |
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
@since |
65 |
|
|
|
|
| 0% |
Uncovered Elements: 66 (66) |
Complexity: 18 |
Complexity Density: 0.41 |
|
66 |
|
public class BlossomFilter extends OncePerRequestAbstractMgnlFilter { |
67 |
|
|
68 |
|
public static final String PREEXECUTION_CONTEXT_PARAMETER_NAME = "_pecid"; |
69 |
|
|
70 |
|
private final Logger logger = LoggerFactory.getLogger(getClass()); |
71 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
72 |
0 |
@Override... |
73 |
|
public void init(FilterConfig filterConfig) throws ServletException { |
74 |
|
} |
75 |
|
|
|
|
| 0% |
Uncovered Elements: 24 (24) |
Complexity: 6 |
Complexity Density: 0.3 |
|
76 |
0 |
@Override... |
77 |
|
public void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException { |
78 |
|
|
79 |
0 |
String preexecutionUuid = request.getParameter(PREEXECUTION_CONTEXT_PARAMETER_NAME); |
80 |
0 |
if (preexecutionUuid == null) { |
81 |
|
|
82 |
0 |
chain.doFilter(request, response); |
83 |
0 |
return; |
84 |
|
} |
85 |
|
|
86 |
|
|
87 |
0 |
Node content; |
88 |
0 |
try { |
89 |
0 |
Session session = MgnlContext.getSystemContext().getJCRSession(RepositoryConstants.WEBSITE); |
90 |
0 |
content = session.getNodeByIdentifier(preexecutionUuid); |
91 |
|
} catch (RepositoryException e) { |
92 |
0 |
logger.error("Content for pre-execution [" + preexecutionUuid + "] not found in repository"); |
93 |
0 |
return; |
94 |
|
} |
95 |
|
|
96 |
|
|
97 |
0 |
PreexecutionContext preexecutionContext = new PreexecutionContext(preexecutionUuid); |
98 |
0 |
PreexecutionContextHolder.put(request, preexecutionContext); |
99 |
0 |
try { |
100 |
|
|
101 |
0 |
executeHandler(content, response); |
102 |
|
|
103 |
|
|
104 |
0 |
ModelAndView mv = preexecutionContext.getModelAndView(); |
105 |
0 |
if (mv == null || mv.wasCleared()) { |
106 |
0 |
return; |
107 |
|
} |
108 |
|
|
109 |
|
|
110 |
0 |
chain.doFilter(request, response); |
111 |
|
|
112 |
|
} catch (RepositoryException e) { |
113 |
0 |
throw new ServletException(e); |
114 |
|
} finally { |
115 |
0 |
PreexecutionContextHolder.remove(request); |
116 |
|
} |
117 |
|
} |
118 |
|
|
|
|
| 0% |
Uncovered Elements: 22 (22) |
Complexity: 5 |
Complexity Density: 0.31 |
|
119 |
0 |
private void executeHandler(Node content, HttpServletResponse response) throws IOException, RepositoryException {... |
120 |
|
|
121 |
0 |
AggregationState state = getAggregationStateSafely(); |
122 |
0 |
Node orgMainContent = null; |
123 |
0 |
Node orgCurrentContent = null; |
124 |
|
|
125 |
0 |
if (state != null) { |
126 |
0 |
orgMainContent = state.getMainContentNode(); |
127 |
0 |
orgCurrentContent = state.getCurrentContentNode(); |
128 |
|
|
129 |
0 |
state.setCurrentContentNode(content); |
130 |
0 |
if (orgMainContent == null) { |
131 |
0 |
state.setMainContentNode(findMainContent(content)); |
132 |
|
} |
133 |
|
} |
134 |
0 |
try { |
135 |
|
|
136 |
0 |
try { |
137 |
0 |
Components.getComponent(RenderingEngine.class).render(content, new ResponseOutputProvider(response)); |
138 |
|
} catch (info.magnolia.rendering.engine.RenderException e) { |
139 |
0 |
throw new NestedIOException("Error pre-executing handler", e); |
140 |
|
} |
141 |
|
|
142 |
|
} finally { |
143 |
0 |
if (state != null) { |
144 |
0 |
state.setMainContentNode(orgMainContent); |
145 |
0 |
state.setCurrentContentNode(orgCurrentContent); |
146 |
|
} |
147 |
|
} |
148 |
|
} |
149 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 3 |
Complexity Density: 0.6 |
|
150 |
0 |
protected Node findMainContent(Node content) throws RepositoryException {... |
151 |
0 |
while (content.getDepth() != 0) { |
152 |
0 |
if (content.getPrimaryNodeType().getName().equals(NodeTypes.Content.NAME)) { |
153 |
0 |
return content; |
154 |
|
} |
155 |
0 |
content = content.getParent(); |
156 |
|
} |
157 |
0 |
return null; |
158 |
|
} |
159 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
160 |
0 |
protected AggregationState getAggregationStateSafely() {... |
161 |
0 |
if (MgnlContext.isWebContext()) { |
162 |
0 |
return MgnlContext.getAggregationState(); |
163 |
|
} |
164 |
0 |
return null; |
165 |
|
} |
166 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
167 |
0 |
@Override... |
168 |
|
public void destroy() { |
169 |
|
} |
170 |
|
} |