Coverage Report

Created: 2026-04-09 11:41

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/xmloff/source/draw/XMLReplacementImageContext.cxx
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/*
3
 * This file is part of the LibreOffice project.
4
 *
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/.
8
 *
9
 * This file incorporates work covered by the following license notice:
10
 *
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 .
18
 */
19
20
#include <com/sun/star/beans/XPropertySet.hpp>
21
#include <com/sun/star/graphic/XGraphic.hpp>
22
#include <osl/diagnose.h>
23
#include <xmloff/xmlimp.hxx>
24
#include <xmloff/xmltoken.hxx>
25
#include <xmloff/xmlnamespace.hxx>
26
#include <xmloff/XMLBase64ImportContext.hxx>
27
#include <XMLReplacementImageContext.hxx>
28
#include <sal/log.hxx>
29
30
using ::com::sun::star::uno::Reference;
31
using namespace ::com::sun::star::xml::sax;
32
using namespace ::com::sun::star::beans;
33
using namespace css;
34
using namespace ::xmloff::token;
35
36
XMLReplacementImageContext::XMLReplacementImageContext(
37
        SvXMLImport& rImport,
38
        sal_Int32 /*nElement*/,
39
        const Reference< XFastAttributeList > & rAttrList,
40
        const Reference< XPropertySet > & rPropSet ) :
41
34
    SvXMLImportContext( rImport ),
42
34
    m_xPropSet( rPropSet )
43
34
{
44
34
    m_sHRef = rAttrList->getOptionalValue(XML_ELEMENT(XLINK, XML_HREF));
45
34
}
46
47
XMLReplacementImageContext::~XMLReplacementImageContext()
48
34
{
49
34
}
50
51
void XMLReplacementImageContext::endFastElement(sal_Int32 )
52
24
{
53
24
    OSL_ENSURE( !m_sHRef.isEmpty() || m_xBase64Stream.is(),
54
24
                "neither URL nor base64 image data given" );
55
24
    uno::Reference<graphic::XGraphic> xGraphic;
56
57
24
    try
58
24
    {
59
24
        if( !m_sHRef.isEmpty() )
60
0
        {
61
0
            xGraphic = GetImport().loadGraphicByURL(m_sHRef);
62
0
        }
63
24
        else if( m_xBase64Stream.is() )
64
24
        {
65
24
            xGraphic = GetImport().loadGraphicFromBase64(m_xBase64Stream);
66
24
            m_xBase64Stream = nullptr;
67
24
        }
68
24
    }
69
24
    catch (uno::Exception const &)
70
24
    {}
71
72
24
    Reference < XPropertySetInfo > xPropSetInfo = m_xPropSet->getPropertySetInfo();
73
74
24
    if (xGraphic.is() && xPropSetInfo->hasPropertyByName(u"Graphic"_ustr))
75
21
    {
76
21
        m_xPropSet->setPropertyValue(u"Graphic"_ustr, uno::Any(xGraphic));
77
21
    }
78
24
}
79
80
css::uno::Reference< css::xml::sax::XFastContextHandler > XMLReplacementImageContext::createFastChildContext(
81
    sal_Int32 nElement,
82
    const css::uno::Reference< css::xml::sax::XFastAttributeList >&  )
83
35
{
84
35
    if( nElement == XML_ELEMENT(OFFICE, XML_BINARY_DATA) &&
85
33
        !m_xBase64Stream.is() )
86
33
    {
87
33
        m_xBase64Stream = GetImport().GetStreamForGraphicObjectURLFromBase64();
88
33
        if( m_xBase64Stream.is() )
89
33
            return new XMLBase64ImportContext( GetImport(),
90
33
                                                    m_xBase64Stream );
91
33
    }
92
93
2
    XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement);
94
2
    return nullptr;
95
2
}
96
97
98
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */