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.OfficeStyle;
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  * This class reads a single style rule. The resulting 'office-style' element
41  * is added to an 'office-styles' set.
42  */
43 public class OfficeStyleReadHandler extends ElementReadHandler
44 {
45 
46     private final OfficeStyle officeStyle;
47     private final List childs;
48 
OfficeStyleReadHandler()49     public OfficeStyleReadHandler()
50     {
51         this.officeStyle = new OfficeStyle();
52         this.childs = new ArrayList();
53     }
54 
55     /**
56      * Returns the handler for a child element.
57      *
58      * @param tagName the tag name.
59      * @param atts    the attributes.
60      * @return the handler or null, if the tagname is invalid.
61      *
62      * @throws org.xml.sax.SAXException if there is a parsing error.
63      */
getHandlerForChild(final String uri, final String tagName, final Attributes atts)64     protected XmlReadHandler getHandlerForChild(final String uri,
65             final String tagName,
66             final Attributes atts)
67             throws SAXException
68     {
69 //    if (OfficeParserUtil.getInstance().isValidStyleElement(uri, tagName))
70 //    {
71 //    }
72         final StyleDefinitionReadHandler readHandler =
73                 new StyleDefinitionReadHandler();
74         childs.add(readHandler);
75         return readHandler;
76     }
77 
78     /**
79      * Done parsing.
80      *
81      * @throws org.xml.sax.SAXException if there is a parsing error.
82      */
doneParsing()83     protected void doneParsing() throws SAXException
84     {
85         for (int i = 0; i < childs.size(); i++)
86         {
87             final ElementReadHandler handler = (ElementReadHandler) childs.get(i);
88             officeStyle.addNode(handler.getElement());
89         }
90     }
91 
getOfficeStyle()92     public OfficeStyle getOfficeStyle()
93     {
94         return officeStyle;
95     }
96 
getElement()97     public Element getElement()
98     {
99         return officeStyle;
100     }
101 }
102