LibreOffice Module xmerge (master) 1
NameDefinition.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
19package org.openoffice.xmerge.converter.xml.sxc;
20
21import org.w3c.dom.Node;
22import org.w3c.dom.Element;
23import org.w3c.dom.NamedNodeMap;
24
28
35public class NameDefinition implements OfficeConstants {
36
37 private String name; // name which identifies the definition
38 private String definition; // the definition itself
39 private String baseCellAddress; // the basecelladdress
40 private boolean rangeType = false; // true if definition of type range
41 private boolean expressionType = false; // true if definition of type expression
42
46 public NameDefinition() {
47 }
48
54 public NameDefinition(Node root) {
55 readNode(root);
56 }
57
67 public NameDefinition(String name, String definition, String
68 baseCellAddress, boolean rangeType, boolean expressionType ) {
69 this.name = name;
70 this.definition = definition;
71 this.baseCellAddress = baseCellAddress;
72 this.rangeType = rangeType;
73 this.expressionType = expressionType;
74 }
75
81 private String getName() {
82 return name;
83 }
84
90 public void setDefinition(String newDefinition) {
91 definition = newDefinition;
92 }
93
100 return definition;
101 }
102
109 return baseCellAddress;
110 }
111
117 private boolean isExpressionType() {
118 return expressionType;
119 }
120
126 private boolean isRangeType() {
127 return rangeType;
128 }
129
136 public void writeNode(org.w3c.dom.Document doc, Node root) {
137
138 if(isRangeType()) {
139
140 Debug.log(Debug.TRACE, "Found Range Name : " + getName());
141 Element namedRangeElement = doc.createElement(TAG_TABLE_NAMED_RANGE);
142 namedRangeElement.setAttribute(ATTRIBUTE_TABLE_NAME, getName());
143 namedRangeElement.setAttribute(ATTRIBUTE_TABLE_BASE_CELL_ADDRESS, getBaseCellAddress());
144 namedRangeElement.setAttribute(ATTRIBUTE_TABLE_CELL_RANGE_ADDRESS, getDefinition());
145 root.appendChild(namedRangeElement);
146 } else if (isExpressionType()) {
147
148 Debug.log(Debug.TRACE, "Found Expression Name : " + getName());
149 Element namedExpressionElement = doc.createElement(TAG_TABLE_NAMED_EXPRESSION);
150 namedExpressionElement.setAttribute(ATTRIBUTE_TABLE_NAME, getName());
151 namedExpressionElement.setAttribute(ATTRIBUTE_TABLE_BASE_CELL_ADDRESS,getBaseCellAddress());
152 namedExpressionElement.setAttribute(ATTRIBUTE_TABLE_EXPRESSION, getDefinition());
153 root.appendChild(namedExpressionElement);
154 } else {
155
156 Debug.log(Debug.TRACE, "Unknown Name Definition : " + getName());
157 }
158 }
159
165 private void readNode(Node root) {
166
167 String nodeName = root.getNodeName();
168 NamedNodeMap cellAtt = root.getAttributes();
169
170 if (nodeName.equals(TAG_TABLE_NAMED_RANGE)) {
171
172 Node tableNameNode =
173 cellAtt.getNamedItem(ATTRIBUTE_TABLE_NAME);
174 Node tableBaseCellAddress =
175 cellAtt.getNamedItem(ATTRIBUTE_TABLE_BASE_CELL_ADDRESS);
176 Node tableCellRangeAddress =
177 cellAtt.getNamedItem(ATTRIBUTE_TABLE_CELL_RANGE_ADDRESS);
178 Debug.log(Debug.TRACE,"Named-range : " + tableNameNode.getNodeValue());
179 // Create a named-range name definition
180 name = tableNameNode.getNodeValue();
181 definition = tableCellRangeAddress.getNodeValue();
182 baseCellAddress = tableBaseCellAddress.getNodeValue();
183 expressionType = true;
184 rangeType = false;
185
186 } else if (nodeName.equals(TAG_TABLE_NAMED_EXPRESSION)) {
187
188 Node tableNameNode =
189 cellAtt.getNamedItem(ATTRIBUTE_TABLE_NAME);
190 Node tableBaseCellAddress =
191 cellAtt.getNamedItem(ATTRIBUTE_TABLE_BASE_CELL_ADDRESS);
192 Node tableExpression=
193 cellAtt.getNamedItem(ATTRIBUTE_TABLE_EXPRESSION);
194 Debug.log(Debug.TRACE,"Named-expression: " + tableNameNode.getNodeValue());
195 // Create a named-range name definition
196 name = tableNameNode.getNodeValue();
197 definition = tableExpression.getNodeValue();
198 baseCellAddress = tableBaseCellAddress.getNodeValue();
199 expressionType = false;
200 rangeType = true;
201 } else {
202 Debug.log(Debug.TRACE, "<OTHERS " + XmlUtil.getNodeInfo(root) + " />");
203 }
204 }
205}
This is a class to define a Name Definition structure.
void writeNode(org.w3c.dom.Document doc, Node root)
Writes out a content.xml entry for this NameDefinition object.
String getBaseCellAddress()
Returns the base Cell address.
NameDefinition(String name, String definition, String baseCellAddress, boolean rangeType, boolean expressionType)
Constructor for a NameDefinition.
NameDefinition()
Default Constructor for a NameDefinition.
void readNode(Node root)
Reads document settings from xml and inits Settings variables.
String getDefinition()
Returns the definition itself.
boolean isRangeType()
Tests if definition is of type range.
boolean isExpressionType()
Tests if definition is of type expression.
void setDefinition(String newDefinition)
Sets the definition.
String getName()
Returns Name of the definition.
NameDefinition(Node root)
Constructor that takes a Node to build a NameDefinition.
This class is used for logging debug messages.
Definition: Debug.java:39
static final int TRACE
Trace messages.
Definition: Debug.java:46
static void log(int flag, String msg)
Log message based on the flag type.
Definition: Debug.java:205
Class containing static utility methods for handling XML trees.
Definition: XmlUtil.java:30
static String getNodeInfo(Node node)
Returns the name and type of an XML DOM Node.
Definition: XmlUtil.java:120
This interface contains constants for StarOffice XML tags, attributes (StarCalc cell types,...
String ATTRIBUTE_TABLE_BASE_CELL_ADDRESS
Attribute tag for table:base-cell-address of element table:named-range.
String ATTRIBUTE_TABLE_CELL_RANGE_ADDRESS
Attribute tag for table:cell-range-address of element table:named-range.
String TAG_TABLE_NAMED_RANGE
Element tag for table:named-range.
String TAG_TABLE_NAMED_EXPRESSION
Element tag for table:named-expression.
String ATTRIBUTE_TABLE_EXPRESSION
Attribute tag for table:expression of element table:named-range.
String ATTRIBUTE_TABLE_NAME
Attribute tag for table:name of element table:table.
Document and PluginFactory implementations for XML based formats.
Provides general purpose utilities.
Provides interfaces for converting between two Document formats, and supports a "merge" interface for...
Definition: Convert.java:19