Version 6.1.0.2, tag libreoffice-6.1.0.2
[LibreOffice.git] / xmlscript / source / xmldlg_imexp / xmldlg_addfunc.cxx
blobd0daa3746c65a6c8e1229935d007bc72cab5ed3c
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 <com/sun/star/lang/XMultiServiceFactory.hpp>
21 #include <com/sun/star/io/XActiveDataSource.hpp>
22 #include <com/sun/star/xml/sax/Parser.hpp>
23 #include <com/sun/star/xml/sax/Writer.hpp>
25 #include <cppuhelper/implbase.hxx>
26 #include <xmlscript/xml_helper.hxx>
27 #include <xmlscript/xmldlg_imexp.hxx>
29 using namespace ::rtl;
30 using namespace ::com::sun::star;
31 using namespace ::com::sun::star::frame;
33 namespace xmlscript
36 class InputStreamProvider
37 : public ::cppu::WeakImplHelper< io::XInputStreamProvider >
39 std::vector<sal_Int8> _bytes;
41 public:
42 explicit InputStreamProvider( std::vector<sal_Int8> const & rBytes )
43 : _bytes( rBytes )
47 // XInputStreamProvider
48 virtual uno::Reference< io::XInputStream > SAL_CALL createInputStream() override;
50 uno::Reference< io::XInputStream > InputStreamProvider::createInputStream()
52 return ::xmlscript::createInputStream( _bytes );
55 uno::Reference< io::XInputStreamProvider > exportDialogModel(
56 uno::Reference< container::XNameContainer > const & xDialogModel,
57 uno::Reference< uno::XComponentContext > const & xContext,
58 uno::Reference< XModel > const & xDocument )
60 uno::Reference< xml::sax::XWriter > xWriter = xml::sax::Writer::create(xContext);
62 std::vector<sal_Int8> aBytes;
63 xWriter->setOutputStream( createOutputStream( &aBytes ) );
65 uno::Reference< xml::sax::XExtendedDocumentHandler > xHandler(xWriter, uno::UNO_QUERY_THROW);
66 exportDialogModel( xHandler, xDialogModel, xDocument );
68 return new InputStreamProvider( aBytes );
71 void importDialogModel(
72 uno::Reference< io::XInputStream > const & xInput,
73 uno::Reference< container::XNameContainer > const & xDialogModel,
74 uno::Reference< uno::XComponentContext > const & xContext,
75 uno::Reference< XModel > const & xDocument )
77 uno::Reference< xml::sax::XParser > xParser = xml::sax::Parser::create( xContext );
79 // error handler, entity resolver omitted for this helper function
80 xParser->setDocumentHandler( importDialogModel( xDialogModel, xContext, xDocument ) );
82 xml::sax::InputSource source;
83 source.aInputStream = xInput;
84 source.sSystemId = "virtual file";
86 xParser->parseStream( source );
91 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */