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.model.PageLayout;
26 import com.sun.star.report.pentaho.parser.ElementReadHandler;
27 
28 import java.util.ArrayList;
29 import java.util.List;
30 
31 import org.jfree.report.structure.Element;
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 a page-layout element.
41  *
42  * @author Thomas Morgner
43  * @since 13.03.2007
44  */
45 public class PageLayoutReadHandler extends ElementReadHandler
46 {
47 
48     private final PageLayout pageLayout;
49     private final List childs;
50 
PageLayoutReadHandler()51     public PageLayoutReadHandler()
52     {
53         this.pageLayout = new PageLayout();
54         this.childs = new ArrayList();
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         final StyleDefinitionReadHandler readHandler =
72                 new StyleDefinitionReadHandler();
73         childs.add(readHandler);
74         return readHandler;
75     }
76 
77     /**
78      * Done parsing.
79      *
80      * @throws org.xml.sax.SAXException if there is a parsing error.
81      */
doneParsing()82     protected void doneParsing() throws SAXException
83     {
84         for (int i = 0; i < childs.size(); i++)
85         {
86             final ElementReadHandler handler = (ElementReadHandler) childs.get(i);
87             pageLayout.addNode(handler.getElement());
88         }
89     }
90 
getPageLayout()91     public PageLayout getPageLayout()
92     {
93         return pageLayout;
94     }
95 
getElement()96     public Element getElement()
97     {
98         return pageLayout;
99     }
100 }
101