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