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 com.sun.star.report.pentaho.OfficeNamespaces; 26 27 import org.jfree.report.structure.Element; 28 29 /** 30 * Holds all style-definitions and provides some simplified lookup methods to 31 * grab them by their type and name. 32 * <p/> 33 * For now, we are only interested in 'style:style' nodes. Each of these nodes 34 * has a style-name and a style-family. Each style declaration can have a parent 35 * style, from which properties are inherited. 36 * <p/> 37 * Style names are unique within the family, no matter whether the style is an 38 * automatic style, an common style or a master style. 39 * <p/> 40 * The contents of this element are the union of the 'styles.xml' file (if it 41 * exists), the font-declarations and auto-styles of the document-content.xml 42 * and the styles declared in the main document. 43 * 44 * @author Thomas Morgner 45 * @since 06.03.2007 46 */ 47 public class OfficeStylesCollection extends Element 48 { 49 // Font-face declarations are copied as is. We simply merge them by adding 50 // them all in one set. This may result in duplicate entries, but as the 51 // fileformat does not forbid that, it therefore must be ok. 52 53 private final FontFaceDeclsSection fontFaceDecls; 54 private final OfficeStyles automaticStyles; 55 private final OfficeStyles commonStyles; 56 private final OfficeMasterStyles masterStyles; 57 OfficeStylesCollection()58 public OfficeStylesCollection() 59 { 60 fontFaceDecls = new FontFaceDeclsSection(); 61 62 automaticStyles = new OfficeStyles(); 63 automaticStyles.setType("automatic-styles"); 64 automaticStyles.setNamespace(OfficeNamespaces.OFFICE_NS); 65 66 commonStyles = new OfficeStyles(); 67 commonStyles.setType("styles"); 68 commonStyles.setNamespace(OfficeNamespaces.OFFICE_NS); 69 70 masterStyles = new OfficeMasterStyles(); 71 masterStyles.setType("master-styles"); 72 masterStyles.setNamespace(OfficeNamespaces.OFFICE_NS); 73 } 74 getStyle(final String family, final String name)75 public OfficeStyle getStyle(final String family, final String name) 76 { 77 final OfficeStyle commonStyle = commonStyles.getStyle(family, name); 78 if (commonStyle != null) 79 { 80 return commonStyle; 81 } 82 final OfficeStyle autoStyle = automaticStyles.getStyle(family, name); 83 if (autoStyle != null) 84 { 85 return autoStyle; 86 } 87 88 // And later: Autogenerate one of the default styles. 89 // However, at this moment, we dont have a clue about the default styles 90 // at all. Maybe we should add them to make this implementation more robust 91 // against invalid documents. 92 return null; 93 } 94 containsStyle(final String family, final String name)95 public boolean containsStyle(final String family, final String name) 96 { 97 return (getStyle(family, name) != null); 98 } 99 getAutomaticStyles()100 public OfficeStyles getAutomaticStyles() 101 { 102 return automaticStyles; 103 } 104 getCommonStyles()105 public OfficeStyles getCommonStyles() 106 { 107 return commonStyles; 108 } 109 getMasterStyles()110 public OfficeMasterStyles getMasterStyles() 111 { 112 return masterStyles; 113 } 114 getFontFaceDecls()115 public FontFaceDeclsSection getFontFaceDecls() 116 { 117 return fontFaceDecls; 118 } 119 } 120