1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 package com.sun.star.report.pentaho.parser.rpt; 28 29 import com.sun.star.report.OfficeToken; 30 import com.sun.star.report.pentaho.OfficeNamespaces; 31 import com.sun.star.report.pentaho.model.FormatCondition; 32 import com.sun.star.report.pentaho.model.ReportElement; 33 34 import org.jfree.report.expressions.FormulaExpression; 35 36 import org.pentaho.reporting.libraries.xmlns.parser.AbstractXmlReadHandler; 37 import org.pentaho.reporting.libraries.xmlns.parser.ParseException; 38 39 import org.xml.sax.Attributes; 40 import org.xml.sax.SAXException; 41 42 /** 43 * I'm quite sure I should parse something here. But what? 44 * 45 * @author Ocke Janssen 46 */ 47 public class FormatConditionReadHandler extends AbstractXmlReadHandler 48 { 49 50 private final ReportElement element; 51 52 public FormatConditionReadHandler(final ReportElement element) 53 { 54 if (element == null) 55 { 56 throw new NullPointerException(); 57 } 58 this.element = element; 59 } 60 61 protected void startParsing(final Attributes attrs) throws SAXException 62 { 63 super.startParsing(attrs); 64 65 66 final String formula = 67 attrs.getValue(OfficeNamespaces.OOREPORT_NS, "formula"); 68 if (formula == null) 69 { 70 throw new ParseException("Required attribute 'formula' is missing.", getLocator()); 71 } 72 final String stylename = 73 attrs.getValue(OfficeNamespaces.OOREPORT_NS, OfficeToken.STYLE_NAME); 74 if (stylename == null) 75 { 76 throw new ParseException("Required attribute 'style-name' is missing.", getLocator()); 77 } 78 final FormulaExpression valueExpression = new FormulaExpression(); 79 valueExpression.setFormula(formula); 80 81 final String enabledText = attrs.getValue(OfficeNamespaces.OOREPORT_NS, "enabled"); 82 final boolean enabled = (enabledText == null || OfficeToken.TRUE.equals(enabledText)); 83 final FormatCondition formatCondition = 84 new FormatCondition(valueExpression, stylename, enabled); 85 element.addFormatCondition(formatCondition); 86 87 } 88 89 /** 90 * Returns the object for this element or null, if this element does not 91 * create an object. 92 * 93 * @return the object. 94 */ 95 public Object getObject() 96 throws SAXException 97 { 98 return element; 99 } 100 } 101