LibreOffice Module xmerge (master)  1
SheetUtil.java
Go to the documentation of this file.
1 /*
2  * This file is part of the LibreOffice project.
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7  *
8  * This file incorporates work covered by the following license notice:
9  *
10  * Licensed to the Apache Software Foundation (ASF) under one or more
11  * contributor license agreements. See the NOTICE file distributed
12  * with this work for additional information regarding copyright
13  * ownership. The ASF licenses this file to you under the Apache
14  * License, Version 2.0 (the "License"); you may not use this file
15  * except in compliance with the License. You may obtain a copy of
16  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
17  */
18 
19 package org.openoffice.xmerge.merger.merge;
20 
21 import org.w3c.dom.Node;
22 import org.w3c.dom.Element;
23 import org.w3c.dom.NodeList;
24 import org.w3c.dom.NamedNodeMap;
25 
28 
32 public class SheetUtil {
33 
50  public static void emptyCell(ConverterCapabilities cc, Node node) {
51 
52  NamedNodeMap attrNodes = node.getAttributes();
53 
54  if (attrNodes != null) {
55 
56  // empty the first text:p node.
57  // Note: it's not necessary only string type cell contain text:p
58  // basically, all different type of cell will contain one
59  Element cell = (Element)node;
60 
61  // get the paragraph node list
62  NodeList paraNodes =
63  cell.getElementsByTagName(OfficeConstants.TAG_PARAGRAPH);
64 
65  Node firstParaNode = paraNodes.item(0);
66 
67  // remove the first paragraph element node
68  if (firstParaNode != null) {
69  Node parent = firstParaNode.getParentNode();
70  parent.removeChild(firstParaNode);
71  }
72 
73  // check all the attributes and remove those we supported in
74  // converter
75  // NOTE: for attribute list, refer to section 4.7.2 in specification
76  int len = attrNodes.getLength();
77 
78  for (int i = 0; i < len; ) {
79  Node attr = attrNodes.item(i);
80 
81  // when we hit the end of the attribute nodes, return
82  // it may happen sooner as we keep on removing nodes
83  if (attr == null) {
84  break;
85  }
86  // remove the supported attr except columns repeated attribute
88  attr.getNodeName()) &&
89  !attr.getNodeName().equals(
91 
92  attrNodes.removeNamedItem(attr.getNodeName());
93  } else {
94  i++;
95  }
96  }
97  }
98  }
99 }
boolean canConvertAttribute(String tag, String attribute)
Test to see if the device document format supports the tag attribute in question. ...
Utility methods to handle sheet XML tree.
Definition: SheetUtil.java:32
This interface contains constants for StarOffice XML tags, attributes (StarCalc cell types...
String TAG_TABLE_CELL
Element tag for table:table-cell.
int i
static void emptyCell(ConverterCapabilities cc, Node node)
Empty the content of a cell value.
Definition: SheetUtil.java:50
String ATTRIBUTE_TABLE_NUM_COLUMNS_REPEATED
Attribute tag for table:number-columns-repeated of element table:table-cell.
Provides interfaces for converting between two.
Definition: Convert.java:19