Update ooo320-m1
[ooovba.git] / comphelper / source / misc / synchronousdispatch.cxx
blob4d7b6e8dd8f3912bfb4420ef211b438126753d65
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: synchronousdispatch.cxx,v $
10 * $Revision: 1.2 $
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_comphelper.hxx"
34 /** === begin UNO includes === **/
35 #include "com/sun/star/frame/XDispatchProvider.hpp"
36 #include "com/sun/star/frame/XSynchronousDispatch.hpp"
37 #include "com/sun/star/lang/XComponent.hpp"
38 #include "com/sun/star/lang/XMultiServiceFactory.hpp"
39 #include "com/sun/star/util/XURLTransformer.hpp"
40 /** === end UNO includes === **/
42 #include "comphelper/synchronousdispatch.hxx"
43 #include "comphelper/processfactory.hxx"
45 #define UNISTRING(s) rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(s))
47 //.........................................................................
48 namespace comphelper
50 //.........................................................................
52 using namespace ::com::sun::star;
54 //====================================================================
55 //= SynchronousDispatch
56 //====================================================================
58 uno::Reference< lang::XComponent > SynchronousDispatch::dispatch(
59 const uno::Reference< uno::XInterface > &xStartPoint,
60 const rtl::OUString &sURL,
61 const rtl::OUString &sTarget,
62 const sal_Int32 nFlags,
63 const uno::Sequence< beans::PropertyValue > &lArguments )
65 util::URL aURL;
66 aURL.Complete = sURL;
67 uno::Reference < util::XURLTransformer > xTrans( ::comphelper::getProcessServiceFactory()->createInstance(
68 UNISTRING("com.sun.star.util.URLTransformer" )),
69 uno::UNO_QUERY );
70 if ( xTrans.is() )
71 xTrans->parseStrict( aURL );
73 uno::Reference < frame::XDispatch > xDispatcher;
74 uno::Reference < frame::XDispatchProvider > xProvider( xStartPoint, uno::UNO_QUERY );
76 if ( xProvider.is() )
77 xDispatcher = xProvider->queryDispatch( aURL, sTarget, nFlags );
79 uno::Reference < lang::XComponent > aComponent;
81 if ( xDispatcher.is() )
83 try
85 uno::Any aRet;
86 uno::Reference < frame::XSynchronousDispatch > xSyncDisp( xDispatcher, uno::UNO_QUERY_THROW );
88 aRet = xSyncDisp->dispatchWithReturnValue( aURL, lArguments );
90 aRet >>= aComponent;
92 catch ( uno::Exception& )
94 rtl::OUString aMsg = UNISTRING( "SynchronousDispatch::dispatch() Error while dispatching! ");
95 OSL_ENSURE( sal_False, OUStringToOString(aMsg, RTL_TEXTENCODING_ASCII_US).getStr());
99 return aComponent;
102 //.........................................................................
103 } // namespace comphelper
104 //.........................................................................