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.pentaho.OfficeNamespaces;
26 import com.sun.star.report.pentaho.model.FormattedTextElement;
27 import com.sun.star.report.pentaho.parser.ElementReadHandler;
28 
29 import org.jfree.report.expressions.FormulaExpression;
30 import org.jfree.report.structure.Element;
31 
32 import org.pentaho.reporting.libraries.xmlns.parser.IgnoreAnyChildReadHandler;
33 import org.pentaho.reporting.libraries.xmlns.parser.XmlReadHandler;
34 
35 import org.xml.sax.Attributes;
36 import org.xml.sax.SAXException;
37 
38 /**
39  * Creation-Date: 01.10.2006, 19:06:45
40  *
41  * @author Thomas Morgner
42  */
43 public class FormattedTextReadHandler extends ElementReadHandler
44 {
45 
46     private final FormattedTextElement element;
47 
FormattedTextReadHandler()48     public FormattedTextReadHandler()
49     {
50         element = new FormattedTextElement();
51     }
52 
53     /**
54      * Starts parsing.
55      *
56      * @param attrs the attributes.
57      * @throws org.xml.sax.SAXException if there is a parsing error.
58      */
startParsing(final Attributes attrs)59     protected void startParsing(final Attributes attrs) throws SAXException
60     {
61         super.startParsing(attrs);
62 
63         final String formula = attrs.getValue(OfficeNamespaces.OOREPORT_NS, "formula");
64         if (formula != null)
65         {
66             final FormulaExpression valueExpression = new FormulaExpression();
67             valueExpression.setFormula(formula);
68             element.setValueExpression(valueExpression);
69         }
70 
71         // * Print-Repeated-Values
72         // * Print-In-First-New-Section
73         // * Print-When-Group-Changes
74 
75         // * Print-When-Section-Overflows
76         // That property cannot be evaluated yet, as this would require us to
77         // have a clue about pagebreaking. We dont have that - not yet and never
78         // in the future, as pagebreaks are computed by OpenOffice instead
79     }
80 
81     /**
82      * Returns the handler for a child element.
83      *
84      * @param tagName the tag name.
85      * @param atts    the attributes.
86      * @return the handler or null, if the tagname is invalid.
87      * @throws org.xml.sax.SAXException if there is a parsing error.
88      */
getHandlerForChild(final String uri, final String tagName, final Attributes atts)89     protected XmlReadHandler getHandlerForChild(final String uri,
90             final String tagName,
91             final Attributes atts)
92             throws SAXException
93     {
94         if (OfficeNamespaces.OOREPORT_NS.equals(uri))
95         {
96             // expect a report control. The control will modifiy the current
97             // element (as we do not separate the elements that strictly ..)
98             if ("report-control".equals(tagName))
99             {
100                 return new IgnoreAnyChildReadHandler();
101             }
102             if ("report-element".equals(tagName))
103             {
104                 return new ReportElementReadHandler(element);
105             }
106         }
107         return null;
108     }
109 
getElement()110     public Element getElement()
111     {
112         return element;
113     }
114 }
115