Bump for 3.6-28
[LibreOffice.git] / xmlscript / source / xmldlg_imexp / xmldlg_addfunc.cxx
blob8c6f78eb9eb1ae03dfa43db52f0884b6c6aa2d04
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
31 #include <com/sun/star/io/XActiveDataSource.hpp>
32 #include <com/sun/star/xml/sax/XParser.hpp>
34 #include <comphelper/processfactory.hxx>
35 #include <cppuhelper/implbase1.hxx>
36 #include <xmlscript/xml_helper.hxx>
37 #include <xmlscript/xmldlg_imexp.hxx>
40 using namespace ::rtl;
41 using namespace ::com::sun::star;
42 using namespace ::com::sun::star::uno;
43 using namespace ::com::sun::star::frame;
45 namespace xmlscript
48 //==================================================================================================
49 class InputStreamProvider
50 : public ::cppu::WeakImplHelper1< io::XInputStreamProvider >
52 ByteSequence _bytes;
54 public:
55 inline InputStreamProvider( ByteSequence const & rBytes )
56 : _bytes( rBytes )
59 // XInputStreamProvider
60 virtual Reference< io::XInputStream > SAL_CALL createInputStream()
61 throw (RuntimeException);
63 //__________________________________________________________________________________________________
64 Reference< io::XInputStream > InputStreamProvider::createInputStream()
65 throw (RuntimeException)
67 return ::xmlscript::createInputStream( _bytes );
70 //==================================================================================================
71 Reference< io::XInputStreamProvider > SAL_CALL exportDialogModel(
72 Reference< container::XNameContainer > const & xDialogModel,
73 Reference< XComponentContext > const & xContext,
74 Reference< XModel > const & xDocument )
75 SAL_THROW( (Exception) )
77 Reference< lang::XMultiComponentFactory > xSMgr( xContext->getServiceManager() );
78 if (! xSMgr.is())
80 throw RuntimeException(
81 OUString( RTL_CONSTASCII_USTRINGPARAM("no service manager available!") ),
82 Reference< XInterface >() );
85 Reference< xml::sax::XExtendedDocumentHandler > xHandler( xSMgr->createInstanceWithContext(
86 OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.xml.sax.Writer") ), xContext ), UNO_QUERY );
87 OSL_ASSERT( xHandler.is() );
88 if (! xHandler.is())
90 throw RuntimeException(
91 OUString( RTL_CONSTASCII_USTRINGPARAM("could not create sax-writer component!") ),
92 Reference< XInterface >() );
95 ByteSequence aBytes;
97 Reference< io::XActiveDataSource > xSource( xHandler, UNO_QUERY );
98 xSource->setOutputStream( createOutputStream( &aBytes ) );
99 exportDialogModel( xHandler, xDialogModel, xDocument );
101 return new InputStreamProvider( aBytes );
104 //==================================================================================================
105 void SAL_CALL importDialogModel(
106 Reference< io::XInputStream > const & xInput,
107 Reference< container::XNameContainer > const & xDialogModel,
108 Reference< XComponentContext > const & xContext,
109 Reference< XModel > const & xDocument )
110 SAL_THROW( (Exception) )
112 Reference< lang::XMultiComponentFactory > xSMgr( xContext->getServiceManager() );
113 if (! xSMgr.is())
115 throw RuntimeException(
116 OUString( RTL_CONSTASCII_USTRINGPARAM("no service manager available!") ),
117 Reference< XInterface >() );
120 Reference< xml::sax::XParser > xParser( xSMgr->createInstanceWithContext(
121 OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.xml.sax.Parser") ), xContext ), UNO_QUERY );
122 OSL_ASSERT( xParser.is() );
123 if (! xParser.is())
125 throw RuntimeException(
126 OUString( RTL_CONSTASCII_USTRINGPARAM("could not create sax-parser component!") ),
127 Reference< XInterface >() );
130 // error handler, entity resolver omitted for this helper function
131 xParser->setDocumentHandler( importDialogModel( xDialogModel, xContext, xDocument ) );
133 xml::sax::InputSource source;
134 source.aInputStream = xInput;
135 source.sSystemId = OUString( RTL_CONSTASCII_USTRINGPARAM("virtual file") );
137 xParser->parseStream( source );
142 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */