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.style;
24 
25 import com.sun.star.report.pentaho.parser.ElementReadHandler;
26 
27 import java.util.ArrayList;
28 import java.util.List;
29 
30 import org.jfree.report.structure.Element;
31 import org.jfree.report.structure.Section;
32 
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 /**
40  * Reads all childs of a style-definition. This simply copies everything that
41  * is contained in the source-file into a generic structure that can be
42  * written out later.
43  */
44 public class StyleDefinitionReadHandler extends ElementReadHandler
45 {
46 
47     private final Section rawSection;
48     private final List childs;
49 
StyleDefinitionReadHandler()50     public StyleDefinitionReadHandler()
51     {
52         this.rawSection = new Section();
53         this.childs = new ArrayList();
54     }
55 
56     /**
57      * Returns the handler for a child element.
58      *
59      * @param tagName the tag name.
60      * @param atts    the attributes.
61      * @return the handler or null, if the tagname is invalid.
62      *
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         final StyleDefinitionReadHandler readHandler =
71                 new StyleDefinitionReadHandler();
72         childs.add(readHandler);
73         return readHandler;
74     }
75 
76     /**
77      * Done parsing.
78      *
79      * @throws org.xml.sax.SAXException if there is a parsing error.
80      */
doneParsing()81     protected void doneParsing()
82             throws SAXException
83     {
84         for (int i = 0; i < childs.size(); i++)
85         {
86             final ElementReadHandler handler = (ElementReadHandler) childs.get(i);
87             rawSection.addNode(handler.getElement());
88         }
89     }
90 
getElement()91     public Element getElement()
92     {
93         return rawSection;
94     }
95 }
96