Branch data 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 : :
21 : : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
22 : : #include <com/sun/star/io/XActiveDataSource.hpp>
23 : : #include <com/sun/star/xml/sax/XParser.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 : :
31 : : using namespace ::rtl;
32 : : using namespace ::com::sun::star;
33 : : using namespace ::com::sun::star::uno;
34 : : using namespace ::com::sun::star::frame;
35 : :
36 : : namespace xmlscript
37 : : {
38 : :
39 : : //==================================================================================================
40 [ # # ]: 0 : class InputStreamProvider
41 : : : public ::cppu::WeakImplHelper1< io::XInputStreamProvider >
42 : : {
43 : : ByteSequence _bytes;
44 : :
45 : : public:
46 : 0 : inline InputStreamProvider( ByteSequence const & rBytes )
47 : 0 : : _bytes( rBytes )
48 : 0 : {}
49 : :
50 : : // XInputStreamProvider
51 : : virtual Reference< io::XInputStream > SAL_CALL createInputStream()
52 : : throw (RuntimeException);
53 : : };
54 : : //__________________________________________________________________________________________________
55 : 0 : Reference< io::XInputStream > InputStreamProvider::createInputStream()
56 : : throw (RuntimeException)
57 : : {
58 : 0 : return ::xmlscript::createInputStream( _bytes );
59 : : }
60 : :
61 : : //==================================================================================================
62 : 0 : Reference< io::XInputStreamProvider > SAL_CALL exportDialogModel(
63 : : Reference< container::XNameContainer > const & xDialogModel,
64 : : Reference< XComponentContext > const & xContext,
65 : : Reference< XModel > const & xDocument )
66 : : SAL_THROW( (Exception) )
67 : : {
68 [ # # ][ # # ]: 0 : Reference< lang::XMultiComponentFactory > xSMgr( xContext->getServiceManager() );
69 [ # # ]: 0 : if (! xSMgr.is())
70 : : {
71 : : throw RuntimeException(
72 : : OUString( RTL_CONSTASCII_USTRINGPARAM("no service manager available!") ),
73 [ # # ][ # # ]: 0 : Reference< XInterface >() );
74 : : }
75 : :
76 [ # # ]: 0 : Reference< xml::sax::XExtendedDocumentHandler > xHandler( xSMgr->createInstanceWithContext(
77 [ # # ][ # # ]: 0 : OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.xml.sax.Writer") ), xContext ), UNO_QUERY );
[ # # ]
78 : : OSL_ASSERT( xHandler.is() );
79 [ # # ]: 0 : if (! xHandler.is())
80 : : {
81 : : throw RuntimeException(
82 : : OUString( RTL_CONSTASCII_USTRINGPARAM("could not create sax-writer component!") ),
83 [ # # ][ # # ]: 0 : Reference< XInterface >() );
84 : : }
85 : :
86 : 0 : ByteSequence aBytes;
87 : :
88 [ # # ]: 0 : Reference< io::XActiveDataSource > xSource( xHandler, UNO_QUERY );
89 [ # # ][ # # ]: 0 : xSource->setOutputStream( createOutputStream( &aBytes ) );
[ # # ]
90 [ # # ]: 0 : exportDialogModel( xHandler, xDialogModel, xDocument );
91 : :
92 [ # # ][ # # ]: 0 : return new InputStreamProvider( aBytes );
[ # # ]
93 : : }
94 : :
95 : : //==================================================================================================
96 : 0 : void SAL_CALL importDialogModel(
97 : : Reference< io::XInputStream > const & xInput,
98 : : Reference< container::XNameContainer > const & xDialogModel,
99 : : Reference< XComponentContext > const & xContext,
100 : : Reference< XModel > const & xDocument )
101 : : SAL_THROW( (Exception) )
102 : : {
103 [ # # ][ # # ]: 0 : Reference< lang::XMultiComponentFactory > xSMgr( xContext->getServiceManager() );
104 [ # # ]: 0 : if (! xSMgr.is())
105 : : {
106 : : throw RuntimeException(
107 : : OUString( RTL_CONSTASCII_USTRINGPARAM("no service manager available!") ),
108 [ # # ][ # # ]: 0 : Reference< XInterface >() );
109 : : }
110 : :
111 [ # # ]: 0 : Reference< xml::sax::XParser > xParser( xSMgr->createInstanceWithContext(
112 [ # # ][ # # ]: 0 : OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.xml.sax.Parser") ), xContext ), UNO_QUERY );
[ # # ]
113 : : OSL_ASSERT( xParser.is() );
114 [ # # ]: 0 : if (! xParser.is())
115 : : {
116 : : throw RuntimeException(
117 : : OUString( RTL_CONSTASCII_USTRINGPARAM("could not create sax-parser component!") ),
118 [ # # ][ # # ]: 0 : Reference< XInterface >() );
119 : : }
120 : :
121 : : // error handler, entity resolver omitted for this helper function
122 [ # # ][ # # ]: 0 : xParser->setDocumentHandler( importDialogModel( xDialogModel, xContext, xDocument ) );
[ # # ]
123 : :
124 [ # # ]: 0 : xml::sax::InputSource source;
125 [ # # ]: 0 : source.aInputStream = xInput;
126 [ # # ]: 0 : source.sSystemId = OUString( RTL_CONSTASCII_USTRINGPARAM("virtual file") );
127 : :
128 [ # # ][ # # ]: 0 : xParser->parseStream( source );
[ # # ]
129 : 0 : }
130 : :
131 : : }
132 : :
133 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|