19package org.openoffice.xmerge.merger.merge;
22import org.w3c.dom.Node;
47 public void merge(Node orgPara, Node modPara) {
59 System.out.println(
"Diff Result: ");
60 for (
int i = 0;
i < diffResult.length;
i++) {
71 List<TextNodeEntry> orgNodeList = orgParser.
getNodeList();
73 int numNode = orgNodeList.size();
75 for (
int i = 0;
i < numNode;
i++) {
78 int orgDiffCount = diffCount;
84 for (; diffCount < diffs.length; diffCount++) {
87 " of " + diffs.length);
90 diffCount +
"> orgDiffCount <" + orgDiffCount +
">");
94 if (diffs[diffCount].getOrgPosition() > orgTextNode.
endChar() &&
100 if (diffs[diffCount].getOrgPosition()
104 }
else if (diffs[diffCount].getOperation()
113 "> final orgDiffCount <" + orgDiffCount +
">");
116 if (diffCount > orgDiffCount) {
120 orgTextNode.
node().getNodeName() +
">");
122 orgTextNode.
node().getNodeValue() +
">");
124 orgTextNode.
startChar() +
"> TextNode end char <" +
128 coreMerge(orgDiffCount, diffCount, diffs,
129 modParser, orgTextNode, extraChar);
138 Node orgNode = orgTextNode.
node();
143 if (orgNode.getNodeValue() !=
null)
144 tmpString = orgNode.getNodeValue();
148 char[] orgNodeText = tmpString.toCharArray();
151 if (orgNodeText.length + extraChar > 0)
152 newNodeText =
new char[orgNodeText.length + extraChar];
154 newNodeText =
new char[0];
156 int orgTextPosition = orgTextNode.
startChar();
157 int newTextPosition = 0;
158 int unChangedTextLength = 0;
160 char[] cacheCharArray =
new char[endDiffNum - startDiffNum];
163 int lastDiffPosition = -1;
166 for (
int j = startDiffNum; j < endDiffNum; j++) {
169 if (diffs[j].getOrgPosition() > orgTextPosition) {
171 if (cacheLength > 0) {
172 System.arraycopy(cacheCharArray, 0,
173 newNodeText, newTextPosition, cacheLength);
174 newTextPosition += cacheLength;
177 lastDiffPosition = -1;
186 System.arraycopy(orgNodeText,
187 orgTextPosition - orgTextNode.
startChar(),
188 newNodeText, newTextPosition,
189 unChangedTextLength);
190 orgTextPosition += unChangedTextLength;
191 newTextPosition += unChangedTextLength;
200 if (cacheLength > 0) {
201 System.arraycopy(cacheCharArray, 0,
202 newNodeText, newTextPosition, cacheLength);
203 newTextPosition += cacheLength;
206 lastDiffPosition = -1;
220 if (lastDiffOperation != diffs[j].getOperation() ||
227 if (cacheLength > 0) {
228 System.arraycopy(cacheCharArray, 0, newNodeText,
229 newTextPosition, cacheLength);
230 newTextPosition += cacheLength;
240 cacheCharArray[cacheLength] =
243 lastDiffOperation = diffs[j].getOperation();
244 lastDiffPosition = diffs[j].getOrgPosition();
255 if (cacheLength > 0) {
256 System.arraycopy(cacheCharArray, 0, newNodeText,
257 newTextPosition, cacheLength);
258 newTextPosition += cacheLength;
263 int orgStartPosition = orgTextNode.
startChar();
264 if (orgNodeText.length + orgStartPosition > orgTextPosition) {
265 unChangedTextLength = orgNodeText.length + orgStartPosition
267 System.arraycopy(orgNodeText, orgTextPosition - orgStartPosition,
268 newNodeText, newTextPosition,
269 unChangedTextLength);
276 if (endDiffNum > startDiffNum) {
278 orgNode.setNodeValue(newString);
This is the Difference basic unit.
int getOrgPosition()
Get the original Iterator position.
String debug()
Display debug information.
static final int CHANGE
Change operation.
int getModPosition()
Get the modified Iterator position.
static final int DELETE
Delete operation.
static final int UNCHANGE
Unchange operation (i.e.
int getOperation()
Get the operation of the Difference.
static final int ADD
Add operation.
This is an implementations of DiffAlgorithm interface which will difference char arrays.
Difference[] computeDiffs(char[] orgSeq, char[] modSeq)
Return an Difference array.
This is a parser to return a character array for difference purpose.
char[] getCharArray()
Returns the character array representation of the text.
List< TextNodeEntry > getNodeList()
Returns the Node pointer with the given character position.
A small class to hold the start/end character position and the Node pointer in a text Node.
int endChar()
Returns the end character.
int startChar()
Returns the start character.
Node node()
Returns the Node.
This is an implementation of the NodeMergeAlgorithm interface.
void merge(Node orgPara, Node modPara)
Merge two paragraphs Node by using Longest Common Subsequence (LCS) character algorithm defined in Ch...
void applyDifference(CharacterParser orgParser, CharacterParser modParser, Difference[] diffs)
void coreMerge(int startDiffNum, int endDiffNum, Difference[] diffs, CharacterParser modParser, TextNodeEntry orgTextNode, int extraChar)
This class is used for logging debug messages.
static final int INFO
Informational messages.
static void log(int flag, String msg)
Log message based on the flag type.
This is an interface for a MergeAlgorithm to merge two Node objects.
Provides implementations for the Iterator interface and related support classes.
The DiffAlgorithm and MergeAlgorithm are used to provide the merge capabilities of this project.
Provides general purpose utilities.
Provides interfaces for converting between two Document formats, and supports a "merge" interface for...