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_framework.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 32*cdf0e10cSrcweir // my own includes 33*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 34*cdf0e10cSrcweir #include <dispatch/mailtodispatcher.hxx> 35*cdf0e10cSrcweir #include <threadhelp/readguard.hxx> 36*cdf0e10cSrcweir #include <general.h> 37*cdf0e10cSrcweir #include <services.h> 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 40*cdf0e10cSrcweir // interface includes 41*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 42*cdf0e10cSrcweir #include <com/sun/star/system/XSystemShellExecute.hpp> 43*cdf0e10cSrcweir #include <com/sun/star/system/SystemShellExecuteFlags.hpp> 44*cdf0e10cSrcweir #include <com/sun/star/frame/DispatchResultState.hpp> 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 47*cdf0e10cSrcweir // includes of other projects 48*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir #include <vcl/svapp.hxx> 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 53*cdf0e10cSrcweir // namespace 54*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir namespace framework{ 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 59*cdf0e10cSrcweir // non exported const 60*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir #define PROTOCOL_VALUE "mailto:" 63*cdf0e10cSrcweir #define PROTOCOL_LENGTH 7 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 66*cdf0e10cSrcweir // non exported definitions 67*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 70*cdf0e10cSrcweir // declarations 71*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 74*cdf0e10cSrcweir // XInterface, XTypeProvider, XServiceInfo 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir DEFINE_XINTERFACE_5(MailToDispatcher , 77*cdf0e10cSrcweir OWeakObject , 78*cdf0e10cSrcweir DIRECT_INTERFACE(css::lang::XTypeProvider ), 79*cdf0e10cSrcweir DIRECT_INTERFACE(css::lang::XServiceInfo ), 80*cdf0e10cSrcweir DIRECT_INTERFACE(css::frame::XDispatchProvider ), 81*cdf0e10cSrcweir DIRECT_INTERFACE(css::frame::XNotifyingDispatch), 82*cdf0e10cSrcweir DIRECT_INTERFACE(css::frame::XDispatch )) 83*cdf0e10cSrcweir 84*cdf0e10cSrcweir DEFINE_XTYPEPROVIDER_5(MailToDispatcher , 85*cdf0e10cSrcweir css::lang::XTypeProvider , 86*cdf0e10cSrcweir css::lang::XServiceInfo , 87*cdf0e10cSrcweir css::frame::XDispatchProvider , 88*cdf0e10cSrcweir css::frame::XNotifyingDispatch, 89*cdf0e10cSrcweir css::frame::XDispatch ) 90*cdf0e10cSrcweir 91*cdf0e10cSrcweir DEFINE_XSERVICEINFO_MULTISERVICE(MailToDispatcher , 92*cdf0e10cSrcweir ::cppu::OWeakObject , 93*cdf0e10cSrcweir SERVICENAME_PROTOCOLHANDLER , 94*cdf0e10cSrcweir IMPLEMENTATIONNAME_MAILTODISPATCHER) 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir DEFINE_INIT_SERVICE(MailToDispatcher, 97*cdf0e10cSrcweir { 98*cdf0e10cSrcweir /*Attention 99*cdf0e10cSrcweir I think we don't need any mutex or lock here ... because we are called by our own static method impl_createInstance() 100*cdf0e10cSrcweir to create a new instance of this class by our own supported service factory. 101*cdf0e10cSrcweir see macro DEFINE_XSERVICEINFO_MULTISERVICE and "impl_initService()" for further informations! 102*cdf0e10cSrcweir */ 103*cdf0e10cSrcweir } 104*cdf0e10cSrcweir ) 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 107*cdf0e10cSrcweir 108*cdf0e10cSrcweir /** 109*cdf0e10cSrcweir @short standard ctor 110*cdf0e10cSrcweir @descr These initialize a new instance of ths class with needed informations for work. 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir @param xFactory 113*cdf0e10cSrcweir reference to uno servicemanager for creation of new services 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir @modified 30.04.2002 14:10, as96863 116*cdf0e10cSrcweir */ 117*cdf0e10cSrcweir MailToDispatcher::MailToDispatcher( const css::uno::Reference< css::lang::XMultiServiceFactory >& xFactory ) 118*cdf0e10cSrcweir // Init baseclasses first 119*cdf0e10cSrcweir : ThreadHelpBase( &Application::GetSolarMutex() ) 120*cdf0e10cSrcweir , OWeakObject ( ) 121*cdf0e10cSrcweir // Init member 122*cdf0e10cSrcweir , m_xFactory ( xFactory ) 123*cdf0e10cSrcweir { 124*cdf0e10cSrcweir } 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir /** 129*cdf0e10cSrcweir @short standard dtor 130*cdf0e10cSrcweir @descr - 131*cdf0e10cSrcweir 132*cdf0e10cSrcweir @modified 30.04.2002 14:10, as96863 133*cdf0e10cSrcweir */ 134*cdf0e10cSrcweir MailToDispatcher::~MailToDispatcher() 135*cdf0e10cSrcweir { 136*cdf0e10cSrcweir m_xFactory = NULL; 137*cdf0e10cSrcweir } 138*cdf0e10cSrcweir 139*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir /** 142*cdf0e10cSrcweir @short decide if this dispatch implementation can be used for requested URL or not 143*cdf0e10cSrcweir @descr A protocol handler is registerd for an URL pattern inside configuration and will 144*cdf0e10cSrcweir be asked by the generic dispatch mechanism inside framework, if he can handle this 145*cdf0e10cSrcweir special URL wich match his registration. He can agree by returning of a valid dispatch 146*cdf0e10cSrcweir instance or disagree by returning <NULL/>. 147*cdf0e10cSrcweir We don't create new dispatch instances here realy - we return THIS as result to handle it 148*cdf0e10cSrcweir at the same implementation. 149*cdf0e10cSrcweir 150*cdf0e10cSrcweir @modified 02.05.2002 15:25, as96863 151*cdf0e10cSrcweir */ 152*cdf0e10cSrcweir css::uno::Reference< css::frame::XDispatch > SAL_CALL MailToDispatcher::queryDispatch( const css::util::URL& aURL , 153*cdf0e10cSrcweir const ::rtl::OUString& /*sTarget*/ , 154*cdf0e10cSrcweir sal_Int32 /*nFlags*/ ) throw( css::uno::RuntimeException ) 155*cdf0e10cSrcweir { 156*cdf0e10cSrcweir css::uno::Reference< css::frame::XDispatch > xDispatcher; 157*cdf0e10cSrcweir if (aURL.Complete.compareToAscii(PROTOCOL_VALUE,PROTOCOL_LENGTH)==0) 158*cdf0e10cSrcweir xDispatcher = this; 159*cdf0e10cSrcweir return xDispatcher; 160*cdf0e10cSrcweir } 161*cdf0e10cSrcweir 162*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 163*cdf0e10cSrcweir 164*cdf0e10cSrcweir /** 165*cdf0e10cSrcweir @short do the same like dispatch() but for multiple requests at the same time 166*cdf0e10cSrcweir @descr - 167*cdf0e10cSrcweir 168*cdf0e10cSrcweir @modified 02.05.2002 15:27, as96863 169*cdf0e10cSrcweir */ 170*cdf0e10cSrcweir css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > > SAL_CALL MailToDispatcher::queryDispatches( const css::uno::Sequence< css::frame::DispatchDescriptor >& lDescriptor ) throw( css::uno::RuntimeException ) 171*cdf0e10cSrcweir { 172*cdf0e10cSrcweir sal_Int32 nCount = lDescriptor.getLength(); 173*cdf0e10cSrcweir css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > > lDispatcher( nCount ); 174*cdf0e10cSrcweir for( sal_Int32 i=0; i<nCount; ++i ) 175*cdf0e10cSrcweir { 176*cdf0e10cSrcweir lDispatcher[i] = this->queryDispatch( 177*cdf0e10cSrcweir lDescriptor[i].FeatureURL, 178*cdf0e10cSrcweir lDescriptor[i].FrameName, 179*cdf0e10cSrcweir lDescriptor[i].SearchFlags); 180*cdf0e10cSrcweir } 181*cdf0e10cSrcweir return lDispatcher; 182*cdf0e10cSrcweir } 183*cdf0e10cSrcweir 184*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 185*cdf0e10cSrcweir 186*cdf0e10cSrcweir /** 187*cdf0e10cSrcweir @short dispatch URL with arguments 188*cdf0e10cSrcweir @descr We use threadsafe internal method to do so. It returns a state value - but we ignore it. 189*cdf0e10cSrcweir Because we doesn't support status listener notifications here. Status events are not guaranteed - 190*cdf0e10cSrcweir and we call another service internaly which doesn't return any notifications too. 191*cdf0e10cSrcweir 192*cdf0e10cSrcweir @param aURL 193*cdf0e10cSrcweir mail URL which should be executed 194*cdf0e10cSrcweir @param lArguments 195*cdf0e10cSrcweir list of optional arguments for this mail request 196*cdf0e10cSrcweir 197*cdf0e10cSrcweir @modified 30.04.2002 14:15, as96863 198*cdf0e10cSrcweir */ 199*cdf0e10cSrcweir void SAL_CALL MailToDispatcher::dispatch( const css::util::URL& aURL , 200*cdf0e10cSrcweir const css::uno::Sequence< css::beans::PropertyValue >& lArguments ) throw( css::uno::RuntimeException ) 201*cdf0e10cSrcweir { 202*cdf0e10cSrcweir // dispatch() is an [oneway] call ... and may our user release his reference to us immediatly. 203*cdf0e10cSrcweir // So we should hold us self alive till this call ends. 204*cdf0e10cSrcweir css::uno::Reference< css::frame::XNotifyingDispatch > xSelfHold(static_cast< ::cppu::OWeakObject* >(this), css::uno::UNO_QUERY); 205*cdf0e10cSrcweir implts_dispatch(aURL,lArguments); 206*cdf0e10cSrcweir // No notification for status listener! 207*cdf0e10cSrcweir } 208*cdf0e10cSrcweir 209*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 210*cdf0e10cSrcweir 211*cdf0e10cSrcweir /** 212*cdf0e10cSrcweir @short dispatch with guaranteed notifications about success 213*cdf0e10cSrcweir @descr We use threadsafe internal method to do so. Return state of this function will be used 214*cdf0e10cSrcweir for notification if an optional listener is given. 215*cdf0e10cSrcweir 216*cdf0e10cSrcweir @param aURL 217*cdf0e10cSrcweir mail URL which should be executed 218*cdf0e10cSrcweir @param lArguments 219*cdf0e10cSrcweir list of optional arguments for this mail request 220*cdf0e10cSrcweir @param xListener 221*cdf0e10cSrcweir reference to a valid listener for state events 222*cdf0e10cSrcweir 223*cdf0e10cSrcweir @modified 30.04.2002 14:49, as96863 224*cdf0e10cSrcweir */ 225*cdf0e10cSrcweir void SAL_CALL MailToDispatcher::dispatchWithNotification( const css::util::URL& aURL , 226*cdf0e10cSrcweir const css::uno::Sequence< css::beans::PropertyValue >& lArguments, 227*cdf0e10cSrcweir const css::uno::Reference< css::frame::XDispatchResultListener >& xListener ) throw( css::uno::RuntimeException ) 228*cdf0e10cSrcweir { 229*cdf0e10cSrcweir // This class was designed to die by reference. And if user release his reference to us immediatly after calling this method 230*cdf0e10cSrcweir // we can run into some problems. So we hold us self alive till this method ends. 231*cdf0e10cSrcweir // Another reason: We can use this reference as source of sending event at the end too. 232*cdf0e10cSrcweir css::uno::Reference< css::frame::XNotifyingDispatch > xThis(static_cast< ::cppu::OWeakObject* >(this), css::uno::UNO_QUERY); 233*cdf0e10cSrcweir 234*cdf0e10cSrcweir sal_Bool bState = implts_dispatch(aURL,lArguments); 235*cdf0e10cSrcweir if (xListener.is()) 236*cdf0e10cSrcweir { 237*cdf0e10cSrcweir css::frame::DispatchResultEvent aEvent; 238*cdf0e10cSrcweir if (bState) 239*cdf0e10cSrcweir aEvent.State = css::frame::DispatchResultState::SUCCESS; 240*cdf0e10cSrcweir else 241*cdf0e10cSrcweir aEvent.State = css::frame::DispatchResultState::FAILURE; 242*cdf0e10cSrcweir aEvent.Source = xThis; 243*cdf0e10cSrcweir 244*cdf0e10cSrcweir xListener->dispatchFinished( aEvent ); 245*cdf0e10cSrcweir } 246*cdf0e10cSrcweir } 247*cdf0e10cSrcweir 248*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 249*cdf0e10cSrcweir 250*cdf0e10cSrcweir /** 251*cdf0e10cSrcweir @short threadsafe helper for dispatch calls 252*cdf0e10cSrcweir @descr We support two interfaces for the same process - dispatch URLs. That the reason for this internal 253*cdf0e10cSrcweir function. It implements the real dispatch operation and returns a state value which inform caller 254*cdf0e10cSrcweir about success. He can notify listener then by using this return value. 255*cdf0e10cSrcweir 256*cdf0e10cSrcweir @param aURL 257*cdf0e10cSrcweir mail URL which should be executed 258*cdf0e10cSrcweir @param lArguments 259*cdf0e10cSrcweir list of optional arguments for this mail request 260*cdf0e10cSrcweir 261*cdf0e10cSrcweir @return <TRUE/> if dispatch could be started successfully 262*cdf0e10cSrcweir Note: Our internal used shell executor doesn't return any state value - so we must 263*cdf0e10cSrcweir belive that call was successfully. 264*cdf0e10cSrcweir <FALSE/> if neccessary ressource couldn't be created or an exception was thrown. 265*cdf0e10cSrcweir 266*cdf0e10cSrcweir @modified 30.04.2002 14:49, as96863 267*cdf0e10cSrcweir */ 268*cdf0e10cSrcweir sal_Bool MailToDispatcher::implts_dispatch( const css::util::URL& aURL , 269*cdf0e10cSrcweir const css::uno::Sequence< css::beans::PropertyValue >& /*lArguments*/ ) throw( css::uno::RuntimeException ) 270*cdf0e10cSrcweir { 271*cdf0e10cSrcweir sal_Bool bSuccess = sal_False; 272*cdf0e10cSrcweir 273*cdf0e10cSrcweir css::uno::Reference< css::lang::XMultiServiceFactory > xFactory; 274*cdf0e10cSrcweir /* SAFE */{ 275*cdf0e10cSrcweir ReadGuard aReadLock( m_aLock ); 276*cdf0e10cSrcweir xFactory = m_xFactory; 277*cdf0e10cSrcweir /* SAFE */} 278*cdf0e10cSrcweir 279*cdf0e10cSrcweir css::uno::Reference< css::system::XSystemShellExecute > xSystemShellExecute( xFactory->createInstance(SERVICENAME_SYSTEMSHELLEXECUTE), css::uno::UNO_QUERY ); 280*cdf0e10cSrcweir if (xSystemShellExecute.is()) 281*cdf0e10cSrcweir { 282*cdf0e10cSrcweir try 283*cdf0e10cSrcweir { 284*cdf0e10cSrcweir // start mail client 285*cdf0e10cSrcweir // Because there is no notofocation about success - we use case of 286*cdf0e10cSrcweir // no detected exception as SUCCESS - FAILED otherwhise. 287*cdf0e10cSrcweir xSystemShellExecute->execute( aURL.Complete, ::rtl::OUString(), css::system::SystemShellExecuteFlags::DEFAULTS ); 288*cdf0e10cSrcweir bSuccess = sal_True; 289*cdf0e10cSrcweir } 290*cdf0e10cSrcweir catch (css::lang::IllegalArgumentException&) 291*cdf0e10cSrcweir { 292*cdf0e10cSrcweir } 293*cdf0e10cSrcweir catch (css::system::SystemShellExecuteException&) 294*cdf0e10cSrcweir { 295*cdf0e10cSrcweir } 296*cdf0e10cSrcweir } 297*cdf0e10cSrcweir 298*cdf0e10cSrcweir return bSuccess; 299*cdf0e10cSrcweir } 300*cdf0e10cSrcweir 301*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 302*cdf0e10cSrcweir 303*cdf0e10cSrcweir /** 304*cdf0e10cSrcweir @short add/remove listener for state events 305*cdf0e10cSrcweir @descr Because we use an external process to forward such mail URLs, and this process doesn't 306*cdf0e10cSrcweir return any notifications about success or failed state - we doesn't support such status 307*cdf0e10cSrcweir listener. We have no status to send. 308*cdf0e10cSrcweir 309*cdf0e10cSrcweir @param xListener 310*cdf0e10cSrcweir reference to a valid listener for state events 311*cdf0e10cSrcweir @param aURL 312*cdf0e10cSrcweir URL about listener will be informed, if something occured 313*cdf0e10cSrcweir 314*cdf0e10cSrcweir @modified 30.04.2002 14:49, as96863 315*cdf0e10cSrcweir */ 316*cdf0e10cSrcweir void SAL_CALL MailToDispatcher::addStatusListener( const css::uno::Reference< css::frame::XStatusListener >& /*xListener*/ , 317*cdf0e10cSrcweir const css::util::URL& /*aURL*/ ) throw( css::uno::RuntimeException ) 318*cdf0e10cSrcweir { 319*cdf0e10cSrcweir // not suported yet 320*cdf0e10cSrcweir } 321*cdf0e10cSrcweir 322*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 323*cdf0e10cSrcweir 324*cdf0e10cSrcweir void SAL_CALL MailToDispatcher::removeStatusListener( const css::uno::Reference< css::frame::XStatusListener >& /*xListener*/ , 325*cdf0e10cSrcweir const css::util::URL& /*aURL*/ ) throw( css::uno::RuntimeException ) 326*cdf0e10cSrcweir { 327*cdf0e10cSrcweir // not suported yet 328*cdf0e10cSrcweir } 329*cdf0e10cSrcweir 330*cdf0e10cSrcweir } // namespace framework 331