1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 package org.openoffice.xmerge.converter.xml.sxw.aportisdoc; 25 26 import org.w3c.dom.Document; 27 28 import org.openoffice.xmerge.DocumentMerger; 29 import org.openoffice.xmerge.MergeException; 30 import org.openoffice.xmerge.ConverterCapabilities; 31 import org.openoffice.xmerge.converter.xml.sxw.SxwDocument; 32 import org.openoffice.xmerge.merger.DiffAlgorithm; 33 import org.openoffice.xmerge.merger.Difference; 34 import org.openoffice.xmerge.merger.NodeMergeAlgorithm; 35 import org.openoffice.xmerge.merger.Iterator; 36 import org.openoffice.xmerge.merger.diff.ParaNodeIterator; 37 import org.openoffice.xmerge.merger.diff.IteratorLCSAlgorithm; 38 import org.openoffice.xmerge.merger.merge.DocumentMerge; 39 import org.openoffice.xmerge.merger.merge.CharacterBaseParagraphMerge; 40 import org.openoffice.xmerge.util.Debug; 41 42 43 /** 44 * AportisDoc implementation of <code>DocumentMerger</code> 45 * for the {@link 46 * org.openoffice.xmerge.converter.xml.sxw.aportisdoc.PluginFactoryImpl 47 * PluginFactoryImpl}. 48 */ 49 public class DocumentMergerImpl implements DocumentMerger { 50 51 private ConverterCapabilities cc_; 52 private org.openoffice.xmerge.Document orig = null; 53 DocumentMergerImpl(org.openoffice.xmerge.Document doc, ConverterCapabilities cc)54 public DocumentMergerImpl(org.openoffice.xmerge.Document doc, ConverterCapabilities cc) { 55 cc_ = cc; 56 this.orig = doc; 57 } 58 merge(org.openoffice.xmerge.Document modifiedDoc)59 public void merge(org.openoffice.xmerge.Document modifiedDoc) throws MergeException { 60 61 SxwDocument wdoc1 = (SxwDocument) orig; 62 SxwDocument wdoc2 = (SxwDocument) modifiedDoc; 63 64 Document doc1 = wdoc1.getContentDOM(); 65 Document doc2 = wdoc2.getContentDOM(); 66 67 Iterator i1 = new ParaNodeIterator(cc_, doc1.getDocumentElement()); 68 Iterator i2 = new ParaNodeIterator(cc_, doc2.getDocumentElement()); 69 70 DiffAlgorithm diffAlgo = new IteratorLCSAlgorithm(); 71 72 // find out the paragrah level diffs 73 Difference[] diffTable = diffAlgo.computeDiffs(i1, i2); 74 75 if (Debug.isFlagSet(Debug.INFO)) { 76 Debug.log(Debug.INFO, "Diff Result: "); 77 78 for (int i = 0; i < diffTable.length; i++) { 79 Debug.log(Debug.INFO, diffTable[i].debug()); 80 } 81 } 82 83 // merge the paragraphs 84 NodeMergeAlgorithm charMerge = new CharacterBaseParagraphMerge(); 85 DocumentMerge docMerge = new DocumentMerge(cc_, charMerge); 86 87 Iterator result = null; 88 89 docMerge.applyDifference(i1, i2, diffTable); 90 } 91 } 92 93 94