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 org.pentaho.reporting.libraries.xmlns.parser.AbstractXmlReadHandler; 26 import org.pentaho.reporting.libraries.xmlns.parser.ParseException; 27 28 import org.xml.sax.Attributes; 29 import org.xml.sax.SAXException; 30 31 /** 32 * Todo: Document me! 33 * 34 * @author Thomas Morgner 35 * @since 12.03.2007 36 */ 37 public class StyleMappingReadHandler extends AbstractXmlReadHandler 38 { 39 40 private StyleMappingRule rule; 41 StyleMappingReadHandler()42 public StyleMappingReadHandler() 43 { 44 } 45 46 /** 47 * Starts parsing. 48 * 49 * @param attrs the attributes. 50 * @throws org.xml.sax.SAXException if there is a parsing error. 51 */ startParsing(final Attributes attrs)52 protected void startParsing(final Attributes attrs) 53 throws SAXException 54 { 55 final String elementNamespace = attrs.getValue(getUri(), 56 "element-namespace"); 57 if (elementNamespace == null) 58 { 59 throw new ParseException("Required attribute 'element-namespace' is missing", getLocator()); 60 } 61 62 final String elementName = attrs.getValue(getUri(), "element-name"); 63 64 if (elementName == null) 65 { 66 throw new ParseException("Required attribute 'element-name' is missing", getLocator()); 67 } 68 69 final String attributeNamespace = attrs.getValue(getUri(), 70 "attribute-namespace"); 71 final String attributeName = attrs.getValue(getUri(), "attribute-name"); 72 73 final boolean listOfValues = 74 "styleNameRefs".equals(attrs.getValue(getUri(), "type")); 75 76 final String family = attrs.getValue(getUri(), "style-family"); 77 final StyleMapperKey key = new StyleMapperKey(elementNamespace, elementName, attributeNamespace, attributeName); 78 rule = new StyleMappingRule(key, family, listOfValues); 79 } 80 getRule()81 public StyleMappingRule getRule() 82 { 83 return rule; 84 } 85 86 /** 87 * Returns the object for this element or null, if this element does not 88 * create an object. 89 * 90 * @return the object. 91 */ getObject()92 public Object getObject() 93 throws SAXException 94 { 95 return rule; 96 } 97 } 98