16d739b60SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
36d739b60SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
46d739b60SAndrew Rist * or more contributor license agreements. See the NOTICE file
56d739b60SAndrew Rist * distributed with this work for additional information
66d739b60SAndrew Rist * regarding copyright ownership. The ASF licenses this file
76d739b60SAndrew Rist * to you under the Apache License, Version 2.0 (the
86d739b60SAndrew Rist * "License"); you may not use this file except in compliance
96d739b60SAndrew Rist * with the License. You may obtain a copy of the License at
106d739b60SAndrew Rist *
116d739b60SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
126d739b60SAndrew Rist *
136d739b60SAndrew Rist * Unless required by applicable law or agreed to in writing,
146d739b60SAndrew Rist * software distributed under the License is distributed on an
156d739b60SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
166d739b60SAndrew Rist * KIND, either express or implied. See the License for the
176d739b60SAndrew Rist * specific language governing permissions and limitations
186d739b60SAndrew Rist * under the License.
196d739b60SAndrew Rist *
206d739b60SAndrew Rist *************************************************************/
216d739b60SAndrew Rist
226d739b60SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_framework.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir //_________________________________________________________________________________________________________________
28cdf0e10cSrcweir // my own includes
29cdf0e10cSrcweir //_________________________________________________________________________________________________________________
30cdf0e10cSrcweir #include <dispatch/mailtodispatcher.hxx>
31cdf0e10cSrcweir #include <threadhelp/readguard.hxx>
32cdf0e10cSrcweir #include <general.h>
33cdf0e10cSrcweir #include <services.h>
34cdf0e10cSrcweir
35cdf0e10cSrcweir //_________________________________________________________________________________________________________________
36cdf0e10cSrcweir // interface includes
37cdf0e10cSrcweir //_________________________________________________________________________________________________________________
389807c9deSAriel Constenla-Haile #include <com/sun/star/system/SystemShellExecute.hpp>
39cdf0e10cSrcweir #include <com/sun/star/system/SystemShellExecuteFlags.hpp>
40cdf0e10cSrcweir #include <com/sun/star/frame/DispatchResultState.hpp>
41cdf0e10cSrcweir
42cdf0e10cSrcweir //_________________________________________________________________________________________________________________
43cdf0e10cSrcweir // includes of other projects
44cdf0e10cSrcweir //_________________________________________________________________________________________________________________
45cdf0e10cSrcweir
46cdf0e10cSrcweir #include <vcl/svapp.hxx>
47cdf0e10cSrcweir
48cdf0e10cSrcweir //_________________________________________________________________________________________________________________
49cdf0e10cSrcweir // namespace
50cdf0e10cSrcweir //_________________________________________________________________________________________________________________
51cdf0e10cSrcweir
52cdf0e10cSrcweir namespace framework{
53cdf0e10cSrcweir
54cdf0e10cSrcweir //_________________________________________________________________________________________________________________
55cdf0e10cSrcweir // non exported const
56cdf0e10cSrcweir //_________________________________________________________________________________________________________________
57cdf0e10cSrcweir
58cdf0e10cSrcweir #define PROTOCOL_VALUE "mailto:"
59cdf0e10cSrcweir #define PROTOCOL_LENGTH 7
60cdf0e10cSrcweir
61cdf0e10cSrcweir //_________________________________________________________________________________________________________________
62cdf0e10cSrcweir // non exported definitions
63cdf0e10cSrcweir //_________________________________________________________________________________________________________________
64cdf0e10cSrcweir
65cdf0e10cSrcweir //_________________________________________________________________________________________________________________
66cdf0e10cSrcweir // declarations
67cdf0e10cSrcweir //_________________________________________________________________________________________________________________
68cdf0e10cSrcweir
69cdf0e10cSrcweir //_________________________________________________________________________________________________________________
70cdf0e10cSrcweir // XInterface, XTypeProvider, XServiceInfo
71cdf0e10cSrcweir
DEFINE_XINTERFACE_5(MailToDispatcher,OWeakObject,DIRECT_INTERFACE (css::lang::XTypeProvider),DIRECT_INTERFACE (css::lang::XServiceInfo),DIRECT_INTERFACE (css::frame::XDispatchProvider),DIRECT_INTERFACE (css::frame::XNotifyingDispatch),DIRECT_INTERFACE (css::frame::XDispatch))72cdf0e10cSrcweir DEFINE_XINTERFACE_5(MailToDispatcher ,
73cdf0e10cSrcweir OWeakObject ,
74cdf0e10cSrcweir DIRECT_INTERFACE(css::lang::XTypeProvider ),
75cdf0e10cSrcweir DIRECT_INTERFACE(css::lang::XServiceInfo ),
76cdf0e10cSrcweir DIRECT_INTERFACE(css::frame::XDispatchProvider ),
77cdf0e10cSrcweir DIRECT_INTERFACE(css::frame::XNotifyingDispatch),
78cdf0e10cSrcweir DIRECT_INTERFACE(css::frame::XDispatch ))
79cdf0e10cSrcweir
80cdf0e10cSrcweir DEFINE_XTYPEPROVIDER_5(MailToDispatcher ,
81cdf0e10cSrcweir css::lang::XTypeProvider ,
82cdf0e10cSrcweir css::lang::XServiceInfo ,
83cdf0e10cSrcweir css::frame::XDispatchProvider ,
84cdf0e10cSrcweir css::frame::XNotifyingDispatch,
85cdf0e10cSrcweir css::frame::XDispatch )
86cdf0e10cSrcweir
879807c9deSAriel Constenla-Haile DEFINE_XSERVICEINFO_MULTISERVICE_2(MailToDispatcher ,
889807c9deSAriel Constenla-Haile ::cppu::OWeakObject ,
899807c9deSAriel Constenla-Haile SERVICENAME_PROTOCOLHANDLER ,
909807c9deSAriel Constenla-Haile IMPLEMENTATIONNAME_MAILTODISPATCHER)
91cdf0e10cSrcweir
92cdf0e10cSrcweir DEFINE_INIT_SERVICE(MailToDispatcher,
93cdf0e10cSrcweir {
94cdf0e10cSrcweir /*Attention
95cdf0e10cSrcweir I think we don't need any mutex or lock here ... because we are called by our own static method impl_createInstance()
96cdf0e10cSrcweir to create a new instance of this class by our own supported service factory.
97cdf0e10cSrcweir see macro DEFINE_XSERVICEINFO_MULTISERVICE and "impl_initService()" for further informations!
98cdf0e10cSrcweir */
99cdf0e10cSrcweir }
100cdf0e10cSrcweir )
101cdf0e10cSrcweir
102cdf0e10cSrcweir //_________________________________________________________________________________________________________________
103cdf0e10cSrcweir
104cdf0e10cSrcweir /**
105cdf0e10cSrcweir @short standard ctor
10607a3d7f1SPedro Giffuni @descr These initialize a new instance of this class with needed informations for work.
107cdf0e10cSrcweir
1089807c9deSAriel Constenla-Haile @param xContext
1099807c9deSAriel Constenla-Haile reference to uno component context
110cdf0e10cSrcweir
111cdf0e10cSrcweir @modified 30.04.2002 14:10, as96863
112cdf0e10cSrcweir */
1139807c9deSAriel Constenla-Haile MailToDispatcher::MailToDispatcher( const css::uno::Reference< css::uno::XComponentContext >& xContext )
114cdf0e10cSrcweir // Init baseclasses first
115cdf0e10cSrcweir : ThreadHelpBase( &Application::GetSolarMutex() )
116cdf0e10cSrcweir , OWeakObject ( )
117cdf0e10cSrcweir // Init member
1189807c9deSAriel Constenla-Haile , m_xContext ( xContext )
119cdf0e10cSrcweir {
120cdf0e10cSrcweir }
121cdf0e10cSrcweir
122cdf0e10cSrcweir //_________________________________________________________________________________________________________________
123cdf0e10cSrcweir
124cdf0e10cSrcweir /**
125cdf0e10cSrcweir @short standard dtor
126cdf0e10cSrcweir @descr -
127cdf0e10cSrcweir
128cdf0e10cSrcweir @modified 30.04.2002 14:10, as96863
129cdf0e10cSrcweir */
~MailToDispatcher()130cdf0e10cSrcweir MailToDispatcher::~MailToDispatcher()
131cdf0e10cSrcweir {
1329807c9deSAriel Constenla-Haile m_xContext = NULL;
133cdf0e10cSrcweir }
134cdf0e10cSrcweir
135cdf0e10cSrcweir //_________________________________________________________________________________________________________________
136cdf0e10cSrcweir
137cdf0e10cSrcweir /**
138cdf0e10cSrcweir @short decide if this dispatch implementation can be used for requested URL or not
139cdf0e10cSrcweir @descr A protocol handler is registerd for an URL pattern inside configuration and will
140cdf0e10cSrcweir be asked by the generic dispatch mechanism inside framework, if he can handle this
14130acf5e8Spfg special URL which match his registration. He can agree by returning of a valid dispatch
142cdf0e10cSrcweir instance or disagree by returning <NULL/>.
14307a3d7f1SPedro Giffuni We don't create new dispatch instances here really - we return THIS as result to handle it
144cdf0e10cSrcweir at the same implementation.
145cdf0e10cSrcweir
146cdf0e10cSrcweir @modified 02.05.2002 15:25, as96863
147cdf0e10cSrcweir */
queryDispatch(const css::util::URL & aURL,const::rtl::OUString &,sal_Int32)148cdf0e10cSrcweir css::uno::Reference< css::frame::XDispatch > SAL_CALL MailToDispatcher::queryDispatch( const css::util::URL& aURL ,
149cdf0e10cSrcweir const ::rtl::OUString& /*sTarget*/ ,
150cdf0e10cSrcweir sal_Int32 /*nFlags*/ ) throw( css::uno::RuntimeException )
151cdf0e10cSrcweir {
152cdf0e10cSrcweir css::uno::Reference< css::frame::XDispatch > xDispatcher;
153cdf0e10cSrcweir if (aURL.Complete.compareToAscii(PROTOCOL_VALUE,PROTOCOL_LENGTH)==0)
154cdf0e10cSrcweir xDispatcher = this;
155cdf0e10cSrcweir return xDispatcher;
156cdf0e10cSrcweir }
157cdf0e10cSrcweir
158cdf0e10cSrcweir //_________________________________________________________________________________________________________________
159cdf0e10cSrcweir
160cdf0e10cSrcweir /**
161cdf0e10cSrcweir @short do the same like dispatch() but for multiple requests at the same time
162cdf0e10cSrcweir @descr -
163cdf0e10cSrcweir
164cdf0e10cSrcweir @modified 02.05.2002 15:27, as96863
165cdf0e10cSrcweir */
queryDispatches(const css::uno::Sequence<css::frame::DispatchDescriptor> & lDescriptor)166cdf0e10cSrcweir 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 )
167cdf0e10cSrcweir {
168cdf0e10cSrcweir sal_Int32 nCount = lDescriptor.getLength();
169cdf0e10cSrcweir css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > > lDispatcher( nCount );
170cdf0e10cSrcweir for( sal_Int32 i=0; i<nCount; ++i )
171cdf0e10cSrcweir {
172cdf0e10cSrcweir lDispatcher[i] = this->queryDispatch(
173cdf0e10cSrcweir lDescriptor[i].FeatureURL,
174cdf0e10cSrcweir lDescriptor[i].FrameName,
175cdf0e10cSrcweir lDescriptor[i].SearchFlags);
176cdf0e10cSrcweir }
177cdf0e10cSrcweir return lDispatcher;
178cdf0e10cSrcweir }
179cdf0e10cSrcweir
180cdf0e10cSrcweir //_________________________________________________________________________________________________________________
181cdf0e10cSrcweir
182cdf0e10cSrcweir /**
183cdf0e10cSrcweir @short dispatch URL with arguments
184cdf0e10cSrcweir @descr We use threadsafe internal method to do so. It returns a state value - but we ignore it.
18506fea5ebSmseidel Because we don't support status listener notifications here. Status events are not guaranteed -
18606fea5ebSmseidel and we call another service internally which doesn't return any notifications too.
187cdf0e10cSrcweir
188cdf0e10cSrcweir @param aURL
189cdf0e10cSrcweir mail URL which should be executed
190cdf0e10cSrcweir @param lArguments
191cdf0e10cSrcweir list of optional arguments for this mail request
192cdf0e10cSrcweir
193cdf0e10cSrcweir @modified 30.04.2002 14:15, as96863
194cdf0e10cSrcweir */
dispatch(const css::util::URL & aURL,const css::uno::Sequence<css::beans::PropertyValue> & lArguments)195cdf0e10cSrcweir void SAL_CALL MailToDispatcher::dispatch( const css::util::URL& aURL ,
196cdf0e10cSrcweir const css::uno::Sequence< css::beans::PropertyValue >& lArguments ) throw( css::uno::RuntimeException )
197cdf0e10cSrcweir {
19807a3d7f1SPedro Giffuni // dispatch() is an [oneway] call ... and may our user release his reference to us immediately.
199cdf0e10cSrcweir // So we should hold us self alive till this call ends.
200cdf0e10cSrcweir css::uno::Reference< css::frame::XNotifyingDispatch > xSelfHold(static_cast< ::cppu::OWeakObject* >(this), css::uno::UNO_QUERY);
201cdf0e10cSrcweir implts_dispatch(aURL,lArguments);
202cdf0e10cSrcweir // No notification for status listener!
203cdf0e10cSrcweir }
204cdf0e10cSrcweir
205cdf0e10cSrcweir //_________________________________________________________________________________________________________________
206cdf0e10cSrcweir
207cdf0e10cSrcweir /**
208cdf0e10cSrcweir @short dispatch with guaranteed notifications about success
209cdf0e10cSrcweir @descr We use threadsafe internal method to do so. Return state of this function will be used
210cdf0e10cSrcweir for notification if an optional listener is given.
211cdf0e10cSrcweir
212cdf0e10cSrcweir @param aURL
213cdf0e10cSrcweir mail URL which should be executed
214cdf0e10cSrcweir @param lArguments
215cdf0e10cSrcweir list of optional arguments for this mail request
216cdf0e10cSrcweir @param xListener
217cdf0e10cSrcweir reference to a valid listener for state events
218cdf0e10cSrcweir
219cdf0e10cSrcweir @modified 30.04.2002 14:49, as96863
220cdf0e10cSrcweir */
dispatchWithNotification(const css::util::URL & aURL,const css::uno::Sequence<css::beans::PropertyValue> & lArguments,const css::uno::Reference<css::frame::XDispatchResultListener> & xListener)221cdf0e10cSrcweir void SAL_CALL MailToDispatcher::dispatchWithNotification( const css::util::URL& aURL ,
222cdf0e10cSrcweir const css::uno::Sequence< css::beans::PropertyValue >& lArguments,
223cdf0e10cSrcweir const css::uno::Reference< css::frame::XDispatchResultListener >& xListener ) throw( css::uno::RuntimeException )
224cdf0e10cSrcweir {
22507a3d7f1SPedro Giffuni // This class was designed to die by reference. And if user release his reference to us immediately after calling this method
226cdf0e10cSrcweir // we can run into some problems. So we hold us self alive till this method ends.
227cdf0e10cSrcweir // Another reason: We can use this reference as source of sending event at the end too.
228cdf0e10cSrcweir css::uno::Reference< css::frame::XNotifyingDispatch > xThis(static_cast< ::cppu::OWeakObject* >(this), css::uno::UNO_QUERY);
229cdf0e10cSrcweir
230cdf0e10cSrcweir sal_Bool bState = implts_dispatch(aURL,lArguments);
231cdf0e10cSrcweir if (xListener.is())
232cdf0e10cSrcweir {
233cdf0e10cSrcweir css::frame::DispatchResultEvent aEvent;
234cdf0e10cSrcweir if (bState)
235cdf0e10cSrcweir aEvent.State = css::frame::DispatchResultState::SUCCESS;
236cdf0e10cSrcweir else
237cdf0e10cSrcweir aEvent.State = css::frame::DispatchResultState::FAILURE;
238cdf0e10cSrcweir aEvent.Source = xThis;
239cdf0e10cSrcweir
240cdf0e10cSrcweir xListener->dispatchFinished( aEvent );
241cdf0e10cSrcweir }
242cdf0e10cSrcweir }
243cdf0e10cSrcweir
244cdf0e10cSrcweir //_________________________________________________________________________________________________________________
245cdf0e10cSrcweir
246cdf0e10cSrcweir /**
247cdf0e10cSrcweir @short threadsafe helper for dispatch calls
248cdf0e10cSrcweir @descr We support two interfaces for the same process - dispatch URLs. That the reason for this internal
249cdf0e10cSrcweir function. It implements the real dispatch operation and returns a state value which inform caller
250cdf0e10cSrcweir about success. He can notify listener then by using this return value.
251cdf0e10cSrcweir
252cdf0e10cSrcweir @param aURL
253cdf0e10cSrcweir mail URL which should be executed
254cdf0e10cSrcweir @param lArguments
255cdf0e10cSrcweir list of optional arguments for this mail request
256cdf0e10cSrcweir
257cdf0e10cSrcweir @return <TRUE/> if dispatch could be started successfully
258cdf0e10cSrcweir Note: Our internal used shell executor doesn't return any state value - so we must
25907a3d7f1SPedro Giffuni believe that call was successfully.
26007a3d7f1SPedro Giffuni <FALSE/> if necessary ressource couldn't be created or an exception was thrown.
261cdf0e10cSrcweir
262cdf0e10cSrcweir @modified 30.04.2002 14:49, as96863
263cdf0e10cSrcweir */
implts_dispatch(const css::util::URL & aURL,const css::uno::Sequence<css::beans::PropertyValue> &)264cdf0e10cSrcweir sal_Bool MailToDispatcher::implts_dispatch( const css::util::URL& aURL ,
265cdf0e10cSrcweir const css::uno::Sequence< css::beans::PropertyValue >& /*lArguments*/ ) throw( css::uno::RuntimeException )
266cdf0e10cSrcweir {
267cdf0e10cSrcweir sal_Bool bSuccess = sal_False;
268cdf0e10cSrcweir
2699807c9deSAriel Constenla-Haile css::uno::Reference< css::uno::XComponentContext > xContext;
270cdf0e10cSrcweir /* SAFE */{
271cdf0e10cSrcweir ReadGuard aReadLock( m_aLock );
2729807c9deSAriel Constenla-Haile xContext = m_xContext;
273cdf0e10cSrcweir /* SAFE */}
274cdf0e10cSrcweir
2759807c9deSAriel Constenla-Haile css::uno::Reference< css::system::XSystemShellExecute > xSystemShellExecute(
2769807c9deSAriel Constenla-Haile css::system::SystemShellExecute::create( xContext ) );
277cdf0e10cSrcweir if (xSystemShellExecute.is())
278cdf0e10cSrcweir {
279cdf0e10cSrcweir try
280cdf0e10cSrcweir {
281cdf0e10cSrcweir // start mail client
282*15289133Smseidel // Because there is no notification about success - we use case of
283*15289133Smseidel // no detected exception as SUCCESS - FAILED otherwise.
284cdf0e10cSrcweir xSystemShellExecute->execute( aURL.Complete, ::rtl::OUString(), css::system::SystemShellExecuteFlags::DEFAULTS );
285cdf0e10cSrcweir bSuccess = sal_True;
286cdf0e10cSrcweir }
287cdf0e10cSrcweir catch (css::lang::IllegalArgumentException&)
288cdf0e10cSrcweir {
289cdf0e10cSrcweir }
290cdf0e10cSrcweir catch (css::system::SystemShellExecuteException&)
291cdf0e10cSrcweir {
292cdf0e10cSrcweir }
293cdf0e10cSrcweir }
294cdf0e10cSrcweir
295cdf0e10cSrcweir return bSuccess;
296cdf0e10cSrcweir }
297cdf0e10cSrcweir
298cdf0e10cSrcweir //_________________________________________________________________________________________________________________
299cdf0e10cSrcweir
300cdf0e10cSrcweir /**
301cdf0e10cSrcweir @short add/remove listener for state events
302cdf0e10cSrcweir @descr Because we use an external process to forward such mail URLs, and this process doesn't
303cdf0e10cSrcweir return any notifications about success or failed state - we doesn't support such status
304cdf0e10cSrcweir listener. We have no status to send.
305cdf0e10cSrcweir
306cdf0e10cSrcweir @param xListener
307cdf0e10cSrcweir reference to a valid listener for state events
308cdf0e10cSrcweir @param aURL
30907a3d7f1SPedro Giffuni URL about listener will be informed, if something occurred
310cdf0e10cSrcweir
311cdf0e10cSrcweir @modified 30.04.2002 14:49, as96863
312cdf0e10cSrcweir */
addStatusListener(const css::uno::Reference<css::frame::XStatusListener> &,const css::util::URL &)313cdf0e10cSrcweir void SAL_CALL MailToDispatcher::addStatusListener( const css::uno::Reference< css::frame::XStatusListener >& /*xListener*/ ,
314cdf0e10cSrcweir const css::util::URL& /*aURL*/ ) throw( css::uno::RuntimeException )
315cdf0e10cSrcweir {
316cdf0e10cSrcweir // not suported yet
317cdf0e10cSrcweir }
318cdf0e10cSrcweir
319cdf0e10cSrcweir //_________________________________________________________________________________________________________________
320cdf0e10cSrcweir
removeStatusListener(const css::uno::Reference<css::frame::XStatusListener> &,const css::util::URL &)321cdf0e10cSrcweir void SAL_CALL MailToDispatcher::removeStatusListener( const css::uno::Reference< css::frame::XStatusListener >& /*xListener*/ ,
322cdf0e10cSrcweir const css::util::URL& /*aURL*/ ) throw( css::uno::RuntimeException )
323cdf0e10cSrcweir {
324cdf0e10cSrcweir // not suported yet
325cdf0e10cSrcweir }
326cdf0e10cSrcweir
327cdf0e10cSrcweir } // namespace framework
328