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.parser.rpt; 24 25 import com.sun.star.report.OfficeToken; 26 import com.sun.star.report.pentaho.OfficeNamespaces; 27 import com.sun.star.report.pentaho.model.FormatCondition; 28 import com.sun.star.report.pentaho.model.ReportElement; 29 30 import org.jfree.report.expressions.FormulaExpression; 31 32 import org.pentaho.reporting.libraries.xmlns.parser.AbstractXmlReadHandler; 33 import org.pentaho.reporting.libraries.xmlns.parser.ParseException; 34 35 import org.xml.sax.Attributes; 36 import org.xml.sax.SAXException; 37 38 /** 39 * I'm quite sure I should parse something here. But what? 40 * 41 * @author Ocke Janssen 42 */ 43 public class FormatConditionReadHandler extends AbstractXmlReadHandler 44 { 45 46 private final ReportElement element; 47 FormatConditionReadHandler(final ReportElement element)48 public FormatConditionReadHandler(final ReportElement element) 49 { 50 if (element == null) 51 { 52 throw new NullPointerException(); 53 } 54 this.element = element; 55 } 56 startParsing(final Attributes attrs)57 protected void startParsing(final Attributes attrs) throws SAXException 58 { 59 super.startParsing(attrs); 60 61 62 final String formula = 63 attrs.getValue(OfficeNamespaces.OOREPORT_NS, "formula"); 64 if (formula == null) 65 { 66 throw new ParseException("Required attribute 'formula' is missing.", getLocator()); 67 } 68 final String stylename = 69 attrs.getValue(OfficeNamespaces.OOREPORT_NS, OfficeToken.STYLE_NAME); 70 if (stylename == null) 71 { 72 throw new ParseException("Required attribute 'style-name' is missing.", getLocator()); 73 } 74 final FormulaExpression valueExpression = new FormulaExpression(); 75 valueExpression.setFormula(formula); 76 77 final String enabledText = attrs.getValue(OfficeNamespaces.OOREPORT_NS, "enabled"); 78 final boolean enabled = (enabledText == null || OfficeToken.TRUE.equals(enabledText)); 79 final FormatCondition formatCondition = 80 new FormatCondition(valueExpression, stylename, enabled); 81 element.addFormatCondition(formatCondition); 82 83 } 84 85 /** 86 * Returns the object for this element or null, if this element does not 87 * create an object. 88 * 89 * @return the object. 90 */ getObject()91 public Object getObject() 92 throws SAXException 93 { 94 return element; 95 } 96 } 97