19package org.openoffice.xmerge.converter.xml;
21import java.lang.reflect.Constructor;
22import java.util.ArrayList;
25import org.w3c.dom.Element;
26import org.w3c.dom.NamedNodeMap;
27import org.w3c.dom.Node;
28import org.w3c.dom.NodeList;
42 private final ArrayList<Style>
styles;
51 styles =
new ArrayList<Style>(initialEntries);
86 public void add(Node node, String families[], Class<?> classes[],
87 Class<?> defaultClass,
boolean alwaysCreateDefault) {
95 classes =
new Class[0];
96 if (!node.hasChildNodes()) {
99 NodeList children = node.getChildNodes();
100 int len = children.getLength();
102 for (
int i = 0;
i < len;
i++) {
103 boolean found =
false;
104 Node child = children.item(
i);
106 if (
name.equals(
"style:default-style")
107 ||
name.equals(
"style:style")) {
109 if (familyName ==
null) {
114 for (
int j = 0; j < families.length; j++) {
115 if (families[j].equals(familyName)) {
120 if ((!found || alwaysCreateDefault)
121 && (defaultClass !=
null))
135 Class<?> params[] =
new Class[2];
136 params[0] = Node.class;
139 Constructor<?> c = cls.getConstructor(params);
174 Class<?> styleClass) {
175 int nStyles =
styles.size();
176 for (
int i = 0;
i < nStyles;
i++) {
181 if ((family !=
null) && (s.
getFamily() !=
null)
184 if ((parent !=
null) && (s.
getParent() !=
null)
187 if ((styleClass !=
null) && (s.getClass() != styleClass))
189 if (s.
getName() ==
null)
continue;
208 int nStyles =
styles.size();
209 for (
int j = 0; j < nStyles; j++) {
211 if (
p.isSubset(s)) matchCount++;
217 for (
int j = 0; j < nStyles; j++) {
237 public Element
writeNode(
org.w3c.dom.Document parentDoc, String name) {
238 Element rootNode = parentDoc.createElement(
name);
241 for (
int j = 0; j < len; j++) {
244 Element styleNode = parentDoc.createElement(
"style:style");
247 styleNode.setAttribute(
"style:name", s.
getName());
249 styleNode.setAttribute(
"style:parent-style-name", s.
getParent());
251 styleNode.setAttribute(
"style:family", s.
getFamily());
253 Element propertiesNode = (Element) s.
createNode(parentDoc,
"style:properties");
255 if (propertiesNode !=
null)
256 styleNode.appendChild(propertiesNode);
258 rootNode.appendChild(styleNode);
272 NamedNodeMap attributes = node.getAttributes();
273 if (attributes !=
null) {
274 int len = attributes.getLength();
275 for (
int i = 0;
i < len;
i++) {
276 Node attr = attributes.item(
i);
277 if (attr.getNodeName().equals(
"style:family")) {
278 return attr.getNodeValue();
A StyleCatalog holds a collection of Style objects.
Style[] getMatching(Style s)
Given a Style s return all Style objects that match.
final ArrayList< Style > styles
Element writeNode(org.w3c.dom.Document parentDoc, String name)
Create a Node named name in Document parentDoc, and write the entire StyleCatalog to it.
StyleCatalog(int initialEntries)
Constructor.
void add(Style s)
Add a Style to the catalog.
Style lookup(String name, String family, String parent, Class<?> styleClass)
Return the first Style matching the specified names.
void callConstructor(Class<?> cls, Node node)
Call the constructor of class cls with parameters node, and add the resulting Style to the catalog.
void add(Node node, String families[], Class<?> classes[], Class<?> defaultClass, boolean alwaysCreateDefault)
Parse the Document starting from node and working downward, and add all styles found,...
String getFamilyName(Node node)
Find the family attribute of a Style Node.
An object of class Style represents a style in an OpenOffice document.
Node createNode(org.w3c.dom.Document parentDoc, String name)
Write a Node in parentDoc representing this Style.
String getName()
Returns the name of this Style.
String getFamily()
Return the family of this Style.
String getParent()
Return the name of the parent of this Style.
This class is used for logging debug messages.
static void log(int flag, String msg)
Log message based on the flag type.
static final int ERROR
Error messages.
Provides general purpose utilities.
Provides interfaces for converting between two Document formats, and supports a "merge" interface for...
PyRef getClass(const OUString &name, const Runtime &runtime)
const char * matchArray(const char *pSource, sal_Int32 nSourceSize, const char *pSearch, sal_Int32 nSearchSize)