systemexec.cxx (6d739b60) systemexec.cxx (9807c9de)
1/**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance

--- 21 unchanged lines hidden (view full) ---

30#include <dispatch/systemexec.hxx>
31#include <threadhelp/readguard.hxx>
32#include <general.h>
33#include <services.h>
34
35//_________________________________________________________________________________________________________________
36// interface includes
37//_________________________________________________________________________________________________________________
1/**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance

--- 21 unchanged lines hidden (view full) ---

30#include <dispatch/systemexec.hxx>
31#include <threadhelp/readguard.hxx>
32#include <general.h>
33#include <services.h>
34
35//_________________________________________________________________________________________________________________
36// interface includes
37//_________________________________________________________________________________________________________________
38#include <com/sun/star/system/XSystemShellExecute.hpp>
38#include <com/sun/star/system/SystemShellExecute.hpp>
39#include <com/sun/star/util/XStringSubstitution.hpp>
40#include <com/sun/star/system/SystemShellExecuteFlags.hpp>
41#include <com/sun/star/frame/DispatchResultState.hpp>
42
43//_________________________________________________________________________________________________________________
44// includes of other projects
45//_________________________________________________________________________________________________________________
46

--- 33 unchanged lines hidden (view full) ---

80
81DEFINE_XTYPEPROVIDER_5(SystemExec ,
82 css::lang::XTypeProvider ,
83 css::lang::XServiceInfo ,
84 css::frame::XDispatchProvider ,
85 css::frame::XNotifyingDispatch,
86 css::frame::XDispatch )
87
39#include <com/sun/star/util/XStringSubstitution.hpp>
40#include <com/sun/star/system/SystemShellExecuteFlags.hpp>
41#include <com/sun/star/frame/DispatchResultState.hpp>
42
43//_________________________________________________________________________________________________________________
44// includes of other projects
45//_________________________________________________________________________________________________________________
46

--- 33 unchanged lines hidden (view full) ---

80
81DEFINE_XTYPEPROVIDER_5(SystemExec ,
82 css::lang::XTypeProvider ,
83 css::lang::XServiceInfo ,
84 css::frame::XDispatchProvider ,
85 css::frame::XNotifyingDispatch,
86 css::frame::XDispatch )
87
88DEFINE_XSERVICEINFO_MULTISERVICE(SystemExec ,
89 ::cppu::OWeakObject ,
90 SERVICENAME_PROTOCOLHANDLER ,
91 IMPLEMENTATIONNAME_SYSTEMEXEC)
88DEFINE_XSERVICEINFO_MULTISERVICE_2(SystemExec ,
89 ::cppu::OWeakObject ,
90 SERVICENAME_PROTOCOLHANDLER ,
91 IMPLEMENTATIONNAME_SYSTEMEXEC)
92
93DEFINE_INIT_SERVICE(SystemExec,
94 {
95 /*Attention
96 I think we don't need any mutex or lock here ... because we are called by our own static method impl_createInstance()
97 to create a new instance of this class by our own supported service factory.
98 see macro DEFINE_XSERVICEINFO_MULTISERVICE and "impl_initService()" for further informations!
99 */
100 }
101 )
102
103//_________________________________________________________________________________________________________________
104
92
93DEFINE_INIT_SERVICE(SystemExec,
94 {
95 /*Attention
96 I think we don't need any mutex or lock here ... because we are called by our own static method impl_createInstance()
97 to create a new instance of this class by our own supported service factory.
98 see macro DEFINE_XSERVICEINFO_MULTISERVICE and "impl_initService()" for further informations!
99 */
100 }
101 )
102
103//_________________________________________________________________________________________________________________
104
105SystemExec::SystemExec( const css::uno::Reference< css::lang::XMultiServiceFactory >& xFactory )
105SystemExec::SystemExec( const css::uno::Reference< css::uno::XComponentContext >& xContext )
106 // Init baseclasses first
107 : ThreadHelpBase( &Application::GetSolarMutex() )
108 , OWeakObject ( )
109 // Init member
106 // Init baseclasses first
107 : ThreadHelpBase( &Application::GetSolarMutex() )
108 , OWeakObject ( )
109 // Init member
110 , m_xFactory ( xFactory )
110 , m_xContext ( xContext )
111{
112}
113
114//_________________________________________________________________________________________________________________
115
116SystemExec::~SystemExec()
117{
111{
112}
113
114//_________________________________________________________________________________________________________________
115
116SystemExec::~SystemExec()
117{
118 m_xFactory = NULL;
118 m_xContext = NULL;
119}
120
121//_________________________________________________________________________________________________________________
122
123css::uno::Reference< css::frame::XDispatch > SAL_CALL SystemExec::queryDispatch( const css::util::URL& aURL ,
124 const ::rtl::OUString&,
125 sal_Int32 ) throw( css::uno::RuntimeException )
126{

--- 39 unchanged lines hidden (view full) ---

166 {
167 impl_notifyResultListener(xListener, css::frame::DispatchResultState::FAILURE);
168 return;
169 }
170 ::rtl::OUString sSystemURLWithVariables = aURL.Complete.copy(PROTOCOL_LENGTH, c);
171
172 // SAFE ->
173 ReadGuard aReadLock(m_aLock);
119}
120
121//_________________________________________________________________________________________________________________
122
123css::uno::Reference< css::frame::XDispatch > SAL_CALL SystemExec::queryDispatch( const css::util::URL& aURL ,
124 const ::rtl::OUString&,
125 sal_Int32 ) throw( css::uno::RuntimeException )
126{

--- 39 unchanged lines hidden (view full) ---

166 {
167 impl_notifyResultListener(xListener, css::frame::DispatchResultState::FAILURE);
168 return;
169 }
170 ::rtl::OUString sSystemURLWithVariables = aURL.Complete.copy(PROTOCOL_LENGTH, c);
171
172 // SAFE ->
173 ReadGuard aReadLock(m_aLock);
174 css::uno::Reference< css::lang::XMultiServiceFactory > xFactory = m_xFactory;
174 css::uno::Reference< css::uno::XComponentContext > xContext = m_xContext;
175 aReadLock.unlock();
176 // <- SAFE
177
178 // TODO check security settings ...
179
180 try
181 {
182 css::uno::Reference< css::util::XStringSubstitution > xPathSubst(
175 aReadLock.unlock();
176 // <- SAFE
177
178 // TODO check security settings ...
179
180 try
181 {
182 css::uno::Reference< css::util::XStringSubstitution > xPathSubst(
183 xFactory->createInstance(SERVICENAME_SUBSTITUTEPATHVARIABLES),
183 xContext->getServiceManager()->createInstanceWithContext(
184 SERVICENAME_SUBSTITUTEPATHVARIABLES, xContext),
184 css::uno::UNO_QUERY_THROW);
185
186 ::rtl::OUString sSystemURL = xPathSubst->substituteVariables(sSystemURLWithVariables, sal_True); // sal_True force an exception if unknown variables exists !
187
188 css::uno::Reference< css::system::XSystemShellExecute > xShell(
185 css::uno::UNO_QUERY_THROW);
186
187 ::rtl::OUString sSystemURL = xPathSubst->substituteVariables(sSystemURLWithVariables, sal_True); // sal_True force an exception if unknown variables exists !
188
189 css::uno::Reference< css::system::XSystemShellExecute > xShell(
189 xFactory->createInstance(SERVICENAME_SYSTEMSHELLEXECUTE),
190 css::uno::UNO_QUERY_THROW);
190 css::system::SystemShellExecute::create(xContext));
191
192 xShell->execute(sSystemURL, ::rtl::OUString(), css::system::SystemShellExecuteFlags::DEFAULTS);
193 impl_notifyResultListener(xListener, css::frame::DispatchResultState::SUCCESS);
194 }
195 catch(const css::uno::Exception&)
196 {
197 impl_notifyResultListener(xListener, css::frame::DispatchResultState::FAILURE);
198 }

--- 32 unchanged lines hidden ---
191
192 xShell->execute(sSystemURL, ::rtl::OUString(), css::system::SystemShellExecuteFlags::DEFAULTS);
193 impl_notifyResultListener(xListener, css::frame::DispatchResultState::SUCCESS);
194 }
195 catch(const css::uno::Exception&)
196 {
197 impl_notifyResultListener(xListener, css::frame::DispatchResultState::FAILURE);
198 }

--- 32 unchanged lines hidden ---