1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package com.xpn.xwiki.doc.rcs; |
21 |
|
|
22 |
|
import java.util.ArrayList; |
23 |
|
import java.util.Arrays; |
24 |
|
import java.util.List; |
25 |
|
|
26 |
|
import org.slf4j.Logger; |
27 |
|
import org.slf4j.LoggerFactory; |
28 |
|
import org.suigeneris.jrcs.util.ToString; |
29 |
|
|
30 |
|
import com.xpn.xwiki.XWikiContext; |
31 |
|
import com.xpn.xwiki.XWikiException; |
32 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
@version |
39 |
|
@since |
40 |
|
|
|
|
| 77.2% |
Uncovered Elements: 13 (57) |
Complexity: 20 |
Complexity Density: 0.59 |
|
41 |
|
public class XWikiPatch |
42 |
|
{ |
43 |
|
|
44 |
|
private static final Logger LOGGER = LoggerFactory.getLogger(XWikiPatch.class); |
45 |
|
|
46 |
|
|
47 |
|
private String content; |
48 |
|
|
49 |
|
|
50 |
|
private boolean isDiff; |
51 |
|
|
52 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
53 |
13298 |
public XWikiPatch()... |
54 |
|
{ |
55 |
|
} |
56 |
|
|
57 |
|
|
58 |
|
@param |
59 |
|
@param |
60 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
61 |
150 |
public XWikiPatch(String content, boolean isDiff)... |
62 |
|
{ |
63 |
150 |
setContent(content); |
64 |
150 |
setDiff(isDiff); |
65 |
|
} |
66 |
|
|
67 |
|
|
68 |
|
@return |
69 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
70 |
20393 |
public String getContent()... |
71 |
|
{ |
72 |
20393 |
return this.content; |
73 |
|
} |
74 |
|
|
75 |
|
|
76 |
|
@param |
77 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
78 |
13830 |
public void setContent(String content)... |
79 |
|
{ |
80 |
13830 |
this.content = content; |
81 |
|
} |
82 |
|
|
83 |
|
|
84 |
|
@return |
85 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
86 |
32365 |
private boolean isContentDiff()... |
87 |
|
{ |
88 |
32365 |
return !this.content.startsWith("<"); |
89 |
|
} |
90 |
|
|
91 |
|
|
92 |
|
@return |
93 |
|
|
|
|
| 55.6% |
Uncovered Elements: 4 (9) |
Complexity: 3 |
Complexity Density: 0.6 |
|
94 |
25953 |
public boolean isDiff()... |
95 |
|
{ |
96 |
25953 |
if (this.content != null) { |
97 |
25953 |
if (this.isDiff != isContentDiff()) { |
98 |
0 |
LOGGER.warn("isDiff: Patch is inconsistent. Content and diff field are contradicting"); |
99 |
0 |
return isContentDiff(); |
100 |
|
} |
101 |
|
} |
102 |
25953 |
return this.isDiff; |
103 |
|
} |
104 |
|
|
105 |
|
|
106 |
|
@param |
107 |
|
|
|
|
| 60% |
Uncovered Elements: 4 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
108 |
13958 |
public void setDiff(boolean isDiff)... |
109 |
|
{ |
110 |
13958 |
if (this.content != null) { |
111 |
6412 |
if (isDiff != isContentDiff()) { |
112 |
0 |
LOGGER.warn("setDiff: Patch is inconsistent. Content and diff field are contradicting"); |
113 |
0 |
this.isDiff = isContentDiff(); |
114 |
0 |
return; |
115 |
|
} |
116 |
|
} |
117 |
13958 |
this.isDiff = isDiff; |
118 |
|
} |
119 |
|
|
120 |
|
|
121 |
|
|
122 |
|
|
123 |
|
@param |
124 |
|
@param |
125 |
|
@return |
126 |
|
@throws |
127 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
128 |
5752 |
public XWikiPatch setFullVersion(XWikiDocument version, XWikiContext context)... |
129 |
|
throws XWikiException |
130 |
|
{ |
131 |
5752 |
return setFullVersion(version.toXML(context)); |
132 |
|
} |
133 |
|
|
134 |
|
|
135 |
|
|
136 |
|
|
137 |
|
@param |
138 |
|
@return |
139 |
|
@throws |
140 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
141 |
5754 |
public XWikiPatch setFullVersion(String versionXml) throws XWikiException... |
142 |
|
{ |
143 |
5754 |
setContent(versionXml); |
144 |
5754 |
setDiff(false); |
145 |
5754 |
return this; |
146 |
|
} |
147 |
|
|
148 |
|
|
149 |
|
|
150 |
|
|
151 |
|
|
152 |
|
@param |
153 |
|
@param |
154 |
|
@param |
155 |
|
@return |
156 |
|
@throws |
157 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
158 |
0 |
public XWikiPatch setDiffVersion(XWikiDocument originalVersion, XWikiDocument newVersion,... |
159 |
|
XWikiContext context) throws XWikiException |
160 |
|
{ |
161 |
0 |
return setDiffVersion(originalVersion.toXML(context), newVersion.toXML(context), |
162 |
|
newVersion.getFullName()); |
163 |
|
} |
164 |
|
|
165 |
|
|
166 |
|
|
167 |
|
|
168 |
|
|
169 |
|
@param |
170 |
|
@param |
171 |
|
@param |
172 |
|
@return |
173 |
|
@throws |
174 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
175 |
379 |
public XWikiPatch setDiffVersion(String originalVersionXml, XWikiDocument newVersion,... |
176 |
|
XWikiContext context) throws XWikiException |
177 |
|
{ |
178 |
379 |
return setDiffVersion(originalVersionXml, newVersion.toXML(context), newVersion |
179 |
|
.getFullName()); |
180 |
|
} |
181 |
|
|
182 |
|
|
183 |
|
|
184 |
|
|
185 |
|
|
186 |
|
@param |
187 |
|
@param |
188 |
|
@param |
189 |
|
@return |
190 |
|
@throws |
191 |
|
|
|
|
| 66.7% |
Uncovered Elements: 2 (6) |
Complexity: 2 |
Complexity Density: 0.33 |
|
192 |
380 |
public XWikiPatch setDiffVersion(String originalVersionXml, String newVersionXml,... |
193 |
|
String docName) throws XWikiException |
194 |
|
{ |
195 |
380 |
try { |
196 |
|
|
197 |
380 |
setContent(XWikiPatchUtils.getDiff(newVersionXml, originalVersionXml)); |
198 |
380 |
setDiff(true); |
199 |
|
} catch (Exception e) { |
200 |
0 |
Object[] args = { docName }; |
201 |
0 |
throw new XWikiException(XWikiException.MODULE_XWIKI_DIFF, |
202 |
|
XWikiException.ERROR_XWIKI_DIFF_XML_ERROR, |
203 |
|
"Failed to create diff for doc {0}", |
204 |
|
e, |
205 |
|
args); |
206 |
|
} |
207 |
380 |
return this; |
208 |
|
} |
209 |
|
|
210 |
|
|
211 |
|
|
212 |
|
|
213 |
|
@param |
214 |
|
@throws |
215 |
|
|
|
|
| 87.5% |
Uncovered Elements: 1 (8) |
Complexity: 3 |
Complexity Density: 0.5 |
|
216 |
74 |
public void patch(List<String> origText) throws XWikiException... |
217 |
|
{ |
218 |
74 |
if (!isDiff()) { |
219 |
37 |
origText.clear(); |
220 |
37 |
origText.addAll( |
221 |
|
new ArrayList<String>(Arrays.asList(ToString.stringToArray(getContent())))); |
222 |
|
} else { |
223 |
37 |
try { |
224 |
37 |
XWikiPatchUtils.patch(origText, getContent()); |
225 |
|
} catch (Exception e) { |
226 |
0 |
throw new XWikiException(XWikiException.MODULE_XWIKI_DIFF, |
227 |
|
XWikiException.ERROR_XWIKI_DIFF_XML_ERROR, |
228 |
|
"Exception while patching", |
229 |
|
e); |
230 |
|
} |
231 |
|
} |
232 |
|
} |
233 |
|
} |