1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_comphelper.hxx"
26 
27 /** === begin UNO includes === **/
28 #include "com/sun/star/frame/XDispatchProvider.hpp"
29 #include "com/sun/star/frame/XSynchronousDispatch.hpp"
30 #include "com/sun/star/lang/XComponent.hpp"
31 #include "com/sun/star/lang/XMultiServiceFactory.hpp"
32 #include "com/sun/star/util/XURLTransformer.hpp"
33 /** === end UNO includes === **/
34 
35 #include "comphelper/synchronousdispatch.hxx"
36 #include "comphelper/processfactory.hxx"
37 
38 #define UNISTRING(s) rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(s))
39 
40 //.........................................................................
41 namespace comphelper
42 {
43 //.........................................................................
44 
45 using namespace ::com::sun::star;
46 
47 //====================================================================
48 //= SynchronousDispatch
49 //====================================================================
50 
dispatch(const uno::Reference<uno::XInterface> & xStartPoint,const rtl::OUString & sURL,const rtl::OUString & sTarget,const sal_Int32 nFlags,const uno::Sequence<beans::PropertyValue> & lArguments)51 uno::Reference< lang::XComponent > SynchronousDispatch::dispatch(
52         const uno::Reference< uno::XInterface > &xStartPoint,
53         const rtl::OUString &sURL,
54         const rtl::OUString &sTarget,
55         const sal_Int32 nFlags,
56         const uno::Sequence< beans::PropertyValue > &lArguments )
57 {
58     util::URL aURL;
59     aURL.Complete = sURL;
60     uno::Reference < util::XURLTransformer > xTrans( ::comphelper::getProcessServiceFactory()->createInstance(
61 													               UNISTRING("com.sun.star.util.URLTransformer" )),
62                                                      uno::UNO_QUERY );
63     if ( xTrans.is() )
64         xTrans->parseStrict( aURL );
65 
66     uno::Reference < frame::XDispatch > xDispatcher;
67     uno::Reference < frame::XDispatchProvider > xProvider( xStartPoint, uno::UNO_QUERY );
68 
69     if ( xProvider.is() )
70         xDispatcher = xProvider->queryDispatch( aURL, sTarget, nFlags );
71 
72     uno::Reference < lang::XComponent > aComponent;
73 
74     if ( xDispatcher.is() )
75     {
76         try
77         {
78             uno::Any aRet;
79             uno::Reference < frame::XSynchronousDispatch > xSyncDisp( xDispatcher, uno::UNO_QUERY_THROW );
80 
81             aRet = xSyncDisp->dispatchWithReturnValue( aURL, lArguments );
82 
83             aRet >>= aComponent;
84         }
85         catch ( uno::Exception& )
86         {
87             rtl::OUString aMsg = UNISTRING( "SynchronousDispatch::dispatch() Error while dispatching! ");
88             OSL_ENSURE( sal_False, OUStringToOString(aMsg, RTL_TEXTENCODING_ASCII_US).getStr());
89         }
90     }
91 
92     return aComponent;
93 }
94 
95 //.........................................................................
96 }	// namespace comphelper
97 //.........................................................................
98 
99