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;
24 
25 import org.jfree.report.structure.Element;
26 
27 import org.pentaho.reporting.libraries.xmlns.parser.AbstractXmlReadHandler;
28 
29 import org.xml.sax.Attributes;
30 import org.xml.sax.SAXException;
31 
32 /**
33  * Creation-Date: 03.07.2006, 14:22:34
34  *
35  * @author Thomas Morgner
36  */
37 public abstract class ElementReadHandler extends AbstractXmlReadHandler
38 {
39 
ElementReadHandler()40     public ElementReadHandler()
41     {
42     }
43 
44     /**
45      * Starts parsing.
46      *
47      * @param attrs the attributes.
48      * @throws org.xml.sax.SAXException if there is a parsing error.
49      */
startParsing(final Attributes attrs)50     protected void startParsing(final Attributes attrs) throws SAXException
51     {
52         final Element element = getElement();
53         copyElementType(element);
54         copyAttributes(attrs, element);
55     }
56 
copyElementType(final Element element)57     protected void copyElementType(final Element element)
58     {
59         element.setType(getTagName());
60         element.setNamespace(getUri());
61     }
62 
copyAttributes(final Attributes attrs, final Element element)63     protected void copyAttributes(final Attributes attrs, final Element element)
64     {
65         final int length = attrs.getLength();
66         for (int i = 0; i < length; i++)
67         {
68             final String value = attrs.getValue(i);
69             final String namespace = attrs.getURI(i);
70             final String attr = attrs.getLocalName(i);
71             element.setAttribute(namespace, attr, value);
72         }
73     }
74 
75     /**
76      * Returns the object for this element or null, if this element does not
77      * create an object.
78      *
79      * @return the object.
80      */
getObject()81     public Object getObject() throws SAXException
82     {
83         return getElement();
84     }
85 
getElement()86     public abstract Element getElement();
87 }
88