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  * Creation-Date: 03.07.2006, 13:51:47
43  *
44  * @author Thomas Morgner
45  */
46 public class TableRowReadHandler extends ElementReadHandler
47 {
48 
49     private final List tableCells;
50     private final Section tableRow;
51 
TableRowReadHandler()52     public TableRowReadHandler()
53     {
54         tableCells = new ArrayList();
55         tableRow = new Section();
56     }
57 
58     /**
59      * Returns the handler for a child element.
60      *
61      * @param tagName the tag name.
62      * @param atts    the attributes.
63      * @return the handler or null, if the tagname is invalid.
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         final XmlReadHandler rh;
72         if (OfficeNamespaces.TABLE_NS.equals(uri))
73         {
74             if (OfficeToken.TABLE_CELL.equals(tagName))
75             {
76                 rh = new TableCellReadHandler();
77             }
78             else if (OfficeToken.COVERED_TABLE_CELL.equals(tagName))
79             {
80                 rh = new CoveredCellReadHandler();
81             }
82             else
83             {
84                 rh = null;
85             }
86             if (rh != null)
87             {
88                 tableCells.add(rh);
89             }
90         }
91         else
92         {
93             rh = null;
94         }
95         return rh;
96     }
97 
98     /**
99      * Done parsing.
100      *
101      * @throws org.xml.sax.SAXException if there is a parsing error.
102      */
doneParsing()103     protected void doneParsing() throws SAXException
104     {
105         for (int i = 0; i < tableCells.size(); i++)
106         {
107             final ElementReadHandler handler = (ElementReadHandler) tableCells.get(i);
108             tableRow.addNode(handler.getElement());
109         }
110     }
111 
112     /**
113      * Returns the object for this element or null, if this element does not
114      * create an object.
115      *
116      * @return the object.
117      */
getElement()118     public Element getElement()
119     {
120         return tableRow;
121     }
122 }
123