LibreOffice Module xmerge (master) 1
BookSettings.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 java.util.ArrayList;
22
26import org.w3c.dom.Element;
27import org.w3c.dom.NamedNodeMap;
28import org.w3c.dom.Node;
29import org.w3c.dom.NodeList;
30
35public class BookSettings implements OfficeConstants {
36
38 private org.w3c.dom.Document settings = null;
39
40 private boolean hasColumnRowHeaders = true;
41 private String activeSheet = "";
42 private ArrayList<SheetSettings> worksheetSettings
43 = new ArrayList<SheetSettings>();
44
52 public BookSettings(Node root) {
53 readNode(root);
54 }
55
61 public BookSettings(ArrayList<SheetSettings> worksheetSettings) {
62 this.worksheetSettings = worksheetSettings;
63 }
64
71 this.hasColumnRowHeaders = hasColumnRowHeaders;
72 }
73
79 public ArrayList<SheetSettings> getSheetSettings() {
80 return worksheetSettings;
81 }
82
89 return activeSheet;
90 }
91
97 public void setActiveSheet(String activeSheet) {
98 this.activeSheet = activeSheet;
99 }
100
109 private void addConfigItem(Node root, String attribute, String type,
110 String value) {
111
112 Element configItem = settings.createElement(TAG_CONFIG_ITEM);
113 configItem.setAttribute(ATTRIBUTE_CONFIG_NAME, attribute);
114 configItem.setAttribute(ATTRIBUTE_CONFIG_TYPE, type);
115
116 configItem.appendChild(settings.createTextNode(value));
117
118 root.appendChild(configItem);
119 }
120
127 public void writeNode(org.w3c.dom.Document settings, Node root) {
128
129 this.settings = settings;
130 Element configItemMapNamed = settings.createElement(TAG_CONFIG_ITEM_MAP_NAMED);
131 configItemMapNamed.setAttribute(ATTRIBUTE_CONFIG_NAME, "Tables");
133 s.writeNode(settings, configItemMapNamed);
134 }
135 addConfigItem(root, "ActiveTable", "string", activeSheet);
136 String booleanValue = Boolean.toString(hasColumnRowHeaders);
137 addConfigItem(root, "HasColumnRowHeaders", "boolean", booleanValue);
138 root.appendChild(configItemMapNamed);
139 }
140
147 private void addAttribute(String name, String value) {
148 if(name.equals("ActiveTable")) {
150 } else if(name.equals("HasColumnRowHeaders")) {
151 hasColumnRowHeaders = Boolean.parseBoolean(value);
152 }
153 }
154
160 private void readNode(Node root) {
161
162 if (root.hasChildNodes()) {
163
164 NodeList nodeList = root.getChildNodes();
165 int len = nodeList.getLength();
166 for (int i = 0; i < len; i++) {
167 Node child = nodeList.item(i);
168
169 if (child.getNodeType() == Node.ELEMENT_NODE) {
170 String nodeName = child.getNodeName();
171
172 if (nodeName.equals(TAG_CONFIG_ITEM)) {
173
174 NamedNodeMap cellAtt = child.getAttributes();
175
176 Node configNameNode =
177 cellAtt.getNamedItem(ATTRIBUTE_CONFIG_NAME);
178
179 String name = configNameNode.getNodeValue();
180 NodeList nodeList2 = child.getChildNodes();
181 int len2 = nodeList2.getLength();
182 String s = "";
183 for (int j = 0; j < len2; j++) {
184 Node child2 = nodeList2.item(j);
185 if (child2.getNodeType() == Node.TEXT_NODE) {
186 s = child2.getNodeValue();
187 }
188 }
189 addAttribute(name, s);
190
191 } else if (nodeName.equals(TAG_CONFIG_ITEM_MAP_NAMED)) {
192
193 readNode(child);
194
195 } else if (nodeName.equals(TAG_CONFIG_ITEM_MAP_ENTRY)) {
196
197 SheetSettings s = new SheetSettings(child);
198 worksheetSettings.add(s);
199
200 } else {
201
202 Debug.log(Debug.TRACE, "<OTHERS " + XmlUtil.getNodeInfo(child) + " />");
203 }
204 }
205 }
206 }
207 }
208}
This is a class representing the different attributes for a worksheet contained in settings....
void readNode(Node root)
Reads document settings from xml and inits SheetSettings variables.
BookSettings(Node root)
Constructor for a BookSettings.
void addConfigItem(Node root, String attribute, String type, String value)
Adds an XML entry for a particular setting.
void setColumnRowHeaders(boolean hasColumnRowHeaders)
Set the flag indicating whether we have row/column headers.
void writeNode(org.w3c.dom.Document settings, Node root)
Writes out a settings.xml entry for this BookSettings object.
org.w3c.dom.Document settings
A w3c Document.
BookSettings(ArrayList< SheetSettings > worksheetSettings)
Constructor for a BookSettings.
void setActiveSheet(String activeSheet)
Sets the active sheet name.
String getActiveSheet()
Gets the active sheet name.
ArrayList< SheetSettings > getSheetSettings()
Gets the Vector of SheetSettings.
void addAttribute(String name, String value)
Sets a variable based on a String value read from XML.
This is a class representing the different attributes for a worksheet contained in settings....
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
Any value
const char * name
This interface contains constants for StarOffice XML tags, attributes (StarCalc cell types,...
String ATTRIBUTE_CONFIG_NAME
Attribute tag for config:name of element config:config-item.
String TAG_CONFIG_ITEM
Element tag for config:config-item.
String TAG_CONFIG_ITEM_MAP_ENTRY
Element tag for config:config-item-map-entry.
String ATTRIBUTE_CONFIG_TYPE
Attribute tag for config:type of element config:config-item.
String TAG_CONFIG_ITEM_MAP_NAMED
Element tag for config:config-item-map-named.
int i
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
sal_Int32 attribute
ResultType type