Avoid potential negative array index access to cached text.
[LibreOffice.git] / xmloff / source / chart / XMLSymbolImageContext.cxx
blob646f1b8c0e625b40baa22b2733f00298ad168f13
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "XMLSymbolImageContext.hxx"
21 #include <xmloff/xmltoken.hxx>
22 #include <xmloff/xmltkmap.hxx>
23 #include <xmloff/xmlnamespace.hxx>
24 #include <xmloff/xmlimp.hxx>
25 #include <xmloff/namespacemap.hxx>
26 #include <xmloff/XMLBase64ImportContext.hxx>
27 #include <com/sun/star/io/XOutputStream.hpp>
28 #include <com/sun/star/graphic/XGraphic.hpp>
29 #include <sal/log.hxx>
31 using namespace css;
32 using namespace xmloff::token;
34 XMLSymbolImageContext::XMLSymbolImageContext(
35 SvXMLImport& rImport, sal_Int32 nElement,
36 const XMLPropertyState& rProp,
37 ::std::vector< XMLPropertyState > &rProps ) :
38 XMLElementPropertyContext(
39 rImport, nElement, rProp, rProps )
43 XMLSymbolImageContext::~XMLSymbolImageContext()
46 void XMLSymbolImageContext::startFastElement(
47 sal_Int32 /*nElement*/,
48 const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
50 for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
52 const OUString sValue = aIter.toString();
54 switch( aIter.getToken() )
56 case XML_ELEMENT(XLINK, XML_HREF):
57 msURL = sValue;
58 break;
59 case XML_ELEMENT(XLINK, XML_ACTUATE):
60 case XML_ELEMENT(XLINK, XML_TYPE):
61 case XML_ELEMENT(XLINK, XML_SHOW):
62 // these values are currently not interpreted
63 // it is always assumed 'actuate=onLoad', 'type=simple', 'show=embed'
64 break;
65 default:
66 XMLOFF_WARN_UNKNOWN("xmloff", aIter);
71 css::uno::Reference< css::xml::sax::XFastContextHandler > XMLSymbolImageContext::createFastChildContext(
72 sal_Int32 nElement,
73 const css::uno::Reference< css::xml::sax::XFastAttributeList >& /*xAttrList*/ )
75 if( (nElement & TOKEN_MASK) == xmloff::token::XML_BINARY_DATA )
77 if( msURL.isEmpty() && ! mxBase64Stream.is() )
79 mxBase64Stream = GetImport().GetStreamForGraphicObjectURLFromBase64();
80 if( mxBase64Stream.is() )
81 return new XMLBase64ImportContext( GetImport(), mxBase64Stream );
84 XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement);
85 return nullptr;
88 void XMLSymbolImageContext::endFastElement(sal_Int32 nElement)
90 uno::Reference<graphic::XGraphic> xGraphic;
92 if (!msURL.isEmpty())
94 xGraphic = GetImport().loadGraphicByURL(msURL);
96 else if (mxBase64Stream.is())
98 xGraphic = GetImport().loadGraphicFromBase64(mxBase64Stream);
99 mxBase64Stream = nullptr;
102 if (xGraphic.is())
104 // aProp is a member of XMLElementPropertyContext
105 aProp.maValue <<= xGraphic;
106 SetInsert( true );
109 XMLElementPropertyContext::endFastElement(nElement);
112 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */