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 28 import org.openoffice.xmerge.converter.xml.OfficeConstants; 29 30 31 /** 32 * <p>This is an implementation of the <code>Iterator</code> interface. 33 * It will traverse the tree and find text/space/tab <code>Node</code> 34 * sequences.</p> 35 * 36 * <p>Note: Once the XML Tree is parsed, then the <code>Iterator</code> 37 * will be a snap shot of that tree. That means even the tree is modified 38 * later, than the cached paragraph <code>Node</code> list will not be 39 * updated accordingly. For this reason and for performance reasons 40 * this <code>Iterator</code> does not support any operation methods 41 * such as insert, remove or replace. The main purpose of this 42 * <code>Iterator</code> is to be used with difference, not with merge.</p> 43 * 44 * @author smak 45 */ 46 public final class TextNodeIterator extends NodeIterator { 47 48 /** 49 * Standard constructor. 50 * 51 * @param node The initial root <code>Node</code>. 52 */ TextNodeIterator(Node node)53 public TextNodeIterator(Node node) { 54 super(null, node); 55 } 56 57 /** 58 * Overwrite the parent <code>nodeSupported</code> method. Only text 59 * <code>Node</code> objects are supported. 60 * 61 * @param node <code>Node</code> to check. 62 * 63 * @return true if the <code>Node</code> is supported, false 64 * otherwise. 65 */ nodeSupported(Node node)66 protected boolean nodeSupported(Node node) { 67 68 // can use an array later to check all possible tags for 69 // future expansion 70 if (node.getNodeType() == Node.TEXT_NODE || 71 node.getNodeName().equals(OfficeConstants.TAG_SPACE) || 72 node.getNodeName().equals(OfficeConstants.TAG_TAB_STOP) || 73 node.getNodeName().equals(OfficeConstants.TAG_LINE_BREAK)) { 74 return true; 75 } else { 76 return false; 77 } 78 } 79 } 80 81