xref: /aoo42x/main/sw/source/ui/uno/unomailmerge.cxx (revision 86e1cf34)
1efeef26fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3efeef26fSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4efeef26fSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5efeef26fSAndrew Rist  * distributed with this work for additional information
6efeef26fSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7efeef26fSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8efeef26fSAndrew Rist  * "License"); you may not use this file except in compliance
9efeef26fSAndrew Rist  * with the License.  You may obtain a copy of the License at
10efeef26fSAndrew Rist  *
11efeef26fSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12efeef26fSAndrew Rist  *
13efeef26fSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14efeef26fSAndrew Rist  * software distributed under the License is distributed on an
15efeef26fSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16efeef26fSAndrew Rist  * KIND, either express or implied.  See the License for the
17efeef26fSAndrew Rist  * specific language governing permissions and limitations
18efeef26fSAndrew Rist  * under the License.
19efeef26fSAndrew Rist  *
20efeef26fSAndrew Rist  *************************************************************/
21efeef26fSAndrew Rist 
22efeef26fSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sw.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include <vcl/svapp.hxx>
29cdf0e10cSrcweir #include <vos/mutex.hxx>
30cdf0e10cSrcweir #include <osl/mutex.hxx>
31cdf0e10cSrcweir #include <svl/itemprop.hxx>
32cdf0e10cSrcweir #include <svl/urihelper.hxx>
33cdf0e10cSrcweir #include <svx/dataaccessdescriptor.hxx>
34cdf0e10cSrcweir #include <tools/shl.hxx>    // GetAppData
35cdf0e10cSrcweir #include <tools/tempfile.hxx>
36cdf0e10cSrcweir #include <sfx2/app.hxx>
37cdf0e10cSrcweir #include <sfx2/docfile.hxx>
38cdf0e10cSrcweir #include <sfx2/docfilt.hxx>
39cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
40cdf0e10cSrcweir #include <vcl/timer.hxx>
41cdf0e10cSrcweir #include <com/sun/star/sdb/CommandType.hpp>
42cdf0e10cSrcweir #include <com/sun/star/text/MailMergeType.hpp>
43cdf0e10cSrcweir #include <com/sun/star/text/MailMergeEvent.hpp>
44cdf0e10cSrcweir #include <com/sun/star/text/XMailMergeListener.hpp>
45cdf0e10cSrcweir #include <com/sun/star/text/XMailMergeBroadcaster.hpp>
46cdf0e10cSrcweir #include <com/sun/star/beans/PropertyAttribute.hpp>
47cdf0e10cSrcweir #include <com/sun/star/lang/XUnoTunnel.hpp>
48cdf0e10cSrcweir #include <com/sun/star/sdbc/XResultSet.hpp>
49cdf0e10cSrcweir #include <com/sun/star/sdbc/XConnection.hpp>
50cdf0e10cSrcweir #include <com/sun/star/sdbc/XRowSet.hpp>
51cdf0e10cSrcweir #include <com/sun/star/frame/XComponentLoader.hpp>
52cdf0e10cSrcweir #include <com/sun/star/util/XCloseable.hpp>
53cdf0e10cSrcweir #ifndef _COM_SUN_STAR_UTIL_CloseVetoException_HPP_
54cdf0e10cSrcweir #include <com/sun/star/util/CloseVetoException.hpp>
55cdf0e10cSrcweir #endif
56cdf0e10cSrcweir #include <com/sun/star/sdbcx/XRowLocate.hpp>
57cdf0e10cSrcweir #include <com/sun/star/frame/XStorable.hpp>
58cdf0e10cSrcweir #include "com/sun/star/mail/XSmtpService.hpp"
59cdf0e10cSrcweir #include <sfx2/viewfrm.hxx>
60cdf0e10cSrcweir #include <sfx2/event.hxx>
61cdf0e10cSrcweir #include <swevent.hxx>
62cdf0e10cSrcweir #include <unomailmerge.hxx>
63cdf0e10cSrcweir #include <swdll.hxx>
64cdf0e10cSrcweir #include <swmodule.hxx>
65cdf0e10cSrcweir #include <unoprnms.hxx>
66cdf0e10cSrcweir #include <unomap.hxx>
67cdf0e10cSrcweir #include <swunohelper.hxx>
68cdf0e10cSrcweir #include <docsh.hxx>
69cdf0e10cSrcweir #ifndef IDOCUMENTDEVICEACCESS_HXX_INCLUDED
70cdf0e10cSrcweir #include <IDocumentDeviceAccess.hxx>
71cdf0e10cSrcweir #endif
72cdf0e10cSrcweir #include <view.hxx>
73cdf0e10cSrcweir #include <dbmgr.hxx>
74cdf0e10cSrcweir #include <unotxdoc.hxx>
75cdf0e10cSrcweir #include <prtopt.hxx>
76cdf0e10cSrcweir #include <wrtsh.hxx>
77cdf0e10cSrcweir #include <shellio.hxx>
78cdf0e10cSrcweir #include <mmconfigitem.hxx>
79cdf0e10cSrcweir #include <mailmergehelper.hxx>
80cdf0e10cSrcweir #include <memory>
81cdf0e10cSrcweir 
82cdf0e10cSrcweir #include <unomid.h>
83cdf0e10cSrcweir 
84cdf0e10cSrcweir 
85cdf0e10cSrcweir #define SN_MAIL_MERGE               "com.sun.star.text.MailMerge"
86cdf0e10cSrcweir #define SN_DATA_ACCESS_DESCRIPTOR   "com.sun.star.sdb.DataAccessDescriptor"
87cdf0e10cSrcweir 
88cdf0e10cSrcweir using namespace ::com::sun::star;
89cdf0e10cSrcweir using namespace ::com::sun::star::frame;
90cdf0e10cSrcweir using namespace ::com::sun::star::uno;
91cdf0e10cSrcweir using namespace ::com::sun::star::lang;
92cdf0e10cSrcweir using namespace ::com::sun::star::beans;
93cdf0e10cSrcweir using namespace ::com::sun::star::text;
94cdf0e10cSrcweir using ::rtl::OUString;
95cdf0e10cSrcweir using namespace SWUnoHelper;
96cdf0e10cSrcweir 
97cdf0e10cSrcweir ////////////////////////////////////////////////////////////
98cdf0e10cSrcweir 
99cdf0e10cSrcweir typedef ::utl::SharedUNOComponent< XInterface > SharedComponent;
100cdf0e10cSrcweir 
101cdf0e10cSrcweir ////////////////////////////////////////////////////////////
102cdf0e10cSrcweir 
GetMailMergeMutex()103cdf0e10cSrcweir osl::Mutex &    GetMailMergeMutex()
104cdf0e10cSrcweir {
105cdf0e10cSrcweir     static osl::Mutex   aMutex;
106cdf0e10cSrcweir     return aMutex;
107cdf0e10cSrcweir }
108cdf0e10cSrcweir 
109cdf0e10cSrcweir ////////////////////////////////////////////////////////////
110cdf0e10cSrcweir 
111cdf0e10cSrcweir enum CloseResult
112cdf0e10cSrcweir {
113cdf0e10cSrcweir 	eSuccess,		// successfully closed
114*86e1cf34SPedro Giffuni 	eVetoed,		// vetoed, ownership transferred to the vetoing instance
115cdf0e10cSrcweir 	eFailed			// failed for some unknown reason
116cdf0e10cSrcweir };
CloseModelAndDocSh(Reference<frame::XModel> & rxModel,SfxObjectShellRef & rxDocSh)117cdf0e10cSrcweir static CloseResult CloseModelAndDocSh(
118cdf0e10cSrcweir        Reference< frame::XModel > &rxModel,
119cdf0e10cSrcweir        SfxObjectShellRef &rxDocSh )
120cdf0e10cSrcweir {
121cdf0e10cSrcweir 	CloseResult eResult = eSuccess;
122cdf0e10cSrcweir 
123cdf0e10cSrcweir     rxDocSh = 0;
124cdf0e10cSrcweir 
125cdf0e10cSrcweir     //! models/documents should never be disposed (they may still be
126cdf0e10cSrcweir     //! used for printing which is called asynchronously for example)
127cdf0e10cSrcweir     //! instead call close
128cdf0e10cSrcweir     Reference< util::XCloseable > xClose( rxModel, UNO_QUERY );
129cdf0e10cSrcweir     if (xClose.is())
130cdf0e10cSrcweir     {
131cdf0e10cSrcweir         try
132cdf0e10cSrcweir         {
133cdf0e10cSrcweir             //! 'sal_True' -> transfer ownership to vetoing object if vetoed!
134cdf0e10cSrcweir             //! I.e. now that object is responsible for closing the model and doc shell.
135cdf0e10cSrcweir             xClose->close( sal_True );
136cdf0e10cSrcweir         }
137cdf0e10cSrcweir         catch (util::CloseVetoException &)
138cdf0e10cSrcweir         {
139cdf0e10cSrcweir             //! here we have the problem that the temporary file that is
140cdf0e10cSrcweir 			//! currently being printed will never be deleted. :-(
141cdf0e10cSrcweir 			eResult = eVetoed;
142cdf0e10cSrcweir         }
143cdf0e10cSrcweir 		catch ( const uno::RuntimeException& )
144cdf0e10cSrcweir 		{
145cdf0e10cSrcweir 			eResult = eFailed;
146cdf0e10cSrcweir 		}
147cdf0e10cSrcweir     }
148cdf0e10cSrcweir 	return eResult;
149cdf0e10cSrcweir }
150cdf0e10cSrcweir 
151cdf0e10cSrcweir ////////////////////////////////////////////////////////////
152cdf0e10cSrcweir 
LoadFromURL_impl(Reference<frame::XModel> & rxModel,SfxObjectShellRef & rxDocSh,const String & rURL,sal_Bool bClose)153cdf0e10cSrcweir static sal_Bool LoadFromURL_impl(
154cdf0e10cSrcweir         Reference< frame::XModel > &rxModel,
155cdf0e10cSrcweir         SfxObjectShellRef &rxDocSh,
156cdf0e10cSrcweir         const String &rURL,
157cdf0e10cSrcweir         sal_Bool bClose )
158cdf0e10cSrcweir     throw (RuntimeException)
159cdf0e10cSrcweir {
160cdf0e10cSrcweir     // try to open the document readonly and hidden
161cdf0e10cSrcweir     Reference< frame::XModel > xTmpModel;
162cdf0e10cSrcweir     Sequence < PropertyValue > aArgs( 1 );
163cdf0e10cSrcweir     aArgs[0].Name = C2U("Hidden");
164cdf0e10cSrcweir     sal_Bool bVal = sal_True;
165cdf0e10cSrcweir     aArgs[0].Value <<= bVal;
166cdf0e10cSrcweir     try
167cdf0e10cSrcweir     {
168cdf0e10cSrcweir         Reference < XComponentLoader > xDesktop( ::comphelper::getProcessServiceFactory()->
169cdf0e10cSrcweir                 createInstance( C2U("com.sun.star.frame.Desktop") ), UNO_QUERY );
170cdf0e10cSrcweir         xTmpModel = Reference < XModel >( xDesktop->loadComponentFromURL(
171cdf0e10cSrcweir                 rURL, C2U("_blank"), 0, aArgs ), UNO_QUERY );
172cdf0e10cSrcweir     }
173cdf0e10cSrcweir     catch( Exception & )
174cdf0e10cSrcweir     {
175cdf0e10cSrcweir         return sal_False;
176cdf0e10cSrcweir     }
177cdf0e10cSrcweir 
178cdf0e10cSrcweir     // try to get the DocShell
179cdf0e10cSrcweir     SwDocShell *pTmpDocShell = 0;
180cdf0e10cSrcweir     Reference < XUnoTunnel > xTunnel( xTmpModel, UNO_QUERY );
181cdf0e10cSrcweir     if (xTunnel.is())
182cdf0e10cSrcweir     {
183cdf0e10cSrcweir         SwXTextDocument* pTextDoc = reinterpret_cast<SwXTextDocument *>(
184cdf0e10cSrcweir                 xTunnel->getSomething( SwXTextDocument::getUnoTunnelId() ));
185cdf0e10cSrcweir         pTmpDocShell = pTextDoc ? pTextDoc->GetDocShell() : 0;
186cdf0e10cSrcweir     }
187cdf0e10cSrcweir 
188cdf0e10cSrcweir     sal_Bool bRes = sal_False;
189cdf0e10cSrcweir     if (xTmpModel.is() && pTmpDocShell)    // everything available?
190cdf0e10cSrcweir     {
191cdf0e10cSrcweir         if (bClose)
192cdf0e10cSrcweir             CloseModelAndDocSh( rxModel, rxDocSh );
193cdf0e10cSrcweir         // set new stuff
194cdf0e10cSrcweir         rxModel = xTmpModel;
195cdf0e10cSrcweir         rxDocSh = pTmpDocShell;
196cdf0e10cSrcweir         bRes = sal_True;
197cdf0e10cSrcweir     }
198cdf0e10cSrcweir     else
199cdf0e10cSrcweir     {
200cdf0e10cSrcweir         // SfxObjectShellRef is ok here, since the document will be explicitly closed
201cdf0e10cSrcweir         SfxObjectShellRef xTmpDocSh = pTmpDocShell;
202cdf0e10cSrcweir         CloseModelAndDocSh( xTmpModel, xTmpDocSh );
203cdf0e10cSrcweir     }
204cdf0e10cSrcweir 
205cdf0e10cSrcweir     return bRes;
206cdf0e10cSrcweir }
207cdf0e10cSrcweir 
208cdf0e10cSrcweir //==========================================================
209cdf0e10cSrcweir namespace
210cdf0e10cSrcweir {
211cdf0e10cSrcweir     class DelayedFileDeletion : public ::cppu::WeakImplHelper1< util::XCloseListener >
212cdf0e10cSrcweir 	{
213cdf0e10cSrcweir 	protected:
214cdf0e10cSrcweir 		::osl::Mutex					m_aMutex;
215cdf0e10cSrcweir 		Reference< util::XCloseable >	m_xDocument;
216cdf0e10cSrcweir 		Timer							m_aDeleteTimer;
217cdf0e10cSrcweir 		String							m_sTemporaryFile;
218cdf0e10cSrcweir 		sal_Int32						m_nPendingDeleteAttempts;
219cdf0e10cSrcweir 
220cdf0e10cSrcweir 	public:
221cdf0e10cSrcweir 		DelayedFileDeletion( const Reference< XModel >& _rxModel,
222cdf0e10cSrcweir 							 const String& _rTemporaryFile );
223cdf0e10cSrcweir 
224cdf0e10cSrcweir 	protected:
225cdf0e10cSrcweir 		~DelayedFileDeletion( );
226cdf0e10cSrcweir 
227cdf0e10cSrcweir 		// XCloseListener
228cdf0e10cSrcweir 		virtual void SAL_CALL queryClosing( const EventObject& _rSource, sal_Bool _bGetsOwnership ) throw (util::CloseVetoException, RuntimeException);
229cdf0e10cSrcweir 		virtual void SAL_CALL notifyClosing( const EventObject& _rSource ) throw (RuntimeException);
230cdf0e10cSrcweir 
231cdf0e10cSrcweir 		// XEventListener
232cdf0e10cSrcweir 		virtual void SAL_CALL disposing( const EventObject& Source ) throw (RuntimeException);
233cdf0e10cSrcweir 
234cdf0e10cSrcweir 	private:
235cdf0e10cSrcweir 		void implTakeOwnership( );
236cdf0e10cSrcweir 		DECL_LINK( OnTryDeleteFile, void* );
237cdf0e10cSrcweir 
238cdf0e10cSrcweir 	private:
239cdf0e10cSrcweir 		DelayedFileDeletion( const DelayedFileDeletion& );					// never implemented
240cdf0e10cSrcweir 		DelayedFileDeletion& operator=( const DelayedFileDeletion& );		// never implemented
241cdf0e10cSrcweir 	};
242cdf0e10cSrcweir 
DBG_NAME(DelayedFileDeletion)243cdf0e10cSrcweir 	DBG_NAME( DelayedFileDeletion )
244cdf0e10cSrcweir 	//------------------------------------------------------
245cdf0e10cSrcweir 	DelayedFileDeletion::DelayedFileDeletion( const Reference< XModel >& _rxModel, const String& _rTemporaryFile )
246cdf0e10cSrcweir         :
247cdf0e10cSrcweir         m_xDocument( _rxModel, UNO_QUERY )
248cdf0e10cSrcweir         ,m_sTemporaryFile( _rTemporaryFile )
249cdf0e10cSrcweir 		,m_nPendingDeleteAttempts( 0 )
250cdf0e10cSrcweir 	{
251cdf0e10cSrcweir 		DBG_CTOR( DelayedFileDeletion, NULL );
252cdf0e10cSrcweir 
253cdf0e10cSrcweir 		osl_incrementInterlockedCount( &m_refCount );
254cdf0e10cSrcweir 		try
255cdf0e10cSrcweir 		{
256cdf0e10cSrcweir 			if ( m_xDocument.is() )
257cdf0e10cSrcweir 			{
258cdf0e10cSrcweir 				m_xDocument->addCloseListener( this );
259cdf0e10cSrcweir 				// successfully added -> keep ourself alive
260cdf0e10cSrcweir 				acquire();
261cdf0e10cSrcweir 			}
262cdf0e10cSrcweir 			else {
263cdf0e10cSrcweir 				DBG_ERROR( "DelayedFileDeletion::DelayedFileDeletion: model is no component!" );
264cdf0e10cSrcweir             }
265cdf0e10cSrcweir 		}
266cdf0e10cSrcweir 		catch( const Exception& )
267cdf0e10cSrcweir 		{
268cdf0e10cSrcweir 			DBG_ERROR( "DelayedFileDeletion::DelayedFileDeletion: could not register as event listener at the model!" );
269cdf0e10cSrcweir 		}
270cdf0e10cSrcweir 		osl_decrementInterlockedCount( &m_refCount );
271cdf0e10cSrcweir 	}
272cdf0e10cSrcweir 
273cdf0e10cSrcweir 	//--------------------------------------------------------------------
IMPL_LINK(DelayedFileDeletion,OnTryDeleteFile,void *,EMPTYARG)274cdf0e10cSrcweir     IMPL_LINK( DelayedFileDeletion, OnTryDeleteFile, void*, EMPTYARG )
275cdf0e10cSrcweir 	{
276cdf0e10cSrcweir 		::osl::ClearableMutexGuard aGuard( m_aMutex );
277cdf0e10cSrcweir 
278cdf0e10cSrcweir 		sal_Bool bSuccess = sal_False;
279cdf0e10cSrcweir 		try
280cdf0e10cSrcweir 		{
281cdf0e10cSrcweir 			sal_Bool bDeliverOwnership = ( 0 == m_nPendingDeleteAttempts );
282*86e1cf34SPedro Giffuni 				// if this is our last attempt, then anybody which vetoes this has to take the consequences
283cdf0e10cSrcweir 				// (means take the ownership)
284cdf0e10cSrcweir 			m_xDocument->close( bDeliverOwnership );
285cdf0e10cSrcweir 			bSuccess = sal_True;
286cdf0e10cSrcweir 		}
287cdf0e10cSrcweir 		catch( const util::CloseVetoException& )
288cdf0e10cSrcweir 		{
289cdf0e10cSrcweir 			// somebody vetoed -> next try
290cdf0e10cSrcweir 			if ( m_nPendingDeleteAttempts )
291cdf0e10cSrcweir 			{
292cdf0e10cSrcweir 				// next attempt
293cdf0e10cSrcweir 				--m_nPendingDeleteAttempts;
294cdf0e10cSrcweir 				m_aDeleteTimer.Start();
295cdf0e10cSrcweir 			}
296cdf0e10cSrcweir 			else
297cdf0e10cSrcweir 				bSuccess = sal_True;	// can't do anything here ...
298cdf0e10cSrcweir 		}
299cdf0e10cSrcweir 		catch( const Exception& )
300cdf0e10cSrcweir 		{
301cdf0e10cSrcweir 			DBG_ERROR( "DelayedFileDeletion::OnTryDeleteFile: caught a strange exception!" );
302cdf0e10cSrcweir 			bSuccess = sal_True;
303cdf0e10cSrcweir 				// can't do anything here ...
304cdf0e10cSrcweir 		}
305cdf0e10cSrcweir 
306cdf0e10cSrcweir 		if ( bSuccess )
307cdf0e10cSrcweir 		{
308cdf0e10cSrcweir 			SWUnoHelper::UCB_DeleteFile( m_sTemporaryFile );
309cdf0e10cSrcweir 			aGuard.clear();
310cdf0e10cSrcweir 			release();	// this should be our last reference, we should be dead after this
311cdf0e10cSrcweir 		}
312cdf0e10cSrcweir 		return 0L;
313cdf0e10cSrcweir 	}
314cdf0e10cSrcweir 
315cdf0e10cSrcweir 	//--------------------------------------------------------------------
implTakeOwnership()316cdf0e10cSrcweir 	void DelayedFileDeletion::implTakeOwnership( )
317cdf0e10cSrcweir 	{
318cdf0e10cSrcweir 		// revoke ourself as listener
319cdf0e10cSrcweir 		try
320cdf0e10cSrcweir 		{
321cdf0e10cSrcweir 			m_xDocument->removeCloseListener( this );
322cdf0e10cSrcweir 		}
323cdf0e10cSrcweir 		catch( const Exception & )
324cdf0e10cSrcweir 		{
325cdf0e10cSrcweir 			DBG_ERROR( "DelayedFileDeletion::implTakeOwnership: could not revoke the listener!" );
326cdf0e10cSrcweir 		}
327cdf0e10cSrcweir 
328cdf0e10cSrcweir 		m_aDeleteTimer.SetTimeout( 3000 );	// 3 seconds
329cdf0e10cSrcweir 		m_aDeleteTimer.SetTimeoutHdl( LINK( this, DelayedFileDeletion, OnTryDeleteFile ) );
330cdf0e10cSrcweir 		m_nPendingDeleteAttempts = 3;	// try 3 times at most
331cdf0e10cSrcweir 		m_aDeleteTimer.Start( );
332cdf0e10cSrcweir 	}
333cdf0e10cSrcweir 
334cdf0e10cSrcweir 	//--------------------------------------------------------------------
queryClosing(const EventObject &,sal_Bool _bGetsOwnership)335cdf0e10cSrcweir     void SAL_CALL DelayedFileDeletion::queryClosing( const EventObject& , sal_Bool _bGetsOwnership ) throw (util::CloseVetoException, RuntimeException)
336cdf0e10cSrcweir 	{
337cdf0e10cSrcweir 		::osl::MutexGuard aGuard( m_aMutex );
338cdf0e10cSrcweir 		if ( _bGetsOwnership )
339cdf0e10cSrcweir 			implTakeOwnership( );
340cdf0e10cSrcweir 
341cdf0e10cSrcweir 		// always veto: We want to take the ownership ourself, as this is the only chance to delete
342cdf0e10cSrcweir 		// the temporary file which the model is based on
343cdf0e10cSrcweir 		throw util::CloseVetoException( );
344cdf0e10cSrcweir 	}
345cdf0e10cSrcweir 
346cdf0e10cSrcweir 	//--------------------------------------------------------------------
notifyClosing(const EventObject &)347cdf0e10cSrcweir     void SAL_CALL DelayedFileDeletion::notifyClosing( const EventObject&  ) throw (RuntimeException)
348cdf0e10cSrcweir 	{
349cdf0e10cSrcweir 		DBG_ERROR( "DelayedFileDeletion::notifyClosing: how this?" );
350cdf0e10cSrcweir 		// this should not happen:
351cdf0e10cSrcweir 		// Either, a foreign instance closes the document, then we should veto this, and take the ownership
352cdf0e10cSrcweir 		// Or, we ourself close the document, then we should not be a listener anymore
353cdf0e10cSrcweir 	}
354cdf0e10cSrcweir 
355cdf0e10cSrcweir 	//------------------------------------------------------
disposing(const EventObject &)356cdf0e10cSrcweir     void SAL_CALL DelayedFileDeletion::disposing( const EventObject&  ) throw (RuntimeException)
357cdf0e10cSrcweir 	{
358cdf0e10cSrcweir 		DBG_ERROR( "DelayedFileDeletion::disposing: how this?" );
359cdf0e10cSrcweir 		// this should not happen:
360cdf0e10cSrcweir 		// Either, a foreign instance closes the document, then we should veto this, and take the ownership
361cdf0e10cSrcweir 		// Or, we ourself close the document, then we should not be a listener anymore
362cdf0e10cSrcweir 	}
363cdf0e10cSrcweir 
364cdf0e10cSrcweir 	//------------------------------------------------------
~DelayedFileDeletion()365cdf0e10cSrcweir 	DelayedFileDeletion::~DelayedFileDeletion( )
366cdf0e10cSrcweir 	{
367cdf0e10cSrcweir 		DBG_DTOR( DelayedFileDeletion, NULL );
368cdf0e10cSrcweir 	}
369cdf0e10cSrcweir }
370cdf0e10cSrcweir 
371cdf0e10cSrcweir ////////////////////////////////////////////////////////////
372cdf0e10cSrcweir 
DeleteTmpFile_Impl(Reference<frame::XModel> & rxModel,SfxObjectShellRef & rxDocSh,const String & rTmpFileURL)373cdf0e10cSrcweir static sal_Bool DeleteTmpFile_Impl(
374cdf0e10cSrcweir         Reference< frame::XModel > &rxModel,
375cdf0e10cSrcweir         SfxObjectShellRef &rxDocSh,
376cdf0e10cSrcweir         const String &rTmpFileURL )
377cdf0e10cSrcweir {
378cdf0e10cSrcweir     sal_Bool bRes = sal_False;
379cdf0e10cSrcweir     if (rTmpFileURL.Len())
380cdf0e10cSrcweir     {
381cdf0e10cSrcweir 		sal_Bool bDelete = sal_True;
382cdf0e10cSrcweir 		if ( eVetoed == CloseModelAndDocSh( rxModel, rxDocSh ) )
383cdf0e10cSrcweir 		{
384cdf0e10cSrcweir 			// somebody vetoed the closing, and took the ownership of the document
385cdf0e10cSrcweir 			// -> ensure that the temporary file is deleted later on
386cdf0e10cSrcweir 			Reference< XEventListener > xEnsureDelete( new DelayedFileDeletion( rxModel, rTmpFileURL ) );
387cdf0e10cSrcweir 				// note: as soon as #106931# is fixed, the whole DelayedFileDeletion is to be superseeded by
388cdf0e10cSrcweir 				// a better solution
389cdf0e10cSrcweir 			bDelete = sal_False;
390cdf0e10cSrcweir 		}
391cdf0e10cSrcweir 
392cdf0e10cSrcweir         rxModel = 0;
393cdf0e10cSrcweir         rxDocSh = 0; // destroy doc shell
394cdf0e10cSrcweir 
395cdf0e10cSrcweir 		if ( bDelete )
396cdf0e10cSrcweir 		{
397cdf0e10cSrcweir 			if ( !SWUnoHelper::UCB_DeleteFile( rTmpFileURL ) )
398cdf0e10cSrcweir 			{
399cdf0e10cSrcweir 				Reference< XEventListener > xEnsureDelete( new DelayedFileDeletion( rxModel, rTmpFileURL ) );
400cdf0e10cSrcweir 					// same not as above: as soon as #106931#, ...
401cdf0e10cSrcweir 			}
402cdf0e10cSrcweir 		}
403cdf0e10cSrcweir 		else
404cdf0e10cSrcweir 			bRes = sal_True;	// file will be deleted delayed
405cdf0e10cSrcweir     }
406cdf0e10cSrcweir     return bRes;
407cdf0e10cSrcweir }
408cdf0e10cSrcweir 
409cdf0e10cSrcweir ////////////////////////////////////////////////////////////
410cdf0e10cSrcweir 
SwXMailMerge()411cdf0e10cSrcweir SwXMailMerge::SwXMailMerge() :
412cdf0e10cSrcweir     aEvtListeners   ( GetMailMergeMutex() ),
413cdf0e10cSrcweir     aMergeListeners ( GetMailMergeMutex() ),
414cdf0e10cSrcweir     aPropListeners  ( GetMailMergeMutex() ),
415cdf0e10cSrcweir     pPropSet( aSwMapProvider.GetPropertySet( PROPERTY_MAP_MAILMERGE ) ),
416cdf0e10cSrcweir     bSendAsHTML(sal_False),
417cdf0e10cSrcweir     bSendAsAttachment(sal_False),
418cdf0e10cSrcweir     bSaveAsSingleFile(sal_False)
419cdf0e10cSrcweir 
420cdf0e10cSrcweir {
421cdf0e10cSrcweir     // create empty document
422cdf0e10cSrcweir     // like in: SwModule::InsertEnv (appenv.cxx)
423cdf0e10cSrcweir     SwDocShell *pDocShell = new SwDocShell( SFX_CREATE_MODE_STANDARD );
424cdf0e10cSrcweir     xDocSh = pDocShell;
425cdf0e10cSrcweir     xDocSh->DoInitNew( 0 );
426cdf0e10cSrcweir     SfxViewFrame *pFrame = SfxViewFrame::LoadHiddenDocument( *xDocSh, 0 );
427cdf0e10cSrcweir     SwView *pView = (SwView*) pFrame->GetViewShell();
428cdf0e10cSrcweir     pView->AttrChangedNotify( &pView->GetWrtShell() );//Damit SelectShell gerufen wird.
429cdf0e10cSrcweir 
430cdf0e10cSrcweir     xModel = pDocShell->GetModel();
431cdf0e10cSrcweir 
432cdf0e10cSrcweir     nDataCommandType    = sdb::CommandType::TABLE;
433cdf0e10cSrcweir     nOutputType         = MailMergeType::PRINTER;
434cdf0e10cSrcweir     bEscapeProcessing   = sal_True;     //!! allow to process properties like "Filter", "Order", ...
435cdf0e10cSrcweir     bSinglePrintJobs    = sal_False;
436cdf0e10cSrcweir     bFileNameFromColumn = sal_False;
437cdf0e10cSrcweir 
438cdf0e10cSrcweir     bDisposing = sal_False;
439cdf0e10cSrcweir }
440cdf0e10cSrcweir 
~SwXMailMerge()441cdf0e10cSrcweir SwXMailMerge::~SwXMailMerge()
442cdf0e10cSrcweir {
443cdf0e10cSrcweir 	if (aTmpFileName.Len())
444cdf0e10cSrcweir 		DeleteTmpFile_Impl( xModel, xDocSh, aTmpFileName );
445cdf0e10cSrcweir 	else	// there was no temporary file in use
446cdf0e10cSrcweir 	{
447cdf0e10cSrcweir 		//! we still need to close the model and doc shell manually
448cdf0e10cSrcweir 		//! because there is no automatism that will do that later.
449cdf0e10cSrcweir 		//! #120086#
450cdf0e10cSrcweir 		if ( eVetoed == CloseModelAndDocSh( xModel, xDocSh ) )
451*86e1cf34SPedro Giffuni 			DBG_WARNING( "owner ship transferred to vetoing object!" );
452cdf0e10cSrcweir 
453cdf0e10cSrcweir         xModel = 0;
454cdf0e10cSrcweir         xDocSh = 0; // destroy doc shell
455cdf0e10cSrcweir 	}
456cdf0e10cSrcweir }
457cdf0e10cSrcweir 
execute(const uno::Sequence<beans::NamedValue> & rArguments)458cdf0e10cSrcweir uno::Any SAL_CALL SwXMailMerge::execute(
459cdf0e10cSrcweir         const uno::Sequence< beans::NamedValue >& rArguments )
460cdf0e10cSrcweir     throw (IllegalArgumentException, Exception, RuntimeException)
461cdf0e10cSrcweir {
462cdf0e10cSrcweir     vos::OGuard aGuard( Application::GetSolarMutex() );
463cdf0e10cSrcweir 
464cdf0e10cSrcweir     //
465cdf0e10cSrcweir     // get property values to be used
466cdf0e10cSrcweir     // (use values from the service as default and override them with
467cdf0e10cSrcweir     // the values that are provided as arguments)
468cdf0e10cSrcweir     //
469cdf0e10cSrcweir     uno::Sequence< uno::Any >           aCurSelection   = aSelection;
470cdf0e10cSrcweir     uno::Reference< sdbc::XResultSet >  xCurResultSet   = xResultSet;
471cdf0e10cSrcweir     uno::Reference< sdbc::XConnection > xCurConnection  = xConnection;
472cdf0e10cSrcweir     uno::Reference< frame::XModel >     xCurModel       = xModel;
473cdf0e10cSrcweir     OUString   aCurDataSourceName       = aDataSourceName;
474cdf0e10cSrcweir     OUString   aCurDataCommand          = aDataCommand;
475cdf0e10cSrcweir     OUString   aCurFilter               = aFilter;
476cdf0e10cSrcweir     OUString   aCurDocumentURL          = aDocumentURL;
477cdf0e10cSrcweir     OUString   aCurOutputURL            = aOutputURL;
478cdf0e10cSrcweir     OUString   aCurFileNamePrefix       = aFileNamePrefix;
479cdf0e10cSrcweir     sal_Int32  nCurDataCommandType      = nDataCommandType;
480cdf0e10cSrcweir     sal_Int16  nCurOutputType           = nOutputType;
481cdf0e10cSrcweir     sal_Bool   bCurEscapeProcessing     = bEscapeProcessing;
482cdf0e10cSrcweir     sal_Bool   bCurSinglePrintJobs      = bSinglePrintJobs;
483cdf0e10cSrcweir     sal_Bool   bCurFileNameFromColumn   = bFileNameFromColumn;
484cdf0e10cSrcweir     //
485cdf0e10cSrcweir     SfxObjectShellRef xCurDocSh = xDocSh;   // the document
486cdf0e10cSrcweir     //
487cdf0e10cSrcweir     const beans::NamedValue *pArguments = rArguments.getConstArray();
488cdf0e10cSrcweir     sal_Int32 nArgs = rArguments.getLength();
489cdf0e10cSrcweir     for (sal_Int32 i = 0;  i < nArgs;  ++i)
490cdf0e10cSrcweir     {
491cdf0e10cSrcweir         const OUString &rName   = pArguments[i].Name;
492cdf0e10cSrcweir         const Any &rValue       = pArguments[i].Value;
493cdf0e10cSrcweir 
494cdf0e10cSrcweir         sal_Bool bOK = sal_True;
495cdf0e10cSrcweir         if (rName.equalsAscii( GetPropName( UNO_NAME_SELECTION ) ))
496cdf0e10cSrcweir             bOK = rValue >>= aCurSelection;
497cdf0e10cSrcweir         else if (rName.equalsAscii( GetPropName( UNO_NAME_RESULT_SET ) ))
498cdf0e10cSrcweir             bOK = rValue >>= xCurResultSet;
499cdf0e10cSrcweir         else if (rName.equalsAscii( GetPropName( UNO_NAME_CONNECTION ) ))
500cdf0e10cSrcweir             bOK = rValue >>= xCurConnection;
501cdf0e10cSrcweir         else if (rName.equalsAscii( GetPropName( UNO_NAME_MODEL ) ))
502cdf0e10cSrcweir             throw PropertyVetoException( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Property is read-only: " ) ) + rName, static_cast < cppu::OWeakObject * > ( this ) );
503cdf0e10cSrcweir         else if (rName.equalsAscii( GetPropName( UNO_NAME_DATA_SOURCE_NAME ) ))
504cdf0e10cSrcweir             bOK = rValue >>= aCurDataSourceName;
505cdf0e10cSrcweir         else if (rName.equalsAscii( GetPropName( UNO_NAME_DAD_COMMAND ) ))
506cdf0e10cSrcweir             bOK = rValue >>= aCurDataCommand;
507cdf0e10cSrcweir         else if (rName.equalsAscii( GetPropName( UNO_NAME_FILTER ) ))
508cdf0e10cSrcweir             bOK = rValue >>= aCurFilter;
509cdf0e10cSrcweir         else if (rName.equalsAscii( GetPropName( UNO_NAME_DOCUMENT_URL ) ))
510cdf0e10cSrcweir         {
511cdf0e10cSrcweir             bOK = rValue >>= aCurDocumentURL;
512cdf0e10cSrcweir             if (aCurDocumentURL.getLength()
513cdf0e10cSrcweir                 && !LoadFromURL_impl( xCurModel, xCurDocSh, aCurDocumentURL, sal_False ))
514cdf0e10cSrcweir                 throw RuntimeException( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Failed to create document from URL: " ) ) + aCurDocumentURL, static_cast < cppu::OWeakObject * > ( this ) );
515cdf0e10cSrcweir         }
516cdf0e10cSrcweir         else if (rName.equalsAscii( GetPropName( UNO_NAME_OUTPUT_URL ) ))
517cdf0e10cSrcweir         {
518cdf0e10cSrcweir             bOK = rValue >>= aCurOutputURL;
519cdf0e10cSrcweir             if (aCurOutputURL.getLength())
520cdf0e10cSrcweir             {
521cdf0e10cSrcweir                 if (!UCB_IsDirectory(aCurOutputURL))
522cdf0e10cSrcweir                     throw IllegalArgumentException( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "URL does not point to a directory: " ) ) + aCurOutputURL, static_cast < cppu::OWeakObject * > ( this ), 0 );
523cdf0e10cSrcweir                 if (UCB_IsReadOnlyFileName(aCurOutputURL))
524cdf0e10cSrcweir                     throw IllegalArgumentException( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "URL is read-only: " ) ) + aCurOutputURL, static_cast < cppu::OWeakObject * > ( this ), 0 );
525cdf0e10cSrcweir             }
526cdf0e10cSrcweir         }
527cdf0e10cSrcweir         else if (rName.equalsAscii( GetPropName( UNO_NAME_FILE_NAME_PREFIX ) ))
528cdf0e10cSrcweir             bOK = rValue >>= aCurFileNamePrefix;
529cdf0e10cSrcweir         else if (rName.equalsAscii( GetPropName( UNO_NAME_DAD_COMMAND_TYPE ) ))
530cdf0e10cSrcweir             bOK = rValue >>= nCurDataCommandType;
531cdf0e10cSrcweir         else if (rName.equalsAscii( GetPropName( UNO_NAME_OUTPUT_TYPE ) ))
532cdf0e10cSrcweir             bOK = rValue >>= nCurOutputType;
533cdf0e10cSrcweir         else if (rName.equalsAscii( GetPropName( UNO_NAME_ESCAPE_PROCESSING ) ))
534cdf0e10cSrcweir             bOK = rValue >>= bCurEscapeProcessing;
535cdf0e10cSrcweir         else if (rName.equalsAscii( GetPropName( UNO_NAME_SINGLE_PRINT_JOBS ) ))
536cdf0e10cSrcweir             bOK = rValue >>= bCurSinglePrintJobs;
537cdf0e10cSrcweir         else if (rName.equalsAscii( GetPropName( UNO_NAME_FILE_NAME_FROM_COLUMN ) ))
538cdf0e10cSrcweir             bOK = rValue >>= bCurFileNameFromColumn;
539cdf0e10cSrcweir         else if (rName.equalsAscii( GetPropName( UNO_NAME_SUBJECT ) ))
540cdf0e10cSrcweir             bOK = rValue >>= sSubject;
541cdf0e10cSrcweir         else if (rName.equalsAscii( GetPropName( UNO_NAME_ADDRESS_FROM_COLUMN ) ))
542cdf0e10cSrcweir             bOK = rValue >>= sAddressFromColumn;
543cdf0e10cSrcweir         else if (rName.equalsAscii( GetPropName( UNO_NAME_SEND_AS_HTML ) ))
544cdf0e10cSrcweir             bOK = rValue >>= bSendAsHTML;
545cdf0e10cSrcweir         else if (rName.equalsAscii( GetPropName( UNO_NAME_MAIL_BODY ) ))
546cdf0e10cSrcweir             bOK = rValue >>= sMailBody;
547cdf0e10cSrcweir         else if (rName.equalsAscii( GetPropName( UNO_NAME_ATTACHMENT_NAME ) ))
548cdf0e10cSrcweir             bOK = rValue >>= sAttachmentName;
549cdf0e10cSrcweir         else if (rName.equalsAscii( GetPropName( UNO_NAME_ATTACHMENT_FILTER ) ))
550cdf0e10cSrcweir             bOK = rValue >>= sAttachmentFilter;
551cdf0e10cSrcweir         else if (rName.equalsAscii( GetPropName( UNO_NAME_COPIES_TO ) ))
552cdf0e10cSrcweir             bOK = rValue >>= aCopiesTo;
553cdf0e10cSrcweir         else if (rName.equalsAscii( GetPropName( UNO_NAME_BLIND_COPIES_TO ) ))
554cdf0e10cSrcweir             bOK = rValue >>= aBlindCopiesTo;
555cdf0e10cSrcweir         else if (rName.equalsAscii( GetPropName( UNO_NAME_SEND_AS_ATTACHMENT ) ))
556cdf0e10cSrcweir             bOK = rValue >>= bSendAsAttachment;
557cdf0e10cSrcweir         else if (rName.equalsAscii( GetPropName( UNO_NAME_PRINT_OPTIONS ) ))
558cdf0e10cSrcweir             bOK = rValue >>= aPrintSettings;
559cdf0e10cSrcweir         else if (rName.equalsAscii( GetPropName( UNO_NAME_SAVE_AS_SINGLE_FILE ) ))
560cdf0e10cSrcweir             bOK = rValue >>= bSaveAsSingleFile;
561cdf0e10cSrcweir         else if (rName.equalsAscii( GetPropName( UNO_NAME_SAVE_FILTER ) ))
562cdf0e10cSrcweir             bOK = rValue >>= sSaveFilter;
563cdf0e10cSrcweir         else if (rName.equalsAscii( GetPropName( UNO_NAME_SAVE_FILTER_OPTIONS ) ))
564cdf0e10cSrcweir             bOK = rValue >>= sSaveFilterOptions;
565cdf0e10cSrcweir         else if (rName.equalsAscii( GetPropName( UNO_NAME_SAVE_FILTER_DATA ) ))
566cdf0e10cSrcweir             bOK = rValue >>= aSaveFilterData;
567cdf0e10cSrcweir         else if (rName.equalsAscii( GetPropName( UNO_NAME_IN_SERVER_PASSWORD ) ))
568cdf0e10cSrcweir             bOK = rValue >>= sInServerPassword;
569cdf0e10cSrcweir         else if (rName.equalsAscii( GetPropName( UNO_NAME_OUT_SERVER_PASSWORD ) ))
570cdf0e10cSrcweir             bOK = rValue >>= sOutServerPassword;
571cdf0e10cSrcweir         else
572cdf0e10cSrcweir             throw UnknownPropertyException( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Property is unknown: " ) ) + rName, static_cast < cppu::OWeakObject * > ( this ) );
573cdf0e10cSrcweir 
574cdf0e10cSrcweir         if (!bOK)
575cdf0e10cSrcweir             throw IllegalArgumentException( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Property type mismatch or property not set: " ) ) + rName, static_cast < cppu::OWeakObject * > ( this ), 0 );
576cdf0e10cSrcweir     }
577cdf0e10cSrcweir 
578cdf0e10cSrcweir 	// need to translate the selection: the API here requires a sequence of bookmarks, but the MergeNew
579cdf0e10cSrcweir 	// method we will call below requires a sequence of indicies.
580cdf0e10cSrcweir 	if ( aCurSelection.getLength() )
581cdf0e10cSrcweir 	{
582cdf0e10cSrcweir 		Sequence< Any > aTranslated( aCurSelection.getLength() );
583cdf0e10cSrcweir 
584cdf0e10cSrcweir 		sal_Bool bValid = sal_False;
585cdf0e10cSrcweir 		Reference< sdbcx::XRowLocate > xRowLocate( xCurResultSet, UNO_QUERY );
586cdf0e10cSrcweir 		if ( xRowLocate.is() )
587cdf0e10cSrcweir 		{
588cdf0e10cSrcweir 
589cdf0e10cSrcweir 			const Any* pBookmarks = aCurSelection.getConstArray();
590cdf0e10cSrcweir 			const Any* pBookmarksEnd = pBookmarks + aCurSelection.getLength();
591cdf0e10cSrcweir 			Any* pTranslated = aTranslated.getArray();
592cdf0e10cSrcweir 
593cdf0e10cSrcweir 			try
594cdf0e10cSrcweir 			{
595cdf0e10cSrcweir 				sal_Bool bEverythingsFine = sal_True;
596cdf0e10cSrcweir 				for ( ; ( pBookmarks != pBookmarksEnd ) && bEverythingsFine; ++pBookmarks )
597cdf0e10cSrcweir 				{
598cdf0e10cSrcweir 					if ( xRowLocate->moveToBookmark( *pBookmarks ) )
599cdf0e10cSrcweir 						*pTranslated <<= xCurResultSet->getRow();
600cdf0e10cSrcweir 					else
601cdf0e10cSrcweir 						bEverythingsFine = sal_False;
602cdf0e10cSrcweir 				}
603cdf0e10cSrcweir 				if ( bEverythingsFine )
604cdf0e10cSrcweir 					bValid = sal_True;
605cdf0e10cSrcweir 			}
606cdf0e10cSrcweir 			catch( const Exception& )
607cdf0e10cSrcweir 			{
608cdf0e10cSrcweir 				bValid = sal_False;
609cdf0e10cSrcweir 			}
610cdf0e10cSrcweir 		}
611cdf0e10cSrcweir 
612cdf0e10cSrcweir 		if ( !bValid )
613cdf0e10cSrcweir 		{
614cdf0e10cSrcweir             throw IllegalArgumentException(
615cdf0e10cSrcweir 				OUString ( RTL_CONSTASCII_USTRINGPARAM ( "The current 'Selection' does not describe a valid array of bookmarks, relative to the current 'ResultSet'." ) ),
616cdf0e10cSrcweir 				static_cast < cppu::OWeakObject * > ( this ),
617cdf0e10cSrcweir 				0
618cdf0e10cSrcweir 			);
619cdf0e10cSrcweir 		}
620cdf0e10cSrcweir 
621cdf0e10cSrcweir 		aCurSelection = aTranslated;
622cdf0e10cSrcweir 	}
623cdf0e10cSrcweir 
624cdf0e10cSrcweir     SfxViewFrame*   pFrame = SfxViewFrame::GetFirst( xCurDocSh, sal_False);
625cdf0e10cSrcweir     SwView *pView = PTR_CAST( SwView, pFrame->GetViewShell() );
626cdf0e10cSrcweir     if (!pView)
627cdf0e10cSrcweir         throw RuntimeException();
628cdf0e10cSrcweir     SwWrtShell &rSh = *pView->GetWrtShellPtr();
629cdf0e10cSrcweir 
630cdf0e10cSrcweir     // avoid assertion in 'Update' from Sfx by supplying a shell
631cdf0e10cSrcweir     // and thus avoiding the SelectShell call in Writers GetState function
632cdf0e10cSrcweir     // while still in Update of Sfx.
633cdf0e10cSrcweir     // (GetSelection in Update is not allowed)
634cdf0e10cSrcweir     if (pView && aCurDocumentURL.getLength())
635cdf0e10cSrcweir         pView->AttrChangedNotify( &pView->GetWrtShell() );//Damit SelectShell gerufen wird.
636cdf0e10cSrcweir 
637cdf0e10cSrcweir     SharedComponent aRowSetDisposeHelper;
638cdf0e10cSrcweir     if (!xCurResultSet.is())
639cdf0e10cSrcweir     {
640cdf0e10cSrcweir         if (!aCurDataSourceName.getLength() || !aCurDataCommand.getLength() )
641cdf0e10cSrcweir         {
642cdf0e10cSrcweir             DBG_ERROR("PropertyValues missing or unset");
643cdf0e10cSrcweir             throw IllegalArgumentException( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Either the ResultSet or DataSourceName and DataCommand must be set." ) ), static_cast < cppu::OWeakObject * > ( this ), 0 );
644cdf0e10cSrcweir         }
645cdf0e10cSrcweir 
646cdf0e10cSrcweir         //
647cdf0e10cSrcweir         // build ResultSet from DataSourceName, DataCommand and DataCommandType
648cdf0e10cSrcweir         //
649cdf0e10cSrcweir         Reference< XMultiServiceFactory > xMgr( ::comphelper::getProcessServiceFactory() );
650cdf0e10cSrcweir         if (xMgr.is())
651cdf0e10cSrcweir         {
652cdf0e10cSrcweir             Reference< XInterface > xInstance = xMgr->createInstance(
653cdf0e10cSrcweir                     C2U( "com.sun.star.sdb.RowSet" ));
654cdf0e10cSrcweir             aRowSetDisposeHelper.reset( xInstance, SharedComponent::TakeOwnership );
655cdf0e10cSrcweir             Reference< XPropertySet > xRowSetPropSet( xInstance, UNO_QUERY );
656cdf0e10cSrcweir             DBG_ASSERT( xRowSetPropSet.is(), "failed to get XPropertySet interface from RowSet" );
657cdf0e10cSrcweir             if (xRowSetPropSet.is())
658cdf0e10cSrcweir             {
659cdf0e10cSrcweir                 if (xCurConnection.is())
660cdf0e10cSrcweir                     xRowSetPropSet->setPropertyValue( C2U("ActiveConnection"),  makeAny( xCurConnection ) );
661cdf0e10cSrcweir                 xRowSetPropSet->setPropertyValue( C2U("DataSourceName"),    makeAny( aCurDataSourceName ) );
662cdf0e10cSrcweir                 xRowSetPropSet->setPropertyValue( C2U("Command"),           makeAny( aCurDataCommand ) );
663cdf0e10cSrcweir                 xRowSetPropSet->setPropertyValue( C2U("CommandType"),       makeAny( nCurDataCommandType ) );
664cdf0e10cSrcweir                 xRowSetPropSet->setPropertyValue( C2U("EscapeProcessing"),  makeAny( bCurEscapeProcessing ) );
665cdf0e10cSrcweir                 xRowSetPropSet->setPropertyValue( C2U("ApplyFilter"),       makeAny( sal_True ) );
666cdf0e10cSrcweir                 xRowSetPropSet->setPropertyValue( C2U("Filter"),            makeAny( aCurFilter ) );
667cdf0e10cSrcweir 
668cdf0e10cSrcweir                 Reference< sdbc::XRowSet > xRowSet( xInstance, UNO_QUERY );
669cdf0e10cSrcweir                 if (xRowSet.is())
670cdf0e10cSrcweir                     xRowSet->execute(); // build ResultSet from properties
671cdf0e10cSrcweir                 if( !xCurConnection.is() )
672cdf0e10cSrcweir                     xCurConnection.set( xRowSetPropSet->getPropertyValue( C2U( "ActiveConnection" )), UNO_QUERY );
673cdf0e10cSrcweir                 xCurResultSet = Reference< sdbc::XResultSet >( xRowSet, UNO_QUERY );
674cdf0e10cSrcweir                 DBG_ASSERT( xCurResultSet.is(), "failed to build ResultSet" );
675cdf0e10cSrcweir             }
676cdf0e10cSrcweir         }
677cdf0e10cSrcweir     }
678cdf0e10cSrcweir 
679cdf0e10cSrcweir     svx::ODataAccessDescriptor aDescriptor;
680cdf0e10cSrcweir     aDescriptor.setDataSource(aCurDataSourceName);
681cdf0e10cSrcweir     aDescriptor[ svx::daConnection ]         <<= xCurConnection;
682cdf0e10cSrcweir     aDescriptor[ svx::daCommand ]            <<= aCurDataCommand;
683cdf0e10cSrcweir     aDescriptor[ svx::daCommandType ]        <<= nCurDataCommandType;
684cdf0e10cSrcweir     aDescriptor[ svx::daEscapeProcessing ]   <<= bCurEscapeProcessing;
685cdf0e10cSrcweir     aDescriptor[ svx::daCursor ]             <<= xCurResultSet;
686cdf0e10cSrcweir     // aDescriptor[ svx::daColumnName ]      not used
687cdf0e10cSrcweir     // aDescriptor[ svx::daColumnObject ]    not used
688cdf0e10cSrcweir     aDescriptor[ svx::daSelection ]          <<= aCurSelection;
689cdf0e10cSrcweir 
690cdf0e10cSrcweir     sal_uInt16 nMergeType;
691cdf0e10cSrcweir     switch (nCurOutputType)
692cdf0e10cSrcweir     {
693cdf0e10cSrcweir         case MailMergeType::PRINTER : nMergeType = DBMGR_MERGE_MAILMERGE; break;
694cdf0e10cSrcweir         case MailMergeType::FILE    : nMergeType = DBMGR_MERGE_MAILFILES; break;
695cdf0e10cSrcweir         case MailMergeType::MAIL    : nMergeType = DBMGR_MERGE_MAILING; break;
696cdf0e10cSrcweir         default:
697cdf0e10cSrcweir             throw IllegalArgumentException( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Invalid value of property:" ) ) + C2U("OutputType"), static_cast < cppu::OWeakObject * > ( this ), 0 );
698cdf0e10cSrcweir     }
699cdf0e10cSrcweir 
700cdf0e10cSrcweir     SwNewDBMgr* pMgr = rSh.GetNewDBMgr();
701cdf0e10cSrcweir     //force layout creation
702cdf0e10cSrcweir     rSh.CalcLayout();
703cdf0e10cSrcweir     DBG_ASSERT( pMgr, "database manager missing" );
704cdf0e10cSrcweir 
705cdf0e10cSrcweir     SwMergeDescriptor aMergeDesc( nMergeType, rSh, aDescriptor );
706cdf0e10cSrcweir 
707cdf0e10cSrcweir     std::auto_ptr< SwMailMergeConfigItem > pMMConfigItem;
708cdf0e10cSrcweir     uno::Reference< mail::XMailService > xInService;
709cdf0e10cSrcweir     if (MailMergeType::PRINTER == nCurOutputType)
710cdf0e10cSrcweir     {
711cdf0e10cSrcweir         IDocumentDeviceAccess* pIDDA = rSh.getIDocumentDeviceAccess();
712cdf0e10cSrcweir         SwPrintData aPrtData( pIDDA->getPrintData() );
713cdf0e10cSrcweir         aPrtData.SetPrintSingleJobs( bCurSinglePrintJobs );
714cdf0e10cSrcweir         pIDDA->setPrintData( aPrtData );
715cdf0e10cSrcweir         // #i25686# printing should not be done asynchronously to prevent dangling offices
716cdf0e10cSrcweir         // when mail merge is called as command line macro
717cdf0e10cSrcweir         aMergeDesc.bPrintAsync = sal_False;
718cdf0e10cSrcweir         aMergeDesc.aPrintOptions = aPrintSettings;
719cdf0e10cSrcweir         aMergeDesc.bCreateSingleFile = true;
720cdf0e10cSrcweir     }
721cdf0e10cSrcweir     else /* FILE and MAIL*/
722cdf0e10cSrcweir     {
723cdf0e10cSrcweir 		INetURLObject aURLObj;
724cdf0e10cSrcweir         aURLObj.SetSmartProtocol( INET_PROT_FILE );
725cdf0e10cSrcweir 
726cdf0e10cSrcweir 		if (aCurDocumentURL.getLength())
727cdf0e10cSrcweir 		{
728cdf0e10cSrcweir 			// if OutputURL or FileNamePrefix are missing get
729cdf0e10cSrcweir 			// them from DocumentURL
730cdf0e10cSrcweir             aURLObj.SetSmartURL( aCurDocumentURL );
731cdf0e10cSrcweir 			if (!aCurFileNamePrefix.getLength())
732cdf0e10cSrcweir                 aCurFileNamePrefix = aURLObj.GetBase(); // filename without extension
733cdf0e10cSrcweir             if (!aCurOutputURL.getLength())
734cdf0e10cSrcweir             {
735cdf0e10cSrcweir                 //aCurOutputURL = aURLObj.GetURLPath();
736cdf0e10cSrcweir                 aURLObj.removeSegment();
737cdf0e10cSrcweir                 aCurOutputURL = aURLObj.GetMainURL( INetURLObject::DECODE_TO_IURI );
738cdf0e10cSrcweir             }
739cdf0e10cSrcweir 		}
740cdf0e10cSrcweir 		else	// default empty document without URL
741cdf0e10cSrcweir 		{
742cdf0e10cSrcweir 			if (!aCurOutputURL.getLength())
743cdf0e10cSrcweir 				throw RuntimeException( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "OutputURL is not set and can not be obtained." ) ), static_cast < cppu::OWeakObject * > ( this ) );
744cdf0e10cSrcweir 		}
745cdf0e10cSrcweir 
746cdf0e10cSrcweir 		aURLObj.SetSmartURL( aCurOutputURL );
747cdf0e10cSrcweir         String aPath = aURLObj.GetMainURL( INetURLObject::DECODE_TO_IURI );
748cdf0e10cSrcweir 
749cdf0e10cSrcweir         String aDelim( INET_PATH_TOKEN );
750cdf0e10cSrcweir         if (aPath.Len() >= aDelim.Len() &&
751cdf0e10cSrcweir             aPath.Copy( aPath.Len()-aDelim.Len() ).CompareTo( aDelim ) != COMPARE_EQUAL)
752cdf0e10cSrcweir             aPath += aDelim;
753cdf0e10cSrcweir         if (bCurFileNameFromColumn)
754cdf0e10cSrcweir             pMgr->SetEMailColumn( aCurFileNamePrefix );
755cdf0e10cSrcweir         else
756cdf0e10cSrcweir         {
757cdf0e10cSrcweir             aPath += String( aCurFileNamePrefix );
758cdf0e10cSrcweir             pMgr->SetEMailColumn( String() );
759cdf0e10cSrcweir         }
760cdf0e10cSrcweir         pMgr->SetSubject( aPath );
761cdf0e10cSrcweir         if(MailMergeType::FILE == nCurOutputType)
762cdf0e10cSrcweir         {
763cdf0e10cSrcweir             aMergeDesc.sSaveToFilter = sSaveFilter;
764cdf0e10cSrcweir             aMergeDesc.sSaveToFilterOptions = sSaveFilterOptions;
765cdf0e10cSrcweir             aMergeDesc.aSaveToFilterData = aSaveFilterData;
766cdf0e10cSrcweir             aMergeDesc.bCreateSingleFile = bSaveAsSingleFile;
767cdf0e10cSrcweir         }
768cdf0e10cSrcweir         else /*if(MailMergeType::MAIL == nCurOutputType)*/
769cdf0e10cSrcweir         {
770cdf0e10cSrcweir             pMgr->SetEMailColumn( sAddressFromColumn );
771cdf0e10cSrcweir             if(!sAddressFromColumn.getLength())
772cdf0e10cSrcweir                 throw RuntimeException( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Mail address column not set." ) ), static_cast < cppu::OWeakObject * > ( this ) );
773cdf0e10cSrcweir             aMergeDesc.sSaveToFilter     = sAttachmentFilter;
774cdf0e10cSrcweir             aMergeDesc.sSubject          = sSubject;
775cdf0e10cSrcweir             aMergeDesc.sMailBody         = sMailBody;
776cdf0e10cSrcweir             aMergeDesc.sAttachmentName   = sAttachmentName;
777cdf0e10cSrcweir             aMergeDesc.aCopiesTo         = aCopiesTo;
778cdf0e10cSrcweir             aMergeDesc.aBlindCopiesTo    = aBlindCopiesTo;
779cdf0e10cSrcweir             aMergeDesc.bSendAsHTML       = bSendAsHTML;
780cdf0e10cSrcweir             aMergeDesc.bSendAsAttachment = bSendAsAttachment;
781cdf0e10cSrcweir 
782cdf0e10cSrcweir             aMergeDesc.bCreateSingleFile = sal_False;
783cdf0e10cSrcweir             pMMConfigItem = std::auto_ptr< SwMailMergeConfigItem >(new SwMailMergeConfigItem);
784cdf0e10cSrcweir             aMergeDesc.pMailMergeConfigItem = pMMConfigItem.get();
785cdf0e10cSrcweir             aMergeDesc.xSmtpServer = SwMailMergeHelper::ConnectToSmtpServer(
786cdf0e10cSrcweir                     *pMMConfigItem,
787cdf0e10cSrcweir                     xInService,
788cdf0e10cSrcweir                     sInServerPassword, sOutServerPassword );
789cdf0e10cSrcweir             if( !aMergeDesc.xSmtpServer.is() || !aMergeDesc.xSmtpServer->isConnected())
790cdf0e10cSrcweir                 throw RuntimeException( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Failed to connect to mail server." ) ), static_cast < cppu::OWeakObject * > ( this ) );
791cdf0e10cSrcweir         }
792cdf0e10cSrcweir     }
793cdf0e10cSrcweir 
794cdf0e10cSrcweir 
795cdf0e10cSrcweir     // save document with temporary filename
796cdf0e10cSrcweir     const SfxFilter *pSfxFlt = SwIoSystem::GetFilterOfFormat(
797cdf0e10cSrcweir             String::CreateFromAscii( FILTER_XML ),
798cdf0e10cSrcweir             SwDocShell::Factory().GetFilterContainer() );
799cdf0e10cSrcweir     String aExtension( pSfxFlt->GetDefaultExtension() );
800cdf0e10cSrcweir     aExtension.EraseLeadingChars( '*' );
801cdf0e10cSrcweir     TempFile aTempFile( C2U("SwMM"), &aExtension );
802cdf0e10cSrcweir     aTmpFileName = aTempFile.GetName();
803cdf0e10cSrcweir 
804cdf0e10cSrcweir 	Reference< XStorable > xStorable( xCurModel, UNO_QUERY );
805cdf0e10cSrcweir 	sal_Bool bStoredAsTemporary = sal_False;
806cdf0e10cSrcweir 	if ( xStorable.is() )
807cdf0e10cSrcweir 	{
808cdf0e10cSrcweir 		try
809cdf0e10cSrcweir 		{
810cdf0e10cSrcweir 			xStorable->storeAsURL( aTmpFileName, Sequence< PropertyValue >() );
811cdf0e10cSrcweir 			bStoredAsTemporary = sal_True;
812cdf0e10cSrcweir 		}
813cdf0e10cSrcweir 		catch( const Exception& )
814cdf0e10cSrcweir 		{
815cdf0e10cSrcweir 		}
816cdf0e10cSrcweir 	}
817cdf0e10cSrcweir 	if ( !bStoredAsTemporary )
818cdf0e10cSrcweir         throw RuntimeException( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Failed to save temporary file." ) ), static_cast < cppu::OWeakObject * > ( this ) );
819cdf0e10cSrcweir 
820cdf0e10cSrcweir     pMgr->SetMergeSilent( sal_True );       // suppress dialogs, message boxes, etc.
821cdf0e10cSrcweir     const SwXMailMerge *pOldSrc = pMgr->GetMailMergeEvtSrc();
822cdf0e10cSrcweir     DBG_ASSERT( !pOldSrc || pOldSrc == this, "Ooops... different event source already set." );
823cdf0e10cSrcweir     pMgr->SetMailMergeEvtSrc( this );   // launch events for listeners
824cdf0e10cSrcweir 
825cdf0e10cSrcweir     SFX_APP()->NotifyEvent(SfxEventHint(SW_EVENT_MAIL_MERGE, SwDocShell::GetEventName(STR_SW_EVENT_MAIL_MERGE), xCurDocSh));
826cdf0e10cSrcweir     sal_Bool bSucc = pMgr->MergeNew( aMergeDesc );
827cdf0e10cSrcweir     SFX_APP()->NotifyEvent(SfxEventHint(SW_EVENT_MAIL_MERGE_END, SwDocShell::GetEventName(STR_SW_EVENT_MAIL_MERGE_END), xCurDocSh));
828cdf0e10cSrcweir 
829cdf0e10cSrcweir     pMgr->SetMailMergeEvtSrc( pOldSrc );
830cdf0e10cSrcweir 
831cdf0e10cSrcweir 	if ( xCurModel.get() != xModel.get() )
832cdf0e10cSrcweir 	{	// in case it was a temporary model -> close it, and delete the file
833cdf0e10cSrcweir 	    DeleteTmpFile_Impl( xCurModel, xCurDocSh, aTmpFileName );
834cdf0e10cSrcweir 		aTmpFileName.Erase();
835cdf0e10cSrcweir 	}
836cdf0e10cSrcweir 	// (in case it wasn't a temporary model, it will be closed in the dtor, at the latest)
837cdf0e10cSrcweir 
838cdf0e10cSrcweir     if (!bSucc)
839cdf0e10cSrcweir         throw Exception( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Mail merge failed. Sorry, no further information available." ) ), static_cast < cppu::OWeakObject * > ( this ) );
840cdf0e10cSrcweir 
841cdf0e10cSrcweir     //de-initialize services
842cdf0e10cSrcweir     if(xInService.is() && xInService->isConnected())
843cdf0e10cSrcweir         xInService->disconnect();
844cdf0e10cSrcweir     if(aMergeDesc.xSmtpServer.is() && aMergeDesc.xSmtpServer->isConnected())
845cdf0e10cSrcweir         aMergeDesc.xSmtpServer->disconnect();
846cdf0e10cSrcweir 
847cdf0e10cSrcweir     return makeAny( sal_True );
848cdf0e10cSrcweir }
849cdf0e10cSrcweir 
LaunchMailMergeEvent(const MailMergeEvent & rEvt) const850cdf0e10cSrcweir void SwXMailMerge::LaunchMailMergeEvent( const MailMergeEvent &rEvt ) const
851cdf0e10cSrcweir {
852cdf0e10cSrcweir     cppu::OInterfaceIteratorHelper aIt( ((SwXMailMerge *) this)->aMergeListeners );
853cdf0e10cSrcweir     while (aIt.hasMoreElements())
854cdf0e10cSrcweir     {
855cdf0e10cSrcweir         Reference< XMailMergeListener > xRef( aIt.next(), UNO_QUERY );
856cdf0e10cSrcweir         if (xRef.is())
857cdf0e10cSrcweir             xRef->notifyMailMergeEvent( rEvt );
858cdf0e10cSrcweir     }
859cdf0e10cSrcweir }
860cdf0e10cSrcweir 
launchEvent(const PropertyChangeEvent & rEvt) const861cdf0e10cSrcweir void SwXMailMerge::launchEvent( const PropertyChangeEvent &rEvt ) const
862cdf0e10cSrcweir {
863cdf0e10cSrcweir     cppu::OInterfaceContainerHelper *pContainer =
864cdf0e10cSrcweir             aPropListeners.getContainer( rEvt.PropertyHandle );
865cdf0e10cSrcweir     if (pContainer)
866cdf0e10cSrcweir     {
867cdf0e10cSrcweir         cppu::OInterfaceIteratorHelper aIt( *pContainer );
868cdf0e10cSrcweir         while (aIt.hasMoreElements())
869cdf0e10cSrcweir         {
870cdf0e10cSrcweir             Reference< XPropertyChangeListener > xRef( aIt.next(), UNO_QUERY );
871cdf0e10cSrcweir             if (xRef.is())
872cdf0e10cSrcweir                 xRef->propertyChange( rEvt );
873cdf0e10cSrcweir         }
874cdf0e10cSrcweir     }
875cdf0e10cSrcweir }
876cdf0e10cSrcweir 
877cdf0e10cSrcweir 
getPropertySetInfo()878cdf0e10cSrcweir uno::Reference< beans::XPropertySetInfo > SAL_CALL SwXMailMerge::getPropertySetInfo(  )
879cdf0e10cSrcweir     throw (RuntimeException)
880cdf0e10cSrcweir {
881cdf0e10cSrcweir     vos::OGuard aGuard( Application::GetSolarMutex() );
882cdf0e10cSrcweir     static Reference< XPropertySetInfo > aRef = pPropSet->getPropertySetInfo();
883cdf0e10cSrcweir     return aRef;
884cdf0e10cSrcweir }
885cdf0e10cSrcweir 
setPropertyValue(const OUString & rPropertyName,const uno::Any & rValue)886cdf0e10cSrcweir void SAL_CALL SwXMailMerge::setPropertyValue(
887cdf0e10cSrcweir         const OUString& rPropertyName, const uno::Any& rValue )
888cdf0e10cSrcweir     throw (UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException)
889cdf0e10cSrcweir {
890cdf0e10cSrcweir     vos::OGuard aGuard( Application::GetSolarMutex() );
891cdf0e10cSrcweir 
892cdf0e10cSrcweir     const SfxItemPropertySimpleEntry* pCur = pPropSet->getPropertyMap()->getByName( rPropertyName );
893cdf0e10cSrcweir     if (!pCur)
894cdf0e10cSrcweir         throw UnknownPropertyException();
895cdf0e10cSrcweir     else if (pCur->nFlags & PropertyAttribute::READONLY)
896cdf0e10cSrcweir         throw PropertyVetoException();
897cdf0e10cSrcweir     else
898cdf0e10cSrcweir     {
899cdf0e10cSrcweir         void *pData = NULL;
900cdf0e10cSrcweir         const uno::Type* pType = pCur->pType;
901cdf0e10cSrcweir         switch (pCur->nWID)
902cdf0e10cSrcweir         {
903cdf0e10cSrcweir             case WID_SELECTION :                pData = &aSelection;  break;
904cdf0e10cSrcweir             case WID_RESULT_SET :               pData = &xResultSet;  break;
905cdf0e10cSrcweir             case WID_CONNECTION :               pData = &xConnection;  break;
906cdf0e10cSrcweir             case WID_MODEL :                    pData = &xModel;  break;
907cdf0e10cSrcweir             case WID_DATA_SOURCE_NAME :         pData = &aDataSourceName;  break;
908cdf0e10cSrcweir             case WID_DATA_COMMAND :             pData = &aDataCommand;  break;
909cdf0e10cSrcweir             case WID_FILTER :                   pData = &aFilter;  break;
910cdf0e10cSrcweir             case WID_DOCUMENT_URL :             pData = &aDocumentURL;  break;
911cdf0e10cSrcweir             case WID_OUTPUT_URL :               pData = &aOutputURL;  break;
912cdf0e10cSrcweir             case WID_DATA_COMMAND_TYPE :        pData = &nDataCommandType;  break;
913cdf0e10cSrcweir             case WID_OUTPUT_TYPE :              pData = &nOutputType;  break;
914cdf0e10cSrcweir             case WID_ESCAPE_PROCESSING :        pData = &bEscapeProcessing;  break;
915cdf0e10cSrcweir             case WID_SINGLE_PRINT_JOBS :        pData = &bSinglePrintJobs;  break;
916cdf0e10cSrcweir             case WID_FILE_NAME_FROM_COLUMN :    pData = &bFileNameFromColumn;  break;
917cdf0e10cSrcweir             case WID_FILE_NAME_PREFIX :         pData = &aFileNamePrefix;  break;
918cdf0e10cSrcweir             case WID_MAIL_SUBJECT:              pData = &sSubject; break;
919cdf0e10cSrcweir             case WID_ADDRESS_FROM_COLUMN:       pData = &sAddressFromColumn; break;
920cdf0e10cSrcweir             case WID_SEND_AS_HTML:              pData = &bSendAsHTML; break;
921cdf0e10cSrcweir             case WID_SEND_AS_ATTACHMENT:        pData = &bSendAsAttachment; break;
922cdf0e10cSrcweir             case WID_MAIL_BODY:                 pData = &sMailBody; break;
923cdf0e10cSrcweir             case WID_ATTACHMENT_NAME:           pData = &sAttachmentName; break;
924cdf0e10cSrcweir             case WID_ATTACHMENT_FILTER:         pData = &sAttachmentFilter;break;
925cdf0e10cSrcweir             case WID_PRINT_OPTIONS:             pData = &aPrintSettings; break;
926cdf0e10cSrcweir             case WID_SAVE_AS_SINGLE_FILE:       pData = &bSaveAsSingleFile; break;
927cdf0e10cSrcweir             case WID_SAVE_FILTER:               pData = &sSaveFilter; break;
928cdf0e10cSrcweir             case WID_SAVE_FILTER_OPTIONS:       pData = &sSaveFilterOptions; break;
929cdf0e10cSrcweir             case WID_SAVE_FILTER_DATA:          pData = &aSaveFilterData; break;
930cdf0e10cSrcweir             case WID_COPIES_TO:                 pData = &aCopiesTo; break;
931cdf0e10cSrcweir             case WID_BLIND_COPIES_TO:           pData = &aBlindCopiesTo;break;
932cdf0e10cSrcweir             case WID_IN_SERVER_PASSWORD:        pData = &sInServerPassword; break;
933cdf0e10cSrcweir             case WID_OUT_SERVER_PASSWORD:       pData = &sOutServerPassword; break;
934cdf0e10cSrcweir             default :
935cdf0e10cSrcweir                 DBG_ERROR("unknown WID");
936cdf0e10cSrcweir         }
937cdf0e10cSrcweir         Any aOld( pData, *pType );
938cdf0e10cSrcweir 
939cdf0e10cSrcweir         sal_Bool bChanged = sal_False;
940cdf0e10cSrcweir         sal_Bool bOK = sal_True;
941cdf0e10cSrcweir         if (aOld != rValue)
942cdf0e10cSrcweir         {
943cdf0e10cSrcweir             if (pData == &aSelection)
944cdf0e10cSrcweir                 bOK = rValue >>= aSelection;
945cdf0e10cSrcweir             else if (pData == &xResultSet)
946cdf0e10cSrcweir                 bOK = rValue >>= xResultSet;
947cdf0e10cSrcweir             else if (pData == &xConnection)
948cdf0e10cSrcweir                 bOK = rValue >>= xConnection;
949cdf0e10cSrcweir             else if (pData == &xModel)
950cdf0e10cSrcweir                 bOK = rValue >>= xModel;
951cdf0e10cSrcweir             else if (pData == &aDataSourceName)
952cdf0e10cSrcweir                 bOK = rValue >>= aDataSourceName;
953cdf0e10cSrcweir             else if (pData == &aDataCommand)
954cdf0e10cSrcweir                 bOK = rValue >>= aDataCommand;
955cdf0e10cSrcweir             else if (pData == &aFilter)
956cdf0e10cSrcweir                 bOK = rValue >>= aFilter;
957cdf0e10cSrcweir             else if (pData == &aDocumentURL)
958cdf0e10cSrcweir             {
959cdf0e10cSrcweir                 OUString aText;
960cdf0e10cSrcweir                 bOK = rValue >>= aText;
961cdf0e10cSrcweir                 if (aText.getLength()
962cdf0e10cSrcweir                     && !LoadFromURL_impl( xModel, xDocSh, aText, sal_True ))
963cdf0e10cSrcweir                     throw RuntimeException( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Failed to create document from URL: " ) ) + aText, static_cast < cppu::OWeakObject * > ( this ) );
964cdf0e10cSrcweir                 aDocumentURL = aText;
965cdf0e10cSrcweir             }
966cdf0e10cSrcweir             else if (pData == &aOutputURL)
967cdf0e10cSrcweir             {
968cdf0e10cSrcweir                 OUString aText;
969cdf0e10cSrcweir                 bOK = rValue >>= aText;
970cdf0e10cSrcweir                 if (aText.getLength())
971cdf0e10cSrcweir                 {
972cdf0e10cSrcweir                     if (!UCB_IsDirectory(aText))
973cdf0e10cSrcweir                         throw IllegalArgumentException( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "URL does not point to a directory: " ) ) + aText, static_cast < cppu::OWeakObject * > ( this ), 0 );
974cdf0e10cSrcweir                     if (UCB_IsReadOnlyFileName(aText))
975cdf0e10cSrcweir                         throw IllegalArgumentException( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "URL is read-only: " ) ) + aText, static_cast < cppu::OWeakObject * > ( this ), 0 );
976cdf0e10cSrcweir                 }
977cdf0e10cSrcweir                 aOutputURL = aText;
978cdf0e10cSrcweir             }
979cdf0e10cSrcweir             else if (pData == &nDataCommandType)
980cdf0e10cSrcweir                 bOK = rValue >>= nDataCommandType;
981cdf0e10cSrcweir             else if (pData == &nOutputType)
982cdf0e10cSrcweir                 bOK = rValue >>= nOutputType;
983cdf0e10cSrcweir             else if (pData == &bEscapeProcessing)
984cdf0e10cSrcweir                 bOK = rValue >>= bEscapeProcessing;
985cdf0e10cSrcweir             else if (pData == &bSinglePrintJobs)
986cdf0e10cSrcweir                 bOK = rValue >>= bSinglePrintJobs;
987cdf0e10cSrcweir             else if (pData == &bFileNameFromColumn)
988cdf0e10cSrcweir                 bOK = rValue >>= bFileNameFromColumn;
989cdf0e10cSrcweir             else if (pData == &aFileNamePrefix)
990cdf0e10cSrcweir                 bOK = rValue >>= aFileNamePrefix;
991cdf0e10cSrcweir             else if (pData == &sSubject)
992cdf0e10cSrcweir                 bOK = rValue >>= sSubject;
993cdf0e10cSrcweir             else if (pData == &sAddressFromColumn)
994cdf0e10cSrcweir                 bOK = rValue >>= sAddressFromColumn;
995cdf0e10cSrcweir             else if (pData == &bSendAsHTML)
996cdf0e10cSrcweir                 bOK = rValue >>= bSendAsHTML;
997cdf0e10cSrcweir             else if (pData == &bSendAsAttachment)
998cdf0e10cSrcweir                 bOK = rValue >>= bSendAsAttachment;
999cdf0e10cSrcweir             else if (pData == &sMailBody)
1000cdf0e10cSrcweir                 bOK = rValue >>= sMailBody;
1001cdf0e10cSrcweir             else if (pData == &sAttachmentName)
1002cdf0e10cSrcweir                 bOK = rValue >>= sAttachmentName;
1003cdf0e10cSrcweir             else if (pData == &sAttachmentFilter)
1004cdf0e10cSrcweir                 bOK = rValue >>= sAttachmentFilter;
1005cdf0e10cSrcweir             else if (pData == &aPrintSettings)
1006cdf0e10cSrcweir                 bOK = rValue >>= aPrintSettings;
1007cdf0e10cSrcweir             else if (pData == &bSaveAsSingleFile)
1008cdf0e10cSrcweir                 bOK = rValue >>= bSaveAsSingleFile;
1009cdf0e10cSrcweir             else if (pData == &sSaveFilter)
1010cdf0e10cSrcweir                 bOK = rValue >>= sSaveFilter;
1011cdf0e10cSrcweir             else if (pData == &sSaveFilterOptions)
1012cdf0e10cSrcweir                 bOK = rValue >>= sSaveFilterOptions;
1013cdf0e10cSrcweir             else if (pData == &aSaveFilterData)
1014cdf0e10cSrcweir                 bOK = rValue >>= aSaveFilterData;
1015cdf0e10cSrcweir             else if (pData == &aCopiesTo)
1016cdf0e10cSrcweir                 bOK = rValue >>= aCopiesTo;
1017cdf0e10cSrcweir             else if (pData == &aBlindCopiesTo)
1018cdf0e10cSrcweir                 bOK = rValue >>= aBlindCopiesTo;
1019cdf0e10cSrcweir             else if(pData == &sInServerPassword)
1020cdf0e10cSrcweir                 bOK = rValue >>= sInServerPassword;
1021cdf0e10cSrcweir             else if(pData == &sOutServerPassword)
1022cdf0e10cSrcweir                 bOK = rValue >>= sInServerPassword;
1023cdf0e10cSrcweir             else {
1024cdf0e10cSrcweir                 DBG_ERROR( "invalid pointer" );
1025cdf0e10cSrcweir             }
1026cdf0e10cSrcweir             DBG_ASSERT( bOK, "set value failed" );
1027cdf0e10cSrcweir             bChanged = sal_True;
1028cdf0e10cSrcweir         }
1029cdf0e10cSrcweir         if (!bOK)
1030cdf0e10cSrcweir             throw IllegalArgumentException( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Property type mismatch or property not set: " ) ) + rPropertyName, static_cast < cppu::OWeakObject * > ( this ), 0 );
1031cdf0e10cSrcweir 
1032cdf0e10cSrcweir         if (bChanged)
1033cdf0e10cSrcweir         {
1034cdf0e10cSrcweir             PropertyChangeEvent aChgEvt( (XPropertySet *) this, rPropertyName,
1035cdf0e10cSrcweir                     sal_False, pCur->nWID, aOld, rValue );
1036cdf0e10cSrcweir             launchEvent( aChgEvt );
1037cdf0e10cSrcweir         }
1038cdf0e10cSrcweir     }
1039cdf0e10cSrcweir }
1040cdf0e10cSrcweir 
getPropertyValue(const OUString & rPropertyName)1041cdf0e10cSrcweir uno::Any SAL_CALL SwXMailMerge::getPropertyValue(
1042cdf0e10cSrcweir         const OUString& rPropertyName )
1043cdf0e10cSrcweir     throw (UnknownPropertyException, WrappedTargetException, RuntimeException)
1044cdf0e10cSrcweir {
1045cdf0e10cSrcweir     vos::OGuard aGuard( Application::GetSolarMutex() );
1046cdf0e10cSrcweir 
1047cdf0e10cSrcweir     Any aRet;
1048cdf0e10cSrcweir 
1049cdf0e10cSrcweir     const SfxItemPropertySimpleEntry* pCur = pPropSet->getPropertyMap()->getByName( rPropertyName );
1050cdf0e10cSrcweir     if (!pCur)
1051cdf0e10cSrcweir         throw UnknownPropertyException();
1052cdf0e10cSrcweir     else
1053cdf0e10cSrcweir     {
1054cdf0e10cSrcweir         switch (pCur->nWID)
1055cdf0e10cSrcweir         {
1056cdf0e10cSrcweir             case WID_SELECTION :                aRet <<= aSelection;  break;
1057cdf0e10cSrcweir             case WID_RESULT_SET :               aRet <<= xResultSet;  break;
1058cdf0e10cSrcweir             case WID_CONNECTION :               aRet <<= xConnection;  break;
1059cdf0e10cSrcweir             case WID_MODEL :                    aRet <<= xModel;  break;
1060cdf0e10cSrcweir             case WID_DATA_SOURCE_NAME :         aRet <<= aDataSourceName;  break;
1061cdf0e10cSrcweir             case WID_DATA_COMMAND :             aRet <<= aDataCommand;  break;
1062cdf0e10cSrcweir             case WID_FILTER :                   aRet <<= aFilter;  break;
1063cdf0e10cSrcweir             case WID_DOCUMENT_URL :             aRet <<= aDocumentURL;  break;
1064cdf0e10cSrcweir             case WID_OUTPUT_URL :               aRet <<= aOutputURL;  break;
1065cdf0e10cSrcweir             case WID_DATA_COMMAND_TYPE :        aRet <<= nDataCommandType;  break;
1066cdf0e10cSrcweir             case WID_OUTPUT_TYPE :              aRet <<= nOutputType;  break;
1067cdf0e10cSrcweir             case WID_ESCAPE_PROCESSING :        aRet <<= bEscapeProcessing;  break;
1068cdf0e10cSrcweir             case WID_SINGLE_PRINT_JOBS :        aRet <<= bSinglePrintJobs;  break;
1069cdf0e10cSrcweir             case WID_FILE_NAME_FROM_COLUMN :    aRet <<= bFileNameFromColumn;  break;
1070cdf0e10cSrcweir             case WID_FILE_NAME_PREFIX :         aRet <<= aFileNamePrefix;  break;
1071cdf0e10cSrcweir             case WID_MAIL_SUBJECT:              aRet <<= sSubject; break;
1072cdf0e10cSrcweir             case WID_ADDRESS_FROM_COLUMN:       aRet <<= sAddressFromColumn; break;
1073cdf0e10cSrcweir             case WID_SEND_AS_HTML:              aRet <<= bSendAsHTML; break;
1074cdf0e10cSrcweir             case WID_SEND_AS_ATTACHMENT:        aRet <<= bSendAsAttachment; break;
1075cdf0e10cSrcweir             case WID_MAIL_BODY:                 aRet <<= sMailBody; break;
1076cdf0e10cSrcweir             case WID_ATTACHMENT_NAME:           aRet <<= sAttachmentName; break;
1077cdf0e10cSrcweir             case WID_ATTACHMENT_FILTER:         aRet <<= sAttachmentFilter;break;
1078cdf0e10cSrcweir             case WID_PRINT_OPTIONS:             aRet <<= aPrintSettings; break;
1079cdf0e10cSrcweir             case WID_SAVE_AS_SINGLE_FILE:       aRet <<= bSaveAsSingleFile; break;
1080cdf0e10cSrcweir             case WID_SAVE_FILTER:               aRet <<= sSaveFilter; break;
1081cdf0e10cSrcweir             case WID_SAVE_FILTER_OPTIONS:       aRet <<= sSaveFilterOptions; break;
1082cdf0e10cSrcweir             case WID_SAVE_FILTER_DATA:          aRet <<= aSaveFilterData; break;
1083cdf0e10cSrcweir             case WID_COPIES_TO:                 aRet <<= aCopiesTo; break;
1084cdf0e10cSrcweir             case WID_BLIND_COPIES_TO:           aRet <<= aBlindCopiesTo;break;
1085cdf0e10cSrcweir             case WID_IN_SERVER_PASSWORD:        aRet <<= sInServerPassword; break;
1086cdf0e10cSrcweir             case WID_OUT_SERVER_PASSWORD:       aRet <<= sOutServerPassword; break;
1087cdf0e10cSrcweir             default :
1088cdf0e10cSrcweir                 DBG_ERROR("unknown WID");
1089cdf0e10cSrcweir         }
1090cdf0e10cSrcweir     }
1091cdf0e10cSrcweir 
1092cdf0e10cSrcweir     return aRet;
1093cdf0e10cSrcweir }
1094cdf0e10cSrcweir 
addPropertyChangeListener(const OUString & rPropertyName,const uno::Reference<beans::XPropertyChangeListener> & rListener)1095cdf0e10cSrcweir void SAL_CALL SwXMailMerge::addPropertyChangeListener(
1096cdf0e10cSrcweir         const OUString& rPropertyName,
1097cdf0e10cSrcweir         const uno::Reference< beans::XPropertyChangeListener >& rListener )
1098cdf0e10cSrcweir     throw (UnknownPropertyException, WrappedTargetException, RuntimeException)
1099cdf0e10cSrcweir {
1100cdf0e10cSrcweir     vos::OGuard aGuard( Application::GetSolarMutex() );
1101cdf0e10cSrcweir     if (!bDisposing && rListener.is())
1102cdf0e10cSrcweir     {
1103cdf0e10cSrcweir         const SfxItemPropertySimpleEntry* pCur = pPropSet->getPropertyMap()->getByName( rPropertyName );
1104cdf0e10cSrcweir         if (pCur)
1105cdf0e10cSrcweir             aPropListeners.addInterface( pCur->nWID, rListener );
1106cdf0e10cSrcweir         else
1107cdf0e10cSrcweir             throw UnknownPropertyException();
1108cdf0e10cSrcweir     }
1109cdf0e10cSrcweir }
1110cdf0e10cSrcweir 
removePropertyChangeListener(const OUString & rPropertyName,const uno::Reference<beans::XPropertyChangeListener> & rListener)1111cdf0e10cSrcweir void SAL_CALL SwXMailMerge::removePropertyChangeListener(
1112cdf0e10cSrcweir         const OUString& rPropertyName,
1113cdf0e10cSrcweir         const uno::Reference< beans::XPropertyChangeListener >& rListener )
1114cdf0e10cSrcweir     throw (UnknownPropertyException, WrappedTargetException, RuntimeException)
1115cdf0e10cSrcweir {
1116cdf0e10cSrcweir     vos::OGuard aGuard( Application::GetSolarMutex() );
1117cdf0e10cSrcweir     if (!bDisposing && rListener.is())
1118cdf0e10cSrcweir     {
1119cdf0e10cSrcweir         const SfxItemPropertySimpleEntry* pCur = pPropSet->getPropertyMap()->getByName( rPropertyName );
1120cdf0e10cSrcweir         if (pCur)
1121cdf0e10cSrcweir             aPropListeners.removeInterface( pCur->nWID, rListener );
1122cdf0e10cSrcweir         else
1123cdf0e10cSrcweir             throw UnknownPropertyException();
1124cdf0e10cSrcweir     }
1125cdf0e10cSrcweir }
1126cdf0e10cSrcweir 
addVetoableChangeListener(const OUString &,const uno::Reference<beans::XVetoableChangeListener> &)1127cdf0e10cSrcweir void SAL_CALL SwXMailMerge::addVetoableChangeListener(
1128cdf0e10cSrcweir         const OUString& /*rPropertyName*/,
1129cdf0e10cSrcweir         const uno::Reference< beans::XVetoableChangeListener >& /*rListener*/ )
1130cdf0e10cSrcweir     throw (UnknownPropertyException, WrappedTargetException, RuntimeException)
1131cdf0e10cSrcweir {
1132cdf0e10cSrcweir     // no vetoable property, thus no support for vetoable change listeners
1133cdf0e10cSrcweir     DBG_WARNING( "not implemented");
1134cdf0e10cSrcweir }
1135cdf0e10cSrcweir 
removeVetoableChangeListener(const OUString &,const uno::Reference<beans::XVetoableChangeListener> &)1136cdf0e10cSrcweir void SAL_CALL SwXMailMerge::removeVetoableChangeListener(
1137cdf0e10cSrcweir         const OUString& /*rPropertyName*/,
1138cdf0e10cSrcweir         const uno::Reference< beans::XVetoableChangeListener >& /*rListener*/ )
1139cdf0e10cSrcweir     throw (UnknownPropertyException, WrappedTargetException, RuntimeException)
1140cdf0e10cSrcweir {
1141cdf0e10cSrcweir     // no vetoable property, thus no support for vetoable change listeners
1142cdf0e10cSrcweir     DBG_WARNING( "not implemented");
1143cdf0e10cSrcweir }
1144cdf0e10cSrcweir 
1145cdf0e10cSrcweir 
dispose()1146cdf0e10cSrcweir void SAL_CALL SwXMailMerge::dispose()
1147cdf0e10cSrcweir     throw(RuntimeException)
1148cdf0e10cSrcweir {
1149cdf0e10cSrcweir     vos::OGuard aGuard( Application::GetSolarMutex() );
1150cdf0e10cSrcweir 
1151cdf0e10cSrcweir     if (!bDisposing)
1152cdf0e10cSrcweir     {
1153cdf0e10cSrcweir         bDisposing = sal_True;
1154cdf0e10cSrcweir 
1155cdf0e10cSrcweir         EventObject aEvtObj( (XPropertySet *) this );
1156cdf0e10cSrcweir         aEvtListeners.disposeAndClear( aEvtObj );
1157cdf0e10cSrcweir         aMergeListeners.disposeAndClear( aEvtObj );
1158cdf0e10cSrcweir         aPropListeners.disposeAndClear( aEvtObj );
1159cdf0e10cSrcweir     }
1160cdf0e10cSrcweir }
1161cdf0e10cSrcweir 
addEventListener(const Reference<XEventListener> & rxListener)1162cdf0e10cSrcweir void SAL_CALL SwXMailMerge::addEventListener(
1163cdf0e10cSrcweir         const Reference< XEventListener >& rxListener )
1164cdf0e10cSrcweir     throw(RuntimeException)
1165cdf0e10cSrcweir {
1166cdf0e10cSrcweir     vos::OGuard aGuard( Application::GetSolarMutex() );
1167cdf0e10cSrcweir     if (!bDisposing && rxListener.is())
1168cdf0e10cSrcweir         aEvtListeners.addInterface( rxListener );
1169cdf0e10cSrcweir }
1170cdf0e10cSrcweir 
removeEventListener(const Reference<XEventListener> & rxListener)1171cdf0e10cSrcweir void SAL_CALL SwXMailMerge::removeEventListener(
1172cdf0e10cSrcweir         const Reference< XEventListener >& rxListener )
1173cdf0e10cSrcweir     throw(RuntimeException)
1174cdf0e10cSrcweir {
1175cdf0e10cSrcweir     vos::OGuard aGuard( Application::GetSolarMutex() );
1176cdf0e10cSrcweir     if (!bDisposing && rxListener.is())
1177cdf0e10cSrcweir         aEvtListeners.removeInterface( rxListener );
1178cdf0e10cSrcweir }
1179cdf0e10cSrcweir 
addMailMergeEventListener(const uno::Reference<XMailMergeListener> & rxListener)1180cdf0e10cSrcweir void SAL_CALL SwXMailMerge::addMailMergeEventListener(
1181cdf0e10cSrcweir         const uno::Reference< XMailMergeListener >& rxListener )
1182cdf0e10cSrcweir     throw (RuntimeException)
1183cdf0e10cSrcweir {
1184cdf0e10cSrcweir     vos::OGuard aGuard( Application::GetSolarMutex() );
1185cdf0e10cSrcweir     if (!bDisposing && rxListener.is())
1186cdf0e10cSrcweir         aMergeListeners.addInterface( rxListener );
1187cdf0e10cSrcweir }
1188cdf0e10cSrcweir 
removeMailMergeEventListener(const uno::Reference<XMailMergeListener> & rxListener)1189cdf0e10cSrcweir void SAL_CALL SwXMailMerge::removeMailMergeEventListener(
1190cdf0e10cSrcweir         const uno::Reference< XMailMergeListener >& rxListener )
1191cdf0e10cSrcweir     throw (RuntimeException)
1192cdf0e10cSrcweir {
1193cdf0e10cSrcweir     vos::OGuard aGuard( Application::GetSolarMutex() );
1194cdf0e10cSrcweir     if (!bDisposing && rxListener.is())
1195cdf0e10cSrcweir         aMergeListeners.removeInterface( rxListener );
1196cdf0e10cSrcweir }
1197cdf0e10cSrcweir 
getImplementationName()1198cdf0e10cSrcweir OUString SAL_CALL SwXMailMerge::getImplementationName()
1199cdf0e10cSrcweir     throw(RuntimeException)
1200cdf0e10cSrcweir {
1201cdf0e10cSrcweir     vos::OGuard aGuard( Application::GetSolarMutex() );
1202cdf0e10cSrcweir     return SwXMailMerge_getImplementationName();
1203cdf0e10cSrcweir }
1204cdf0e10cSrcweir 
supportsService(const OUString & rServiceName)1205cdf0e10cSrcweir sal_Bool SAL_CALL SwXMailMerge::supportsService( const OUString& rServiceName )
1206cdf0e10cSrcweir     throw(RuntimeException)
1207cdf0e10cSrcweir {
1208cdf0e10cSrcweir     vos::OGuard aGuard( Application::GetSolarMutex() );
1209cdf0e10cSrcweir     return C2U( SN_MAIL_MERGE ) == rServiceName ||
1210cdf0e10cSrcweir            C2U( SN_DATA_ACCESS_DESCRIPTOR ) == rServiceName;
1211cdf0e10cSrcweir }
1212cdf0e10cSrcweir 
getSupportedServiceNames()1213cdf0e10cSrcweir uno::Sequence< OUString > SAL_CALL SwXMailMerge::getSupportedServiceNames()
1214cdf0e10cSrcweir     throw(RuntimeException)
1215cdf0e10cSrcweir {
1216cdf0e10cSrcweir     vos::OGuard aGuard( Application::GetSolarMutex() );
1217cdf0e10cSrcweir     return SwXMailMerge_getSupportedServiceNames();
1218cdf0e10cSrcweir }
1219cdf0e10cSrcweir 
1220cdf0e10cSrcweir ////////////////////////////////////////////////////////////
1221cdf0e10cSrcweir 
SwXMailMerge_getSupportedServiceNames()1222cdf0e10cSrcweir uno::Sequence< OUString > SAL_CALL SwXMailMerge_getSupportedServiceNames()
1223cdf0e10cSrcweir     throw()
1224cdf0e10cSrcweir {
1225cdf0e10cSrcweir     uno::Sequence< OUString > aNames(2);
1226cdf0e10cSrcweir     OUString *pName = aNames.getArray();
1227cdf0e10cSrcweir     pName[0] = C2U( SN_MAIL_MERGE );
1228cdf0e10cSrcweir     pName[1] = C2U( SN_DATA_ACCESS_DESCRIPTOR );
1229cdf0e10cSrcweir     return aNames;
1230cdf0e10cSrcweir }
1231cdf0e10cSrcweir 
SwXMailMerge_getImplementationName()1232cdf0e10cSrcweir OUString SAL_CALL SwXMailMerge_getImplementationName()
1233cdf0e10cSrcweir     throw()
1234cdf0e10cSrcweir {
1235cdf0e10cSrcweir     return OUString( C2U( "SwXMailMerge" ) );
1236cdf0e10cSrcweir }
1237cdf0e10cSrcweir 
SwXMailMerge_createInstance(const uno::Reference<XMultiServiceFactory> &)1238cdf0e10cSrcweir uno::Reference< uno::XInterface > SAL_CALL SwXMailMerge_createInstance(
1239cdf0e10cSrcweir         const uno::Reference< XMultiServiceFactory > & /*rSMgr*/)
1240cdf0e10cSrcweir     throw( uno::Exception )
1241cdf0e10cSrcweir {
1242cdf0e10cSrcweir     vos::OGuard aGuard( Application::GetSolarMutex() );
1243cdf0e10cSrcweir 
1244cdf0e10cSrcweir     //the module may not be loaded
1245cdf0e10cSrcweir 	SwDLL::Init();
1246cdf0e10cSrcweir     uno::Reference< uno::XInterface > xRef = (cppu::OWeakObject *) new SwXMailMerge();
1247cdf0e10cSrcweir     return xRef;
1248cdf0e10cSrcweir }
1249cdf0e10cSrcweir 
1250