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.merge;
25 
26 import org.w3c.dom.Node;
27 import org.w3c.dom.NodeList;
28 
29 import org.openoffice.xmerge.ConverterCapabilities;
30 import org.openoffice.xmerge.merger.NodeMergeAlgorithm;
31 
32 /**
33  *  This class extends the <code>DocumentMerge</code> class.
34  *  This class will merge two spreadsheet documents.
35  *  The main difference between this implementation and
36  *  <code>DocumentMerge</code>
37  *  is that this merge will try to maintain unsupported features by
38  *  examing the cell <code>node</code> objects one by one when it
39  *  removes a node from the original <code>Iterator</code>.
40  *
41  * @author smak
42  */
43 public final class SheetMerge extends DocumentMerge {
44 
45     /**
46      *  Constructor.
47      *
48      *  @param  cc     The <code>ConverterCapabilities</code>.
49      *  @param  merge  The <code>NodeMergeAlgorithm</code>.
50      */
SheetMerge(ConverterCapabilities cc, NodeMergeAlgorithm merge)51     public SheetMerge(ConverterCapabilities cc, NodeMergeAlgorithm merge) {
52         super(cc, merge);
53     }
54 
55 
56     /**
57      *  Remove specified <code>Node</code>.
58      *
59      *  @param  node  <code>Node</code> to remove.
60      */
removeNode(Node node)61     protected void removeNode(Node node) {
62 
63         clearRow(node);
64     }
65 
66 
67     /**
68      *  Clear the row corresponding to the <code>Node</code>
69      *
70      *  @param  node  <code>Node</code> containing the row to clear.
71      */
clearRow(Node node)72     private void clearRow(Node node) {
73         NodeList children = node.getChildNodes();
74         int numOfChildren = children.getLength();
75 
76         // clear all the cells under the row node but maintain any unsupported
77         // features
78         // TODO: we can actually check anything left after the clear up.
79         // if there is nothing left, then we can even delete the cell nodes
80         for (int i = 0; i < numOfChildren; i++) {
81             SheetUtil.emptyCell(cc_, children.item(i));
82         }
83     }
84 }
85 
86