2010-10-14 08:30:41 +02:00
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2003-03-27 14:45:43 +00:00
/*************************************************************************
*
2008-04-10 20:58:01 +00:00
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER .
2003-03-27 14:45:43 +00:00
*
2010-02-12 15:01:35 +01:00
* Copyright 2000 , 2010 Oracle and / or its affiliates .
2003-03-27 14:45:43 +00:00
*
2008-04-10 20:58:01 +00:00
* OpenOffice . org - a multi - platform office productivity suite
2003-03-27 14:45:43 +00:00
*
2008-04-10 20:58:01 +00:00
* This file is part of OpenOffice . org .
2003-03-27 14:45:43 +00:00
*
2008-04-10 20:58:01 +00:00
* OpenOffice . org is free software : you can redistribute it and / or modify
* it under the terms of the GNU Lesser General Public License version 3
* only , as published by the Free Software Foundation .
2003-03-27 14:45:43 +00:00
*
2008-04-10 20:58:01 +00:00
* OpenOffice . org is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU Lesser General Public License version 3 for more details
* ( a copy is included in the LICENSE file that accompanied this code ) .
2003-03-27 14:45:43 +00:00
*
2008-04-10 20:58:01 +00:00
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice . org . If not , see
* < http : //www.openoffice.org/license.html>
* for a copy of the LGPLv3 License .
2003-03-27 14:45:43 +00:00
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2006-09-16 22:30:33 +00:00
// MARKER(update_precomp.py): autogen include statement, do not remove
# include "precompiled_sw.hxx"
2003-03-27 14:45:43 +00:00
# include <vcl/svapp.hxx>
2010-10-16 03:22:02 -05:00
# include <osl/mutex.hxx>
2003-03-27 14:45:43 +00:00
# include <osl/mutex.hxx>
2009-10-16 00:05:16 +02:00
# include <svl/itemprop.hxx>
# include <svl/urihelper.hxx>
2003-03-27 14:45:43 +00:00
# include <svx/dataaccessdescriptor.hxx>
# include <tools/shl.hxx> // GetAppData
# include <tools/tempfile.hxx>
# include <sfx2/app.hxx>
# include <sfx2/docfile.hxx>
# include <sfx2/docfilt.hxx>
# include <comphelper/processfactory.hxx>
2003-04-01 14:43:08 +00:00
# include <vcl/timer.hxx>
2003-03-27 14:45:43 +00:00
# include <com/sun/star/sdb/CommandType.hpp>
# include <com/sun/star/text/MailMergeType.hpp>
# include <com/sun/star/text/MailMergeEvent.hpp>
# include <com/sun/star/text/XMailMergeListener.hpp>
# include <com/sun/star/text/XMailMergeBroadcaster.hpp>
# include <com/sun/star/beans/PropertyAttribute.hpp>
# include <com/sun/star/lang/XUnoTunnel.hpp>
# include <com/sun/star/sdbc/XResultSet.hpp>
# include <com/sun/star/sdbc/XConnection.hpp>
# include <com/sun/star/sdbc/XRowSet.hpp>
# include <com/sun/star/frame/XComponentLoader.hpp>
# include <com/sun/star/util/XCloseable.hpp>
# include <com/sun/star/util/CloseVetoException.hpp>
2003-04-01 14:43:08 +00:00
# include <com/sun/star/sdbcx/XRowLocate.hpp>
# include <com/sun/star/frame/XStorable.hpp>
2005-01-28 14:33:13 +00:00
# include "com/sun/star/mail/XSmtpService.hpp"
2004-10-04 18:34:36 +00:00
# include <sfx2/viewfrm.hxx>
2005-03-11 09:50:41 +00:00
# include <sfx2/event.hxx>
# include <swevent.hxx>
2003-03-27 14:45:43 +00:00
# include <unomailmerge.hxx>
# include <swdll.hxx>
# include <swmodule.hxx>
# include <unoprnms.hxx>
# include <unomap.hxx>
# include <swunohelper.hxx>
# include <docsh.hxx>
2006-08-14 17:01:10 +00:00
# include <IDocumentDeviceAccess.hxx>
2003-03-27 14:45:43 +00:00
# include <view.hxx>
# include <dbmgr.hxx>
# include <unotxdoc.hxx>
# include <prtopt.hxx>
# include <wrtsh.hxx>
# include <shellio.hxx>
2005-01-28 14:33:13 +00:00
# include <mmconfigitem.hxx>
# include <mailmergehelper.hxx>
# include <memory>
2003-03-27 14:45:43 +00:00
2007-09-27 11:42:59 +00:00
# include <unomid.h>
2003-09-29 14:06:15 +00:00
# define SN_MAIL_MERGE "com.sun.star.text.MailMerge"
# define SN_DATA_ACCESS_DESCRIPTOR "com.sun.star.sdb.DataAccessDescriptor"
2003-03-27 14:45:43 +00:00
2007-09-27 11:42:59 +00:00
using namespace : : com : : sun : : star ;
using namespace : : com : : sun : : star : : frame ;
using namespace : : com : : sun : : star : : uno ;
using namespace : : com : : sun : : star : : lang ;
using namespace : : com : : sun : : star : : beans ;
using namespace : : com : : sun : : star : : text ;
2005-09-23 10:49:30 +00:00
using : : rtl : : OUString ;
2003-03-27 14:45:43 +00:00
using namespace SWUnoHelper ;
////////////////////////////////////////////////////////////
2005-09-23 10:49:30 +00:00
typedef : : utl : : SharedUNOComponent < XInterface > SharedComponent ;
2003-03-27 14:45:43 +00:00
////////////////////////////////////////////////////////////
osl : : Mutex & GetMailMergeMutex ( )
{
static osl : : Mutex aMutex ;
return aMutex ;
}
////////////////////////////////////////////////////////////
2003-04-01 14:43:08 +00:00
enum CloseResult
{
eSuccess , // successfully closed
eVetoed , // vetoed, ownership transfered to the vetoing instance
eFailed // failed for some unknown reason
} ;
static CloseResult CloseModelAndDocSh (
Reference < frame : : XModel > & rxModel ,
SfxObjectShellRef & rxDocSh )
{
CloseResult eResult = eSuccess ;
2003-03-27 14:45:43 +00:00
rxDocSh = 0 ;
//! models/documents should never be disposed (they may still be
//! used for printing which is called asynchronously for example)
//! instead call close
Reference < util : : XCloseable > xClose ( rxModel , UNO_QUERY ) ;
if ( xClose . is ( ) )
{
try
{
2005-07-12 10:22:18 +00:00
//! 'sal_True' -> transfer ownership to vetoing object if vetoed!
//! I.e. now that object is responsible for closing the model and doc shell.
2003-03-27 14:45:43 +00:00
xClose - > close ( sal_True ) ;
}
catch ( util : : CloseVetoException & )
{
2003-04-01 14:43:08 +00:00
//! here we have the problem that the temporary file that is
//! currently being printed will never be deleted. :-(
eResult = eVetoed ;
}
catch ( const uno : : RuntimeException & )
{
eResult = eFailed ;
2003-03-27 14:45:43 +00:00
}
}
2003-04-01 14:43:08 +00:00
return eResult ;
2003-03-27 14:45:43 +00:00
}
////////////////////////////////////////////////////////////
static BOOL LoadFromURL_impl (
Reference < frame : : XModel > & rxModel ,
SfxObjectShellRef & rxDocSh ,
const String & rURL ,
BOOL bClose )
throw ( RuntimeException )
{
// try to open the document readonly and hidden
Reference < frame : : XModel > xTmpModel ;
Sequence < PropertyValue > aArgs ( 1 ) ;
aArgs [ 0 ] . Name = C2U ( " Hidden " ) ;
sal_Bool bVal = sal_True ;
aArgs [ 0 ] . Value < < = bVal ;
try
{
Reference < XComponentLoader > xDesktop ( : : comphelper : : getProcessServiceFactory ( ) - >
createInstance ( C2U ( " com.sun.star.frame.Desktop " ) ) , UNO_QUERY ) ;
xTmpModel = Reference < XModel > ( xDesktop - > loadComponentFromURL (
rURL , C2U ( " _blank " ) , 0 , aArgs ) , UNO_QUERY ) ;
}
catch ( Exception & )
{
return FALSE ;
}
// try to get the DocShell
SwDocShell * pTmpDocShell = 0 ;
Reference < XUnoTunnel > xTunnel ( xTmpModel , UNO_QUERY ) ;
if ( xTunnel . is ( ) )
{
2007-09-27 11:42:59 +00:00
SwXTextDocument * pTextDoc = reinterpret_cast < SwXTextDocument * > (
xTunnel - > getSomething ( SwXTextDocument : : getUnoTunnelId ( ) ) ) ;
2003-03-27 14:45:43 +00:00
pTmpDocShell = pTextDoc ? pTextDoc - > GetDocShell ( ) : 0 ;
}
BOOL bRes = FALSE ;
if ( xTmpModel . is ( ) & & pTmpDocShell ) // everything available?
{
if ( bClose )
CloseModelAndDocSh ( rxModel , rxDocSh ) ;
// set new stuff
rxModel = xTmpModel ;
rxDocSh = pTmpDocShell ;
bRes = TRUE ;
}
else
{
SfxObjectShellRef xTmpDocSh = pTmpDocShell ;
CloseModelAndDocSh ( xTmpModel , xTmpDocSh ) ;
}
return bRes ;
}
2003-04-01 14:43:08 +00:00
//==========================================================
namespace
{
2007-09-27 11:42:59 +00:00
class DelayedFileDeletion : public : : cppu : : WeakImplHelper1 < util : : XCloseListener >
2003-04-01 14:43:08 +00:00
{
protected :
: : osl : : Mutex m_aMutex ;
Reference < util : : XCloseable > m_xDocument ;
Timer m_aDeleteTimer ;
String m_sTemporaryFile ;
sal_Int32 m_nPendingDeleteAttempts ;
public :
DelayedFileDeletion ( const Reference < XModel > & _rxModel ,
const String & _rTemporaryFile ) ;
protected :
~ DelayedFileDeletion ( ) ;
// XCloseListener
virtual void SAL_CALL queryClosing ( const EventObject & _rSource , sal_Bool _bGetsOwnership ) throw ( util : : CloseVetoException , RuntimeException ) ;
virtual void SAL_CALL notifyClosing ( const EventObject & _rSource ) throw ( RuntimeException ) ;
// XEventListener
virtual void SAL_CALL disposing ( const EventObject & Source ) throw ( RuntimeException ) ;
private :
void implTakeOwnership ( ) ;
DECL_LINK ( OnTryDeleteFile , void * ) ;
private :
DelayedFileDeletion ( const DelayedFileDeletion & ) ; // never implemented
DelayedFileDeletion & operator = ( const DelayedFileDeletion & ) ; // never implemented
} ;
DBG_NAME ( DelayedFileDeletion )
//------------------------------------------------------
DelayedFileDeletion : : DelayedFileDeletion ( const Reference < XModel > & _rxModel , const String & _rTemporaryFile )
2007-09-27 11:42:59 +00:00
:
m_xDocument ( _rxModel , UNO_QUERY )
, m_sTemporaryFile ( _rTemporaryFile )
2003-04-01 14:43:08 +00:00
, m_nPendingDeleteAttempts ( 0 )
{
DBG_CTOR ( DelayedFileDeletion , NULL ) ;
osl_incrementInterlockedCount ( & m_refCount ) ;
try
{
if ( m_xDocument . is ( ) )
{
m_xDocument - > addCloseListener ( this ) ;
// successfully added -> keep ourself alive
acquire ( ) ;
}
2008-04-22 14:05:53 +00:00
else {
2010-10-24 23:48:32 +02:00
OSL_ENSURE ( false , " DelayedFileDeletion::DelayedFileDeletion: model is no component! " ) ;
2008-04-22 14:05:53 +00:00
}
2003-04-01 14:43:08 +00:00
}
catch ( const Exception & )
{
2010-10-24 23:48:32 +02:00
OSL_ENSURE ( false , " DelayedFileDeletion::DelayedFileDeletion: could not register as event listener at the model! " ) ;
2003-04-01 14:43:08 +00:00
}
osl_decrementInterlockedCount ( & m_refCount ) ;
}
//--------------------------------------------------------------------
2007-09-27 11:42:59 +00:00
IMPL_LINK ( DelayedFileDeletion , OnTryDeleteFile , void * , EMPTYARG )
2003-04-01 14:43:08 +00:00
{
: : osl : : ClearableMutexGuard aGuard ( m_aMutex ) ;
sal_Bool bSuccess = sal_False ;
try
{
sal_Bool bDeliverOwnership = ( 0 = = m_nPendingDeleteAttempts ) ;
// if this is our last attemt, then anybody which vetoes this has to take the consequences
// (means take the ownership)
m_xDocument - > close ( bDeliverOwnership ) ;
bSuccess = sal_True ;
}
catch ( const util : : CloseVetoException & )
{
// somebody vetoed -> next try
if ( m_nPendingDeleteAttempts )
{
// next attempt
- - m_nPendingDeleteAttempts ;
m_aDeleteTimer . Start ( ) ;
}
else
bSuccess = sal_True ; // can't do anything here ...
}
catch ( const Exception & )
{
2010-10-24 23:48:32 +02:00
OSL_ENSURE ( false , " DelayedFileDeletion::OnTryDeleteFile: caught a strange exception! " ) ;
2003-04-01 14:43:08 +00:00
bSuccess = sal_True ;
// can't do anything here ...
}
if ( bSuccess )
{
SWUnoHelper : : UCB_DeleteFile ( m_sTemporaryFile ) ;
aGuard . clear ( ) ;
release ( ) ; // this should be our last reference, we should be dead after this
}
return 0L ;
}
//--------------------------------------------------------------------
void DelayedFileDeletion : : implTakeOwnership ( )
{
// revoke ourself as listener
try
{
m_xDocument - > removeCloseListener ( this ) ;
}
catch ( const Exception & )
{
2010-10-24 23:48:32 +02:00
OSL_ENSURE ( false , " DelayedFileDeletion::implTakeOwnership: could not revoke the listener! " ) ;
2003-04-01 14:43:08 +00:00
}
m_aDeleteTimer . SetTimeout ( 3000 ) ; // 3 seconds
m_aDeleteTimer . SetTimeoutHdl ( LINK ( this , DelayedFileDeletion , OnTryDeleteFile ) ) ;
m_nPendingDeleteAttempts = 3 ; // try 3 times at most
m_aDeleteTimer . Start ( ) ;
}
//--------------------------------------------------------------------
2007-09-27 11:42:59 +00:00
void SAL_CALL DelayedFileDeletion : : queryClosing ( const EventObject & , sal_Bool _bGetsOwnership ) throw ( util : : CloseVetoException , RuntimeException )
2003-04-01 14:43:08 +00:00
{
: : osl : : MutexGuard aGuard ( m_aMutex ) ;
if ( _bGetsOwnership )
implTakeOwnership ( ) ;
// always veto: We want to take the ownership ourself, as this is the only chance to delete
// the temporary file which the model is based on
throw util : : CloseVetoException ( ) ;
}
//--------------------------------------------------------------------
2007-09-27 11:42:59 +00:00
void SAL_CALL DelayedFileDeletion : : notifyClosing ( const EventObject & ) throw ( RuntimeException )
2003-04-01 14:43:08 +00:00
{
2010-10-24 23:48:32 +02:00
OSL_ENSURE ( false , " DelayedFileDeletion::notifyClosing: how this? " ) ;
2003-04-01 14:43:08 +00:00
// this should not happen:
// Either, a foreign instance closes the document, then we should veto this, and take the ownership
// Or, we ourself close the document, then we should not be a listener anymore
}
//------------------------------------------------------
2007-09-27 11:42:59 +00:00
void SAL_CALL DelayedFileDeletion : : disposing ( const EventObject & ) throw ( RuntimeException )
2003-04-01 14:43:08 +00:00
{
2010-10-24 23:48:32 +02:00
OSL_ENSURE ( false , " DelayedFileDeletion::disposing: how this? " ) ;
2003-04-01 14:43:08 +00:00
// this should not happen:
// Either, a foreign instance closes the document, then we should veto this, and take the ownership
// Or, we ourself close the document, then we should not be a listener anymore
}
//------------------------------------------------------
DelayedFileDeletion : : ~ DelayedFileDeletion ( )
{
DBG_DTOR ( DelayedFileDeletion , NULL ) ;
}
}
2003-03-27 14:45:43 +00:00
////////////////////////////////////////////////////////////
static BOOL DeleteTmpFile_Impl (
Reference < frame : : XModel > & rxModel ,
SfxObjectShellRef & rxDocSh ,
2003-04-01 14:43:08 +00:00
const String & rTmpFileURL )
2003-03-27 14:45:43 +00:00
{
BOOL bRes = FALSE ;
if ( rTmpFileURL . Len ( ) )
{
2003-04-01 14:43:08 +00:00
BOOL bDelete = TRUE ;
if ( eVetoed = = CloseModelAndDocSh ( rxModel , rxDocSh ) )
2003-03-27 14:45:43 +00:00
{
2003-04-01 14:43:08 +00:00
// somebody vetoed the closing, and took the ownership of the document
// -> ensure that the temporary file is deleted later on
Reference < XEventListener > xEnsureDelete ( new DelayedFileDeletion ( rxModel , rTmpFileURL ) ) ;
// note: as soon as #106931# is fixed, the whole DelayedFileDeletion is to be superseeded by
// a better solution
bDelete = FALSE ;
2003-03-27 14:45:43 +00:00
}
rxModel = 0 ;
rxDocSh = 0 ; // destroy doc shell
2003-04-01 14:43:08 +00:00
if ( bDelete )
{
if ( ! SWUnoHelper : : UCB_DeleteFile ( rTmpFileURL ) )
{
Reference < XEventListener > xEnsureDelete ( new DelayedFileDeletion ( rxModel , rTmpFileURL ) ) ;
// same not as above: as soon as #106931#, ...
}
}
else
bRes = TRUE ; // file will be deleted delayed
2003-03-27 14:45:43 +00:00
}
return bRes ;
}
////////////////////////////////////////////////////////////
SwXMailMerge : : SwXMailMerge ( ) :
aEvtListeners ( GetMailMergeMutex ( ) ) ,
aMergeListeners ( GetMailMergeMutex ( ) ) ,
2005-01-28 14:33:13 +00:00
aPropListeners ( GetMailMergeMutex ( ) ) ,
2009-06-03 11:26:39 +00:00
pPropSet ( aSwMapProvider . GetPropertySet ( PROPERTY_MAP_MAILMERGE ) ) ,
2005-01-28 14:33:13 +00:00
bSendAsHTML ( sal_False ) ,
bSendAsAttachment ( sal_False ) ,
bSaveAsSingleFile ( sal_False )
2003-03-27 14:45:43 +00:00
{
// create empty document
// like in: SwModule::InsertEnv (appenv.cxx)
SwDocShell * pDocShell = new SwDocShell ( SFX_CREATE_MODE_STANDARD ) ;
xDocSh = pDocShell ;
xDocSh - > DoInitNew ( 0 ) ;
2009-12-09 10:11:48 +01:00
SfxViewFrame * pFrame = SfxViewFrame : : LoadHiddenDocument ( * xDocSh , 0 ) ;
2003-03-27 14:45:43 +00:00
SwView * pView = ( SwView * ) pFrame - > GetViewShell ( ) ;
pView - > AttrChangedNotify ( & pView - > GetWrtShell ( ) ) ; //Damit SelectShell gerufen wird.
xModel = pDocShell - > GetModel ( ) ;
nDataCommandType = sdb : : CommandType : : TABLE ;
nOutputType = MailMergeType : : PRINTER ;
2003-09-29 14:06:15 +00:00
bEscapeProcessing = sal_True ; //!! allow to process properties like "Filter", "Order", ...
2003-03-27 14:45:43 +00:00
bSinglePrintJobs = sal_False ;
bFileNameFromColumn = sal_False ;
bDisposing = sal_False ;
}
SwXMailMerge : : ~ SwXMailMerge ( )
{
2005-07-12 10:22:18 +00:00
if ( aTmpFileName . Len ( ) )
DeleteTmpFile_Impl ( xModel , xDocSh , aTmpFileName ) ;
else // there was no temporary file in use
{
//! we still need to close the model and doc shell manually
//! because there is no automatism that will do that later.
//! #120086#
if ( eVetoed = = CloseModelAndDocSh ( xModel , xDocSh ) )
2010-10-24 23:48:32 +02:00
OSL_ENSURE ( false , " owner ship transfered to vetoing object! " ) ;
2005-07-12 10:22:18 +00:00
xModel = 0 ;
xDocSh = 0 ; // destroy doc shell
}
2003-03-27 14:45:43 +00:00
}
uno : : Any SAL_CALL SwXMailMerge : : execute (
const uno : : Sequence < beans : : NamedValue > & rArguments )
throw ( IllegalArgumentException , Exception , RuntimeException )
{
2010-10-13 01:44:10 -05:00
SolarMutexGuard aGuard ;
2003-03-27 14:45:43 +00:00
//
// get property values to be used
// (use values from the service as default and override them with
// the values that are provided as arguments)
//
uno : : Sequence < uno : : Any > aCurSelection = aSelection ;
uno : : Reference < sdbc : : XResultSet > xCurResultSet = xResultSet ;
uno : : Reference < sdbc : : XConnection > xCurConnection = xConnection ;
uno : : Reference < frame : : XModel > xCurModel = xModel ;
OUString aCurDataSourceName = aDataSourceName ;
OUString aCurDataCommand = aDataCommand ;
OUString aCurFilter = aFilter ;
OUString aCurDocumentURL = aDocumentURL ;
OUString aCurOutputURL = aOutputURL ;
OUString aCurFileNamePrefix = aFileNamePrefix ;
sal_Int32 nCurDataCommandType = nDataCommandType ;
sal_Int16 nCurOutputType = nOutputType ;
sal_Bool bCurEscapeProcessing = bEscapeProcessing ;
sal_Bool bCurSinglePrintJobs = bSinglePrintJobs ;
sal_Bool bCurFileNameFromColumn = bFileNameFromColumn ;
//
SfxObjectShellRef xCurDocSh = xDocSh ; // the document
//
const beans : : NamedValue * pArguments = rArguments . getConstArray ( ) ;
sal_Int32 nArgs = rArguments . getLength ( ) ;
for ( sal_Int32 i = 0 ; i < nArgs ; + + i )
{
const OUString & rName = pArguments [ i ] . Name ;
const Any & rValue = pArguments [ i ] . Value ;
BOOL bOK = TRUE ;
if ( rName . equalsAscii ( GetPropName ( UNO_NAME_SELECTION ) ) )
bOK = rValue > > = aCurSelection ;
else if ( rName . equalsAscii ( GetPropName ( UNO_NAME_RESULT_SET ) ) )
bOK = rValue > > = xCurResultSet ;
else if ( rName . equalsAscii ( GetPropName ( UNO_NAME_CONNECTION ) ) )
bOK = rValue > > = xCurConnection ;
else if ( rName . equalsAscii ( GetPropName ( UNO_NAME_MODEL ) ) )
throw PropertyVetoException ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( " Property is read-only: " ) ) + rName , static_cast < cppu : : OWeakObject * > ( this ) ) ;
else if ( rName . equalsAscii ( GetPropName ( UNO_NAME_DATA_SOURCE_NAME ) ) )
bOK = rValue > > = aCurDataSourceName ;
2003-04-04 17:17:51 +00:00
else if ( rName . equalsAscii ( GetPropName ( UNO_NAME_DAD_COMMAND ) ) )
2003-03-27 14:45:43 +00:00
bOK = rValue > > = aCurDataCommand ;
else if ( rName . equalsAscii ( GetPropName ( UNO_NAME_FILTER ) ) )
bOK = rValue > > = aCurFilter ;
else if ( rName . equalsAscii ( GetPropName ( UNO_NAME_DOCUMENT_URL ) ) )
{
bOK = rValue > > = aCurDocumentURL ;
if ( aCurDocumentURL . getLength ( )
& & ! LoadFromURL_impl ( xCurModel , xCurDocSh , aCurDocumentURL , FALSE ) )
throw RuntimeException ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( " Failed to create document from URL: " ) ) + aCurDocumentURL , static_cast < cppu : : OWeakObject * > ( this ) ) ;
}
else if ( rName . equalsAscii ( GetPropName ( UNO_NAME_OUTPUT_URL ) ) )
{
bOK = rValue > > = aCurOutputURL ;
if ( aCurOutputURL . getLength ( ) )
{
if ( ! UCB_IsDirectory ( aCurOutputURL ) )
throw IllegalArgumentException ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( " URL does not point to a directory: " ) ) + aCurOutputURL , static_cast < cppu : : OWeakObject * > ( this ) , 0 ) ;
if ( UCB_IsReadOnlyFileName ( aCurOutputURL ) )
throw IllegalArgumentException ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( " URL is read-only: " ) ) + aCurOutputURL , static_cast < cppu : : OWeakObject * > ( this ) , 0 ) ;
}
}
else if ( rName . equalsAscii ( GetPropName ( UNO_NAME_FILE_NAME_PREFIX ) ) )
bOK = rValue > > = aCurFileNamePrefix ;
2003-04-04 17:17:51 +00:00
else if ( rName . equalsAscii ( GetPropName ( UNO_NAME_DAD_COMMAND_TYPE ) ) )
2003-03-27 14:45:43 +00:00
bOK = rValue > > = nCurDataCommandType ;
else if ( rName . equalsAscii ( GetPropName ( UNO_NAME_OUTPUT_TYPE ) ) )
bOK = rValue > > = nCurOutputType ;
else if ( rName . equalsAscii ( GetPropName ( UNO_NAME_ESCAPE_PROCESSING ) ) )
bOK = rValue > > = bCurEscapeProcessing ;
else if ( rName . equalsAscii ( GetPropName ( UNO_NAME_SINGLE_PRINT_JOBS ) ) )
bOK = rValue > > = bCurSinglePrintJobs ;
else if ( rName . equalsAscii ( GetPropName ( UNO_NAME_FILE_NAME_FROM_COLUMN ) ) )
bOK = rValue > > = bCurFileNameFromColumn ;
2005-01-28 14:33:13 +00:00
else if ( rName . equalsAscii ( GetPropName ( UNO_NAME_SUBJECT ) ) )
bOK = rValue > > = sSubject ;
else if ( rName . equalsAscii ( GetPropName ( UNO_NAME_ADDRESS_FROM_COLUMN ) ) )
bOK = rValue > > = sAddressFromColumn ;
else if ( rName . equalsAscii ( GetPropName ( UNO_NAME_SEND_AS_HTML ) ) )
bOK = rValue > > = bSendAsHTML ;
else if ( rName . equalsAscii ( GetPropName ( UNO_NAME_MAIL_BODY ) ) )
bOK = rValue > > = sMailBody ;
else if ( rName . equalsAscii ( GetPropName ( UNO_NAME_ATTACHMENT_NAME ) ) )
bOK = rValue > > = sAttachmentName ;
else if ( rName . equalsAscii ( GetPropName ( UNO_NAME_ATTACHMENT_FILTER ) ) )
bOK = rValue > > = sAttachmentFilter ;
else if ( rName . equalsAscii ( GetPropName ( UNO_NAME_COPIES_TO ) ) )
bOK = rValue > > = aCopiesTo ;
else if ( rName . equalsAscii ( GetPropName ( UNO_NAME_BLIND_COPIES_TO ) ) )
bOK = rValue > > = aBlindCopiesTo ;
else if ( rName . equalsAscii ( GetPropName ( UNO_NAME_SEND_AS_ATTACHMENT ) ) )
bOK = rValue > > = bSendAsAttachment ;
else if ( rName . equalsAscii ( GetPropName ( UNO_NAME_PRINT_OPTIONS ) ) )
bOK = rValue > > = aPrintSettings ;
else if ( rName . equalsAscii ( GetPropName ( UNO_NAME_SAVE_AS_SINGLE_FILE ) ) )
bOK = rValue > > = bSaveAsSingleFile ;
else if ( rName . equalsAscii ( GetPropName ( UNO_NAME_SAVE_FILTER ) ) )
bOK = rValue > > = sSaveFilter ;
2005-03-08 12:48:53 +00:00
else if ( rName . equalsAscii ( GetPropName ( UNO_NAME_SAVE_FILTER_OPTIONS ) ) )
bOK = rValue > > = sSaveFilterOptions ;
else if ( rName . equalsAscii ( GetPropName ( UNO_NAME_SAVE_FILTER_DATA ) ) )
bOK = rValue > > = aSaveFilterData ;
2005-01-28 14:33:13 +00:00
else if ( rName . equalsAscii ( GetPropName ( UNO_NAME_IN_SERVER_PASSWORD ) ) )
bOK = rValue > > = sInServerPassword ;
else if ( rName . equalsAscii ( GetPropName ( UNO_NAME_OUT_SERVER_PASSWORD ) ) )
bOK = rValue > > = sOutServerPassword ;
2003-03-27 14:45:43 +00:00
else
throw UnknownPropertyException ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( " Property is unknown: " ) ) + rName , static_cast < cppu : : OWeakObject * > ( this ) ) ;
if ( ! bOK )
throw IllegalArgumentException ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( " Property type mismatch or property not set: " ) ) + rName , static_cast < cppu : : OWeakObject * > ( this ) , 0 ) ;
}
2003-04-01 14:43:08 +00:00
// need to translate the selection: the API here requires a sequence of bookmarks, but the MergeNew
// method we will call below requires a sequence of indicies.
if ( aCurSelection . getLength ( ) )
{
Sequence < Any > aTranslated ( aCurSelection . getLength ( ) ) ;
sal_Bool bValid = sal_False ;
Reference < sdbcx : : XRowLocate > xRowLocate ( xCurResultSet , UNO_QUERY ) ;
if ( xRowLocate . is ( ) )
{
const Any * pBookmarks = aCurSelection . getConstArray ( ) ;
const Any * pBookmarksEnd = pBookmarks + aCurSelection . getLength ( ) ;
Any * pTranslated = aTranslated . getArray ( ) ;
try
{
sal_Bool bEverythingsFine = sal_True ;
for ( ; ( pBookmarks ! = pBookmarksEnd ) & & bEverythingsFine ; + + pBookmarks )
{
if ( xRowLocate - > moveToBookmark ( * pBookmarks ) )
* pTranslated < < = xCurResultSet - > getRow ( ) ;
else
bEverythingsFine = sal_False ;
}
if ( bEverythingsFine )
bValid = sal_True ;
}
catch ( const Exception & )
{
bValid = sal_False ;
}
}
if ( ! bValid )
{
throw IllegalArgumentException (
OUString ( RTL_CONSTASCII_USTRINGPARAM ( " The current 'Selection' does not describe a valid array of bookmarks, relative to the current 'ResultSet'. " ) ) ,
static_cast < cppu : : OWeakObject * > ( this ) ,
0
) ;
}
aCurSelection = aTranslated ;
}
2009-11-30 12:56:04 +01:00
SfxViewFrame * pFrame = SfxViewFrame : : GetFirst ( xCurDocSh , FALSE ) ;
2003-03-27 14:45:43 +00:00
SwView * pView = PTR_CAST ( SwView , pFrame - > GetViewShell ( ) ) ;
if ( ! pView )
throw RuntimeException ( ) ;
SwWrtShell & rSh = * pView - > GetWrtShellPtr ( ) ;
// avoid assertion in 'Update' from Sfx by supplying a shell
// and thus avoiding the SelectShell call in Writers GetState function
// while still in Update of Sfx.
// (GetSelection in Update is not allowed)
if ( pView & & aCurDocumentURL . getLength ( ) )
pView - > AttrChangedNotify ( & pView - > GetWrtShell ( ) ) ; //Damit SelectShell gerufen wird.
2005-09-23 10:49:30 +00:00
SharedComponent aRowSetDisposeHelper ;
2003-03-27 14:45:43 +00:00
if ( ! xCurResultSet . is ( ) )
{
if ( ! aCurDataSourceName . getLength ( ) | | ! aCurDataCommand . getLength ( ) )
{
2010-10-24 23:48:32 +02:00
OSL_ENSURE ( false , " PropertyValues missing or unset " ) ;
2003-03-27 14:45:43 +00:00
throw IllegalArgumentException ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( " Either the ResultSet or DataSourceName and DataCommand must be set. " ) ) , static_cast < cppu : : OWeakObject * > ( this ) , 0 ) ;
}
//
// build ResultSet from DataSourceName, DataCommand and DataCommandType
//
Reference < XMultiServiceFactory > xMgr ( : : comphelper : : getProcessServiceFactory ( ) ) ;
if ( xMgr . is ( ) )
{
Reference < XInterface > xInstance = xMgr - > createInstance (
C2U ( " com.sun.star.sdb.RowSet " ) ) ;
2005-09-23 10:49:30 +00:00
aRowSetDisposeHelper . reset ( xInstance , SharedComponent : : TakeOwnership ) ;
2003-03-27 14:45:43 +00:00
Reference < XPropertySet > xRowSetPropSet ( xInstance , UNO_QUERY ) ;
2010-10-24 23:48:32 +02:00
OSL_ENSURE ( xRowSetPropSet . is ( ) , " failed to get XPropertySet interface from RowSet " ) ;
2003-03-27 14:45:43 +00:00
if ( xRowSetPropSet . is ( ) )
{
if ( xCurConnection . is ( ) )
xRowSetPropSet - > setPropertyValue ( C2U ( " ActiveConnection " ) , makeAny ( xCurConnection ) ) ;
xRowSetPropSet - > setPropertyValue ( C2U ( " DataSourceName " ) , makeAny ( aCurDataSourceName ) ) ;
xRowSetPropSet - > setPropertyValue ( C2U ( " Command " ) , makeAny ( aCurDataCommand ) ) ;
xRowSetPropSet - > setPropertyValue ( C2U ( " CommandType " ) , makeAny ( nCurDataCommandType ) ) ;
xRowSetPropSet - > setPropertyValue ( C2U ( " EscapeProcessing " ) , makeAny ( bCurEscapeProcessing ) ) ;
xRowSetPropSet - > setPropertyValue ( C2U ( " ApplyFilter " ) , makeAny ( sal_True ) ) ;
xRowSetPropSet - > setPropertyValue ( C2U ( " Filter " ) , makeAny ( aCurFilter ) ) ;
Reference < sdbc : : XRowSet > xRowSet ( xInstance , UNO_QUERY ) ;
if ( xRowSet . is ( ) )
xRowSet - > execute ( ) ; // build ResultSet from properties
2008-10-29 11:35:03 +00:00
if ( ! xCurConnection . is ( ) )
xCurConnection . set ( xRowSetPropSet - > getPropertyValue ( C2U ( " ActiveConnection " ) ) , UNO_QUERY ) ;
2003-03-27 14:45:43 +00:00
xCurResultSet = Reference < sdbc : : XResultSet > ( xRowSet , UNO_QUERY ) ;
2010-10-24 23:48:32 +02:00
OSL_ENSURE ( xCurResultSet . is ( ) , " failed to build ResultSet " ) ;
2003-03-27 14:45:43 +00:00
}
}
}
svx : : ODataAccessDescriptor aDescriptor ;
2004-08-02 13:23:55 +00:00
aDescriptor . setDataSource ( aCurDataSourceName ) ;
2003-03-27 14:45:43 +00:00
aDescriptor [ svx : : daConnection ] < < = xCurConnection ;
aDescriptor [ svx : : daCommand ] < < = aCurDataCommand ;
aDescriptor [ svx : : daCommandType ] < < = nCurDataCommandType ;
aDescriptor [ svx : : daEscapeProcessing ] < < = bCurEscapeProcessing ;
aDescriptor [ svx : : daCursor ] < < = xCurResultSet ;
// aDescriptor[ svx::daColumnName ] not used
// aDescriptor[ svx::daColumnObject ] not used
aDescriptor [ svx : : daSelection ] < < = aCurSelection ;
USHORT nMergeType ;
switch ( nCurOutputType )
{
case MailMergeType : : PRINTER : nMergeType = DBMGR_MERGE_MAILMERGE ; break ;
case MailMergeType : : FILE : nMergeType = DBMGR_MERGE_MAILFILES ; break ;
2005-01-28 14:33:13 +00:00
case MailMergeType : : MAIL : nMergeType = DBMGR_MERGE_MAILING ; break ;
2003-03-27 14:45:43 +00:00
default :
throw IllegalArgumentException ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( " Invalid value of property: " ) ) + C2U ( " OutputType " ) , static_cast < cppu : : OWeakObject * > ( this ) , 0 ) ;
}
SwNewDBMgr * pMgr = rSh . GetNewDBMgr ( ) ;
2004-03-17 11:21:07 +00:00
//force layout creation
rSh . CalcLayout ( ) ;
2010-10-24 23:48:32 +02:00
OSL_ENSURE ( pMgr , " database manager missing " ) ;
2005-01-28 14:33:13 +00:00
SwMergeDescriptor aMergeDesc ( nMergeType , rSh , aDescriptor ) ;
std : : auto_ptr < SwMailMergeConfigItem > pMMConfigItem ;
uno : : Reference < mail : : XMailService > xInService ;
2003-03-27 14:45:43 +00:00
if ( MailMergeType : : PRINTER = = nCurOutputType )
{
SwPrintData aPrtData = * SW_MOD ( ) - > GetPrtOptions ( FALSE ) ;
2006-08-14 17:01:10 +00:00
IDocumentDeviceAccess * pIDDA = rSh . getIDocumentDeviceAccess ( ) ;
SwPrintData * pShellPrintData = pIDDA - > getPrintData ( ) ;
2003-03-27 14:45:43 +00:00
if ( pShellPrintData )
aPrtData = * pShellPrintData ;
aPrtData . SetPrintSingleJobs ( bCurSinglePrintJobs ) ;
2006-08-14 17:01:10 +00:00
pIDDA - > setPrintData ( aPrtData ) ;
2005-01-28 14:33:13 +00:00
// #i25686# printing should not be done asynchronously to prevent dangling offices
// when mail merge is called as command line macro
aMergeDesc . bPrintAsync = sal_False ;
aMergeDesc . aPrintOptions = aPrintSettings ;
2009-09-01 08:23:11 +00:00
aMergeDesc . bCreateSingleFile = true ;
2003-03-27 14:45:43 +00:00
}
2005-01-28 14:33:13 +00:00
else /* FILE and MAIL*/
2003-03-27 14:45:43 +00:00
{
INetURLObject aURLObj ;
aURLObj . SetSmartProtocol ( INET_PROT_FILE ) ;
if ( aCurDocumentURL . getLength ( ) )
{
// if OutputURL or FileNamePrefix are missing get
// them from DocumentURL
aURLObj . SetSmartURL ( aCurDocumentURL ) ;
if ( ! aCurFileNamePrefix . getLength ( ) )
aCurFileNamePrefix = aURLObj . GetBase ( ) ; // filename without extension
if ( ! aCurOutputURL . getLength ( ) )
{
//aCurOutputURL = aURLObj.GetURLPath();
aURLObj . removeSegment ( ) ;
aCurOutputURL = aURLObj . GetMainURL ( INetURLObject : : DECODE_TO_IURI ) ;
}
}
else // default empty document without URL
{
if ( ! aCurOutputURL . getLength ( ) )
throw RuntimeException ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( " OutputURL is not set and can not be obtained. " ) ) , static_cast < cppu : : OWeakObject * > ( this ) ) ;
}
aURLObj . SetSmartURL ( aCurOutputURL ) ;
String aPath = aURLObj . GetMainURL ( INetURLObject : : DECODE_TO_IURI ) ;
String aDelim ( INET_PATH_TOKEN ) ;
if ( aPath . Len ( ) > = aDelim . Len ( ) & &
aPath . Copy ( aPath . Len ( ) - aDelim . Len ( ) ) . CompareTo ( aDelim ) ! = COMPARE_EQUAL )
aPath + = aDelim ;
if ( bCurFileNameFromColumn )
pMgr - > SetEMailColumn ( aCurFileNamePrefix ) ;
else
{
aPath + = String ( aCurFileNamePrefix ) ;
pMgr - > SetEMailColumn ( String ( ) ) ;
}
pMgr - > SetSubject ( aPath ) ;
2005-01-28 14:33:13 +00:00
if ( MailMergeType : : FILE = = nCurOutputType )
{
aMergeDesc . sSaveToFilter = sSaveFilter ;
2005-03-08 12:48:53 +00:00
aMergeDesc . sSaveToFilterOptions = sSaveFilterOptions ;
aMergeDesc . aSaveToFilterData = aSaveFilterData ;
2005-01-28 14:33:13 +00:00
aMergeDesc . bCreateSingleFile = bSaveAsSingleFile ;
}
else /*if(MailMergeType::MAIL == nCurOutputType)*/
{
pMgr - > SetEMailColumn ( sAddressFromColumn ) ;
if ( ! sAddressFromColumn . getLength ( ) )
2008-02-19 12:59:54 +00:00
throw RuntimeException ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( " Mail address column not set. " ) ) , static_cast < cppu : : OWeakObject * > ( this ) ) ;
2005-01-28 14:33:13 +00:00
aMergeDesc . sSaveToFilter = sAttachmentFilter ;
aMergeDesc . sSubject = sSubject ;
aMergeDesc . sMailBody = sMailBody ;
aMergeDesc . sAttachmentName = sAttachmentName ;
aMergeDesc . aCopiesTo = aCopiesTo ;
aMergeDesc . aBlindCopiesTo = aBlindCopiesTo ;
aMergeDesc . bSendAsHTML = bSendAsHTML ;
aMergeDesc . bSendAsAttachment = bSendAsAttachment ;
aMergeDesc . bCreateSingleFile = sal_False ;
pMMConfigItem = std : : auto_ptr < SwMailMergeConfigItem > ( new SwMailMergeConfigItem ) ;
aMergeDesc . pMailMergeConfigItem = pMMConfigItem . get ( ) ;
aMergeDesc . xSmtpServer = SwMailMergeHelper : : ConnectToSmtpServer (
* pMMConfigItem ,
xInService ,
sInServerPassword , sOutServerPassword ) ;
if ( ! aMergeDesc . xSmtpServer . is ( ) | | ! aMergeDesc . xSmtpServer - > isConnected ( ) )
2008-02-19 12:59:54 +00:00
throw RuntimeException ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( " Failed to connect to mail server. " ) ) , static_cast < cppu : : OWeakObject * > ( this ) ) ;
2005-01-28 14:33:13 +00:00
}
2003-03-27 14:45:43 +00:00
}
2005-01-28 14:33:13 +00:00
2003-03-27 14:45:43 +00:00
// save document with temporary filename
2003-04-01 14:43:08 +00:00
const SfxFilter * pSfxFlt = SwIoSystem : : GetFilterOfFormat (
String : : CreateFromAscii ( FILTER_XML ) ,
SwDocShell : : Factory ( ) . GetFilterContainer ( ) ) ;
String aExtension ( pSfxFlt - > GetDefaultExtension ( ) ) ;
aExtension . EraseLeadingChars ( ' * ' ) ;
TempFile aTempFile ( C2U ( " SwMM " ) , & aExtension ) ;
aTmpFileName = aTempFile . GetName ( ) ;
Reference < XStorable > xStorable ( xCurModel , UNO_QUERY ) ;
sal_Bool bStoredAsTemporary = sal_False ;
if ( xStorable . is ( ) )
2003-03-27 14:45:43 +00:00
{
2003-04-01 14:43:08 +00:00
try
{
xStorable - > storeAsURL ( aTmpFileName , Sequence < PropertyValue > ( ) ) ;
bStoredAsTemporary = sal_True ;
}
catch ( const Exception & )
{
}
2003-03-27 14:45:43 +00:00
}
2003-04-01 14:43:08 +00:00
if ( ! bStoredAsTemporary )
throw RuntimeException ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( " Failed to save temporary file. " ) ) , static_cast < cppu : : OWeakObject * > ( this ) ) ;
2003-03-27 14:45:43 +00:00
pMgr - > SetMergeSilent ( TRUE ) ; // suppress dialogs, message boxes, etc.
const SwXMailMerge * pOldSrc = pMgr - > GetMailMergeEvtSrc ( ) ;
2010-10-24 23:48:32 +02:00
OSL_ENSURE ( ! pOldSrc | | pOldSrc = = this , " Ooops... different event source already set. " ) ;
2003-03-27 14:45:43 +00:00
pMgr - > SetMailMergeEvtSrc ( this ) ; // launch events for listeners
2005-03-11 09:50:41 +00:00
2009-09-18 10:15:03 +00:00
SFX_APP ( ) - > NotifyEvent ( SfxEventHint ( SW_EVENT_MAIL_MERGE , SwDocShell : : GetEventName ( STR_SW_EVENT_MAIL_MERGE ) , xCurDocSh ) ) ;
2005-01-28 14:33:13 +00:00
BOOL bSucc = pMgr - > MergeNew ( aMergeDesc ) ;
2009-09-18 10:15:03 +00:00
SFX_APP ( ) - > NotifyEvent ( SfxEventHint ( SW_EVENT_MAIL_MERGE_END , SwDocShell : : GetEventName ( STR_SW_EVENT_MAIL_MERGE_END ) , xCurDocSh ) ) ;
2005-03-11 09:50:41 +00:00
2003-03-27 14:45:43 +00:00
pMgr - > SetMailMergeEvtSrc ( pOldSrc ) ;
2003-04-01 14:43:08 +00:00
if ( xCurModel . get ( ) ! = xModel . get ( ) )
{ // in case it was a temporary model -> close it, and delete the file
DeleteTmpFile_Impl ( xCurModel , xCurDocSh , aTmpFileName ) ;
aTmpFileName . Erase ( ) ;
}
// (in case it wasn't a temporary model, it will be closed in the dtor, at the latest)
2003-03-27 14:45:43 +00:00
if ( ! bSucc )
2003-04-01 14:43:08 +00:00
throw Exception ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( " Mail merge failed. Sorry, no further information available. " ) ) , static_cast < cppu : : OWeakObject * > ( this ) ) ;
2003-03-27 14:45:43 +00:00
2005-01-28 14:33:13 +00:00
//de-initialize services
if ( xInService . is ( ) & & xInService - > isConnected ( ) )
xInService - > disconnect ( ) ;
if ( aMergeDesc . xSmtpServer . is ( ) & & aMergeDesc . xSmtpServer - > isConnected ( ) )
aMergeDesc . xSmtpServer - > disconnect ( ) ;
2003-03-27 14:45:43 +00:00
return makeAny ( sal_True ) ;
}
void SwXMailMerge : : LaunchMailMergeEvent ( const MailMergeEvent & rEvt ) const
{
cppu : : OInterfaceIteratorHelper aIt ( ( ( SwXMailMerge * ) this ) - > aMergeListeners ) ;
while ( aIt . hasMoreElements ( ) )
{
Reference < XMailMergeListener > xRef ( aIt . next ( ) , UNO_QUERY ) ;
if ( xRef . is ( ) )
xRef - > notifyMailMergeEvent ( rEvt ) ;
}
}
void SwXMailMerge : : launchEvent ( const PropertyChangeEvent & rEvt ) const
{
cppu : : OInterfaceContainerHelper * pContainer =
aPropListeners . getContainer ( rEvt . PropertyHandle ) ;
if ( pContainer )
{
cppu : : OInterfaceIteratorHelper aIt ( * pContainer ) ;
while ( aIt . hasMoreElements ( ) )
{
Reference < XPropertyChangeListener > xRef ( aIt . next ( ) , UNO_QUERY ) ;
if ( xRef . is ( ) )
xRef - > propertyChange ( rEvt ) ;
}
}
}
uno : : Reference < beans : : XPropertySetInfo > SAL_CALL SwXMailMerge : : getPropertySetInfo ( )
throw ( RuntimeException )
{
2010-10-13 01:44:10 -05:00
SolarMutexGuard aGuard ;
2009-06-03 11:26:39 +00:00
static Reference < XPropertySetInfo > aRef = pPropSet - > getPropertySetInfo ( ) ;
2003-03-27 14:45:43 +00:00
return aRef ;
}
void SAL_CALL SwXMailMerge : : setPropertyValue (
const OUString & rPropertyName , const uno : : Any & rValue )
throw ( UnknownPropertyException , PropertyVetoException , IllegalArgumentException , WrappedTargetException , RuntimeException )
{
2010-10-13 01:44:10 -05:00
SolarMutexGuard aGuard ;
2003-03-27 14:45:43 +00:00
2009-06-03 11:26:39 +00:00
const SfxItemPropertySimpleEntry * pCur = pPropSet - > getPropertyMap ( ) - > getByName ( rPropertyName ) ;
2003-03-27 14:45:43 +00:00
if ( ! pCur )
throw UnknownPropertyException ( ) ;
else if ( pCur - > nFlags & PropertyAttribute : : READONLY )
throw PropertyVetoException ( ) ;
else
{
void * pData = NULL ;
2007-09-27 11:42:59 +00:00
const uno : : Type * pType = pCur - > pType ;
2003-03-27 14:45:43 +00:00
switch ( pCur - > nWID )
{
case WID_SELECTION : pData = & aSelection ; break ;
case WID_RESULT_SET : pData = & xResultSet ; break ;
case WID_CONNECTION : pData = & xConnection ; break ;
case WID_MODEL : pData = & xModel ; break ;
case WID_DATA_SOURCE_NAME : pData = & aDataSourceName ; break ;
case WID_DATA_COMMAND : pData = & aDataCommand ; break ;
case WID_FILTER : pData = & aFilter ; break ;
case WID_DOCUMENT_URL : pData = & aDocumentURL ; break ;
case WID_OUTPUT_URL : pData = & aOutputURL ; break ;
case WID_DATA_COMMAND_TYPE : pData = & nDataCommandType ; break ;
case WID_OUTPUT_TYPE : pData = & nOutputType ; break ;
case WID_ESCAPE_PROCESSING : pData = & bEscapeProcessing ; break ;
case WID_SINGLE_PRINT_JOBS : pData = & bSinglePrintJobs ; break ;
case WID_FILE_NAME_FROM_COLUMN : pData = & bFileNameFromColumn ; break ;
case WID_FILE_NAME_PREFIX : pData = & aFileNamePrefix ; break ;
2005-01-28 14:33:13 +00:00
case WID_MAIL_SUBJECT : pData = & sSubject ; break ;
case WID_ADDRESS_FROM_COLUMN : pData = & sAddressFromColumn ; break ;
case WID_SEND_AS_HTML : pData = & bSendAsHTML ; break ;
case WID_SEND_AS_ATTACHMENT : pData = & bSendAsAttachment ; break ;
case WID_MAIL_BODY : pData = & sMailBody ; break ;
case WID_ATTACHMENT_NAME : pData = & sAttachmentName ; break ;
case WID_ATTACHMENT_FILTER : pData = & sAttachmentFilter ; break ;
case WID_PRINT_OPTIONS : pData = & aPrintSettings ; break ;
case WID_SAVE_AS_SINGLE_FILE : pData = & bSaveAsSingleFile ; break ;
case WID_SAVE_FILTER : pData = & sSaveFilter ; break ;
2005-03-08 12:48:53 +00:00
case WID_SAVE_FILTER_OPTIONS : pData = & sSaveFilterOptions ; break ;
case WID_SAVE_FILTER_DATA : pData = & aSaveFilterData ; break ;
2005-01-28 14:33:13 +00:00
case WID_COPIES_TO : pData = & aCopiesTo ; break ;
case WID_BLIND_COPIES_TO : pData = & aBlindCopiesTo ; break ;
case WID_IN_SERVER_PASSWORD : pData = & sInServerPassword ; break ;
case WID_OUT_SERVER_PASSWORD : pData = & sOutServerPassword ; break ;
2003-03-27 14:45:43 +00:00
default :
2010-10-24 23:48:32 +02:00
OSL_ENSURE ( false , " unknown WID " ) ;
2003-03-27 14:45:43 +00:00
}
Any aOld ( pData , * pType ) ;
sal_Bool bChanged = sal_False ;
sal_Bool bOK = sal_True ;
if ( aOld ! = rValue )
{
if ( pData = = & aSelection )
bOK = rValue > > = aSelection ;
else if ( pData = = & xResultSet )
bOK = rValue > > = xResultSet ;
else if ( pData = = & xConnection )
bOK = rValue > > = xConnection ;
else if ( pData = = & xModel )
bOK = rValue > > = xModel ;
else if ( pData = = & aDataSourceName )
bOK = rValue > > = aDataSourceName ;
else if ( pData = = & aDataCommand )
bOK = rValue > > = aDataCommand ;
else if ( pData = = & aFilter )
bOK = rValue > > = aFilter ;
else if ( pData = = & aDocumentURL )
{
OUString aText ;
bOK = rValue > > = aText ;
if ( aText . getLength ( )
& & ! LoadFromURL_impl ( xModel , xDocSh , aText , TRUE ) )
throw RuntimeException ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( " Failed to create document from URL: " ) ) + aText , static_cast < cppu : : OWeakObject * > ( this ) ) ;
aDocumentURL = aText ;
}
else if ( pData = = & aOutputURL )
{
OUString aText ;
bOK = rValue > > = aText ;
if ( aText . getLength ( ) )
{
if ( ! UCB_IsDirectory ( aText ) )
throw IllegalArgumentException ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( " URL does not point to a directory: " ) ) + aText , static_cast < cppu : : OWeakObject * > ( this ) , 0 ) ;
if ( UCB_IsReadOnlyFileName ( aText ) )
throw IllegalArgumentException ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( " URL is read-only: " ) ) + aText , static_cast < cppu : : OWeakObject * > ( this ) , 0 ) ;
}
aOutputURL = aText ;
}
else if ( pData = = & nDataCommandType )
bOK = rValue > > = nDataCommandType ;
else if ( pData = = & nOutputType )
bOK = rValue > > = nOutputType ;
else if ( pData = = & bEscapeProcessing )
bOK = rValue > > = bEscapeProcessing ;
else if ( pData = = & bSinglePrintJobs )
bOK = rValue > > = bSinglePrintJobs ;
else if ( pData = = & bFileNameFromColumn )
bOK = rValue > > = bFileNameFromColumn ;
else if ( pData = = & aFileNamePrefix )
bOK = rValue > > = aFileNamePrefix ;
2005-01-28 14:33:13 +00:00
else if ( pData = = & sSubject )
bOK = rValue > > = sSubject ;
else if ( pData = = & sAddressFromColumn )
bOK = rValue > > = sAddressFromColumn ;
else if ( pData = = & bSendAsHTML )
bOK = rValue > > = bSendAsHTML ;
else if ( pData = = & bSendAsAttachment )
bOK = rValue > > = bSendAsAttachment ;
else if ( pData = = & sMailBody )
bOK = rValue > > = sMailBody ;
else if ( pData = = & sAttachmentName )
bOK = rValue > > = sAttachmentName ;
else if ( pData = = & sAttachmentFilter )
bOK = rValue > > = sAttachmentFilter ;
else if ( pData = = & aPrintSettings )
bOK = rValue > > = aPrintSettings ;
else if ( pData = = & bSaveAsSingleFile )
bOK = rValue > > = bSaveAsSingleFile ;
else if ( pData = = & sSaveFilter )
bOK = rValue > > = sSaveFilter ;
2005-03-08 12:48:53 +00:00
else if ( pData = = & sSaveFilterOptions )
bOK = rValue > > = sSaveFilterOptions ;
else if ( pData = = & aSaveFilterData )
bOK = rValue > > = aSaveFilterData ;
2005-01-28 14:33:13 +00:00
else if ( pData = = & aCopiesTo )
bOK = rValue > > = aCopiesTo ;
else if ( pData = = & aBlindCopiesTo )
bOK = rValue > > = aBlindCopiesTo ;
else if ( pData = = & sInServerPassword )
bOK = rValue > > = sInServerPassword ;
else if ( pData = = & sOutServerPassword )
bOK = rValue > > = sInServerPassword ;
2008-04-22 14:05:53 +00:00
else {
2010-10-24 23:48:32 +02:00
OSL_ENSURE ( false , " invalid pointer " ) ;
2008-04-22 14:05:53 +00:00
}
2010-10-24 23:48:32 +02:00
OSL_ENSURE ( bOK , " set value failed " ) ;
2003-03-27 14:45:43 +00:00
bChanged = sal_True ;
}
if ( ! bOK )
throw IllegalArgumentException ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( " Property type mismatch or property not set: " ) ) + rPropertyName , static_cast < cppu : : OWeakObject * > ( this ) , 0 ) ;
if ( bChanged )
{
PropertyChangeEvent aChgEvt ( ( XPropertySet * ) this , rPropertyName ,
FALSE , pCur - > nWID , aOld , rValue ) ;
launchEvent ( aChgEvt ) ;
}
}
}
uno : : Any SAL_CALL SwXMailMerge : : getPropertyValue (
const OUString & rPropertyName )
throw ( UnknownPropertyException , WrappedTargetException , RuntimeException )
{
2010-10-13 01:44:10 -05:00
SolarMutexGuard aGuard ;
2003-03-27 14:45:43 +00:00
Any aRet ;
2009-06-03 11:26:39 +00:00
const SfxItemPropertySimpleEntry * pCur = pPropSet - > getPropertyMap ( ) - > getByName ( rPropertyName ) ;
2003-03-27 14:45:43 +00:00
if ( ! pCur )
throw UnknownPropertyException ( ) ;
else
{
switch ( pCur - > nWID )
{
case WID_SELECTION : aRet < < = aSelection ; break ;
case WID_RESULT_SET : aRet < < = xResultSet ; break ;
case WID_CONNECTION : aRet < < = xConnection ; break ;
case WID_MODEL : aRet < < = xModel ; break ;
case WID_DATA_SOURCE_NAME : aRet < < = aDataSourceName ; break ;
case WID_DATA_COMMAND : aRet < < = aDataCommand ; break ;
case WID_FILTER : aRet < < = aFilter ; break ;
case WID_DOCUMENT_URL : aRet < < = aDocumentURL ; break ;
case WID_OUTPUT_URL : aRet < < = aOutputURL ; break ;
case WID_DATA_COMMAND_TYPE : aRet < < = nDataCommandType ; break ;
case WID_OUTPUT_TYPE : aRet < < = nOutputType ; break ;
case WID_ESCAPE_PROCESSING : aRet < < = bEscapeProcessing ; break ;
case WID_SINGLE_PRINT_JOBS : aRet < < = bSinglePrintJobs ; break ;
case WID_FILE_NAME_FROM_COLUMN : aRet < < = bFileNameFromColumn ; break ;
case WID_FILE_NAME_PREFIX : aRet < < = aFileNamePrefix ; break ;
2005-01-28 14:33:13 +00:00
case WID_MAIL_SUBJECT : aRet < < = sSubject ; break ;
case WID_ADDRESS_FROM_COLUMN : aRet < < = sAddressFromColumn ; break ;
case WID_SEND_AS_HTML : aRet < < = bSendAsHTML ; break ;
case WID_SEND_AS_ATTACHMENT : aRet < < = bSendAsAttachment ; break ;
case WID_MAIL_BODY : aRet < < = sMailBody ; break ;
case WID_ATTACHMENT_NAME : aRet < < = sAttachmentName ; break ;
case WID_ATTACHMENT_FILTER : aRet < < = sAttachmentFilter ; break ;
case WID_PRINT_OPTIONS : aRet < < = aPrintSettings ; break ;
case WID_SAVE_AS_SINGLE_FILE : aRet < < = bSaveAsSingleFile ; break ;
case WID_SAVE_FILTER : aRet < < = sSaveFilter ; break ;
2005-03-08 12:48:53 +00:00
case WID_SAVE_FILTER_OPTIONS : aRet < < = sSaveFilterOptions ; break ;
case WID_SAVE_FILTER_DATA : aRet < < = aSaveFilterData ; break ;
2005-01-28 14:33:13 +00:00
case WID_COPIES_TO : aRet < < = aCopiesTo ; break ;
case WID_BLIND_COPIES_TO : aRet < < = aBlindCopiesTo ; break ;
case WID_IN_SERVER_PASSWORD : aRet < < = sInServerPassword ; break ;
case WID_OUT_SERVER_PASSWORD : aRet < < = sOutServerPassword ; break ;
2003-03-27 14:45:43 +00:00
default :
2010-10-24 23:48:32 +02:00
OSL_ENSURE ( false , " unknown WID " ) ;
2003-03-27 14:45:43 +00:00
}
}
return aRet ;
}
void SAL_CALL SwXMailMerge : : addPropertyChangeListener (
const OUString & rPropertyName ,
const uno : : Reference < beans : : XPropertyChangeListener > & rListener )
throw ( UnknownPropertyException , WrappedTargetException , RuntimeException )
{
2010-10-13 01:44:10 -05:00
SolarMutexGuard aGuard ;
2003-03-27 14:45:43 +00:00
if ( ! bDisposing & & rListener . is ( ) )
{
2009-06-03 11:26:39 +00:00
const SfxItemPropertySimpleEntry * pCur = pPropSet - > getPropertyMap ( ) - > getByName ( rPropertyName ) ;
2003-03-27 14:45:43 +00:00
if ( pCur )
aPropListeners . addInterface ( pCur - > nWID , rListener ) ;
else
throw UnknownPropertyException ( ) ;
}
}
void SAL_CALL SwXMailMerge : : removePropertyChangeListener (
const OUString & rPropertyName ,
const uno : : Reference < beans : : XPropertyChangeListener > & rListener )
throw ( UnknownPropertyException , WrappedTargetException , RuntimeException )
{
2010-10-13 01:44:10 -05:00
SolarMutexGuard aGuard ;
2003-03-27 14:45:43 +00:00
if ( ! bDisposing & & rListener . is ( ) )
{
2009-06-03 11:26:39 +00:00
const SfxItemPropertySimpleEntry * pCur = pPropSet - > getPropertyMap ( ) - > getByName ( rPropertyName ) ;
2003-03-27 14:45:43 +00:00
if ( pCur )
aPropListeners . removeInterface ( pCur - > nWID , rListener ) ;
else
throw UnknownPropertyException ( ) ;
}
}
void SAL_CALL SwXMailMerge : : addVetoableChangeListener (
2007-09-27 11:42:59 +00:00
const OUString & /*rPropertyName*/ ,
const uno : : Reference < beans : : XVetoableChangeListener > & /*rListener*/ )
2003-03-27 14:45:43 +00:00
throw ( UnknownPropertyException , WrappedTargetException , RuntimeException )
{
// no vetoable property, thus no support for vetoable change listeners
2010-10-24 23:48:32 +02:00
OSL_ENSURE ( false , " not implemented " ) ;
2003-03-27 14:45:43 +00:00
}
void SAL_CALL SwXMailMerge : : removeVetoableChangeListener (
2007-09-27 11:42:59 +00:00
const OUString & /*rPropertyName*/ ,
const uno : : Reference < beans : : XVetoableChangeListener > & /*rListener*/ )
2003-03-27 14:45:43 +00:00
throw ( UnknownPropertyException , WrappedTargetException , RuntimeException )
{
// no vetoable property, thus no support for vetoable change listeners
2010-10-24 23:48:32 +02:00
OSL_ENSURE ( false , " not implemented " ) ;
2003-03-27 14:45:43 +00:00
}
void SAL_CALL SwXMailMerge : : dispose ( )
throw ( RuntimeException )
{
2010-10-13 01:44:10 -05:00
SolarMutexGuard aGuard ;
2003-03-27 14:45:43 +00:00
if ( ! bDisposing )
{
bDisposing = sal_True ;
EventObject aEvtObj ( ( XPropertySet * ) this ) ;
aEvtListeners . disposeAndClear ( aEvtObj ) ;
aMergeListeners . disposeAndClear ( aEvtObj ) ;
aPropListeners . disposeAndClear ( aEvtObj ) ;
}
}
void SAL_CALL SwXMailMerge : : addEventListener (
const Reference < XEventListener > & rxListener )
throw ( RuntimeException )
{
2010-10-13 01:44:10 -05:00
SolarMutexGuard aGuard ;
2003-03-27 14:45:43 +00:00
if ( ! bDisposing & & rxListener . is ( ) )
aEvtListeners . addInterface ( rxListener ) ;
}
void SAL_CALL SwXMailMerge : : removeEventListener (
const Reference < XEventListener > & rxListener )
throw ( RuntimeException )
{
2010-10-13 01:44:10 -05:00
SolarMutexGuard aGuard ;
2003-03-27 14:45:43 +00:00
if ( ! bDisposing & & rxListener . is ( ) )
aEvtListeners . removeInterface ( rxListener ) ;
}
void SAL_CALL SwXMailMerge : : addMailMergeEventListener (
const uno : : Reference < XMailMergeListener > & rxListener )
throw ( RuntimeException )
{
2010-10-13 01:44:10 -05:00
SolarMutexGuard aGuard ;
2003-03-27 14:45:43 +00:00
if ( ! bDisposing & & rxListener . is ( ) )
aMergeListeners . addInterface ( rxListener ) ;
}
void SAL_CALL SwXMailMerge : : removeMailMergeEventListener (
const uno : : Reference < XMailMergeListener > & rxListener )
throw ( RuntimeException )
{
2010-10-13 01:44:10 -05:00
SolarMutexGuard aGuard ;
2003-03-27 14:45:43 +00:00
if ( ! bDisposing & & rxListener . is ( ) )
aMergeListeners . removeInterface ( rxListener ) ;
}
OUString SAL_CALL SwXMailMerge : : getImplementationName ( )
throw ( RuntimeException )
{
2010-10-13 01:44:10 -05:00
SolarMutexGuard aGuard ;
2003-03-27 14:45:43 +00:00
return SwXMailMerge_getImplementationName ( ) ;
}
sal_Bool SAL_CALL SwXMailMerge : : supportsService ( const OUString & rServiceName )
throw ( RuntimeException )
{
2010-10-13 01:44:10 -05:00
SolarMutexGuard aGuard ;
2003-09-29 14:06:15 +00:00
return C2U ( SN_MAIL_MERGE ) = = rServiceName | |
C2U ( SN_DATA_ACCESS_DESCRIPTOR ) = = rServiceName ;
2003-03-27 14:45:43 +00:00
}
uno : : Sequence < OUString > SAL_CALL SwXMailMerge : : getSupportedServiceNames ( )
throw ( RuntimeException )
{
2010-10-13 01:44:10 -05:00
SolarMutexGuard aGuard ;
2003-03-27 14:45:43 +00:00
return SwXMailMerge_getSupportedServiceNames ( ) ;
}
////////////////////////////////////////////////////////////
uno : : Sequence < OUString > SAL_CALL SwXMailMerge_getSupportedServiceNames ( )
throw ( )
{
2003-09-30 12:23:14 +00:00
uno : : Sequence < OUString > aNames ( 2 ) ;
2003-09-29 14:06:15 +00:00
OUString * pName = aNames . getArray ( ) ;
pName [ 0 ] = C2U ( SN_MAIL_MERGE ) ;
pName [ 1 ] = C2U ( SN_DATA_ACCESS_DESCRIPTOR ) ;
2003-03-27 14:45:43 +00:00
return aNames ;
}
OUString SAL_CALL SwXMailMerge_getImplementationName ( )
throw ( )
{
return OUString ( C2U ( " SwXMailMerge " ) ) ;
}
uno : : Reference < uno : : XInterface > SAL_CALL SwXMailMerge_createInstance (
2007-09-27 11:42:59 +00:00
const uno : : Reference < XMultiServiceFactory > & /*rSMgr*/ )
2003-03-27 14:45:43 +00:00
throw ( uno : : Exception )
{
2010-10-13 01:44:10 -05:00
SolarMutexGuard aGuard ;
2003-03-27 14:45:43 +00:00
//the module may not be loaded
2003-09-19 07:49:13 +00:00
SwDLL : : Init ( ) ;
2003-03-27 14:45:43 +00:00
uno : : Reference < uno : : XInterface > xRef = ( cppu : : OWeakObject * ) new SwXMailMerge ( ) ;
return xRef ;
}
2010-10-14 08:30:41 +02:00
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */