LibreOffice Module xmlscript (master) 1
xmldlg_addfunc.cxx
Go to the documentation of this file.
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
27
28using namespace ::rtl;
29using namespace ::com::sun::star;
30using namespace ::com::sun::star::frame;
31
32namespace xmlscript
33{
34
35namespace {
36
37class InputStreamProvider
38 : public ::cppu::WeakImplHelper< io::XInputStreamProvider >
39{
40 std::vector<sal_Int8> const _bytes;
41
42public:
43 explicit InputStreamProvider( std::vector<sal_Int8>&& rBytes )
44 : _bytes( std::move(rBytes) )
45 {
46 }
47
48 // XInputStreamProvider
49 virtual uno::Reference< io::XInputStream > SAL_CALL createInputStream() override;
50};
51
52}
53
54uno::Reference< io::XInputStream > InputStreamProvider::createInputStream()
55{
57}
58
59uno::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{
64 uno::Reference< xml::sax::XWriter > xWriter = xml::sax::Writer::create(xContext);
65
66 std::vector<sal_Int8> aBytes;
67 xWriter->setOutputStream( createOutputStream( &aBytes ) );
68
69 uno::Reference< xml::sax::XExtendedDocumentHandler > xHandler(xWriter, uno::UNO_QUERY_THROW);
70 exportDialogModel( xHandler, xDialogModel, xDocument );
71
72 return new InputStreamProvider( std::move(aBytes) );
73}
74
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{
81 uno::Reference< xml::sax::XParser > xParser = xml::sax::Parser::create( xContext );
82
83 // error handler, entity resolver omitted for this helper function
84 xParser->setDocumentHandler( importDialogModel( xDialogModel, xContext, xDocument ) );
85
86 xml::sax::InputSource source;
87 source.aInputStream = xInput;
88 source.sSystemId = "virtual file";
89
90 xParser->parseStream( source );
91}
92
93}
94
95/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< io::XInputStream > createInputStream(std::vector< sal_Int8 > &&rInData)
void importDialogModel(uno::Reference< io::XInputStream > const &xInput, uno::Reference< container::XNameContainer > const &xDialogModel, uno::Reference< uno::XComponentContext > const &xContext, uno::Reference< XModel > const &xDocument)
uno::Reference< io::XInputStreamProvider > exportDialogModel(uno::Reference< container::XNameContainer > const &xDialogModel, uno::Reference< uno::XComponentContext > const &xContext, uno::Reference< XModel > const &xDocument)
Reference< io::XOutputStream > createOutputStream(std::vector< sal_Int8 > *pOutData)
std::vector< sal_Int8 > const _bytes