1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/io/XInputStreamProvider.hpp>
21 #include <com/sun/star/xml/sax/Parser.hpp>
22 #include <com/sun/star/xml/sax/Writer.hpp>
24 #include <cppuhelper/implbase.hxx>
25 #include <xmlscript/xml_helper.hxx>
26 #include <xmlscript/xmldlg_imexp.hxx>
28 using namespace ::rtl
;
29 using namespace ::com::sun::star
;
30 using namespace ::com::sun::star::frame
;
35 class InputStreamProvider
36 : public ::cppu::WeakImplHelper
< io::XInputStreamProvider
>
38 std::vector
<sal_Int8
> const _bytes
;
41 explicit InputStreamProvider( std::vector
<sal_Int8
> const & rBytes
)
46 // XInputStreamProvider
47 virtual uno::Reference
< io::XInputStream
> SAL_CALL
createInputStream() override
;
49 uno::Reference
< io::XInputStream
> InputStreamProvider::createInputStream()
51 return ::xmlscript::createInputStream( _bytes
);
54 uno::Reference
< io::XInputStreamProvider
> exportDialogModel(
55 uno::Reference
< container::XNameContainer
> const & xDialogModel
,
56 uno::Reference
< uno::XComponentContext
> const & xContext
,
57 uno::Reference
< XModel
> const & xDocument
)
59 uno::Reference
< xml::sax::XWriter
> xWriter
= xml::sax::Writer::create(xContext
);
61 std::vector
<sal_Int8
> aBytes
;
62 xWriter
->setOutputStream( createOutputStream( &aBytes
) );
64 uno::Reference
< xml::sax::XExtendedDocumentHandler
> xHandler(xWriter
, uno::UNO_QUERY_THROW
);
65 exportDialogModel( xHandler
, xDialogModel
, xDocument
);
67 return new InputStreamProvider( aBytes
);
70 void importDialogModel(
71 uno::Reference
< io::XInputStream
> const & xInput
,
72 uno::Reference
< container::XNameContainer
> const & xDialogModel
,
73 uno::Reference
< uno::XComponentContext
> const & xContext
,
74 uno::Reference
< XModel
> const & xDocument
)
76 uno::Reference
< xml::sax::XParser
> xParser
= xml::sax::Parser::create( xContext
);
78 // error handler, entity resolver omitted for this helper function
79 xParser
->setDocumentHandler( importDialogModel( xDialogModel
, xContext
, xDocument
) );
81 xml::sax::InputSource source
;
82 source
.aInputStream
= xInput
;
83 source
.sSystemId
= "virtual file";
85 xParser
->parseStream( source
);
90 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */