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
;
37 class InputStreamProvider
38 : public ::cppu::WeakImplHelper
< io::XInputStreamProvider
>
40 std::vector
<sal_Int8
> const _bytes
;
43 explicit InputStreamProvider( std::vector
<sal_Int8
> const & rBytes
)
48 // XInputStreamProvider
49 virtual uno::Reference
< io::XInputStream
> SAL_CALL
createInputStream() override
;
54 uno::Reference
< io::XInputStream
> InputStreamProvider::createInputStream()
56 return ::xmlscript::createInputStream( _bytes
);
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
)
64 uno::Reference
< xml::sax::XWriter
> xWriter
= xml::sax::Writer::create(xContext
);
66 std::vector
<sal_Int8
> aBytes
;
67 xWriter
->setOutputStream( createOutputStream( &aBytes
) );
69 uno::Reference
< xml::sax::XExtendedDocumentHandler
> xHandler(xWriter
, uno::UNO_QUERY_THROW
);
70 exportDialogModel( xHandler
, xDialogModel
, xDocument
);
72 return new InputStreamProvider( aBytes
);
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
)
81 uno::Reference
< xml::sax::XParser
> xParser
= xml::sax::Parser::create( xContext
);
83 // error handler, entity resolver omitted for this helper function
84 xParser
->setDocumentHandler( importDialogModel( xDialogModel
, xContext
, xDocument
) );
86 xml::sax::InputSource source
;
87 source
.aInputStream
= xInput
;
88 source
.sSystemId
= "virtual file";
90 xParser
->parseStream( source
);
95 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */