1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.panels.internal; |
21 |
|
|
22 |
|
import java.lang.reflect.Type; |
23 |
|
import java.util.Collections; |
24 |
|
import java.util.Map; |
25 |
|
|
26 |
|
import org.slf4j.Logger; |
27 |
|
import org.slf4j.LoggerFactory; |
28 |
|
import org.xwiki.component.manager.ComponentLookupException; |
29 |
|
import org.xwiki.component.manager.ComponentManager; |
30 |
|
import org.xwiki.component.wiki.WikiComponent; |
31 |
|
import org.xwiki.component.wiki.WikiComponentScope; |
32 |
|
import org.xwiki.job.event.status.JobProgressManager; |
33 |
|
import org.xwiki.model.reference.DocumentReference; |
34 |
|
import org.xwiki.model.reference.EntityReferenceSerializer; |
35 |
|
import org.xwiki.rendering.block.Block; |
36 |
|
import org.xwiki.rendering.block.CompositeBlock; |
37 |
|
import org.xwiki.rendering.block.XDOM; |
38 |
|
import org.xwiki.rendering.internal.transformation.MutableRenderingContext; |
39 |
|
import org.xwiki.rendering.syntax.Syntax; |
40 |
|
import org.xwiki.rendering.transformation.RenderingContext; |
41 |
|
import org.xwiki.rendering.transformation.Transformation; |
42 |
|
import org.xwiki.rendering.transformation.TransformationContext; |
43 |
|
import org.xwiki.security.authorization.AuthorExecutor; |
44 |
|
import org.xwiki.uiextension.UIExtension; |
45 |
|
|
46 |
|
|
47 |
|
@link |
48 |
|
|
49 |
|
@version |
50 |
|
@since |
51 |
|
|
|
|
| 92.1% |
Uncovered Elements: 3 (38) |
Complexity: 11 |
Complexity Density: 0.39 |
|
52 |
|
public class PanelWikiUIExtension implements UIExtension, WikiComponent |
53 |
|
{ |
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
private static final Logger LOGGER = LoggerFactory.getLogger(PanelWikiUIExtension.class); |
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
private final EntityReferenceSerializer<String> serializer; |
63 |
|
|
64 |
|
|
65 |
|
@see |
66 |
|
|
67 |
|
|
68 |
|
|
69 |
|
private final DocumentReference documentReference; |
70 |
|
|
71 |
|
|
72 |
|
@see |
73 |
|
|
74 |
|
|
75 |
|
|
76 |
|
private final DocumentReference authorReference; |
77 |
|
|
78 |
|
|
79 |
|
@see |
80 |
|
|
81 |
|
|
82 |
|
|
83 |
|
private final XDOM xdom; |
84 |
|
|
85 |
|
|
86 |
|
@see |
87 |
|
|
88 |
|
|
89 |
|
|
90 |
|
private final Syntax syntax; |
91 |
|
|
92 |
|
|
93 |
|
|
94 |
|
|
95 |
|
private final RenderingContext renderingContext; |
96 |
|
|
97 |
|
|
98 |
|
|
99 |
|
|
100 |
|
private final Transformation macroTransformation; |
101 |
|
|
102 |
|
private final AuthorExecutor authorExecutor; |
103 |
|
|
104 |
|
private final JobProgressManager progress; |
105 |
|
|
106 |
|
|
107 |
|
|
108 |
|
|
109 |
|
@param |
110 |
|
@param |
111 |
|
@param |
112 |
|
@param |
113 |
|
@param |
114 |
|
@throws |
115 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
|
116 |
183 |
public PanelWikiUIExtension(DocumentReference documentReference, DocumentReference authorReference, XDOM xdom,... |
117 |
|
Syntax syntax, ComponentManager componentManager) throws ComponentLookupException |
118 |
|
{ |
119 |
183 |
this.documentReference = documentReference; |
120 |
183 |
this.authorReference = authorReference; |
121 |
183 |
this.xdom = xdom; |
122 |
183 |
this.syntax = syntax; |
123 |
183 |
this.macroTransformation = componentManager.getInstance(Transformation.class, "macro"); |
124 |
183 |
this.serializer = componentManager.getInstance(EntityReferenceSerializer.TYPE_STRING); |
125 |
183 |
this.renderingContext = componentManager.getInstance(RenderingContext.class); |
126 |
183 |
this.authorExecutor = componentManager.getInstance(AuthorExecutor.class); |
127 |
183 |
this.progress = componentManager.getInstance(JobProgressManager.class); |
128 |
|
} |
129 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
130 |
1901 |
@Override... |
131 |
|
public String getId() |
132 |
|
{ |
133 |
1901 |
return serializer.serialize(documentReference); |
134 |
|
} |
135 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
136 |
49540 |
@Override... |
137 |
|
public String getExtensionPointId() |
138 |
|
{ |
139 |
49540 |
return "platform.panels"; |
140 |
|
} |
141 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
142 |
616 |
@Override... |
143 |
|
public DocumentReference getDocumentReference() |
144 |
|
{ |
145 |
616 |
return documentReference; |
146 |
|
} |
147 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
148 |
206 |
@Override... |
149 |
|
public DocumentReference getAuthorReference() |
150 |
|
{ |
151 |
206 |
return authorReference; |
152 |
|
} |
153 |
|
|
|
|
| 90.9% |
Uncovered Elements: 1 (11) |
Complexity: 2 |
Complexity Density: 0.18 |
|
154 |
22 |
@Override... |
155 |
|
public Block execute() |
156 |
|
{ |
157 |
|
|
158 |
|
|
159 |
22 |
final XDOM transformedXDOM = xdom.clone(); |
160 |
|
|
161 |
22 |
this.progress.startStep(getDocumentReference(), "panel.progress.execute", "Execute panel [{}]", |
162 |
|
getDocumentReference()); |
163 |
|
|
164 |
|
|
165 |
22 |
try { |
166 |
22 |
this.authorExecutor.call(() -> { |
167 |
22 |
TransformationContext transformationContext = new TransformationContext(transformedXDOM, syntax); |
168 |
22 |
transformationContext.setId(getRoleHint()); |
169 |
22 |
((MutableRenderingContext) renderingContext).transformInContext(macroTransformation, |
170 |
|
transformationContext, transformedXDOM); |
171 |
|
|
172 |
22 |
return null; |
173 |
|
}, getAuthorReference()); |
174 |
|
} catch (Exception e) { |
175 |
0 |
LOGGER.error("Error while executing transformation for panel [{}]", this.documentReference.toString()); |
176 |
|
} finally { |
177 |
22 |
this.progress.endStep(getDocumentReference()); |
178 |
|
} |
179 |
|
|
180 |
22 |
return new CompositeBlock(transformedXDOM.getChildren()); |
181 |
|
} |
182 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
183 |
0 |
@Override... |
184 |
|
public Map<String, String> getParameters() |
185 |
|
{ |
186 |
0 |
return Collections.emptyMap(); |
187 |
|
} |
188 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
189 |
184 |
@Override... |
190 |
|
public Type getRoleType() |
191 |
|
{ |
192 |
184 |
return UIExtension.class; |
193 |
|
} |
194 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
195 |
206 |
@Override... |
196 |
|
public String getRoleHint() |
197 |
|
{ |
198 |
206 |
return getId(); |
199 |
|
} |
200 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
201 |
184 |
@Override... |
202 |
|
public WikiComponentScope getScope() |
203 |
|
{ |
204 |
|
|
205 |
184 |
return WikiComponentScope.GLOBAL; |
206 |
|
} |
207 |
|
} |