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.styles;
24 
25 import java.util.ArrayList;
26 import java.util.List;
27 
28 import org.pentaho.reporting.libraries.xmlns.parser.AbstractXmlReadHandler;
29 import org.pentaho.reporting.libraries.xmlns.parser.XmlReadHandler;
30 
31 import org.xml.sax.Attributes;
32 import org.xml.sax.SAXException;
33 
34 
35 /**
36  * Todo: Document me!
37  *
38  * @author Thomas Morgner
39  * @since 12.03.2007
40  */
41 public class StyleMappingDocumentReadHandler extends AbstractXmlReadHandler
42 {
43 
44     private final StyleMapper styleMapper;
45     private final List mappings;
46 
StyleMappingDocumentReadHandler()47     public StyleMappingDocumentReadHandler()
48     {
49         this.mappings = new ArrayList();
50         this.styleMapper = new StyleMapper();
51     }
52 
53     /**
54      * Returns the handler for a child element.
55      *
56      * @param tagName the tag name.
57      * @param atts    the attributes.
58      * @return the handler or null, if the tagname is invalid.
59      *
60      * @throws org.xml.sax.SAXException if there is a parsing error.
61      */
getHandlerForChild(final String uri, final String tagName, final Attributes atts)62     protected XmlReadHandler getHandlerForChild(final String uri,
63             final String tagName,
64             final Attributes atts)
65             throws SAXException
66     {
67         if (isSameNamespace(uri) && "mapping".equals(tagName))
68         {
69             final StyleMappingReadHandler smr = new StyleMappingReadHandler();
70             mappings.add(smr);
71             return smr;
72         }
73         return null;
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 < mappings.size(); i++)
85         {
86             final StyleMappingReadHandler handler =
87                     (StyleMappingReadHandler) mappings.get(i);
88             styleMapper.addMapping(handler.getRule());
89         }
90     }
91 
92     /**
93      * Returns the object for this element or null, if this element does not
94      * create an object.
95      *
96      * @return the object.
97      */
getObject()98     public Object getObject()
99             throws SAXException
100     {
101         return styleMapper;
102     }
103 }
104