2 * This file is part of the LibreOffice project.
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/.
8 * This file incorporates work covered by the following license notice:
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 .
18 package org
.libreoffice
.report
.pentaho
.model
;
20 import java
.io
.Serializable
;
22 import java
.util
.ArrayList
;
23 import java
.util
.HashMap
;
24 import java
.util
.List
;
27 import org
.jfree
.report
.structure
.Element
;
31 * Holds one style type, either an automatic, common or master style. This is a
32 * marker container that defines the nature of the styles contained within this
33 * container. (Yeah, it is awkward, but that's how the document model describes
36 * The style family can be one of paragraph, text, section, table, table-column,
37 * table-row, table-cell, table-page, chart, default, drawing-page, graphic,
38 * presentation, control and ruby.
42 public class OfficeStyles
extends Element
45 private static class StyleKey
implements Serializable
48 private static final long serialVersionUID
= 4931878927362887477L;
49 private final String family
;
50 private final String name
;
52 private StyleKey(final String family
, final String name
)
56 throw new NullPointerException();
63 public boolean equals(final Object obj
)
67 if (obj
== null || getClass() != obj
.getClass())
72 final StyleKey styleKey
= (StyleKey
) obj
;
74 if (!family
.equals(styleKey
.family
) || (name
!= null ?
!name
.equals(styleKey
.name
) : styleKey
.name
!= null))
85 int result
= family
.hashCode();
86 result
= 31 * result
+ (name
!= null ? name
.hashCode() : 0);
90 private final Map
<String
,PageLayout
> pageStyles
;
91 private final Map
<String
,DataStyle
> dataStyles
;
92 private final Map
<StyleKey
,OfficeStyle
> styles
;
93 private final List
<Element
> otherChildren
;
97 this.styles
= new HashMap
<StyleKey
,OfficeStyle
>();
98 this.dataStyles
= new HashMap
<String
,DataStyle
>();
99 this.pageStyles
= new HashMap
<String
,PageLayout
>();
100 this.otherChildren
= new ArrayList
<Element
>();
103 public OfficeStyle
getStyle(final String family
, final String name
)
105 return styles
.get(new StyleKey(family
, name
));
108 public void addStyle(final OfficeStyle style
)
112 throw new NullPointerException();
114 final String styleFamily
= style
.getStyleFamily();
115 if (styleFamily
== null)
117 throw new NullPointerException();
119 if (style
.getStyleName() == null)
121 throw new NullPointerException();
123 styles
.put(new StyleKey(styleFamily
, style
.getStyleName()), style
);
126 public void addPageStyle(final PageLayout style
)
128 pageStyles
.put(style
.getStyleName(), style
);
131 public PageLayout
getPageStyle(final String name
)
133 return pageStyles
.get(name
);
136 public void addDataStyle(final DataStyle style
)
138 dataStyles
.put(style
.getStyleName(), style
);
141 public DataStyle
getDataStyle(final String name
)
143 return dataStyles
.get(name
);
146 public void addOtherNode(final Element node
)
148 otherChildren
.add(node
);
151 public DataStyle
[] getAllDataStyles()
153 return dataStyles
.values().toArray(new DataStyle
[dataStyles
.size()]);
156 public PageLayout
[] getAllPageStyles()
158 return pageStyles
.values().toArray(new PageLayout
[pageStyles
.size()]);
161 public OfficeStyle
[] getAllStyles()
163 return styles
.values().toArray(new OfficeStyle
[styles
.size()]);
166 public Element
[] getOtherStyles()
168 return otherChildren
.toArray(new Element
[otherChildren
.size()]);
171 public boolean containsStyle(final String family
, final String name
)
173 return styles
.containsKey(new StyleKey(family
, name
));
176 public boolean containsDataStyle(final String styleName
)
178 return dataStyles
.containsKey(styleName
);