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.input; |
21 |
|
|
22 |
|
import java.lang.reflect.ParameterizedType; |
23 |
|
import java.util.ArrayList; |
24 |
|
import java.util.Collections; |
25 |
|
import java.util.Comparator; |
26 |
|
import java.util.List; |
27 |
|
|
28 |
|
import javax.inject.Inject; |
29 |
|
import javax.inject.Provider; |
30 |
|
import javax.inject.Singleton; |
31 |
|
|
32 |
|
import org.slf4j.Logger; |
33 |
|
import org.suigeneris.jrcs.rcs.Version; |
34 |
|
import org.xwiki.component.annotation.Component; |
35 |
|
import org.xwiki.component.util.DefaultParameterizedType; |
36 |
|
import org.xwiki.filter.FilterEventParameters; |
37 |
|
import org.xwiki.filter.FilterException; |
38 |
|
import org.xwiki.filter.event.model.WikiDocumentFilter; |
39 |
|
import org.xwiki.filter.event.xwiki.XWikiWikiDocumentFilter; |
40 |
|
import org.xwiki.filter.instance.input.DocumentInstanceInputProperties; |
41 |
|
import org.xwiki.filter.instance.input.EntityEventGenerator; |
42 |
|
import org.xwiki.filter.instance.internal.input.AbstractBeanEntityEventGenerator; |
43 |
|
|
44 |
|
import com.xpn.xwiki.XWikiContext; |
45 |
|
import com.xpn.xwiki.XWikiException; |
46 |
|
import com.xpn.xwiki.doc.XWikiAttachment; |
47 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
48 |
|
import com.xpn.xwiki.internal.filter.XWikiDocumentFilter; |
49 |
|
import com.xpn.xwiki.objects.BaseObject; |
50 |
|
import com.xpn.xwiki.objects.classes.BaseClass; |
51 |
|
|
52 |
|
|
53 |
|
@version |
54 |
|
@since |
55 |
|
|
56 |
|
@Component |
57 |
|
@Singleton |
|
|
| 75.8% |
Uncovered Elements: 24 (99) |
Complexity: 22 |
Complexity Density: 0.33 |
|
58 |
|
public class XWikiDocumentLocaleEventGenerator |
59 |
|
extends AbstractBeanEntityEventGenerator<XWikiDocument, XWikiDocumentFilter, DocumentInstanceInputProperties> |
60 |
|
{ |
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
public static final ParameterizedType ROLE = new DefaultParameterizedType(null, EntityEventGenerator.class, |
65 |
|
XWikiDocument.class, DocumentInstanceInputProperties.class); |
66 |
|
|
67 |
|
@Inject |
68 |
|
private Provider<XWikiContext> xcontextProvider; |
69 |
|
|
70 |
|
@Inject |
71 |
|
private Logger logger; |
72 |
|
|
73 |
|
@Inject |
74 |
|
private EntityEventGenerator<XWikiAttachment> attachmentEventGenerator; |
75 |
|
|
76 |
|
@Inject |
77 |
|
private EntityEventGenerator<BaseClass> classEventGenerator; |
78 |
|
|
79 |
|
@Inject |
80 |
|
private EntityEventGenerator<BaseObject> objectEventGenerator; |
81 |
|
|
|
|
| 68.2% |
Uncovered Elements: 7 (22) |
Complexity: 5 |
Complexity Density: 0.28 |
|
82 |
6335 |
@Override... |
83 |
|
public void write(XWikiDocument document, Object filter, XWikiDocumentFilter documentFilter, |
84 |
|
DocumentInstanceInputProperties properties) throws FilterException |
85 |
|
{ |
86 |
6335 |
XWikiContext xcontext = this.xcontextProvider.get(); |
87 |
|
|
88 |
|
|
89 |
|
|
90 |
6335 |
FilterEventParameters localeParameters = new FilterEventParameters(); |
91 |
|
|
92 |
6335 |
if (properties.isWithJRCSRevisions()) { |
93 |
153 |
try { |
94 |
153 |
localeParameters.put(XWikiWikiDocumentFilter.PARAMETER_JRCSREVISIONS, |
95 |
|
document.getDocumentArchive(xcontext).getArchive(xcontext)); |
96 |
|
} catch (XWikiException e) { |
97 |
0 |
this.logger.error("Document [{}] has malformed history", document.getDocumentReference(), e); |
98 |
|
} |
99 |
|
} |
100 |
|
|
101 |
6335 |
localeParameters.put(WikiDocumentFilter.PARAMETER_CREATION_AUTHOR, document.getCreator()); |
102 |
6335 |
localeParameters.put(WikiDocumentFilter.PARAMETER_CREATION_DATE, document.getCreationDate()); |
103 |
6335 |
localeParameters.put(WikiDocumentFilter.PARAMETER_LASTREVISION, document.getVersion()); |
104 |
|
|
105 |
6335 |
documentFilter.beginWikiDocumentLocale(document.getLocale(), localeParameters); |
106 |
|
|
107 |
6335 |
if (properties.isWithRevisions()) { |
108 |
0 |
try { |
109 |
0 |
for (Version version : document.getRevisions(xcontext)) { |
110 |
0 |
XWikiDocument revisionDocument = |
111 |
|
xcontext.getWiki().getDocument(document, version.toString(), xcontext); |
112 |
|
|
113 |
0 |
writeRevision(revisionDocument, filter, documentFilter, properties); |
114 |
|
} |
115 |
|
} catch (XWikiException e) { |
116 |
0 |
this.logger.error("Failed to get document [{}] history", document.getDocumentReference(), e); |
117 |
|
} |
118 |
|
} |
119 |
|
|
120 |
6335 |
writeRevision(document, filter, documentFilter, properties); |
121 |
|
|
122 |
|
|
123 |
|
|
124 |
6335 |
documentFilter.endWikiDocumentLocale(document.getLocale(), FilterEventParameters.EMPTY); |
125 |
|
} |
126 |
|
|
|
|
| 90% |
Uncovered Elements: 6 (60) |
Complexity: 12 |
Complexity Density: 0.3 |
|
127 |
6335 |
private void writeRevision(XWikiDocument document, Object filter, XWikiDocumentFilter documentFilter,... |
128 |
|
DocumentInstanceInputProperties properties) throws FilterException |
129 |
|
{ |
130 |
|
|
131 |
|
|
132 |
6335 |
FilterEventParameters revisionParameters = new FilterEventParameters(); |
133 |
|
|
134 |
6335 |
if (document.getRelativeParentReference() != null) { |
135 |
5827 |
revisionParameters.put(WikiDocumentFilter.PARAMETER_PARENT, document.getRelativeParentReference()); |
136 |
|
} |
137 |
6335 |
revisionParameters.put(WikiDocumentFilter.PARAMETER_TITLE, document.getTitle()); |
138 |
6335 |
if (!document.getCustomClass().isEmpty()) { |
139 |
2 |
revisionParameters.put(WikiDocumentFilter.PARAMETER_CUSTOMCLASS, document.getCustomClass()); |
140 |
|
} |
141 |
6335 |
if (!document.getDefaultTemplate().isEmpty()) { |
142 |
2 |
revisionParameters.put(WikiDocumentFilter.PARAMETER_DEFAULTTEMPLATE, document.getDefaultTemplate()); |
143 |
|
} |
144 |
6335 |
if (!document.getValidationScript().isEmpty()) { |
145 |
2 |
revisionParameters.put(WikiDocumentFilter.PARAMETER_VALIDATIONSCRIPT, document.getValidationScript()); |
146 |
|
} |
147 |
6335 |
revisionParameters.put(WikiDocumentFilter.PARAMETER_SYNTAX, document.getSyntax()); |
148 |
6335 |
revisionParameters.put(WikiDocumentFilter.PARAMETER_HIDDEN, document.isHidden()); |
149 |
|
|
150 |
6335 |
revisionParameters.put(WikiDocumentFilter.PARAMETER_REVISION_AUTHOR, document.getAuthor()); |
151 |
6335 |
revisionParameters.put(WikiDocumentFilter.PARAMETER_REVISION_COMMENT, document.getComment()); |
152 |
6335 |
revisionParameters.put(WikiDocumentFilter.PARAMETER_REVISION_DATE, document.getDate()); |
153 |
6335 |
revisionParameters.put(WikiDocumentFilter.PARAMETER_REVISION_MINOR, document.isMinorEdit()); |
154 |
|
|
155 |
6335 |
revisionParameters.put(WikiDocumentFilter.PARAMETER_CONTENT_AUTHOR, document.getContentAuthor()); |
156 |
6335 |
revisionParameters.put(WikiDocumentFilter.PARAMETER_CONTENT_DATE, document.getContentUpdateDate()); |
157 |
6335 |
revisionParameters.put(WikiDocumentFilter.PARAMETER_CONTENT, document.getContent()); |
158 |
|
|
159 |
6335 |
if (properties.isWithWikiDocumentContentHTML()) { |
160 |
0 |
try { |
161 |
0 |
XWikiContext xcontext = this.xcontextProvider.get(); |
162 |
|
|
163 |
0 |
revisionParameters.put(WikiDocumentFilter.PARAMETER_CONTENT_HTML, |
164 |
|
document.getRenderedContent(xcontext)); |
165 |
|
} catch (XWikiException e) { |
166 |
0 |
this.logger.error("Failed to render content of document [{}] as HTML", document.getDocumentReference(), |
167 |
|
e); |
168 |
|
} |
169 |
|
} |
170 |
|
|
171 |
6335 |
documentFilter.beginWikiDocumentRevision(document.getVersion(), revisionParameters); |
172 |
|
|
173 |
|
|
174 |
|
|
175 |
6335 |
if (properties.isWithWikiAttachments()) { |
176 |
183 |
List<XWikiAttachment> sortedAttachments = new ArrayList<XWikiAttachment>(document.getAttachmentList()); |
177 |
183 |
Collections.sort(sortedAttachments, new Comparator<XWikiAttachment>() |
178 |
|
{ |
|
|
| 21.4% |
Uncovered Elements: 11 (14) |
Complexity: 5 |
Complexity Density: 0.62 |
|
179 |
3 |
@Override... |
180 |
|
public int compare(XWikiAttachment attachement1, XWikiAttachment attachement2) |
181 |
|
{ |
182 |
3 |
if (attachement1 == null || attachement2 == null) { |
183 |
0 |
int result = 0; |
184 |
0 |
if (attachement1 != null) { |
185 |
0 |
result = -1; |
186 |
0 |
} else if (attachement2 != null) { |
187 |
0 |
result = 1; |
188 |
|
} |
189 |
0 |
return result; |
190 |
|
} |
191 |
3 |
return attachement1.getFilename().compareTo(attachement2.getFilename()); |
192 |
|
} |
193 |
|
}); |
194 |
|
|
195 |
183 |
for (XWikiAttachment attachment : sortedAttachments) { |
196 |
21 |
((XWikiAttachmentEventGenerator) this.attachmentEventGenerator).write(attachment, filter, |
197 |
|
documentFilter, properties); |
198 |
|
} |
199 |
|
} |
200 |
|
|
201 |
|
|
202 |
6335 |
if (properties.isWithWikiClass()) { |
203 |
6335 |
BaseClass xclass = document.getXClass(); |
204 |
6335 |
if (!xclass.getFieldList().isEmpty()) { |
205 |
1593 |
((BaseClassEventGenerator) this.classEventGenerator).write(xclass, filter, documentFilter, properties); |
206 |
|
} |
207 |
|
} |
208 |
|
|
209 |
|
|
210 |
6335 |
if (properties.isWithWikiObjects()) { |
211 |
6322 |
for (List<BaseObject> xobjects : document.getXObjects().values()) { |
212 |
5346 |
for (BaseObject xobject : xobjects) { |
213 |
8082 |
if (xobject != null) { |
214 |
7667 |
((BaseObjectEventGenerator) this.objectEventGenerator).write(xobject, filter, documentFilter, |
215 |
|
properties); |
216 |
|
} |
217 |
|
} |
218 |
|
} |
219 |
|
} |
220 |
|
|
221 |
|
|
222 |
|
|
223 |
6335 |
documentFilter.endWikiDocumentRevision(document.getVersion(), revisionParameters); |
224 |
|
} |
225 |
|
} |