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/systemexec.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/util/XStringSubstitution.hpp> 44*cdf0e10cSrcweir #include <com/sun/star/system/SystemShellExecuteFlags.hpp> 45*cdf0e10cSrcweir #include <com/sun/star/frame/DispatchResultState.hpp> 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 48*cdf0e10cSrcweir // includes of other projects 49*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir #include <vcl/svapp.hxx> 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 54*cdf0e10cSrcweir // namespace 55*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir namespace framework{ 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 60*cdf0e10cSrcweir // non exported const 61*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 62*cdf0e10cSrcweir 63*cdf0e10cSrcweir #define PROTOCOL_VALUE "systemexecute:" 64*cdf0e10cSrcweir #define PROTOCOL_LENGTH 14 65*cdf0e10cSrcweir 66*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 67*cdf0e10cSrcweir // non exported definitions 68*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 71*cdf0e10cSrcweir // declarations 72*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 73*cdf0e10cSrcweir 74*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 75*cdf0e10cSrcweir // XInterface, XTypeProvider, XServiceInfo 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir DEFINE_XINTERFACE_5(SystemExec , 78*cdf0e10cSrcweir OWeakObject , 79*cdf0e10cSrcweir DIRECT_INTERFACE(css::lang::XTypeProvider ), 80*cdf0e10cSrcweir DIRECT_INTERFACE(css::lang::XServiceInfo ), 81*cdf0e10cSrcweir DIRECT_INTERFACE(css::frame::XDispatchProvider ), 82*cdf0e10cSrcweir DIRECT_INTERFACE(css::frame::XNotifyingDispatch), 83*cdf0e10cSrcweir DIRECT_INTERFACE(css::frame::XDispatch )) 84*cdf0e10cSrcweir 85*cdf0e10cSrcweir DEFINE_XTYPEPROVIDER_5(SystemExec , 86*cdf0e10cSrcweir css::lang::XTypeProvider , 87*cdf0e10cSrcweir css::lang::XServiceInfo , 88*cdf0e10cSrcweir css::frame::XDispatchProvider , 89*cdf0e10cSrcweir css::frame::XNotifyingDispatch, 90*cdf0e10cSrcweir css::frame::XDispatch ) 91*cdf0e10cSrcweir 92*cdf0e10cSrcweir DEFINE_XSERVICEINFO_MULTISERVICE(SystemExec , 93*cdf0e10cSrcweir ::cppu::OWeakObject , 94*cdf0e10cSrcweir SERVICENAME_PROTOCOLHANDLER , 95*cdf0e10cSrcweir IMPLEMENTATIONNAME_SYSTEMEXEC) 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir DEFINE_INIT_SERVICE(SystemExec, 98*cdf0e10cSrcweir { 99*cdf0e10cSrcweir /*Attention 100*cdf0e10cSrcweir I think we don't need any mutex or lock here ... because we are called by our own static method impl_createInstance() 101*cdf0e10cSrcweir to create a new instance of this class by our own supported service factory. 102*cdf0e10cSrcweir see macro DEFINE_XSERVICEINFO_MULTISERVICE and "impl_initService()" for further informations! 103*cdf0e10cSrcweir */ 104*cdf0e10cSrcweir } 105*cdf0e10cSrcweir ) 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir SystemExec::SystemExec( const css::uno::Reference< css::lang::XMultiServiceFactory >& xFactory ) 110*cdf0e10cSrcweir // Init baseclasses first 111*cdf0e10cSrcweir : ThreadHelpBase( &Application::GetSolarMutex() ) 112*cdf0e10cSrcweir , OWeakObject ( ) 113*cdf0e10cSrcweir // Init member 114*cdf0e10cSrcweir , m_xFactory ( xFactory ) 115*cdf0e10cSrcweir { 116*cdf0e10cSrcweir } 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir SystemExec::~SystemExec() 121*cdf0e10cSrcweir { 122*cdf0e10cSrcweir m_xFactory = NULL; 123*cdf0e10cSrcweir } 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir css::uno::Reference< css::frame::XDispatch > SAL_CALL SystemExec::queryDispatch( const css::util::URL& aURL , 128*cdf0e10cSrcweir const ::rtl::OUString&, 129*cdf0e10cSrcweir sal_Int32 ) throw( css::uno::RuntimeException ) 130*cdf0e10cSrcweir { 131*cdf0e10cSrcweir css::uno::Reference< css::frame::XDispatch > xDispatcher; 132*cdf0e10cSrcweir if (aURL.Complete.compareToAscii(PROTOCOL_VALUE,PROTOCOL_LENGTH)==0) 133*cdf0e10cSrcweir xDispatcher = this; 134*cdf0e10cSrcweir return xDispatcher; 135*cdf0e10cSrcweir } 136*cdf0e10cSrcweir 137*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 138*cdf0e10cSrcweir 139*cdf0e10cSrcweir css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > > SAL_CALL SystemExec::queryDispatches( const css::uno::Sequence< css::frame::DispatchDescriptor >& lDescriptor ) throw( css::uno::RuntimeException ) 140*cdf0e10cSrcweir { 141*cdf0e10cSrcweir sal_Int32 nCount = lDescriptor.getLength(); 142*cdf0e10cSrcweir css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > > lDispatcher( nCount ); 143*cdf0e10cSrcweir for( sal_Int32 i=0; i<nCount; ++i ) 144*cdf0e10cSrcweir { 145*cdf0e10cSrcweir lDispatcher[i] = this->queryDispatch( 146*cdf0e10cSrcweir lDescriptor[i].FeatureURL, 147*cdf0e10cSrcweir lDescriptor[i].FrameName, 148*cdf0e10cSrcweir lDescriptor[i].SearchFlags); 149*cdf0e10cSrcweir } 150*cdf0e10cSrcweir return lDispatcher; 151*cdf0e10cSrcweir } 152*cdf0e10cSrcweir 153*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 154*cdf0e10cSrcweir 155*cdf0e10cSrcweir void SAL_CALL SystemExec::dispatch( const css::util::URL& aURL , 156*cdf0e10cSrcweir const css::uno::Sequence< css::beans::PropertyValue >& lArguments ) throw( css::uno::RuntimeException ) 157*cdf0e10cSrcweir { 158*cdf0e10cSrcweir dispatchWithNotification(aURL, lArguments, css::uno::Reference< css::frame::XDispatchResultListener >()); 159*cdf0e10cSrcweir } 160*cdf0e10cSrcweir 161*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir void SAL_CALL SystemExec::dispatchWithNotification( const css::util::URL& aURL , 164*cdf0e10cSrcweir const css::uno::Sequence< css::beans::PropertyValue >&, 165*cdf0e10cSrcweir const css::uno::Reference< css::frame::XDispatchResultListener >& xListener ) throw( css::uno::RuntimeException ) 166*cdf0e10cSrcweir { 167*cdf0e10cSrcweir // convert "systemexec:file:///c:/temp/test.html" => "file:///c:/temp/test.html" 168*cdf0e10cSrcweir sal_Int32 c = aURL.Complete.getLength()-PROTOCOL_LENGTH; 169*cdf0e10cSrcweir if (c<1) // we dont check for valid URLs here! The system will show an error message ... 170*cdf0e10cSrcweir { 171*cdf0e10cSrcweir impl_notifyResultListener(xListener, css::frame::DispatchResultState::FAILURE); 172*cdf0e10cSrcweir return; 173*cdf0e10cSrcweir } 174*cdf0e10cSrcweir ::rtl::OUString sSystemURLWithVariables = aURL.Complete.copy(PROTOCOL_LENGTH, c); 175*cdf0e10cSrcweir 176*cdf0e10cSrcweir // SAFE -> 177*cdf0e10cSrcweir ReadGuard aReadLock(m_aLock); 178*cdf0e10cSrcweir css::uno::Reference< css::lang::XMultiServiceFactory > xFactory = m_xFactory; 179*cdf0e10cSrcweir aReadLock.unlock(); 180*cdf0e10cSrcweir // <- SAFE 181*cdf0e10cSrcweir 182*cdf0e10cSrcweir // TODO check security settings ... 183*cdf0e10cSrcweir 184*cdf0e10cSrcweir try 185*cdf0e10cSrcweir { 186*cdf0e10cSrcweir css::uno::Reference< css::util::XStringSubstitution > xPathSubst( 187*cdf0e10cSrcweir xFactory->createInstance(SERVICENAME_SUBSTITUTEPATHVARIABLES), 188*cdf0e10cSrcweir css::uno::UNO_QUERY_THROW); 189*cdf0e10cSrcweir 190*cdf0e10cSrcweir ::rtl::OUString sSystemURL = xPathSubst->substituteVariables(sSystemURLWithVariables, sal_True); // sal_True force an exception if unknown variables exists ! 191*cdf0e10cSrcweir 192*cdf0e10cSrcweir css::uno::Reference< css::system::XSystemShellExecute > xShell( 193*cdf0e10cSrcweir xFactory->createInstance(SERVICENAME_SYSTEMSHELLEXECUTE), 194*cdf0e10cSrcweir css::uno::UNO_QUERY_THROW); 195*cdf0e10cSrcweir 196*cdf0e10cSrcweir xShell->execute(sSystemURL, ::rtl::OUString(), css::system::SystemShellExecuteFlags::DEFAULTS); 197*cdf0e10cSrcweir impl_notifyResultListener(xListener, css::frame::DispatchResultState::SUCCESS); 198*cdf0e10cSrcweir } 199*cdf0e10cSrcweir catch(const css::uno::Exception&) 200*cdf0e10cSrcweir { 201*cdf0e10cSrcweir impl_notifyResultListener(xListener, css::frame::DispatchResultState::FAILURE); 202*cdf0e10cSrcweir } 203*cdf0e10cSrcweir } 204*cdf0e10cSrcweir 205*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 206*cdf0e10cSrcweir 207*cdf0e10cSrcweir void SAL_CALL SystemExec::addStatusListener( const css::uno::Reference< css::frame::XStatusListener >&, 208*cdf0e10cSrcweir const css::util::URL& ) throw( css::uno::RuntimeException ) 209*cdf0e10cSrcweir { 210*cdf0e10cSrcweir // not suported yet 211*cdf0e10cSrcweir } 212*cdf0e10cSrcweir 213*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 214*cdf0e10cSrcweir 215*cdf0e10cSrcweir void SAL_CALL SystemExec::removeStatusListener( const css::uno::Reference< css::frame::XStatusListener >&, 216*cdf0e10cSrcweir const css::util::URL& ) throw( css::uno::RuntimeException ) 217*cdf0e10cSrcweir { 218*cdf0e10cSrcweir // not suported yet 219*cdf0e10cSrcweir } 220*cdf0e10cSrcweir 221*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 222*cdf0e10cSrcweir 223*cdf0e10cSrcweir void SystemExec::impl_notifyResultListener(const css::uno::Reference< css::frame::XDispatchResultListener >& xListener, 224*cdf0e10cSrcweir const sal_Int16 nState ) 225*cdf0e10cSrcweir { 226*cdf0e10cSrcweir if (xListener.is()) 227*cdf0e10cSrcweir { 228*cdf0e10cSrcweir css::frame::DispatchResultEvent aEvent; 229*cdf0e10cSrcweir aEvent.State = nState; 230*cdf0e10cSrcweir xListener->dispatchFinished(aEvent); 231*cdf0e10cSrcweir } 232*cdf0e10cSrcweir } 233*cdf0e10cSrcweir 234*cdf0e10cSrcweir } // namespace framework 235