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