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.styles; 24 25 import java.util.HashMap; 26 import java.util.Map; 27 28 import org.pentaho.reporting.libraries.resourceloader.Resource; 29 import org.pentaho.reporting.libraries.resourceloader.ResourceException; 30 import org.pentaho.reporting.libraries.resourceloader.ResourceManager; 31 32 33 /** 34 * The style-mapper holds all information about the OpenOffice style mapping 35 * mechanism. OpenOffice references styles by their name and context, a style 36 * has a style-family assigned. The style family is determined by the element 37 * referencing the style, and there is no easily accessible information 38 * available on that. 39 * <p/> 40 * Therefore this mapper acts as gatekeeper for this information. The style 41 * mapping information is read from an external definition file and can be 42 * maintained externally. 43 * 44 * @author Thomas Morgner 45 * @since 11.03.2007 46 */ 47 public class StyleMapper 48 { 49 50 private final Map backend; 51 StyleMapper()52 public StyleMapper() 53 { 54 this.backend = new HashMap(); 55 } 56 addMapping(final StyleMappingRule rule)57 public void addMapping(final StyleMappingRule rule) 58 { 59 backend.put(rule.getKey(), rule); 60 } 61 isListOfStyles(final String elementNamespace, final String elementTagName, final String attributeNamespace, final String attributeName)62 public boolean isListOfStyles(final String elementNamespace, 63 final String elementTagName, 64 final String attributeNamespace, 65 final String attributeName) 66 { 67 final StyleMapperKey key = new StyleMapperKey(elementNamespace, elementTagName, attributeNamespace, attributeName); 68 final StyleMappingRule rule = (StyleMappingRule) backend.get(key); 69 return rule != null && rule.isListOfValues(); 70 } 71 getStyleFamilyFor(final String elementNamespace, final String elementTagName, final String attributeNamespace, final String attributeName)72 public String getStyleFamilyFor(final String elementNamespace, 73 final String elementTagName, 74 final String attributeNamespace, 75 final String attributeName) 76 { 77 final StyleMapperKey key = new StyleMapperKey(elementNamespace, elementTagName, attributeNamespace, attributeName); 78 final StyleMappingRule rule = (StyleMappingRule) backend.get(key); 79 if (rule == null) 80 { 81 return null; 82 } 83 return rule.getFamily(); 84 } 85 loadInstance(final ResourceManager resourceManager)86 public static StyleMapper loadInstance(final ResourceManager resourceManager) 87 throws ResourceException 88 { 89 final Resource resource = resourceManager.createDirectly("res://com/sun/star/report/pentaho/styles/stylemapper.xml", StyleMapper.class); 90 return (StyleMapper) resource.getResource(); 91 } 92 } 93