1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 package com.sun.star.report.pentaho.model;
24 
25 import java.io.Serializable;
26 
27 import java.util.ArrayList;
28 import java.util.HashMap;
29 import java.util.List;
30 import java.util.Map;
31 
32 import org.jfree.report.structure.Element;
33 
34 
35 /**
36  * Holds one style type, either an automatic, common or master style. This is a
37  * marker container that defines the nature of the styles contained within this
38  * container. (Yeah, it is awkward, but that's how the document model describes
39  * it.)
40  *
41  * The style family can be one of paragraph, text, section, table, table-column,
42  * table-row, table-cell, table-page, chart, default, drawing-page, graphic,
43  * presentation, control and ruby.
44  *
45  * @author Thomas Morgner
46  * @since 07.03.2007
47  */
48 public class OfficeStyles extends Element
49 {
50 
51     public static class StyleKey implements Serializable
52     {
53 
54         private static final long serialVersionUID = 4931878927362887477L;
55         private final String family;
56         private final String name;
57 
StyleKey(final String family, final String name)58         public StyleKey(final String family, final String name)
59         {
60             if (family == null)
61             {
62                 throw new NullPointerException();
63             }
64             this.family = family;
65             this.name = name;
66         }
67 
getFamily()68         public String getFamily()
69         {
70             return family;
71         }
72 
getName()73         public String getName()
74         {
75             return name;
76         }
77 
equals(final Object obj)78         public boolean equals(final Object obj)
79         {
80             if (this != obj)
81             {
82                 if (obj == null || getClass() != obj.getClass())
83                 {
84                     return false;
85                 }
86 
87                 final StyleKey styleKey = (StyleKey) obj;
88 
89                 if (!family.equals(styleKey.family) || (name != null ? !name.equals(styleKey.name) : styleKey.name != null))
90                 {
91                     return false;
92                 }
93             }
94             return true;
95         }
96 
hashCode()97         public int hashCode()
98         {
99             int result = family.hashCode();
100             result = 31 * result + (name != null ? name.hashCode() : 0);
101             return result;
102         }
103     }
104     private final Map pageStyles;
105     private final Map dataStyles;
106     private final Map styles;
107     private final List otherChilds;
108 
OfficeStyles()109     public OfficeStyles()
110     {
111         this.styles = new HashMap();
112         this.dataStyles = new HashMap();
113         this.pageStyles = new HashMap();
114         this.otherChilds = new ArrayList();
115     }
116 
getStyle(final String family, final String name)117     public OfficeStyle getStyle(final String family, final String name)
118     {
119         return (OfficeStyle) styles.get(new StyleKey(family, name));
120     }
121 
addStyle(final OfficeStyle style)122     public void addStyle(final OfficeStyle style)
123     {
124         if (style == null)
125         {
126             throw new NullPointerException();
127         }
128         final String styleFamily = style.getStyleFamily();
129         if (styleFamily == null)
130         {
131             throw new NullPointerException();
132         }
133         if (style.getStyleName() == null)
134         {
135             throw new NullPointerException();
136         }
137         styles.put(new StyleKey(styleFamily, style.getStyleName()), style);
138     }
139 
addPageStyle(final PageLayout style)140     public void addPageStyle(final PageLayout style)
141     {
142         pageStyles.put(style.getStyleName(), style);
143     }
144 
getPageStyle(final String name)145     public PageLayout getPageStyle(final String name)
146     {
147         return (PageLayout) pageStyles.get(name);
148     }
149 
addDataStyle(final DataStyle style)150     public void addDataStyle(final DataStyle style)
151     {
152         dataStyles.put(style.getStyleName(), style);
153     }
154 
getDataStyle(final String name)155     public DataStyle getDataStyle(final String name)
156     {
157         return (DataStyle) dataStyles.get(name);
158     }
159 
addOtherNode(final Element node)160     public void addOtherNode(final Element node)
161     {
162         otherChilds.add(node);
163     }
164 
getAllDataStyles()165     public DataStyle[] getAllDataStyles()
166     {
167         return (DataStyle[]) dataStyles.values().toArray(new DataStyle[dataStyles.size()]);
168     }
169 
getAllPageStyles()170     public PageLayout[] getAllPageStyles()
171     {
172         return (PageLayout[]) pageStyles.values().toArray(new PageLayout[pageStyles.size()]);
173     }
174 
getAllStyles()175     public OfficeStyle[] getAllStyles()
176     {
177         return (OfficeStyle[]) styles.values().toArray(new OfficeStyle[styles.size()]);
178     }
179 
getOtherStyles()180     public Element[] getOtherStyles()
181     {
182         return (Element[]) otherChilds.toArray(new Element[otherChilds.size()]);
183     }
184 
containsStyle(final String family, final String name)185     public boolean containsStyle(final String family, final String name)
186     {
187         return styles.containsKey(new StyleKey(family, name));
188     }
189 
containsDataStyle(final String styleName)190     public boolean containsDataStyle(final String styleName)
191     {
192         return dataStyles.containsKey(styleName);
193     }
194 }
195