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.table;
24 
25 import com.sun.star.report.OfficeToken;
26 import com.sun.star.report.pentaho.OfficeNamespaces;
27 import com.sun.star.report.pentaho.parser.ElementReadHandler;
28 
29 import java.util.ArrayList;
30 import java.util.List;
31 
32 import org.jfree.report.structure.Element;
33 import org.jfree.report.structure.Section;
34 
35 import org.pentaho.reporting.libraries.xmlns.parser.XmlReadHandler;
36 
37 import org.xml.sax.Attributes;
38 import org.xml.sax.SAXException;
39 
40 
41 /**
42  *
43  * @author Ocke Janssen
44  */
45 public class TableRowsReadHandler extends ElementReadHandler
46 {
47 
48     private final List rows;
49     private final Section tableRows;
50 
TableRowsReadHandler()51     public TableRowsReadHandler()
52     {
53         rows = new ArrayList();
54         tableRows = new 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      * @throws org.xml.sax.SAXException if there is a parsing error.
64      */
getHandlerForChild(final String uri, final String tagName, final Attributes atts)65     protected XmlReadHandler getHandlerForChild(final String uri,
66             final String tagName,
67             final Attributes atts)
68             throws SAXException
69     {
70         if (OfficeNamespaces.TABLE_NS.equals(uri) && OfficeToken.TABLE_ROW.equals(tagName))
71         {
72             final TableRowReadHandler readHandler = new TableRowReadHandler();
73             rows.add(readHandler);
74             return readHandler;
75         }
76 
77         return null;
78     }
79 
80     /**
81      * Done parsing.
82      *
83      * @throws org.xml.sax.SAXException if there is a parsing error.
84      */
doneParsing()85     protected void doneParsing() throws SAXException
86     {
87         for (int i = 0; i < rows.size(); i++)
88         {
89             final TableRowReadHandler handler = (TableRowReadHandler) rows.get(i);
90             tableRows.addNode(handler.getElement());
91         }
92     }
93 
getElement()94     public Element getElement()
95     {
96         return tableRows;
97     }
98 }
99