merge the formfield patch from ooo-build
[ooovba.git] / framework / source / dispatch / systemexec.cxx
blob2ccf84fdb0876793b9db406036029e3ec5217040
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: systemexec.cxx,v $
10 * $Revision: 1.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_framework.hxx"
34 //_________________________________________________________________________________________________________________
35 // my own includes
36 //_________________________________________________________________________________________________________________
37 #include <dispatch/systemexec.hxx>
38 #include <threadhelp/readguard.hxx>
39 #include <general.h>
40 #include <services.h>
42 //_________________________________________________________________________________________________________________
43 // interface includes
44 //_________________________________________________________________________________________________________________
45 #include <com/sun/star/system/XSystemShellExecute.hpp>
46 #include <com/sun/star/util/XStringSubstitution.hpp>
47 #include <com/sun/star/system/SystemShellExecuteFlags.hpp>
48 #include <com/sun/star/frame/DispatchResultState.hpp>
50 //_________________________________________________________________________________________________________________
51 // includes of other projects
52 //_________________________________________________________________________________________________________________
54 #include <vcl/svapp.hxx>
56 //_________________________________________________________________________________________________________________
57 // namespace
58 //_________________________________________________________________________________________________________________
60 namespace framework{
62 //_________________________________________________________________________________________________________________
63 // non exported const
64 //_________________________________________________________________________________________________________________
66 #define PROTOCOL_VALUE "systemexecute:"
67 #define PROTOCOL_LENGTH 14
69 //_________________________________________________________________________________________________________________
70 // non exported definitions
71 //_________________________________________________________________________________________________________________
73 //_________________________________________________________________________________________________________________
74 // declarations
75 //_________________________________________________________________________________________________________________
77 //_________________________________________________________________________________________________________________
78 // XInterface, XTypeProvider, XServiceInfo
80 DEFINE_XINTERFACE_5(SystemExec ,
81 OWeakObject ,
82 DIRECT_INTERFACE(css::lang::XTypeProvider ),
83 DIRECT_INTERFACE(css::lang::XServiceInfo ),
84 DIRECT_INTERFACE(css::frame::XDispatchProvider ),
85 DIRECT_INTERFACE(css::frame::XNotifyingDispatch),
86 DIRECT_INTERFACE(css::frame::XDispatch ))
88 DEFINE_XTYPEPROVIDER_5(SystemExec ,
89 css::lang::XTypeProvider ,
90 css::lang::XServiceInfo ,
91 css::frame::XDispatchProvider ,
92 css::frame::XNotifyingDispatch,
93 css::frame::XDispatch )
95 DEFINE_XSERVICEINFO_MULTISERVICE(SystemExec ,
96 ::cppu::OWeakObject ,
97 SERVICENAME_PROTOCOLHANDLER ,
98 IMPLEMENTATIONNAME_SYSTEMEXEC)
100 DEFINE_INIT_SERVICE(SystemExec,
102 /*Attention
103 I think we don't need any mutex or lock here ... because we are called by our own static method impl_createInstance()
104 to create a new instance of this class by our own supported service factory.
105 see macro DEFINE_XSERVICEINFO_MULTISERVICE and "impl_initService()" for further informations!
110 //_________________________________________________________________________________________________________________
112 SystemExec::SystemExec( const css::uno::Reference< css::lang::XMultiServiceFactory >& xFactory )
113 // Init baseclasses first
114 : ThreadHelpBase( &Application::GetSolarMutex() )
115 , OWeakObject ( )
116 // Init member
117 , m_xFactory ( xFactory )
121 //_________________________________________________________________________________________________________________
123 SystemExec::~SystemExec()
125 m_xFactory = NULL;
128 //_________________________________________________________________________________________________________________
130 css::uno::Reference< css::frame::XDispatch > SAL_CALL SystemExec::queryDispatch( const css::util::URL& aURL ,
131 const ::rtl::OUString&,
132 sal_Int32 ) throw( css::uno::RuntimeException )
134 css::uno::Reference< css::frame::XDispatch > xDispatcher;
135 if (aURL.Complete.compareToAscii(PROTOCOL_VALUE,PROTOCOL_LENGTH)==0)
136 xDispatcher = this;
137 return xDispatcher;
140 //_________________________________________________________________________________________________________________
142 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 )
144 sal_Int32 nCount = lDescriptor.getLength();
145 css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > > lDispatcher( nCount );
146 for( sal_Int32 i=0; i<nCount; ++i )
148 lDispatcher[i] = this->queryDispatch(
149 lDescriptor[i].FeatureURL,
150 lDescriptor[i].FrameName,
151 lDescriptor[i].SearchFlags);
153 return lDispatcher;
156 //_________________________________________________________________________________________________________________
158 void SAL_CALL SystemExec::dispatch( const css::util::URL& aURL ,
159 const css::uno::Sequence< css::beans::PropertyValue >& lArguments ) throw( css::uno::RuntimeException )
161 dispatchWithNotification(aURL, lArguments, css::uno::Reference< css::frame::XDispatchResultListener >());
164 //_________________________________________________________________________________________________________________
166 void SAL_CALL SystemExec::dispatchWithNotification( const css::util::URL& aURL ,
167 const css::uno::Sequence< css::beans::PropertyValue >&,
168 const css::uno::Reference< css::frame::XDispatchResultListener >& xListener ) throw( css::uno::RuntimeException )
170 // convert "systemexec:file:///c:/temp/test.html" => "file:///c:/temp/test.html"
171 sal_Int32 c = aURL.Complete.getLength()-PROTOCOL_LENGTH;
172 if (c<1) // we dont check for valid URLs here! The system will show an error message ...
174 impl_notifyResultListener(xListener, css::frame::DispatchResultState::FAILURE);
175 return;
177 ::rtl::OUString sSystemURLWithVariables = aURL.Complete.copy(PROTOCOL_LENGTH, c);
179 // SAFE ->
180 ReadGuard aReadLock(m_aLock);
181 css::uno::Reference< css::lang::XMultiServiceFactory > xFactory = m_xFactory;
182 aReadLock.unlock();
183 // <- SAFE
185 // TODO check security settings ...
189 css::uno::Reference< css::util::XStringSubstitution > xPathSubst(
190 xFactory->createInstance(SERVICENAME_SUBSTITUTEPATHVARIABLES),
191 css::uno::UNO_QUERY_THROW);
193 ::rtl::OUString sSystemURL = xPathSubst->substituteVariables(sSystemURLWithVariables, sal_True); // sal_True force an exception if unknown variables exists !
195 css::uno::Reference< css::system::XSystemShellExecute > xShell(
196 xFactory->createInstance(SERVICENAME_SYSTEMSHELLEXECUTE),
197 css::uno::UNO_QUERY_THROW);
199 xShell->execute(sSystemURL, ::rtl::OUString(), css::system::SystemShellExecuteFlags::DEFAULTS);
200 impl_notifyResultListener(xListener, css::frame::DispatchResultState::SUCCESS);
202 catch(const css::uno::Exception&)
204 impl_notifyResultListener(xListener, css::frame::DispatchResultState::FAILURE);
208 //_________________________________________________________________________________________________________________
210 void SAL_CALL SystemExec::addStatusListener( const css::uno::Reference< css::frame::XStatusListener >&,
211 const css::util::URL& ) throw( css::uno::RuntimeException )
213 // not suported yet
216 //_________________________________________________________________________________________________________________
218 void SAL_CALL SystemExec::removeStatusListener( const css::uno::Reference< css::frame::XStatusListener >&,
219 const css::util::URL& ) throw( css::uno::RuntimeException )
221 // not suported yet
224 //_________________________________________________________________________________________________________________
226 void SystemExec::impl_notifyResultListener(const css::uno::Reference< css::frame::XDispatchResultListener >& xListener,
227 const sal_Int16 nState )
229 if (xListener.is())
231 css::frame::DispatchResultEvent aEvent;
232 aEvent.State = nState;
233 xListener->dispatchFinished(aEvent);
237 } // namespace framework