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.merger.diff; 25 26 import org.w3c.dom.Node; 27 import org.w3c.dom.Element; 28 29 import org.openoffice.xmerge.ConverterCapabilities; 30 import org.openoffice.xmerge.converter.xml.OfficeConstants; 31 import org.openoffice.xmerge.util.Resources; 32 33 34 /** 35 * <p>This is an implementations of the <code>Iterator</code> interface. 36 * It will traverse the tree and find cell <code>Node</code> sequences.</p> 37 * 38 * <p>Note: Once the XML Tree is parsed, then the <code>Iterator</code> 39 * will be a snap shot of that tree. That means even the tree is 40 * modified later, than the cached paragraph <code>Node</code> list will 41 * not be updated accordingly. For this reason and for performance reasons 42 * this <code>Iterator</code> does not support any operation methods such 43 * as insert, remove or replace. The main purpose of this 44 * <code>Iterator</code> is to be used with difference, not with merge.</p> 45 * 46 * @author smak 47 */ 48 public final class CellNodeIterator extends NodeIterator { 49 50 private Resources res = Resources.getInstance(); 51 52 // can be expanded to an array in the future, not necessary right now 53 private static final String SUPPORTED_TAG1 = OfficeConstants.TAG_TABLE_CELL; 54 55 /** 56 * The standard constructor. 57 * 58 * @param cc The <code>ConverterCapabilities</code>. 59 * @param node The initial root <code>Node</code>. 60 */ CellNodeIterator(ConverterCapabilities cc, Node node)61 public CellNodeIterator(ConverterCapabilities cc, Node node) { 62 super(cc, node); 63 } 64 65 66 /** 67 * Overwrite the parent <code>nodeSupported</code> method. Only cell 68 * <code>Node</code> objects are supported. 69 * 70 * @param node The <code>Node</code> to check. 71 * 72 * @return true if the <code>Node</code> is supported, false otherwise. 73 */ nodeSupported(Node node)74 protected boolean nodeSupported(Node node) { 75 76 // can use an array later to check all possible tags for 77 // future expansion 78 if (node.getNodeType() == Node.ELEMENT_NODE && 79 node.getNodeName().equals(SUPPORTED_TAG1)) { 80 return true; 81 } else { 82 return false; 83 } 84 } 85 86 childrenEqual(Node node1, Node node2)87 protected boolean childrenEqual(Node node1, Node node2) { 88 89 boolean equal = false; 90 91 if (node1.hasChildNodes() && node2.hasChildNodes()) { 92 Element cell1 = (Element)node1; 93 Element cell2 = (Element)node2; 94 95 // only need compare the first <text:p> children node, don't want 96 // to compare any non-supported features 97 // TODO: need to confirm whether all the text string is the 98 // first <text:p>, though I checked with the openoffice 619 build 99 Node paraNode1 = cell1.getElementsByTagName( 100 OfficeConstants.TAG_PARAGRAPH).item(0); 101 Node paraNode2 = cell2.getElementsByTagName( 102 OfficeConstants.TAG_PARAGRAPH).item(0); 103 104 equal = super.compareNode(paraNode1, paraNode2); 105 } 106 107 return equal; 108 } 109 } 110 111