bump product version to 4.1.6.2
[LibreOffice.git] / xmlscript / source / xmldlg_imexp / xmldlg_addfunc.cxx
blob9918419274c77665fd55559d3513ffcc423d2e88
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 .
21 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
22 #include <com/sun/star/io/XActiveDataSource.hpp>
23 #include <com/sun/star/xml/sax/Parser.hpp>
24 #include <com/sun/star/xml/sax/Writer.hpp>
26 #include <comphelper/processfactory.hxx>
27 #include <cppuhelper/implbase1.hxx>
28 #include <xmlscript/xml_helper.hxx>
29 #include <xmlscript/xmldlg_imexp.hxx>
32 using namespace ::rtl;
33 using namespace ::com::sun::star;
34 using namespace ::com::sun::star::uno;
35 using namespace ::com::sun::star::frame;
37 namespace xmlscript
40 //==================================================================================================
41 class InputStreamProvider
42 : public ::cppu::WeakImplHelper1< io::XInputStreamProvider >
44 ByteSequence _bytes;
46 public:
47 inline InputStreamProvider( ByteSequence const & rBytes )
48 : _bytes( rBytes )
51 // XInputStreamProvider
52 virtual Reference< io::XInputStream > SAL_CALL createInputStream()
53 throw (RuntimeException);
55 //__________________________________________________________________________________________________
56 Reference< io::XInputStream > InputStreamProvider::createInputStream()
57 throw (RuntimeException)
59 return ::xmlscript::createInputStream( _bytes );
62 //==================================================================================================
63 Reference< io::XInputStreamProvider > SAL_CALL exportDialogModel(
64 Reference< container::XNameContainer > const & xDialogModel,
65 Reference< XComponentContext > const & xContext,
66 Reference< XModel > const & xDocument )
67 SAL_THROW( (Exception) )
69 Reference< xml::sax::XWriter > xWriter = xml::sax::Writer::create(xContext);
71 ByteSequence aBytes;
72 xWriter->setOutputStream( createOutputStream( &aBytes ) );
74 Reference< xml::sax::XExtendedDocumentHandler > xHandler(xWriter, UNO_QUERY_THROW);
75 exportDialogModel( xHandler, xDialogModel, xDocument );
77 return new InputStreamProvider( aBytes );
80 //==================================================================================================
81 void SAL_CALL importDialogModel(
82 Reference< io::XInputStream > const & xInput,
83 Reference< container::XNameContainer > const & xDialogModel,
84 Reference< XComponentContext > const & xContext,
85 Reference< XModel > const & xDocument )
86 SAL_THROW( (Exception) )
88 Reference< xml::sax::XParser > xParser = xml::sax::Parser::create( xContext );
90 // error handler, entity resolver omitted for this helper function
91 xParser->setDocumentHandler( importDialogModel( xDialogModel, xContext, xDocument ) );
93 xml::sax::InputSource source;
94 source.aInputStream = xInput;
95 source.sSystemId = "virtual file";
97 xParser->parseStream( source );
102 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */