1 /* 2 * This file is part of the LibreOffice project. 3 * 4 * This Source Code Form is subject to the terms of the Mozilla Public 5 * License, v. 2.0. If a copy of the MPL was not distributed with this 6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 * 8 * This file incorporates work covered by the following license notice: 9 * 10 * Licensed to the Apache Software Foundation (ASF) under one or more 11 * contributor license agreements. See the NOTICE file distributed 12 * with this work for additional information regarding copyright 13 * ownership. The ASF licenses this file to you under the Apache 14 * License, Version 2.0 (the "License"); you may not use this file 15 * except in compliance with the License. You may obtain a copy of 16 * the License at http://www.apache.org/licenses/LICENSE-2.0 . 17 */ 18 package org.libreoffice.report.pentaho.parser.rpt; 19 20 import org.libreoffice.report.pentaho.OfficeNamespaces; 21 import org.libreoffice.report.pentaho.model.FormattedTextElement; 22 import org.libreoffice.report.pentaho.parser.ElementReadHandler; 23 24 import org.jfree.report.expressions.FormulaExpression; 25 import org.jfree.report.structure.Element; 26 27 import org.pentaho.reporting.libraries.xmlns.parser.IgnoreAnyChildReadHandler; 28 import org.pentaho.reporting.libraries.xmlns.parser.XmlReadHandler; 29 30 import org.xml.sax.Attributes; 31 import org.xml.sax.SAXException; 32 33 /** 34 * Creation-Date: 01.10.2006, 19:06:45 35 * 36 */ 37 public class FormattedTextReadHandler extends ElementReadHandler 38 { 39 40 private final FormattedTextElement element; 41 FormattedTextReadHandler()42 public FormattedTextReadHandler() 43 { 44 element = new FormattedTextElement(); 45 } 46 47 /** 48 * Starts parsing. 49 * 50 * @param attrs the attributes. 51 * @throws org.xml.sax.SAXException if there is a parsing error. 52 */ 53 @Override startParsing(final Attributes attrs)54 protected void startParsing(final Attributes attrs) throws SAXException 55 { 56 super.startParsing(attrs); 57 58 final String formula = attrs.getValue(OfficeNamespaces.OOREPORT_NS, "formula"); 59 if (formula != null) 60 { 61 final FormulaExpression valueExpression = new FormulaExpression(); 62 valueExpression.setFormula(formula); 63 element.setValueExpression(valueExpression); 64 } 65 66 // * Print-Repeated-Values 67 // * Print-In-First-New-Section 68 // * Print-When-Group-Change 69 70 // * Print-When-Section-Overflows 71 // That property cannot be evaluated yet, as this would require us to 72 // have a clue about pagebreaking. We don't have that - not yet and never 73 // in the future, as pagebreaks are computed by OpenOffice instead 74 } 75 76 /** 77 * Returns the handler for a child element. 78 * 79 * @param tagName the tag name. 80 * @param atts the attributes. 81 * @return the handler or null, if the tagname is invalid. 82 * @throws org.xml.sax.SAXException if there is a parsing error. 83 */ 84 @Override getHandlerForChild(final String uri, final String tagName, final Attributes atts)85 protected XmlReadHandler getHandlerForChild(final String uri, 86 final String tagName, 87 final Attributes atts) 88 throws SAXException 89 { 90 if (OfficeNamespaces.OOREPORT_NS.equals(uri)) 91 { 92 // expect a report control. The control will modify the current 93 // element (as we do not separate the elements that strictly...) 94 if ("report-control".equals(tagName)) 95 { 96 return new IgnoreAnyChildReadHandler(); 97 } 98 if ("report-element".equals(tagName)) 99 { 100 return new ReportElementReadHandler(element); 101 } 102 } 103 return null; 104 } 105 106 @Override getElement()107 public Element getElement() 108 { 109 return element; 110 } 111 } 112