1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package com.xpn.xwiki.internal.filter.output; |
21 |
|
|
22 |
|
import java.io.IOException; |
23 |
|
import java.io.InputStream; |
24 |
|
import java.util.Date; |
25 |
|
|
26 |
|
import org.apache.commons.lang3.math.NumberUtils; |
27 |
|
import org.xwiki.component.annotation.Component; |
28 |
|
import org.xwiki.component.annotation.InstantiationStrategy; |
29 |
|
import org.xwiki.component.descriptor.ComponentInstantiationStrategy; |
30 |
|
import org.xwiki.filter.FilterEventParameters; |
31 |
|
import org.xwiki.filter.FilterException; |
32 |
|
import org.xwiki.filter.event.model.WikiAttachmentFilter; |
33 |
|
import org.xwiki.filter.event.xwiki.XWikiWikiAttachmentFilter; |
34 |
|
|
35 |
|
import com.xpn.xwiki.XWikiException; |
36 |
|
import com.xpn.xwiki.doc.XWikiAttachment; |
37 |
|
|
38 |
|
|
39 |
|
@version |
40 |
|
@since |
41 |
|
|
42 |
|
@Component |
43 |
|
@InstantiationStrategy(ComponentInstantiationStrategy.PER_LOOKUP) |
|
|
| 78% |
Uncovered Elements: 9 (41) |
Complexity: 12 |
Complexity Density: 0.48 |
|
44 |
|
public class XWikiAttachmentOutputFilterStream extends AbstractEntityOutputFilterStream<XWikiAttachment> |
45 |
|
{ |
46 |
|
|
47 |
|
|
|
|
| 60% |
Uncovered Elements: 6 (15) |
Complexity: 5 |
Complexity Density: 0.71 |
|
48 |
7 |
private void setVersion(FilterEventParameters parameters)... |
49 |
|
{ |
50 |
7 |
if (parameters.containsKey(WikiAttachmentFilter.PARAMETER_REVISION)) { |
51 |
6 |
String version = getString(WikiAttachmentFilter.PARAMETER_REVISION, parameters, null); |
52 |
6 |
if (version != null) { |
53 |
6 |
if (VALID_VERSION.matcher(version).matches()) { |
54 |
6 |
this.entity.setVersion(version); |
55 |
0 |
} else if (NumberUtils.isDigits(version)) { |
56 |
0 |
this.entity.setVersion(version + ".1"); |
57 |
|
} else { |
58 |
|
|
59 |
|
} |
60 |
|
} |
61 |
|
} |
62 |
|
} |
63 |
|
|
|
|
| 87.5% |
Uncovered Elements: 3 (24) |
Complexity: 7 |
Complexity Density: 0.39 |
|
64 |
449 |
@Override... |
65 |
|
public void onWikiAttachment(String name, InputStream content, Long size, FilterEventParameters parameters) |
66 |
|
throws FilterException |
67 |
|
{ |
68 |
449 |
if (this.entity == null) { |
69 |
449 |
this.entity = new XWikiAttachment(); |
70 |
|
} |
71 |
|
|
72 |
449 |
this.entity.setFilename(name); |
73 |
|
|
74 |
449 |
try { |
75 |
449 |
this.entity.setContent(content); |
76 |
|
} catch (IOException e) { |
77 |
0 |
throw new FilterException("Failed to set attachment content", e); |
78 |
|
} |
79 |
|
|
80 |
|
|
81 |
|
|
82 |
449 |
this.entity |
83 |
|
.setAuthorReference(getUserReference(WikiAttachmentFilter.PARAMETER_REVISION_AUTHOR, parameters, null)); |
84 |
|
|
85 |
|
|
86 |
|
|
87 |
449 |
if (this.properties == null || this.properties.isVersionPreserved()) { |
88 |
7 |
setVersion(parameters); |
89 |
7 |
this.entity.setComment(getString(WikiAttachmentFilter.PARAMETER_REVISION_COMMENT, parameters, "")); |
90 |
7 |
this.entity.setDate(getDate(WikiAttachmentFilter.PARAMETER_REVISION_DATE, parameters, new Date())); |
91 |
7 |
this.entity.setMimeType(getString(WikiAttachmentFilter.PARAMETER_MIMETYPE, parameters, null)); |
92 |
|
|
93 |
7 |
String revisions = getString(XWikiWikiAttachmentFilter.PARAMETER_JRCSREVISIONS, parameters, null); |
94 |
7 |
if (revisions != null) { |
95 |
1 |
try { |
96 |
1 |
this.entity.setArchive(revisions); |
97 |
|
} catch (XWikiException e) { |
98 |
0 |
throw new FilterException("Failed to set attachment archive", e); |
99 |
|
} |
100 |
|
} |
101 |
|
|
102 |
7 |
this.entity.setMetaDataDirty(false); |
103 |
|
} |
104 |
|
} |
105 |
|
} |