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.office;
24 
25 import com.sun.star.report.pentaho.OfficeNamespaces;
26 import com.sun.star.report.pentaho.model.OfficeStylesCollection;
27 import com.sun.star.report.pentaho.parser.ElementReadHandler;
28 import com.sun.star.report.pentaho.parser.style.OfficeStylesReadHandler;
29 
30 import org.jfree.report.structure.Element;
31 
32 import org.pentaho.reporting.libraries.xmlns.parser.XmlReadHandler;
33 
34 import org.xml.sax.Attributes;
35 import org.xml.sax.SAXException;
36 
37 /**
38  * The root parser for a 'styles.xml' document. This generates the global
39  * (or common) style collection. These styles contain the named common styles
40  * and the page layouts.
41  *
42  * @author Thomas Morgner
43  * @since 08.03.2007
44  */
45 public class DocumentStylesReadHandler extends ElementReadHandler
46 {
47 
48     private final OfficeStylesCollection officeStylesCollection;
49     private FontFaceDeclsReadHandler fontFaceReadHandler;
50 
DocumentStylesReadHandler()51     public DocumentStylesReadHandler()
52     {
53         officeStylesCollection = new OfficeStylesCollection();
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         if (!OfficeNamespaces.OFFICE_NS.equals(uri))
71         {
72             return null;
73         }
74 
75         if ("font-face-decls".equals(tagName))
76         {
77             if (fontFaceReadHandler == null)
78             {
79                 fontFaceReadHandler = new FontFaceDeclsReadHandler(officeStylesCollection.getFontFaceDecls());
80             }
81             return fontFaceReadHandler;
82         }
83         else if ("automatic-styles".equals(tagName))
84         {
85             return new OfficeStylesReadHandler(officeStylesCollection.getAutomaticStyles());
86         }
87         else if ("styles".equals(tagName))
88         {
89             return new OfficeStylesReadHandler(officeStylesCollection.getCommonStyles());
90         }
91         else if ("master-styles".equals(tagName))
92         {
93             return new MasterStylesReadHandler(officeStylesCollection.getMasterStyles());
94         }
95         return null;
96     }
97 
getElement()98     public Element getElement()
99     {
100         return officeStylesCollection;
101     }
102 }
103