1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_comphelper.hxx"
30 
31 /** === begin UNO includes === **/
32 #include "com/sun/star/frame/XDispatchProvider.hpp"
33 #include "com/sun/star/frame/XSynchronousDispatch.hpp"
34 #include "com/sun/star/lang/XComponent.hpp"
35 #include "com/sun/star/lang/XMultiServiceFactory.hpp"
36 #include "com/sun/star/util/XURLTransformer.hpp"
37 /** === end UNO includes === **/
38 
39 #include "comphelper/synchronousdispatch.hxx"
40 #include "comphelper/processfactory.hxx"
41 
42 #define UNISTRING(s) rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(s))
43 
44 //.........................................................................
45 namespace comphelper
46 {
47 //.........................................................................
48 
49 using namespace ::com::sun::star;
50 
51 //====================================================================
52 //= SynchronousDispatch
53 //====================================================================
54 
55 uno::Reference< lang::XComponent > SynchronousDispatch::dispatch(
56         const uno::Reference< uno::XInterface > &xStartPoint,
57         const rtl::OUString &sURL,
58         const rtl::OUString &sTarget,
59         const sal_Int32 nFlags,
60         const uno::Sequence< beans::PropertyValue > &lArguments )
61 {
62     util::URL aURL;
63     aURL.Complete = sURL;
64     uno::Reference < util::XURLTransformer > xTrans( ::comphelper::getProcessServiceFactory()->createInstance(
65 													               UNISTRING("com.sun.star.util.URLTransformer" )),
66                                                      uno::UNO_QUERY );
67     if ( xTrans.is() )
68         xTrans->parseStrict( aURL );
69 
70     uno::Reference < frame::XDispatch > xDispatcher;
71     uno::Reference < frame::XDispatchProvider > xProvider( xStartPoint, uno::UNO_QUERY );
72 
73     if ( xProvider.is() )
74         xDispatcher = xProvider->queryDispatch( aURL, sTarget, nFlags );
75 
76     uno::Reference < lang::XComponent > aComponent;
77 
78     if ( xDispatcher.is() )
79     {
80         try
81         {
82             uno::Any aRet;
83             uno::Reference < frame::XSynchronousDispatch > xSyncDisp( xDispatcher, uno::UNO_QUERY_THROW );
84 
85             aRet = xSyncDisp->dispatchWithReturnValue( aURL, lArguments );
86 
87             aRet >>= aComponent;
88         }
89         catch ( uno::Exception& )
90         {
91             rtl::OUString aMsg = UNISTRING( "SynchronousDispatch::dispatch() Error while dispatching! ");
92             OSL_ENSURE( sal_False, OUStringToOString(aMsg, RTL_TEXTENCODING_ASCII_US).getStr());
93         }
94     }
95 
96     return aComponent;
97 }
98 
99 //.........................................................................
100 }	// namespace comphelper
101 //.........................................................................
102 
103