1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: mailtodispatcher.cxx,v $
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 //_________________________________________________________________________________________________________________
36 //_________________________________________________________________________________________________________________
37 #include <dispatch/mailtodispatcher.hxx>
38 #include <threadhelp/readguard.hxx>
42 //_________________________________________________________________________________________________________________
44 //_________________________________________________________________________________________________________________
45 #include <com/sun/star/system/XSystemShellExecute.hpp>
46 #include <com/sun/star/system/SystemShellExecuteFlags.hpp>
47 #include <com/sun/star/frame/DispatchResultState.hpp>
49 //_________________________________________________________________________________________________________________
50 // includes of other projects
51 //_________________________________________________________________________________________________________________
53 #include <vcl/svapp.hxx>
55 //_________________________________________________________________________________________________________________
57 //_________________________________________________________________________________________________________________
61 //_________________________________________________________________________________________________________________
63 //_________________________________________________________________________________________________________________
65 #define PROTOCOL_VALUE "mailto:"
66 #define PROTOCOL_LENGTH 7
68 //_________________________________________________________________________________________________________________
69 // non exported definitions
70 //_________________________________________________________________________________________________________________
72 //_________________________________________________________________________________________________________________
74 //_________________________________________________________________________________________________________________
76 //_________________________________________________________________________________________________________________
77 // XInterface, XTypeProvider, XServiceInfo
79 DEFINE_XINTERFACE_5(MailToDispatcher
,
81 DIRECT_INTERFACE(css::lang::XTypeProvider
),
82 DIRECT_INTERFACE(css::lang::XServiceInfo
),
83 DIRECT_INTERFACE(css::frame::XDispatchProvider
),
84 DIRECT_INTERFACE(css::frame::XNotifyingDispatch
),
85 DIRECT_INTERFACE(css::frame::XDispatch
))
87 DEFINE_XTYPEPROVIDER_5(MailToDispatcher
,
88 css::lang::XTypeProvider
,
89 css::lang::XServiceInfo
,
90 css::frame::XDispatchProvider
,
91 css::frame::XNotifyingDispatch
,
92 css::frame::XDispatch
)
94 DEFINE_XSERVICEINFO_MULTISERVICE(MailToDispatcher
,
96 SERVICENAME_PROTOCOLHANDLER
,
97 IMPLEMENTATIONNAME_MAILTODISPATCHER
)
99 DEFINE_INIT_SERVICE(MailToDispatcher
,
102 I think we don't need any mutex or lock here ... because we are called by our own static method impl_createInstance()
103 to create a new instance of this class by our own supported service factory.
104 see macro DEFINE_XSERVICEINFO_MULTISERVICE and "impl_initService()" for further informations!
109 //_________________________________________________________________________________________________________________
113 @descr These initialize a new instance of ths class with needed informations for work.
116 reference to uno servicemanager for creation of new services
118 @modified 30.04.2002 14:10, as96863
120 MailToDispatcher::MailToDispatcher( const css::uno::Reference
< css::lang::XMultiServiceFactory
>& xFactory
)
121 // Init baseclasses first
122 : ThreadHelpBase( &Application::GetSolarMutex() )
125 , m_xFactory ( xFactory
)
129 //_________________________________________________________________________________________________________________
135 @modified 30.04.2002 14:10, as96863
137 MailToDispatcher::~MailToDispatcher()
142 //_________________________________________________________________________________________________________________
145 @short decide if this dispatch implementation can be used for requested URL or not
146 @descr A protocol handler is registerd for an URL pattern inside configuration and will
147 be asked by the generic dispatch mechanism inside framework, if he can handle this
148 special URL wich match his registration. He can agree by returning of a valid dispatch
149 instance or disagree by returning <NULL/>.
150 We don't create new dispatch instances here realy - we return THIS as result to handle it
151 at the same implementation.
153 @modified 02.05.2002 15:25, as96863
155 css::uno::Reference
< css::frame::XDispatch
> SAL_CALL
MailToDispatcher::queryDispatch( const css::util::URL
& aURL
,
156 const ::rtl::OUString
& /*sTarget*/ ,
157 sal_Int32
/*nFlags*/ ) throw( css::uno::RuntimeException
)
159 css::uno::Reference
< css::frame::XDispatch
> xDispatcher
;
160 if (aURL
.Complete
.compareToAscii(PROTOCOL_VALUE
,PROTOCOL_LENGTH
)==0)
165 //_________________________________________________________________________________________________________________
168 @short do the same like dispatch() but for multiple requests at the same time
171 @modified 02.05.2002 15:27, as96863
173 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
)
175 sal_Int32 nCount
= lDescriptor
.getLength();
176 css::uno::Sequence
< css::uno::Reference
< css::frame::XDispatch
> > lDispatcher( nCount
);
177 for( sal_Int32 i
=0; i
<nCount
; ++i
)
179 lDispatcher
[i
] = this->queryDispatch(
180 lDescriptor
[i
].FeatureURL
,
181 lDescriptor
[i
].FrameName
,
182 lDescriptor
[i
].SearchFlags
);
187 //_________________________________________________________________________________________________________________
190 @short dispatch URL with arguments
191 @descr We use threadsafe internal method to do so. It returns a state value - but we ignore it.
192 Because we doesn't support status listener notifications here. Status events are not guaranteed -
193 and we call another service internaly which doesn't return any notifications too.
196 mail URL which should be executed
198 list of optional arguments for this mail request
200 @modified 30.04.2002 14:15, as96863
202 void SAL_CALL
MailToDispatcher::dispatch( const css::util::URL
& aURL
,
203 const css::uno::Sequence
< css::beans::PropertyValue
>& lArguments
) throw( css::uno::RuntimeException
)
205 // dispatch() is an [oneway] call ... and may our user release his reference to us immediatly.
206 // So we should hold us self alive till this call ends.
207 css::uno::Reference
< css::frame::XNotifyingDispatch
> xSelfHold(static_cast< ::cppu::OWeakObject
* >(this), css::uno::UNO_QUERY
);
208 implts_dispatch(aURL
,lArguments
);
209 // No notification for status listener!
212 //_________________________________________________________________________________________________________________
215 @short dispatch with guaranteed notifications about success
216 @descr We use threadsafe internal method to do so. Return state of this function will be used
217 for notification if an optional listener is given.
220 mail URL which should be executed
222 list of optional arguments for this mail request
224 reference to a valid listener for state events
226 @modified 30.04.2002 14:49, as96863
228 void SAL_CALL
MailToDispatcher::dispatchWithNotification( const css::util::URL
& aURL
,
229 const css::uno::Sequence
< css::beans::PropertyValue
>& lArguments
,
230 const css::uno::Reference
< css::frame::XDispatchResultListener
>& xListener
) throw( css::uno::RuntimeException
)
232 // This class was designed to die by reference. And if user release his reference to us immediatly after calling this method
233 // we can run into some problems. So we hold us self alive till this method ends.
234 // Another reason: We can use this reference as source of sending event at the end too.
235 css::uno::Reference
< css::frame::XNotifyingDispatch
> xThis(static_cast< ::cppu::OWeakObject
* >(this), css::uno::UNO_QUERY
);
237 sal_Bool bState
= implts_dispatch(aURL
,lArguments
);
240 css::frame::DispatchResultEvent aEvent
;
242 aEvent
.State
= css::frame::DispatchResultState::SUCCESS
;
244 aEvent
.State
= css::frame::DispatchResultState::FAILURE
;
245 aEvent
.Source
= xThis
;
247 xListener
->dispatchFinished( aEvent
);
251 //_________________________________________________________________________________________________________________
254 @short threadsafe helper for dispatch calls
255 @descr We support two interfaces for the same process - dispatch URLs. That the reason for this internal
256 function. It implements the real dispatch operation and returns a state value which inform caller
257 about success. He can notify listener then by using this return value.
260 mail URL which should be executed
262 list of optional arguments for this mail request
264 @return <TRUE/> if dispatch could be started successfully
265 Note: Our internal used shell executor doesn't return any state value - so we must
266 belive that call was successfully.
267 <FALSE/> if neccessary ressource couldn't be created or an exception was thrown.
269 @modified 30.04.2002 14:49, as96863
271 sal_Bool
MailToDispatcher::implts_dispatch( const css::util::URL
& aURL
,
272 const css::uno::Sequence
< css::beans::PropertyValue
>& /*lArguments*/ ) throw( css::uno::RuntimeException
)
274 sal_Bool bSuccess
= sal_False
;
276 css::uno::Reference
< css::lang::XMultiServiceFactory
> xFactory
;
278 ReadGuard
aReadLock( m_aLock
);
279 xFactory
= m_xFactory
;
282 css::uno::Reference
< css::system::XSystemShellExecute
> xSystemShellExecute( xFactory
->createInstance(SERVICENAME_SYSTEMSHELLEXECUTE
), css::uno::UNO_QUERY
);
283 if (xSystemShellExecute
.is())
288 // Because there is no notofocation about success - we use case of
289 // no detected exception as SUCCESS - FAILED otherwhise.
290 xSystemShellExecute
->execute( aURL
.Complete
, ::rtl::OUString(), css::system::SystemShellExecuteFlags::DEFAULTS
);
293 catch (css::lang::IllegalArgumentException
&)
296 catch (css::system::SystemShellExecuteException
&)
304 //_________________________________________________________________________________________________________________
307 @short add/remove listener for state events
308 @descr Because we use an external process to forward such mail URLs, and this process doesn't
309 return any notifications about success or failed state - we doesn't support such status
310 listener. We have no status to send.
313 reference to a valid listener for state events
315 URL about listener will be informed, if something occured
317 @modified 30.04.2002 14:49, as96863
319 void SAL_CALL
MailToDispatcher::addStatusListener( const css::uno::Reference
< css::frame::XStatusListener
>& /*xListener*/ ,
320 const css::util::URL
& /*aURL*/ ) throw( css::uno::RuntimeException
)
325 //_________________________________________________________________________________________________________________
327 void SAL_CALL
MailToDispatcher::removeStatusListener( const css::uno::Reference
< css::frame::XStatusListener
>& /*xListener*/ ,
328 const css::util::URL
& /*aURL*/ ) throw( css::uno::RuntimeException
)
333 } // namespace framework