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.List; |
23 |
|
import java.util.StringTokenizer; |
24 |
|
|
25 |
|
import org.suigeneris.jrcs.diff.Diff; |
26 |
|
import org.suigeneris.jrcs.diff.DifferentiationFailedException; |
27 |
|
import org.suigeneris.jrcs.diff.PatchFailedException; |
28 |
|
import org.suigeneris.jrcs.diff.Revision; |
29 |
|
import org.suigeneris.jrcs.diff.delta.AddDelta; |
30 |
|
import org.suigeneris.jrcs.diff.delta.Chunk; |
31 |
|
import org.suigeneris.jrcs.diff.delta.DeleteDelta; |
32 |
|
import org.suigeneris.jrcs.rcs.InvalidFileFormatException; |
33 |
|
import org.suigeneris.jrcs.util.ToString; |
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
@version |
39 |
|
@since |
40 |
|
|
|
|
| 86.4% |
Uncovered Elements: 6 (44) |
Complexity: 11 |
Complexity Density: 0.38 |
|
41 |
|
public class XWikiPatchUtils |
42 |
|
{ |
43 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
44 |
0 |
private XWikiPatchUtils()... |
45 |
|
{ |
46 |
|
} |
47 |
|
|
48 |
|
|
49 |
|
@param |
50 |
|
@param |
51 |
|
@return |
52 |
|
@throws |
53 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
54 |
380 |
public static String getDiff(Object[] orig, Object[] rev) throws DifferentiationFailedException... |
55 |
|
{ |
56 |
380 |
return Diff.diff(orig, rev).toRCSString(); |
57 |
|
} |
58 |
|
|
59 |
|
|
60 |
|
@param |
61 |
|
@param |
62 |
|
@return |
63 |
|
@throws |
64 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
65 |
380 |
public static String getDiff(String orig, String rev) throws DifferentiationFailedException... |
66 |
|
{ |
67 |
380 |
return getDiff(ToString.stringToArray(orig), ToString.stringToArray(rev)); |
68 |
|
} |
69 |
|
|
70 |
|
|
71 |
|
@link |
72 |
|
|
73 |
|
@param |
74 |
|
@param@link |
75 |
|
@throws |
76 |
|
@throws |
77 |
|
|
|
|
| 83.9% |
Uncovered Elements: 5 (31) |
Complexity: 6 |
Complexity Density: 0.26 |
|
78 |
37 |
public static void patch(List<String> orig, String diff)... |
79 |
|
throws InvalidFileFormatException, PatchFailedException |
80 |
|
{ |
81 |
37 |
Revision revision = new Revision(); |
82 |
37 |
Object[] lines = ToString.stringToArray(diff); |
83 |
198 |
for (int it = 0; it < lines.length; it++) { |
84 |
161 |
String cmd = lines[it].toString(); |
85 |
161 |
if (cmd.length() == 0) { |
86 |
0 |
break; |
87 |
|
} |
88 |
|
|
89 |
161 |
java.util.StringTokenizer t = new StringTokenizer(cmd, "ad ", true); |
90 |
161 |
char action; |
91 |
161 |
int n; |
92 |
161 |
int count; |
93 |
|
|
94 |
161 |
try { |
95 |
161 |
action = t.nextToken().charAt(0); |
96 |
161 |
n = Integer.parseInt(t.nextToken()); |
97 |
|
|
98 |
161 |
t.nextToken(); |
99 |
161 |
count = Integer.parseInt(t.nextToken()); |
100 |
|
} catch (Exception e) { |
101 |
0 |
throw new InvalidFileFormatException("line:" + ":" + e.getClass().getName(), |
102 |
|
e); |
103 |
|
} |
104 |
|
|
105 |
161 |
if (action == 'd') { |
106 |
83 |
revision.addDelta(new DeleteDelta(new Chunk(n - 1, count))); |
107 |
78 |
} else if (action == 'a') { |
108 |
78 |
revision.addDelta(new AddDelta(n, new Chunk(getTextLines(lines, |
109 |
|
it + 1, it + 1 + count), 0, count, n - 1))); |
110 |
78 |
it += count; |
111 |
|
} else { |
112 |
0 |
throw new InvalidFileFormatException(); |
113 |
|
} |
114 |
|
} |
115 |
37 |
revision.applyTo(orig); |
116 |
|
} |
117 |
|
|
118 |
|
|
119 |
|
@param |
120 |
|
@param |
121 |
|
@param |
122 |
|
@return |
123 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
124 |
78 |
private static Object[] getTextLines(Object[] lines, int from, int to)... |
125 |
|
{ |
126 |
78 |
Object[] ret = new Object[to - from + 1]; |
127 |
164 |
for (int i = from; i < to; i++) { |
128 |
86 |
ret[i - from] = lines[i]; |
129 |
|
} |
130 |
78 |
return ret; |
131 |
|
} |
132 |
|
} |