25#include <com/sun/star/frame/DispatchResultEvent.hpp>
26#include <com/sun/star/frame/DispatchResultState.hpp>
27#include <com/sun/star/frame/ModuleManager.hpp>
28#include <com/sun/star/frame/XNotifyingDispatch.hpp>
29#include <com/sun/star/frame/XDispatch.hpp>
30#include <com/sun/star/frame/XStatusListener.hpp>
31#include <com/sun/star/frame/XDispatchResultListener.hpp>
32#include <com/sun/star/frame/XDispatchProvider.hpp>
33#include <com/sun/star/lang/XInitialization.hpp>
34#include <com/sun/star/lang/XServiceInfo.hpp>
56class JobDispatch :
public ::cppu::WeakImplHelper<
57 css::lang::XServiceInfo
58 , css::lang::XInitialization
59 , css::frame::XDispatchProvider
60 , css::frame::XNotifyingDispatch >
65 css::uno::Reference< css::uno::XComponentContext >
m_xContext;
68 css::uno::Reference< css::frame::XFrame >
m_xFrame;
71 OUString m_sModuleIdentifier;
77 explicit JobDispatch(css::uno::Reference< css::uno::XComponentContext > xContext);
78 virtual ~JobDispatch()
override;
80 void impl_dispatchEvent (
const OUString& sEvent ,
81 const css::uno::Sequence< css::beans::PropertyValue >& lArgs ,
82 const css::uno::Reference< css::frame::XDispatchResultListener >& xListener );
83 void impl_dispatchService(
const OUString& sService ,
84 const css::uno::Sequence< css::beans::PropertyValue >& lArgs ,
85 const css::uno::Reference< css::frame::XDispatchResultListener >& xListener );
86 void impl_dispatchAlias (
const OUString& sAlias ,
87 const css::uno::Sequence< css::beans::PropertyValue >& lArgs ,
88 const css::uno::Reference< css::frame::XDispatchResultListener >& xListener );
93 return "com.sun.star.comp.framework.jobs.JobDispatch";
103 return {
"com.sun.star.frame.ProtocolHandler"};
107 virtual void SAL_CALL initialize(
const css::uno::Sequence< css::uno::Any >& lArguments )
override;
110 virtual css::uno::Reference< css::frame::XDispatch > SAL_CALL queryDispatch (
const css::util::URL& aURL ,
111 const OUString& sTargetFrameName ,
112 sal_Int32 nSearchFlags )
override;
113 virtual css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > > SAL_CALL queryDispatches(
const css::uno::Sequence< css::frame::DispatchDescriptor >& lDescriptor )
override;
116 virtual void SAL_CALL dispatchWithNotification(
const css::util::URL& aURL ,
117 const css::uno::Sequence< css::beans::PropertyValue >& lArgs ,
118 const css::uno::Reference< css::frame::XDispatchResultListener >& xListener )
override;
121 virtual void SAL_CALL dispatch (
const css::util::URL& aURL ,
122 const css::uno::Sequence< css::beans::PropertyValue >& lArgs )
override;
123 virtual void SAL_CALL addStatusListener (
const css::uno::Reference< css::frame::XStatusListener >& xListener ,
124 const css::util::URL& aURL )
override;
125 virtual void SAL_CALL removeStatusListener(
const css::uno::Reference< css::frame::XStatusListener >& xListener ,
126 const css::util::URL& aURL )
override;
136JobDispatch::JobDispatch( css::uno::Reference< css::uno::XComponentContext > xContext )
145JobDispatch::~JobDispatch()
161void SAL_CALL JobDispatch::initialize(
const css::uno::Sequence< css::uno::Any >& lArguments )
165 for (
int a=0;
a<lArguments.getLength(); ++
a)
171 css::uno::Reference< css::frame::XModuleManager2 > xModuleManager =
172 css::frame::ModuleManager::create(
m_xContext);
175 m_sModuleIdentifier = xModuleManager->identify( m_xFrame );
177 catch(
const css::uno::Exception& )
200css::uno::Reference< css::frame::XDispatch > SAL_CALL JobDispatch::queryDispatch(
const css::util::URL& aURL ,
204 css::uno::Reference< css::frame::XDispatch >
xDispatch;
207 if (aAnalyzedURL.isValid())
225css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > > SAL_CALL JobDispatch::queryDispatches(
const css::uno::Sequence< css::frame::DispatchDescriptor >& lDescriptor )
228 sal_Int32
nCount = lDescriptor.getLength();
229 css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > > lDispatches(nCount);
230 auto lDispatchesRange = asNonConstRange(lDispatches);
232 lDispatchesRange[i] = queryDispatch( lDescriptor[i].FeatureURL ,
233 lDescriptor[i].FrameName ,
234 lDescriptor[i].SearchFlags );
262void SAL_CALL JobDispatch::dispatchWithNotification(
const css::util::URL& aURL ,
263 const css::uno::Sequence< css::beans::PropertyValue >& lArgs ,
264 const css::uno::Reference< css::frame::XDispatchResultListener >& xListener )
267 if (aAnalyzedURL.isValid())
270 if (aAnalyzedURL.getEvent(sRequest))
271 impl_dispatchEvent(sRequest, lArgs, xListener);
273 if (aAnalyzedURL.getService(sRequest))
274 impl_dispatchService(sRequest, lArgs, xListener);
276 if (aAnalyzedURL.getAlias(sRequest))
277 impl_dispatchAlias(sRequest, lArgs, xListener);
297void JobDispatch::impl_dispatchEvent(
const OUString& sEvent ,
298 const css::uno::Sequence< css::beans::PropertyValue >& lArgs ,
299 const css::uno::Reference< css::frame::XDispatchResultListener >& xListener )
304 std::vector< OUString > lJobs = JobData::getEnabledJobsForEvent(
m_xContext, sEvent);
306 css::uno::Reference< css::frame::XDispatchResultListener > xThis(
static_cast< ::
cppu::OWeakObject*
>(
this), css::uno::UNO_QUERY );
314 for (
const OUString & lJob : lJobs)
317 aCfg.setEvent(sEvent, lJob);
318 aCfg.setEnvironment(JobData::E_DISPATCH);
319 const bool bIsEnabled=aCfg.hasCorrectContext(m_sModuleIdentifier);
322 pJob->setJobData(aCfg);
333 pJob->setDispatchResultFake(xListener, xThis);
334 pJob->execute(Converter::convert_seqPropVal2seqNamedVal(lArgs));
338 if (nExecutedJobs<1 && xListener.is())
340 css::frame::DispatchResultEvent
aEvent;
342 aEvent.State = css::frame::DispatchResultState::SUCCESS;
343 xListener->dispatchFinished(aEvent);
363void JobDispatch::impl_dispatchService(
const OUString& sService ,
364 const css::uno::Sequence< css::beans::PropertyValue >& lArgs ,
365 const css::uno::Reference< css::frame::XDispatchResultListener >& xListener )
368 aCfg.setService(sService);
369 aCfg.setEnvironment(JobData::E_DISPATCH);
377 pJob->setJobData(aCfg);
379 css::uno::Reference< css::frame::XDispatchResultListener > xThis(
static_cast< ::
cppu::OWeakObject*
>(
this), css::uno::UNO_QUERY );
387 pJob->setDispatchResultFake(xListener, xThis);
388 pJob->execute(Converter::convert_seqPropVal2seqNamedVal(lArgs));
406void JobDispatch::impl_dispatchAlias(
const OUString& sAlias ,
407 const css::uno::Sequence< css::beans::PropertyValue >& lArgs ,
408 const css::uno::Reference< css::frame::XDispatchResultListener >& xListener )
411 aCfg.setAlias(sAlias);
412 aCfg.setEnvironment(JobData::E_DISPATCH);
415 pJob->setJobData(aCfg);
417 css::uno::Reference< css::frame::XDispatchResultListener > xThis(
static_cast< ::
cppu::OWeakObject*
>(
this), css::uno::UNO_QUERY );
425 pJob->setDispatchResultFake(xListener, xThis);
426 pJob->execute(Converter::convert_seqPropVal2seqNamedVal(lArgs));
442void SAL_CALL JobDispatch::dispatch(
const css::util::URL& aURL ,
443 const css::uno::Sequence< css::beans::PropertyValue >& lArgs )
445 dispatchWithNotification(aURL, lArgs, css::uno::Reference< css::frame::XDispatchResultListener >());
451void SAL_CALL JobDispatch::addStatusListener(
const css::uno::Reference< css::frame::XStatusListener >&,
452 const css::util::URL& )
459void SAL_CALL JobDispatch::removeStatusListener(
const css::uno::Reference< css::frame::XStatusListener >&,
460 const css::util::URL& )
466extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
468 css::uno::XComponentContext *context,
469 css::uno::Sequence<css::uno::Any>
const &)
471 return cppu::acquire(
new JobDispatch(context));
css::uno::Reference< css::lang::XComponent > m_xFrame
holds all necessary information about a job and handle it's configuration (if any exist!...
can be used to parse, validate and work with job URL's @descr Job URLs are specified by the following...
it represent a job; execute it and control its lifetime
Reference< XDispatch > xDispatch
css::uno::Reference< css::uno::XComponentContext > m_xContext
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_framework_jobs_JobDispatch_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)