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