Coverage Report

Created: 2026-02-14 09:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/xmlscript/source/xmldlg_imexp/xmldlg_addfunc.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/io/XInputStreamProvider.hpp>
21
#include <com/sun/star/xml/sax/Parser.hpp>
22
#include <com/sun/star/xml/sax/Writer.hpp>
23
24
#include <cppuhelper/implbase.hxx>
25
#include <xmlscript/xml_helper.hxx>
26
#include <xmlscript/xmldlg_imexp.hxx>
27
28
using namespace ::rtl;
29
using namespace ::com::sun::star;
30
using namespace ::com::sun::star::frame;
31
32
namespace xmlscript
33
{
34
35
namespace {
36
37
class InputStreamProvider
38
    : public ::cppu::WeakImplHelper< io::XInputStreamProvider >
39
{
40
    std::vector<sal_Int8> const _bytes;
41
42
public:
43
    explicit InputStreamProvider( std::vector<sal_Int8>&& rBytes )
44
0
        : _bytes( std::move(rBytes) )
45
0
    {
46
0
    }
47
48
    // XInputStreamProvider
49
    virtual uno::Reference< io::XInputStream > SAL_CALL createInputStream() override;
50
};
51
52
}
53
54
uno::Reference< io::XInputStream > InputStreamProvider::createInputStream()
55
0
{
56
0
    return ::xmlscript::createInputStream( std::vector(_bytes) );
57
0
}
58
59
uno::Reference< io::XInputStreamProvider > exportDialogModel(
60
    uno::Reference< container::XNameContainer > const & xDialogModel,
61
    uno::Reference< uno::XComponentContext > const & xContext,
62
    uno::Reference< XModel > const & xDocument )
63
0
{
64
0
    uno::Reference< xml::sax::XWriter > xWriter = xml::sax::Writer::create(xContext);
65
66
0
    std::vector<sal_Int8> aBytes;
67
0
    xWriter->setOutputStream( createOutputStream( &aBytes ) );
68
69
0
    uno::Reference< xml::sax::XExtendedDocumentHandler > xHandler(xWriter, uno::UNO_QUERY_THROW);
70
0
    exportDialogModel( xHandler, xDialogModel, xDocument );
71
72
0
    return new InputStreamProvider( std::move(aBytes) );
73
0
}
74
75
void importDialogModel(
76
    uno::Reference< io::XInputStream > const & xInput,
77
    uno::Reference< container::XNameContainer > const & xDialogModel,
78
    uno::Reference< uno::XComponentContext > const & xContext,
79
    uno::Reference< XModel > const & xDocument )
80
0
{
81
0
    uno::Reference< xml::sax::XParser > xParser = xml::sax::Parser::create( xContext );
82
83
    // error handler, entity resolver omitted for this helper function
84
0
    xParser->setDocumentHandler( importDialogModel( xDialogModel, xContext, xDocument ) );
85
86
0
    xml::sax::InputSource source;
87
0
    source.aInputStream = xInput;
88
0
    source.sSystemId = "virtual file";
89
90
0
    xParser->parseStream( source );
91
0
}
92
93
}
94
95
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */