1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.filter.confluence.xml.internal.input; |
21 |
|
|
22 |
|
import java.io.File; |
23 |
|
import java.io.FileInputStream; |
24 |
|
import java.io.FileNotFoundException; |
25 |
|
import java.io.IOException; |
26 |
|
import java.io.StringReader; |
27 |
|
import java.text.ParseException; |
28 |
|
import java.util.LinkedHashMap; |
29 |
|
import java.util.List; |
30 |
|
import java.util.Locale; |
31 |
|
import java.util.Map; |
32 |
|
|
33 |
|
import javax.inject.Inject; |
34 |
|
import javax.inject.Named; |
35 |
|
|
36 |
|
import org.apache.commons.configuration.ConfigurationException; |
37 |
|
import org.apache.commons.configuration.PropertiesConfiguration; |
38 |
|
import org.apache.commons.lang3.StringUtils; |
39 |
|
import org.slf4j.Logger; |
40 |
|
import org.xwiki.component.annotation.Component; |
41 |
|
import org.xwiki.component.annotation.InstantiationStrategy; |
42 |
|
import org.xwiki.component.descriptor.ComponentInstantiationStrategy; |
43 |
|
import org.xwiki.filter.FilterEventParameters; |
44 |
|
import org.xwiki.filter.FilterException; |
45 |
|
import org.xwiki.filter.confluence.input.ConfluenceInputProperties; |
46 |
|
import org.xwiki.filter.confluence.xml.internal.ConfluenceFilter; |
47 |
|
import org.xwiki.filter.confluence.xml.internal.ConfluenceXMLPackage; |
48 |
|
import org.xwiki.filter.event.model.WikiAttachmentFilter; |
49 |
|
import org.xwiki.filter.event.model.WikiDocumentFilter; |
50 |
|
import org.xwiki.filter.event.user.GroupFilter; |
51 |
|
import org.xwiki.filter.event.user.UserFilter; |
52 |
|
import org.xwiki.filter.input.AbstractBeanInputFilterStream; |
53 |
|
import org.xwiki.rendering.listener.Listener; |
54 |
|
import org.xwiki.rendering.parser.StreamParser; |
55 |
|
import org.xwiki.rendering.syntax.Syntax; |
56 |
|
|
57 |
|
|
58 |
|
@version |
59 |
|
@since |
60 |
|
|
61 |
|
@Component |
62 |
|
@Named(ConfluenceInputFilterStreamFactory.ROLEHINT) |
63 |
|
@InstantiationStrategy(ComponentInstantiationStrategy.PER_LOOKUP) |
|
|
| 75.8% |
Uncovered Elements: 80 (330) |
Complexity: 83 |
Complexity Density: 0.35 |
|
64 |
|
public class ConfluenceInputFilterStream |
65 |
|
extends AbstractBeanInputFilterStream<ConfluenceInputProperties, ConfluenceFilter> |
66 |
|
{ |
67 |
|
@Inject |
68 |
|
private Logger logger; |
69 |
|
|
70 |
|
@Inject |
71 |
|
@Named("confluence/1.0") |
72 |
|
private StreamParser confluenceWIKIParser; |
73 |
|
|
74 |
|
@Inject |
75 |
|
@Named("confluence+xhtml/1.0") |
76 |
|
private StreamParser confluenceXHTMLParser; |
77 |
|
|
78 |
|
private ConfluenceXMLPackage confluencePackage; |
79 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
80 |
3 |
@Override... |
81 |
|
public void close() throws IOException |
82 |
|
{ |
83 |
3 |
this.properties.getSource().close(); |
84 |
|
} |
85 |
|
|
|
|
| 67.9% |
Uncovered Elements: 35 (109) |
Complexity: 25 |
Complexity Density: 0.3 |
|
86 |
3 |
@Override... |
87 |
|
protected void read(Object filter, ConfluenceFilter proxyFilter) throws FilterException |
88 |
|
{ |
89 |
|
|
90 |
3 |
try { |
91 |
3 |
this.confluencePackage = new ConfluenceXMLPackage(this.properties.getSource()); |
92 |
|
} catch (Exception e) { |
93 |
0 |
throw new FilterException("Failed to read package", e); |
94 |
|
} |
95 |
|
|
96 |
|
|
97 |
3 |
for (int userInt : this.confluencePackage.getUsers()) { |
98 |
5 |
PropertiesConfiguration userProperties; |
99 |
5 |
try { |
100 |
5 |
userProperties = this.confluencePackage.getUserProperties(userInt); |
101 |
|
} catch (ConfigurationException e) { |
102 |
0 |
throw new FilterException("Failed to get user properties", e); |
103 |
|
} |
104 |
|
|
105 |
5 |
String userId = userProperties.getString(ConfluenceXMLPackage.KEY_USER_NAME, String.valueOf(userInt)); |
106 |
5 |
if (this.properties.isConvertToXWiki() && userId.equals("admin")) { |
107 |
2 |
userId = "Admin"; |
108 |
|
} |
109 |
|
|
110 |
5 |
FilterEventParameters userParameters = new FilterEventParameters(); |
111 |
|
|
112 |
5 |
userParameters.put(UserFilter.PARAMETER_FIRSTNAME, |
113 |
|
userProperties.getString(ConfluenceXMLPackage.KEY_USER_FIRSTNAME)); |
114 |
5 |
userParameters.put(UserFilter.PARAMETER_LASTNAME, |
115 |
|
userProperties.getString(ConfluenceXMLPackage.KEY_USER_LASTNAME)); |
116 |
5 |
userParameters.put(UserFilter.PARAMETER_EMAIL, |
117 |
|
userProperties.getString(ConfluenceXMLPackage.KEY_USER_EMAIL)); |
118 |
5 |
userParameters.put(UserFilter.PARAMETER_ACTIVE, |
119 |
|
userProperties.getBoolean(ConfluenceXMLPackage.KEY_USER_ACTIVE)); |
120 |
|
|
121 |
5 |
try { |
122 |
5 |
userParameters.put(UserFilter.PARAMETER_REVISION_DATE, |
123 |
|
this.confluencePackage.getDate(userProperties, ConfluenceXMLPackage.KEY_USER_REVISION_DATE)); |
124 |
5 |
userParameters.put(UserFilter.PARAMETER_CREATION_DATE, |
125 |
|
this.confluencePackage.getDate(userProperties, ConfluenceXMLPackage.KEY_USER_CREATION_DATE)); |
126 |
|
} catch (ParseException e) { |
127 |
0 |
if (this.properties.isVerbose()) { |
128 |
0 |
this.logger.error("Failed to parse date", e); |
129 |
|
} |
130 |
|
} |
131 |
|
|
132 |
|
|
133 |
|
|
134 |
|
|
135 |
5 |
proxyFilter.beginUser(userId, userParameters); |
136 |
|
|
137 |
|
|
138 |
5 |
proxyFilter.endUser(userId, userParameters); |
139 |
|
} |
140 |
|
|
141 |
|
|
142 |
3 |
for (int groupInt : this.confluencePackage.getGroups()) { |
143 |
11 |
PropertiesConfiguration groupProperties; |
144 |
11 |
try { |
145 |
11 |
groupProperties = this.confluencePackage.getGroupProperties(groupInt); |
146 |
|
} catch (ConfigurationException e) { |
147 |
0 |
throw new FilterException("Failed to get group properties", e); |
148 |
|
} |
149 |
|
|
150 |
11 |
String groupName = groupProperties.getString(ConfluenceXMLPackage.KEY_GROUP_NAME, String.valueOf(groupInt)); |
151 |
11 |
if (this.properties.isConvertToXWiki()) { |
152 |
11 |
if (groupName.equals("confluence-administrators")) { |
153 |
2 |
groupName = "XWikiAdminGroup"; |
154 |
9 |
} else if (groupName.equals("confluence-users")) { |
155 |
2 |
groupName = "XWikiAllGroup"; |
156 |
|
} |
157 |
|
} |
158 |
|
|
159 |
11 |
FilterEventParameters groupParameters = new FilterEventParameters(); |
160 |
|
|
161 |
11 |
try { |
162 |
11 |
groupParameters.put(GroupFilter.PARAMETER_REVISION_DATE, |
163 |
|
this.confluencePackage.getDate(groupProperties, ConfluenceXMLPackage.KEY_GROUP_REVISION_DATE)); |
164 |
11 |
groupParameters.put(GroupFilter.PARAMETER_CREATION_DATE, |
165 |
|
this.confluencePackage.getDate(groupProperties, ConfluenceXMLPackage.KEY_GROUP_CREATION_DATE)); |
166 |
|
} catch (ParseException e) { |
167 |
0 |
if (this.properties.isVerbose()) { |
168 |
0 |
this.logger.error("Failed to parse date", e); |
169 |
|
} |
170 |
|
} |
171 |
|
|
172 |
|
|
173 |
11 |
proxyFilter.beginGroupContainer(groupName, groupParameters); |
174 |
|
|
175 |
|
|
176 |
11 |
if (groupProperties.containsKey(ConfluenceXMLPackage.KEY_GROUP_MEMBERUSERS)) { |
177 |
8 |
List<Integer> users = |
178 |
|
this.confluencePackage.getIntegertList(groupProperties, ConfluenceXMLPackage.KEY_GROUP_MEMBERUSERS); |
179 |
8 |
for (Integer memberInt : users) { |
180 |
11 |
FilterEventParameters memberParameters = new FilterEventParameters(); |
181 |
|
|
182 |
11 |
try { |
183 |
11 |
String memberId = this.confluencePackage.getUserProperties(memberInt) |
184 |
|
.getString(ConfluenceXMLPackage.KEY_USER_NAME, String.valueOf(memberInt)); |
185 |
|
|
186 |
11 |
if (this.properties.isConvertToXWiki() && memberId.equals("admin")) { |
187 |
6 |
memberId = "Admin"; |
188 |
|
} |
189 |
|
|
190 |
11 |
proxyFilter.onGroupMemberGroup(memberId, memberParameters); |
191 |
|
} catch (ConfigurationException e) { |
192 |
0 |
this.logger.error("Failed to get user properties", e); |
193 |
|
} |
194 |
|
} |
195 |
|
} |
196 |
|
|
197 |
|
|
198 |
11 |
if (groupProperties.containsKey(ConfluenceXMLPackage.KEY_GROUP_MEMBERGROUPS)) { |
199 |
0 |
List<Integer> groups = this.confluencePackage.getIntegertList(groupProperties, |
200 |
|
ConfluenceXMLPackage.KEY_GROUP_MEMBERGROUPS); |
201 |
0 |
for (Integer memberInt : groups) { |
202 |
0 |
FilterEventParameters memberParameters = new FilterEventParameters(); |
203 |
|
|
204 |
0 |
try { |
205 |
0 |
String memberId = this.confluencePackage.getGroupProperties(memberInt) |
206 |
|
.getString(ConfluenceXMLPackage.KEY_GROUP_NAME, String.valueOf(memberInt)); |
207 |
|
|
208 |
0 |
if (this.properties.isConvertToXWiki()) { |
209 |
0 |
if (memberId.equals("confluence-administrators")) { |
210 |
0 |
memberId = "XWikiAdminGroup"; |
211 |
0 |
} else if (memberId.equals("confluence-users")) { |
212 |
0 |
memberId = "XWikiAllGroup"; |
213 |
|
} |
214 |
|
} |
215 |
|
|
216 |
0 |
proxyFilter.onGroupMemberGroup(memberId, memberParameters); |
217 |
|
} catch (ConfigurationException e) { |
218 |
0 |
this.logger.error("Failed to get group properties", e); |
219 |
|
} |
220 |
|
} |
221 |
|
} |
222 |
|
|
223 |
|
|
224 |
11 |
proxyFilter.endGroupContainer(groupName, groupParameters); |
225 |
|
} |
226 |
|
|
227 |
|
|
228 |
3 |
for (Map.Entry<Integer, List<Integer>> entry : this.confluencePackage.getPages().entrySet()) { |
229 |
5 |
int spaceId = entry.getKey(); |
230 |
|
|
231 |
5 |
PropertiesConfiguration spaceProperties; |
232 |
5 |
try { |
233 |
5 |
spaceProperties = this.confluencePackage.getSpaceProperties(spaceId); |
234 |
|
} catch (ConfigurationException e) { |
235 |
0 |
throw new FilterException("Failed to get space properties", e); |
236 |
|
} |
237 |
|
|
238 |
5 |
String spaceName = spaceProperties.getString(ConfluenceXMLPackage.KEY_SPACE_NAME); |
239 |
5 |
FilterEventParameters spaceParameters = new FilterEventParameters(); |
240 |
|
|
241 |
|
|
242 |
5 |
proxyFilter.beginWikiSpace(spaceName, spaceParameters); |
243 |
|
|
244 |
|
|
245 |
5 |
Integer descriptionId = spaceProperties.getInteger(ConfluenceXMLPackage.KEY_SPACE_DESCRIPTION, null); |
246 |
5 |
if (descriptionId != null) { |
247 |
5 |
readPage(descriptionId, filter, proxyFilter); |
248 |
|
} |
249 |
|
|
250 |
|
|
251 |
5 |
for (int pageId : entry.getValue()) { |
252 |
19 |
readPage(pageId, filter, proxyFilter); |
253 |
|
} |
254 |
|
|
255 |
|
|
256 |
5 |
proxyFilter.endWikiSpace(spaceName, spaceParameters); |
257 |
|
} |
258 |
|
|
259 |
|
|
260 |
|
|
261 |
3 |
try { |
262 |
3 |
this.confluencePackage.close(); |
263 |
|
} catch (IOException e) { |
264 |
0 |
throw new FilterException("Failed to close package", e); |
265 |
|
} |
266 |
|
} |
267 |
|
|
|
|
| 83.3% |
Uncovered Elements: 7 (42) |
Complexity: 9 |
Complexity Density: 0.32 |
|
268 |
24 |
private void readPage(int pageId, Object filter, ConfluenceFilter proxyFilter) throws FilterException... |
269 |
|
{ |
270 |
24 |
PropertiesConfiguration pageProperties = getPageProperties(pageId); |
271 |
|
|
272 |
24 |
String documentName; |
273 |
24 |
if (pageProperties.containsKey(ConfluenceXMLPackage.KEY_PAGE_HOMEPAGE)) { |
274 |
5 |
documentName = this.properties.getSpacePageName(); |
275 |
|
} else { |
276 |
19 |
documentName = pageProperties.getString(ConfluenceXMLPackage.KEY_PAGE_TITLE); |
277 |
|
} |
278 |
|
|
279 |
24 |
FilterEventParameters documentParameters = new FilterEventParameters(); |
280 |
24 |
if (this.properties.getDefaultLocale() != null) { |
281 |
0 |
documentParameters.put(WikiDocumentFilter.PARAMETER_LOCALE, this.properties.getDefaultLocale()); |
282 |
|
} |
283 |
|
|
284 |
|
|
285 |
24 |
proxyFilter.beginWikiDocument(documentName, documentParameters); |
286 |
|
|
287 |
24 |
Locale locale = Locale.ROOT; |
288 |
|
|
289 |
24 |
FilterEventParameters documentLocaleParameters = new FilterEventParameters(); |
290 |
24 |
if (pageProperties.containsKey(ConfluenceXMLPackage.KEY_PAGE_CREATION_AUTHOR)) { |
291 |
9 |
documentLocaleParameters.put(WikiDocumentFilter.PARAMETER_CREATION_AUTHOR, |
292 |
|
pageProperties.getString(ConfluenceXMLPackage.KEY_PAGE_CREATION_AUTHOR)); |
293 |
|
} |
294 |
24 |
if (pageProperties.containsKey(ConfluenceXMLPackage.KEY_PAGE_CREATION_DATE)) { |
295 |
23 |
try { |
296 |
23 |
documentLocaleParameters.put(WikiDocumentFilter.PARAMETER_CREATION_DATE, |
297 |
|
this.confluencePackage.getDate(pageProperties, ConfluenceXMLPackage.KEY_PAGE_CREATION_DATE)); |
298 |
|
} catch (ParseException e) { |
299 |
0 |
if (this.properties.isVerbose()) { |
300 |
0 |
this.logger.error("Failed to parse date", e); |
301 |
|
} |
302 |
|
} |
303 |
|
} |
304 |
24 |
if (pageProperties.containsKey(ConfluenceXMLPackage.KEY_PAGE_REVISION)) { |
305 |
24 |
documentLocaleParameters.put(WikiDocumentFilter.PARAMETER_LASTREVISION, |
306 |
|
pageProperties.getString(ConfluenceXMLPackage.KEY_PAGE_REVISION)); |
307 |
|
} |
308 |
|
|
309 |
|
|
310 |
24 |
proxyFilter.beginWikiDocumentLocale(locale, documentLocaleParameters); |
311 |
|
|
312 |
|
|
313 |
24 |
if (pageProperties.containsKey(ConfluenceXMLPackage.KEY_PAGE_REVISIONS)) { |
314 |
3 |
List<Integer> revisions = |
315 |
|
this.confluencePackage.getIntegertList(pageProperties, ConfluenceXMLPackage.KEY_PAGE_REVISIONS); |
316 |
3 |
for (Integer revisionId : revisions) { |
317 |
8 |
readPageRevision(revisionId, filter, proxyFilter); |
318 |
|
} |
319 |
|
} |
320 |
|
|
321 |
|
|
322 |
24 |
readPageRevision(pageId, filter, proxyFilter); |
323 |
|
|
324 |
|
|
325 |
24 |
proxyFilter.endWikiDocumentLocale(locale, documentLocaleParameters); |
326 |
|
|
327 |
|
|
328 |
24 |
proxyFilter.endWikiDocument(documentName, documentParameters); |
329 |
|
} |
330 |
|
|
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
331 |
56 |
private PropertiesConfiguration getPageProperties(Integer pageId) throws FilterException... |
332 |
|
{ |
333 |
56 |
try { |
334 |
56 |
return this.confluencePackage.getPageProperties(pageId); |
335 |
|
} catch (ConfigurationException e) { |
336 |
0 |
throw new FilterException("Failed to get page properties", e); |
337 |
|
} |
338 |
|
} |
339 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
340 |
32 |
private void readPageRevision(Integer pageId, Object filter, ConfluenceFilter proxyFilter) throws FilterException... |
341 |
|
{ |
342 |
32 |
PropertiesConfiguration pageProperties = getPageProperties(pageId); |
343 |
|
|
344 |
32 |
readPageRevision(pageId, pageProperties, filter, proxyFilter); |
345 |
|
} |
346 |
|
|
|
|
| 76.9% |
Uncovered Elements: 21 (91) |
Complexity: 26 |
Complexity Density: 0.39 |
|
347 |
32 |
private void readPageRevision(int pageId, PropertiesConfiguration pageProperties, Object filter,... |
348 |
|
ConfluenceFilter proxyFilter) throws FilterException |
349 |
|
{ |
350 |
32 |
String revision = pageProperties.getString(ConfluenceXMLPackage.KEY_PAGE_REVISION); |
351 |
|
|
352 |
32 |
FilterEventParameters documentRevisionParameters = new FilterEventParameters(); |
353 |
32 |
if (pageProperties.containsKey(ConfluenceXMLPackage.KEY_PAGE_PARENT)) { |
354 |
13 |
try { |
355 |
13 |
documentRevisionParameters.put(WikiDocumentFilter.PARAMETER_PARENT, |
356 |
|
this.confluencePackage.getReferenceFromId(pageProperties, ConfluenceXMLPackage.KEY_PAGE_PARENT)); |
357 |
|
} catch (ConfigurationException e) { |
358 |
0 |
if (this.properties.isVerbose()) { |
359 |
0 |
this.logger.error("Failed to parse parent", e); |
360 |
|
} |
361 |
|
} |
362 |
|
} |
363 |
32 |
if (pageProperties.containsKey(ConfluenceXMLPackage.KEY_PAGE_REVISION_AUTHOR)) { |
364 |
16 |
documentRevisionParameters.put(WikiDocumentFilter.PARAMETER_REVISION_AUTHOR, |
365 |
|
pageProperties.getString(ConfluenceXMLPackage.KEY_PAGE_REVISION_AUTHOR)); |
366 |
|
} |
367 |
32 |
if (pageProperties.containsKey(ConfluenceXMLPackage.KEY_PAGE_REVISION_DATE)) { |
368 |
31 |
try { |
369 |
31 |
documentRevisionParameters.put(WikiDocumentFilter.PARAMETER_REVISION_DATE, |
370 |
|
this.confluencePackage.getDate(pageProperties, ConfluenceXMLPackage.KEY_PAGE_REVISION_DATE)); |
371 |
|
} catch (ParseException e) { |
372 |
0 |
if (this.properties.isVerbose()) { |
373 |
0 |
this.logger.error("Failed to parse date", e); |
374 |
|
} |
375 |
|
} |
376 |
|
} |
377 |
32 |
if (pageProperties.containsKey(ConfluenceXMLPackage.KEY_PAGE_REVISION_COMMENT)) { |
378 |
31 |
documentRevisionParameters.put(WikiDocumentFilter.PARAMETER_REVISION_COMMENT, |
379 |
|
pageProperties.getString(ConfluenceXMLPackage.KEY_PAGE_REVISION_COMMENT)); |
380 |
|
} |
381 |
32 |
documentRevisionParameters.put(WikiDocumentFilter.PARAMETER_TITLE, |
382 |
|
pageProperties.getString(ConfluenceXMLPackage.KEY_PAGE_TITLE)); |
383 |
|
|
384 |
32 |
String bodyContent = null; |
385 |
32 |
Syntax bodySyntax = null; |
386 |
32 |
int bodyType = -1; |
387 |
|
|
388 |
32 |
if (pageProperties.containsKey(ConfluenceXMLPackage.KEY_PAGE_BODY) |
389 |
|
&& pageProperties.containsKey(ConfluenceXMLPackage.KEY_PAGE_BODY_TYPE)) { |
390 |
31 |
bodyContent = pageProperties.getString(ConfluenceXMLPackage.KEY_PAGE_BODY); |
391 |
31 |
bodyType = pageProperties.getInt(ConfluenceXMLPackage.KEY_PAGE_BODY_TYPE); |
392 |
|
|
393 |
31 |
switch (bodyType) { |
394 |
5 |
case 0: |
395 |
5 |
bodySyntax = Syntax.CONFLUENCE_1_0; |
396 |
5 |
break; |
397 |
26 |
case 2: |
398 |
26 |
bodySyntax = Syntax.CONFLUENCEXHTML_1_0; |
399 |
26 |
break; |
400 |
0 |
default: |
401 |
0 |
if (this.properties.isVerbose()) { |
402 |
0 |
this.logger.error("Unknown body type [{}]", bodyType); |
403 |
|
} |
404 |
0 |
break; |
405 |
|
} |
406 |
|
} |
407 |
|
|
408 |
|
|
409 |
32 |
if (!(filter instanceof Listener) && bodyContent != null && bodySyntax != null) { |
410 |
0 |
documentRevisionParameters.put(WikiDocumentFilter.PARAMETER_CONTENT, bodyContent); |
411 |
0 |
documentRevisionParameters.put(WikiDocumentFilter.PARAMETER_SYNTAX, bodySyntax); |
412 |
|
} |
413 |
|
|
414 |
|
|
415 |
32 |
proxyFilter.beginWikiDocumentRevision(revision, documentRevisionParameters); |
416 |
|
|
417 |
|
|
418 |
32 |
if (filter instanceof Listener && bodyContent != null && bodySyntax != null) { |
419 |
31 |
try { |
420 |
31 |
switch (bodyType) { |
421 |
5 |
case 0: |
422 |
5 |
this.confluenceWIKIParser.parse(new StringReader(bodyContent), proxyFilter); |
423 |
5 |
break; |
424 |
26 |
case 2: |
425 |
26 |
this.confluenceXHTMLParser.parse(new StringReader(bodyContent), proxyFilter); |
426 |
26 |
break; |
427 |
0 |
default: |
428 |
0 |
break; |
429 |
|
} |
430 |
|
} catch (org.xwiki.rendering.parser.ParseException e) { |
431 |
0 |
throw new FilterException(String.format("Failed parser content [%s]", bodyContent), e); |
432 |
|
} |
433 |
|
} |
434 |
|
|
435 |
|
|
436 |
32 |
Map<String, PropertiesConfiguration> pageAttachments = new LinkedHashMap<>(); |
437 |
32 |
for (int attachmentId : this.confluencePackage.getAttachments(pageId)) { |
438 |
33 |
PropertiesConfiguration attachmentProperties; |
439 |
33 |
try { |
440 |
33 |
attachmentProperties = this.confluencePackage.getAttachmentProperties(pageId, attachmentId); |
441 |
|
} catch (ConfigurationException e) { |
442 |
0 |
throw new FilterException("Failed to get attachment properties", e); |
443 |
|
} |
444 |
|
|
445 |
33 |
String attachmentName = this.confluencePackage.getAttachmentName(attachmentProperties); |
446 |
|
|
447 |
33 |
PropertiesConfiguration currentAttachmentProperties = pageAttachments.get(attachmentName); |
448 |
33 |
if (currentAttachmentProperties != null) { |
449 |
6 |
int version = this.confluencePackage.getAttachementVersion(attachmentProperties); |
450 |
6 |
int currentVersion = this.confluencePackage.getAttachementVersion(currentAttachmentProperties); |
451 |
|
|
452 |
6 |
if (version > currentVersion) { |
453 |
1 |
pageAttachments.put(attachmentName, attachmentProperties); |
454 |
|
} |
455 |
|
} else { |
456 |
27 |
pageAttachments.put(attachmentName, attachmentProperties); |
457 |
|
} |
458 |
|
} |
459 |
|
|
460 |
32 |
for (PropertiesConfiguration attachmentProperties : pageAttachments.values()) { |
461 |
27 |
readAttachment(pageId, attachmentProperties, filter, proxyFilter); |
462 |
|
} |
463 |
|
|
464 |
|
|
465 |
32 |
proxyFilter.endWikiDocumentRevision(revision, documentRevisionParameters); |
466 |
|
} |
467 |
|
|
|
|
| 78.9% |
Uncovered Elements: 15 (71) |
Complexity: 17 |
Complexity Density: 0.36 |
|
468 |
27 |
private void readAttachment(int pageId, PropertiesConfiguration attachmentProperties, Object filter,... |
469 |
|
ConfluenceFilter proxyFilter) throws FilterException |
470 |
|
{ |
471 |
27 |
String contentStatus = attachmentProperties.getString(ConfluenceXMLPackage.KEY_ATTACHMENT_CONTENTSTATUS, null); |
472 |
27 |
if (StringUtils.equals(contentStatus, "deleted")) { |
473 |
|
|
474 |
2 |
return; |
475 |
|
} |
476 |
|
|
477 |
25 |
int attachmentId = attachmentProperties.getInt("id"); |
478 |
|
|
479 |
25 |
String attachmentName = this.confluencePackage.getAttachmentName(attachmentProperties); |
480 |
|
|
481 |
25 |
long attachmentSize; |
482 |
25 |
String mediaType = null; |
483 |
25 |
if (attachmentProperties.containsKey(ConfluenceXMLPackage.KEY_ATTACHMENT_CONTENTPROPERTIES)) { |
484 |
20 |
PropertiesConfiguration attachmentContentProperties = |
485 |
|
getContentProperties(attachmentProperties, ConfluenceXMLPackage.KEY_ATTACHMENT_CONTENTPROPERTIES); |
486 |
|
|
487 |
20 |
attachmentSize = attachmentContentProperties.getLong(ConfluenceXMLPackage.KEY_ATTACHMENT_CONTENT_FILESIZE); |
488 |
20 |
if (attachmentProperties.containsKey(ConfluenceXMLPackage.KEY_ATTACHMENT_CONTENTTYPE)) { |
489 |
0 |
mediaType = |
490 |
|
attachmentContentProperties.getString(ConfluenceXMLPackage.KEY_ATTACHMENT_CONTENT_MEDIA_TYPE); |
491 |
|
} |
492 |
|
} else { |
493 |
5 |
attachmentSize = attachmentProperties.getLong(ConfluenceXMLPackage.KEY_ATTACHMENT_CONTENT_SIZE); |
494 |
5 |
if (attachmentProperties.containsKey(ConfluenceXMLPackage.KEY_ATTACHMENT_CONTENTTYPE)) { |
495 |
5 |
mediaType = attachmentProperties.getString(ConfluenceXMLPackage.KEY_ATTACHMENT_CONTENTTYPE); |
496 |
|
} |
497 |
|
} |
498 |
|
|
499 |
25 |
Integer version = this.confluencePackage.getAttachementVersion(attachmentProperties); |
500 |
|
|
501 |
25 |
int originalRevisionId = |
502 |
|
this.confluencePackage.getAttachmentOriginalVersionId(attachmentProperties, attachmentId); |
503 |
25 |
File contentFile; |
504 |
25 |
try { |
505 |
25 |
contentFile = this.confluencePackage.getAttachmentFile(pageId, originalRevisionId, version); |
506 |
|
} catch (FileNotFoundException e) { |
507 |
0 |
throw new FilterException( |
508 |
|
String.format("Filed to find file corresponding to version [%s] attachment [%s] in page [%s]", version, |
509 |
|
attachmentName, pageId), |
510 |
|
e); |
511 |
|
} |
512 |
|
|
513 |
25 |
FilterEventParameters attachmentParameters = new FilterEventParameters(); |
514 |
25 |
if (mediaType != null) { |
515 |
5 |
attachmentParameters.put(WikiAttachmentFilter.PARAMETER_CONTENT_TYPE, mediaType); |
516 |
|
} |
517 |
25 |
if (attachmentProperties.containsKey(ConfluenceXMLPackage.KEY_ATTACHMENT_CREATION_AUTHOR)) { |
518 |
4 |
attachmentParameters.put(WikiAttachmentFilter.PARAMETER_CREATION_AUTHOR, |
519 |
|
attachmentProperties.getString(ConfluenceXMLPackage.KEY_ATTACHMENT_CREATION_AUTHOR)); |
520 |
|
} |
521 |
25 |
if (attachmentProperties.containsKey(ConfluenceXMLPackage.KEY_ATTACHMENT_CREATION_DATE)) { |
522 |
25 |
try { |
523 |
25 |
attachmentParameters.put(WikiAttachmentFilter.PARAMETER_CREATION_DATE, this.confluencePackage |
524 |
|
.getDate(attachmentProperties, ConfluenceXMLPackage.KEY_ATTACHMENT_CREATION_DATE)); |
525 |
|
} catch (ParseException e) { |
526 |
0 |
if (this.properties.isVerbose()) { |
527 |
0 |
this.logger.error("Failed to parse date", e); |
528 |
|
} |
529 |
|
} |
530 |
|
} |
531 |
|
|
532 |
25 |
attachmentParameters.put(WikiAttachmentFilter.PARAMETER_REVISION, String.valueOf(version)); |
533 |
25 |
if (attachmentProperties.containsKey(ConfluenceXMLPackage.KEY_ATTACHMENT_REVISION_AUTHOR)) { |
534 |
4 |
attachmentParameters.put(WikiAttachmentFilter.PARAMETER_REVISION_AUTHOR, |
535 |
|
attachmentProperties.getString(ConfluenceXMLPackage.KEY_ATTACHMENT_REVISION_AUTHOR)); |
536 |
|
} |
537 |
25 |
if (attachmentProperties.containsKey(ConfluenceXMLPackage.KEY_ATTACHMENT_REVISION_DATE)) { |
538 |
25 |
try { |
539 |
25 |
attachmentParameters.put(WikiAttachmentFilter.PARAMETER_REVISION_DATE, this.confluencePackage |
540 |
|
.getDate(attachmentProperties, ConfluenceXMLPackage.KEY_ATTACHMENT_REVISION_DATE)); |
541 |
|
} catch (ParseException e) { |
542 |
0 |
if (this.properties.isVerbose()) { |
543 |
0 |
this.logger.error("Failed to parse date", e); |
544 |
|
} |
545 |
|
} |
546 |
|
} |
547 |
25 |
if (attachmentProperties.containsKey(ConfluenceXMLPackage.KEY_ATTACHMENT_REVISION_COMMENT)) { |
548 |
5 |
attachmentParameters.put(WikiAttachmentFilter.PARAMETER_REVISION_COMMENT, |
549 |
|
attachmentProperties.getString(ConfluenceXMLPackage.KEY_ATTACHMENT_REVISION_COMMENT)); |
550 |
|
} |
551 |
|
|
552 |
|
|
553 |
|
|
554 |
25 |
try { |
555 |
25 |
FileInputStream fis = new FileInputStream(contentFile); |
556 |
|
|
557 |
25 |
try { |
558 |
25 |
proxyFilter.onWikiAttachment(attachmentName, fis, attachmentSize, attachmentParameters); |
559 |
|
} finally { |
560 |
25 |
fis.close(); |
561 |
|
} |
562 |
|
} catch (Exception e) { |
563 |
0 |
throw new FilterException("Failed to read attachment", e); |
564 |
|
} |
565 |
|
} |
566 |
|
|
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
567 |
20 |
public PropertiesConfiguration getContentProperties(PropertiesConfiguration properties, String key)... |
568 |
|
throws FilterException |
569 |
|
{ |
570 |
20 |
try { |
571 |
20 |
return this.confluencePackage.getContentProperties(properties, key); |
572 |
|
} catch (Exception e) { |
573 |
0 |
throw new FilterException("Failed to parse content properties", e); |
574 |
|
} |
575 |
|
} |
576 |
|
} |