bump product version to 5.0.4.1
[LibreOffice.git] / comphelper / source / misc / synchronousdispatch.cxx
blob7e650b8aa3e0ec97f3a079029e8a895e0873af16
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <com/sun/star/frame/XDispatchProvider.hpp>
22 #include <com/sun/star/frame/XSynchronousDispatch.hpp>
23 #include <com/sun/star/lang/XComponent.hpp>
24 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
25 #include <com/sun/star/util/URLTransformer.hpp>
27 #include <comphelper/synchronousdispatch.hxx>
28 #include <comphelper/processfactory.hxx>
29 #include <sal/log.hxx>
31 namespace comphelper
35 using namespace ::com::sun::star;
37 uno::Reference< lang::XComponent > SynchronousDispatch::dispatch(
38 const uno::Reference< uno::XInterface > &xStartPoint,
39 const OUString &sURL,
40 const OUString &sTarget,
41 const sal_Int32 nFlags,
42 const uno::Sequence< beans::PropertyValue > &lArguments )
44 util::URL aURL;
45 aURL.Complete = sURL;
46 uno::Reference < util::XURLTransformer > xTrans = util::URLTransformer::create( ::comphelper::getProcessComponentContext() );
47 xTrans->parseStrict( aURL );
49 uno::Reference < frame::XDispatch > xDispatcher;
50 uno::Reference < frame::XDispatchProvider > xProvider( xStartPoint, uno::UNO_QUERY );
52 if ( xProvider.is() )
53 xDispatcher = xProvider->queryDispatch( aURL, sTarget, nFlags );
55 uno::Reference < lang::XComponent > aComponent;
57 if ( xDispatcher.is() )
59 try
61 uno::Any aRet;
62 uno::Reference < frame::XSynchronousDispatch > xSyncDisp( xDispatcher, uno::UNO_QUERY_THROW );
64 aRet = xSyncDisp->dispatchWithReturnValue( aURL, lArguments );
66 aRet >>= aComponent;
68 catch ( uno::Exception& )
70 SAL_WARN("comphelper","SynchronousDispatch::dispatch() Error while dispatching!");
74 return aComponent;
78 } // namespace comphelper
81 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */