1 /*
2  * This file is part of the LibreOffice project.
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7  *
8  * This file incorporates work covered by the following license notice:
9  *
10  *   Licensed to the Apache Software Foundation (ASF) under one or more
11  *   contributor license agreements. See the NOTICE file distributed
12  *   with this work for additional information regarding copyright
13  *   ownership. The ASF licenses this file to you under the Apache
14  *   License, Version 2.0 (the "License"); you may not use this file
15  *   except in compliance with the License. You may obtain a copy of
16  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
17  */
18 package org.libreoffice.report.pentaho.parser.draw;
19 
20 import org.libreoffice.report.pentaho.OfficeNamespaces;
21 import org.libreoffice.report.pentaho.model.ObjectOleElement;
22 import org.libreoffice.report.pentaho.parser.ElementReadHandler;
23 
24 import org.jfree.report.structure.Element;
25 
26 import org.xml.sax.Attributes;
27 import org.xml.sax.SAXException;
28 
29 /**
30  *
31  */
32 public class ObjectOleReadHandler extends ElementReadHandler
33 {
34 
35     private static final String RPT_CHART_CLASS_ID = "80243D39-6741-46C5-926E-069164FF87BB";
36     private static final String OOO_CHART_CLASS_ID = "12DCAE26-281F-416F-A234-C3086127382E";
37     private final ObjectOleElement element;
38 
ObjectOleReadHandler(final ObjectOleElement element)39     public ObjectOleReadHandler(final ObjectOleElement element)
40     {
41         this.element = element;
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      */
50     @Override
startParsing(final Attributes attrs)51     protected void startParsing(final Attributes attrs) throws SAXException
52     {
53         super.startParsing(attrs);
54 
55         final String url = attrs.getValue(OfficeNamespaces.XLINK_NS, "href");
56         if (url != null)
57         {
58             element.setUrl(url);
59         }
60 
61         String classid = attrs.getValue(OfficeNamespaces.DRAWING_NS, "class-id");
62         if (classid != null)
63         {
64             if (classid.equalsIgnoreCase(RPT_CHART_CLASS_ID))
65             {
66                 classid = OOO_CHART_CLASS_ID;
67             }
68             element.setClassId(classid);
69         }
70     }
71 
72     @Override
getElement()73     public Element getElement()
74     {
75         return element;
76     }
77 }
78