/************************************************************************ * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * Copyright 2000, 2010 Oracle and/or its affiliates. * * OpenOffice.org - a multi-platform office productivity suite * * This file is part of OpenOffice.org. * * OpenOffice.org is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License version 3 * only, as published by the Free Software Foundation. * * OpenOffice.org is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License version 3 for more details * (a copy is included in the LICENSE file that accompanied this code). * * You should have received a copy of the GNU Lesser General Public License * version 3 along with OpenOffice.org. If not, see * * for a copy of the LGPLv3 License. * ************************************************************************/ package org.openoffice.xmerge.converter.xml; import org.w3c.dom.NodeList; import org.w3c.dom.Node; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Element; import org.openoffice.xmerge.Document; import org.openoffice.xmerge.ConverterCapabilities; import org.openoffice.xmerge.converter.xml.OfficeDocument; import java.io.IOException; import org.openoffice.xmerge.converter.xml.sxw.SxwDocument; /** * An object of class Style represents a style * in an OpenOffice document. In practice subclasses of this * Style, such as TextStyle, * ParaStyle are used. * * @author David Proulx * @see TextStyle, * ParaStyle */ public class Style { /** Name of the Style. */ protected String name = null; /** Family of the Style. */ protected String family = null; /** Parent of the Style. */ protected String parent = null; /** * A reference to the StyleCatalog to be used for * looking up ancestor Style objects. */ protected StyleCatalog sc; /** * Constructor for use when going from DOM to client device format. * * @param node A style:style or style:default-style * Node from the document being parsed. * No checking of Node is done, so if it * is not of the proper type the results will be * unpredictable. * @param sc The StyleCatalog, which is used for * looking up ancestor Style objects. */ public Style(Node node, StyleCatalog sc) { this.sc = sc; // Run through the attributes of this node, saving // the ones we're interested in. if (node.getNodeName().equals("style:default-style")) name = "DEFAULT_STYLE"; NamedNodeMap attrNodes = node.getAttributes(); if (attrNodes != null) { int len = attrNodes.getLength(); for (int i = 0; i < len; i++) { Node attr = attrNodes.item(i); if (attr.getNodeName().equals("style:family")) family = attr.getNodeValue(); else if (attr.getNodeName().equals("style:name")) { name = attr.getNodeValue(); } else if (attr.getNodeName().equals("style:parent-style-name")) parent = attr.getNodeValue(); } } } /** * Constructor for use when going from client device format to DOM. * * @param name Name of the Style. Can be null. * @param family Family of the Style - usually * paragraph, text, etc. Can be null. * @param parent Name of the parent Style, or null if none. * @param sc The StyleCatalog, which is used for * looking up ancestor Style objects. */ public Style(String name, String family, String parent, StyleCatalog sc) { this.sc = sc; this.name = name; this.family = family; this.parent = parent; } /** * Set the StyleCatalog to be used when looking up the * Style parent. * * @param sc The StyleCatalog, which is used for * looking up ancestor Style objects. */ public void setCatalog(StyleCatalog sc) { this.sc = sc; } /** * Returns the name of this Style. * * @return The name of this Style. */ public String getName() { return name; } /** * Sets the name of this Style. * * @param newName The new name of this Style. */ public void setName(String newName) { name = newName; } /** * Return the family of this Style. * * @return The family of this Style. */ public String getFamily() { return family; } /** * Return the name of the parent of this Style. * * @return The parent of this Style. */ public String getParent() { return parent; } /** * Return a Style object corresponding to this one, but with * all of the inherited information from parent Style * objects filled in. The object returned will be a new object, not a * reference to this object, even if it does not need any information * added. * * @return A resolved Style object in which to look up * ancestors. */ public Style getResolved() { return new Style(name, family, parent, sc); } /** * Write a Node in parentDoc * representing this Style. Note that the * Node is returned unconnected. * * @param parentDoc Document to which new Node will * belong. * @param name Name to use for new Node. */ public Node createNode(org.w3c.dom.Document parentDoc, String name) { // DJP: write this! Should call writeAttributes() return null; } /** * Write this Style object's attributes to the given * Node. This may involve writing child * Node objects as well. This is similar to the * writeNode method, but the Node * already exists, and this does not write the name, * family, and parent attributes, which are assumed to already * exist in the Node. * * @param node The Node to add style attributes. */ public void writeAttributes(Node node) { } /** * Return true if Style is a subset of this one. Note * that this will return true even if Style is less * specific than this Style, so long as it does not * contradict this Style in any way. * * This always returns true since only subclasses of * Style contain any actual Style * information. * * @param style The Style to check * * @return true if the Style is a subset, false otherwise. */ public boolean isSubset(Style style) { return true; } }