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