LibreOffice Module xmerge (master) 1
RowStyle.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.NodeList;
22import org.w3c.dom.Node;
23import org.w3c.dom.NamedNodeMap;
24import org.w3c.dom.Element;
25
30
34public class RowStyle extends Style implements Cloneable {
35
36 private int rowHeight = 255;
46 public RowStyle(Node node, StyleCatalog sc) {
47 super(node, sc);
48
49 // Run through the attributes of this node, saving
50 // the ones we're interested in.
51 NamedNodeMap attrNodes = node.getAttributes();
52 if (attrNodes != null) {
53 int len = attrNodes.getLength();
54 for (int i = 0; i < len; i++) {
55 Node attr = attrNodes.item(i);
56 handleAttribute(attr.getNodeName(), attr.getNodeValue());
57 }
58 }
59
60 // Look for children. Only ones we care about are "style:properties"
61 // nodes. If any are found, recursively traverse them, passing
62 // along the style element to add properties to.
63 if (!node.hasChildNodes()) {
64 return;
65 }
66 NodeList children = node.getChildNodes();
67 int len = children.getLength();
68 for (int i = 0; i < len; i++) {
69 Node child = children.item(i);
70 String nodeName = child.getNodeName();
71 if (nodeName.equals("style:properties")) {
72 NamedNodeMap childAttrNodes = child.getAttributes();
73 if (childAttrNodes != null) {
74 int nChildAttrNodes = childAttrNodes.getLength();
75 for (int j = 0; j < nChildAttrNodes; j++) {
76 Node attr = childAttrNodes.item(j);
77 handleAttribute(attr.getNodeName(),
78 attr.getNodeValue());
79 }
80 }
81 }
82 }
83 }
84
97 public RowStyle(String name, String family, String parent,int rowHeight, StyleCatalog sc) {
98 super(name, family, parent, sc);
99 this.rowHeight=rowHeight;
100 }
101
107 public int getRowHeight() {
108 return rowHeight;
109 }
110
116 private void setRowHeight(int RowHeight) {
117 this.rowHeight = RowHeight;
118 }
119
127 private int parseRowHeight(String value) {
129 }
130
137 private void handleAttribute(String attr, String value) {
138
139 if (attr.equals("style:row-height")) {
141 }
142 else {
143 Debug.log(Debug.INFO, "RowStyle Unhandled: " + attr + "=" + value);
144 }
145 }
146
156 @Override
158 // Create a new object to return, which is a clone of this one.
159 RowStyle resolved = null;
160 try {
161 resolved = (RowStyle)this.clone();
162 } catch (Exception e) {
163 Debug.log(Debug.ERROR, "Can't clone", e);
164 }
165
166 // Look up the parentStyle. (If there is no style catalog
167 // specified, we can't do any lookups.)
168 RowStyle parentStyle = null;
169 if (sc != null) {
170 if (parent != null) {
171 parentStyle = (RowStyle)sc.lookup(parent, family, null,
172 this.getClass());
173 if (parentStyle == null)
174 Debug.log(Debug.ERROR, "parent style lookup of "
175 + parent + " failed!");
176 else
177 parentStyle = (RowStyle)parentStyle.getResolved();
178
179 } else if (!name.equals("DEFAULT_STYLE")) {
180 parentStyle = (RowStyle)sc.lookup("DEFAULT_STYLE", null,
181 null, this.getClass());
182 }
183 }
184
185 // If we found a parent, for any attributes which we don't have
186 // set, try to get the values from the parent.
187 if (parentStyle != null) {
188 parentStyle = (RowStyle)parentStyle.getResolved();
189
190 if ((rowHeight == 0) && (parentStyle.getRowHeight() != 0))
191 resolved.setRowHeight(parentStyle.getRowHeight());
192 }
193 return resolved;
194 }
195
206 @Override
207 public Node createNode(org.w3c.dom.Document parentDoc, String name) {
208 Element node = parentDoc.createElement(name);
209 writeAttributes(node);
210 return node;
211 }
212
222 @Override
223 public boolean isSubset(Style style) {
224 if (style.getClass() != this.getClass())
225 return false;
226 RowStyle tStyle = (RowStyle)style;
227
228 return rowHeight == tStyle.getRowHeight();
229 }
230
237 private void writeAttributes(Element node) {
238
239 if(rowHeight!=0) {
240 String height = TwipsConverter.twips2cm(rowHeight) + "cm";
241 node.setAttribute("style:row-height", height);
242 }
243 }
244}
A StyleCatalog holds a collection of Style objects.
An object of class Style represents a style in an OpenOffice document.
Definition: Style.java:34
String parent
Parent of the Style.
Definition: Style.java:41
String family
Family of the Style.
Definition: Style.java:39
String name
Name of the Style.
Definition: Style.java:37
Represents a text Style in an OpenOffice document.
Definition: RowStyle.java:34
void setRowHeight(int RowHeight)
Sets the height of this row.
Definition: RowStyle.java:116
int parseRowHeight(String value)
Parse a rowheight in the form "1.234cm" to twips.
Definition: RowStyle.java:127
RowStyle(Node node, StyleCatalog sc)
Constructor for use when going from DOM to client device format.
Definition: RowStyle.java:46
void handleAttribute(String attr, String value)
Set an attribute.
Definition: RowStyle.java:137
void writeAttributes(Element node)
Write this Style object's attributes to a Node in the Document.
Definition: RowStyle.java:237
Style getResolved()
Return a Style object corresponding to this one, but with all of the inherited information from paren...
Definition: RowStyle.java:157
int getRowHeight()
Returns the height of this row.
Definition: RowStyle.java:107
Node createNode(org.w3c.dom.Document parentDoc, String name)
Create a new Node in the Document, and write this Style to it.
Definition: RowStyle.java:207
RowStyle(String name, String family, String parent, int rowHeight, StyleCatalog sc)
Constructor for use when going from client device format to DOM.
Definition: RowStyle.java:97
boolean isSubset(Style style)
Return true if style specifies as much or less than this Style, and nothing it specifies contradicts ...
Definition: RowStyle.java:223
This class is used for logging debug messages.
Definition: Debug.java:39
static final int INFO
Informational messages.
Definition: Debug.java:42
static void log(int flag, String msg)
Log message based on the flag type.
Definition: Debug.java:205
static final int ERROR
Error messages.
Definition: Debug.java:44
Helper class providing static methods to convert data to/from twips.
static int convert2twips(String value, int defaultValue)
Convert String to twips.
static float twips2cm(int value)
Convert from twips to cm's.
T * clone(T *const other)
Any value
@ Exception
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