LibreOffice Module xmerge (master)  1
xslt/DocumentMergerImpl.java
Go to the documentation of this file.
1 /*
2  * This file is part of the LibreOffice project.
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7  *
8  * This file incorporates work covered by the following license notice:
9  *
10  * Licensed to the Apache Software Foundation (ASF) under one or more
11  * contributor license agreements. See the NOTICE file distributed
12  * with this work for additional information regarding copyright
13  * ownership. The ASF licenses this file to you under the Apache
14  * License, Version 2.0 (the "License"); you may not use this file
15  * except in compliance with the License. You may obtain a copy of
16  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
17  */
18 
19 package org.openoffice.xmerge.converter.xml.xslt;
20 
21 import org.w3c.dom.Document;
22 
35 
40 public class DocumentMergerImpl implements DocumentMerger {
41 
42  private final ConverterCapabilities cc_;
44 
46  cc_ = cc;
47  this.orig = doc;
48  }
49 
50  public void merge(org.openoffice.xmerge.Document modifiedDoc) throws MergeException {
51 
53  GenericOfficeDocument wdoc2 = (GenericOfficeDocument) modifiedDoc;
54 
55  Document doc1 = wdoc1.getContentDOM();
56  Document doc2 = wdoc2.getContentDOM();
57 
58  Iterator i1 = new ParaNodeIterator(cc_, doc1.getDocumentElement());
59  Iterator i2 = new ParaNodeIterator(cc_, doc2.getDocumentElement());
60 
61  DiffAlgorithm diffAlgo = new IteratorLCSAlgorithm();
62 
63  // find out the paragraph level diffs
64  Difference[] diffTable = diffAlgo.computeDiffs(i1, i2);
65 
66  if (Debug.isFlagSet(Debug.INFO)) {
67  Debug.log(Debug.INFO, "Diff Result: ");
68 
69  for (int i = 0; i < diffTable.length; i++) {
70  Debug.log(Debug.INFO, diffTable[i].debug());
71  }
72  }
73 
74  // merge the paragraphs
76  DocumentMerge docMerge = new DocumentMerge(cc_, charMerge);
77 
78  docMerge.applyDifference(i1, i2, diffTable);
79  }
80 }
static final int INFO
Informational messages.
Definition: Debug.java:42
DocumentMergerImpl(org.openoffice.xmerge.Document doc, ConverterCapabilities cc)
Provides general purpose utilities.
static void log(int flag, String msg)
Log message based on the flag type.
Definition: Debug.java:205
int i
static boolean isFlagSet(int f)
Checks if flag is set.
Definition: Debug.java:176
String debug()
Display debug information.
Provides implementations for the MergeAlgorithm interface, the NodeMergeAlgorithm interface...
This is the difference algorithm interface.
void applyDifference(Iterator orgSeq, Iterator modSeq, Difference[] differences)
This method is to merge the difference to an.
This is an interface for a MergeAlgorithm to merge two.
Provides implementations for the Iterator interface and related support classes.
Provides interfaces for converting between two.
Definition: Convert.java:19
This class is used for logging debug messages.
Definition: Debug.java:39
void merge(org.openoffice.xmerge.Document modifiedDoc)
This is an interface used by the DiffAlgorithm and MergeAlgorithm to access a.
Definition: Iterator.java:27