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:50:41
43  *
44  * @author Thomas Morgner
45  */
46 public class TableColumnsReadHandler extends ElementReadHandler
47 {
48 
49     private final List columns;
50     private final Section tableColumns;
51 
TableColumnsReadHandler()52     public TableColumnsReadHandler()
53     {
54         columns = new ArrayList();
55         tableColumns = 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         if (OfficeNamespaces.TABLE_NS.equals(uri) && OfficeToken.TABLE_COLUMN.equals(tagName))
72         {
73             final TableColumnReadHandler readHandler = new TableColumnReadHandler();
74             columns.add(readHandler);
75             return readHandler;
76         }
77 
78         return null;
79     }
80 
81     /**
82      * Done parsing.
83      *
84      * @throws org.xml.sax.SAXException if there is a parsing error.
85      */
doneParsing()86     protected void doneParsing() throws SAXException
87     {
88         for (int i = 0; i < columns.size(); i++)
89         {
90             final TableColumnReadHandler handler = (TableColumnReadHandler) columns.get(i);
91             tableColumns.addNode(handler.getElement());
92         }
93     }
94 
getElement()95     public Element getElement()
96     {
97         return tableColumns;
98     }
99 }
100