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.parser.ElementReadHandler;
27 import com.sun.star.report.pentaho.parser.table.TableReadHandler;
28 
29 import org.jfree.report.structure.Element;
30 import org.jfree.report.structure.Section;
31 
32 import org.pentaho.reporting.libraries.xmlns.parser.XmlReadHandler;
33 
34 import org.xml.sax.Attributes;
35 import org.xml.sax.SAXException;
36 
37 public class RootTableReadHandler extends ElementReadHandler
38 {
39 
40     private TableReadHandler sectionTableReadHandler;
41     private final Section section;
42 
RootTableReadHandler()43     public RootTableReadHandler()
44     {
45         section = new Section();
46     }
47 
RootTableReadHandler(final Section section)48     protected RootTableReadHandler(final Section section)
49     {
50         if (section == null)
51         {
52             throw new NullPointerException();
53         }
54         this.section = section;
55     }
56 
57     /**
58      * Returns the handler for a child element.
59      *
60      * @param tagName the tag name.
61      * @param atts    the attributes.
62      * @return the handler or null, if the tagname is invalid.
63      *
64      * @throws org.xml.sax.SAXException if there is a parsing error.
65      */
getHandlerForChild(final String uri, final String tagName, final Attributes atts)66     protected XmlReadHandler getHandlerForChild(final String uri,
67             final String tagName,
68             final Attributes atts)
69             throws SAXException
70     {
71         if (OfficeNamespaces.TABLE_NS.equals(uri) && "table".equals(tagName))
72         {
73             sectionTableReadHandler = new TableReadHandler();
74             return sectionTableReadHandler;
75         }
76         if (OfficeNamespaces.OOREPORT_NS.equals(uri) && "conditional-print-expression".equals(tagName))
77         {
78             return new ConditionalPrintExpressionReadHandler(section);
79         }
80         return null;
81     }
82 
83     /**
84      * Done parsing.
85      *
86      * @throws org.xml.sax.SAXException if there is a parsing error.
87      */
doneParsing()88     protected void doneParsing()
89             throws SAXException
90     {
91         if (sectionTableReadHandler != null)
92         {
93             section.addNode(sectionTableReadHandler.getElement());
94         }
95     }
96 
getElement()97     public Element getElement()
98     {
99         return section;
100     }
101 }
102