merge the formfield patch from ooo-build
[ooovba.git] / xmlscript / source / xmldlg_imexp / xmldlg_addfunc.cxx
blobb790817c7c571700c4bec0a4508db99410eb99e0
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xmldlg_addfunc.cxx,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmlscript.hxx"
34 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
35 #include <com/sun/star/io/XActiveDataSource.hpp>
36 #include <com/sun/star/xml/sax/XParser.hpp>
38 #include <comphelper/processfactory.hxx>
39 #include <cppuhelper/implbase1.hxx>
40 #include <xmlscript/xml_helper.hxx>
41 #include <xmlscript/xmldlg_imexp.hxx>
44 using namespace ::rtl;
45 using namespace ::com::sun::star;
46 using namespace ::com::sun::star::uno;
47 using namespace ::com::sun::star::frame;
49 namespace xmlscript
52 //==================================================================================================
53 class InputStreamProvider
54 : public ::cppu::WeakImplHelper1< io::XInputStreamProvider >
56 ByteSequence _bytes;
58 public:
59 inline InputStreamProvider( ByteSequence const & rBytes )
60 : _bytes( rBytes )
63 // XInputStreamProvider
64 virtual Reference< io::XInputStream > SAL_CALL createInputStream()
65 throw (RuntimeException);
67 //__________________________________________________________________________________________________
68 Reference< io::XInputStream > InputStreamProvider::createInputStream()
69 throw (RuntimeException)
71 return ::xmlscript::createInputStream( _bytes );
74 //==================================================================================================
75 Reference< io::XInputStreamProvider > SAL_CALL exportDialogModel(
76 Reference< container::XNameContainer > const & xDialogModel,
77 Reference< XComponentContext > const & xContext,
78 Reference< XModel > const & xDocument )
79 SAL_THROW( (Exception) )
81 Reference< lang::XMultiComponentFactory > xSMgr( xContext->getServiceManager() );
82 if (! xSMgr.is())
84 throw RuntimeException(
85 OUString( RTL_CONSTASCII_USTRINGPARAM("no service manager available!") ),
86 Reference< XInterface >() );
89 Reference< xml::sax::XExtendedDocumentHandler > xHandler( xSMgr->createInstanceWithContext(
90 OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.xml.sax.Writer") ), xContext ), UNO_QUERY );
91 OSL_ASSERT( xHandler.is() );
92 if (! xHandler.is())
94 throw RuntimeException(
95 OUString( RTL_CONSTASCII_USTRINGPARAM("could not create sax-writer component!") ),
96 Reference< XInterface >() );
99 ByteSequence aBytes;
101 Reference< io::XActiveDataSource > xSource( xHandler, UNO_QUERY );
102 xSource->setOutputStream( createOutputStream( &aBytes ) );
103 exportDialogModel( xHandler, xDialogModel, xDocument );
105 return new InputStreamProvider( aBytes );
108 //==================================================================================================
109 void SAL_CALL importDialogModel(
110 Reference< io::XInputStream > xInput,
111 Reference< container::XNameContainer > const & xDialogModel,
112 Reference< XComponentContext > const & xContext,
113 Reference< XModel > const & xDocument )
114 SAL_THROW( (Exception) )
116 Reference< lang::XMultiComponentFactory > xSMgr( xContext->getServiceManager() );
117 if (! xSMgr.is())
119 throw RuntimeException(
120 OUString( RTL_CONSTASCII_USTRINGPARAM("no service manager available!") ),
121 Reference< XInterface >() );
124 Reference< xml::sax::XParser > xParser( xSMgr->createInstanceWithContext(
125 OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.xml.sax.Parser") ), xContext ), UNO_QUERY );
126 OSL_ASSERT( xParser.is() );
127 if (! xParser.is())
129 throw RuntimeException(
130 OUString( RTL_CONSTASCII_USTRINGPARAM("could not create sax-parser component!") ),
131 Reference< XInterface >() );
134 // error handler, entity resolver omitted for this helper function
135 xParser->setDocumentHandler( importDialogModel( xDialogModel, xContext, xDocument ) );
137 xml::sax::InputSource source;
138 source.aInputStream = xInput;
139 source.sSystemId = OUString( RTL_CONSTASCII_USTRINGPARAM("virtual file") );
141 xParser->parseStream( source );