xref: /trunk/main/ucbhelper/source/provider/cancelcommandexecution.cxx (revision 9d37da743abb7db0a497688391f6e55a19f27c44)
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_ucbhelper.hxx"
26 
27 /**************************************************************************
28                                 TODO
29  **************************************************************************
30 
31  *************************************************************************/
32 #include <osl/diagnose.h>
33 #include <cppuhelper/exc_hlp.hxx>
34 #include <com/sun/star/ucb/CommandFailedException.hpp>
35 #include <com/sun/star/ucb/XCommandEnvironment.hpp>
36 #ifndef _UCBHELPER_INTERACTIONREQUEST_HXX
37 #include <ucbhelper/interactionrequest.hxx>
38 #endif
39 #include <ucbhelper/cancelcommandexecution.hxx>
40 #include <ucbhelper/simpleioerrorrequest.hxx>
41 
42 using namespace com::sun::star;
43 
44 namespace ucbhelper
45 {
46 
47 //=========================================================================
48 void cancelCommandExecution( const uno::Any & rException,
49                              const uno::Reference<
50                                         ucb::XCommandEnvironment > & xEnv )
51 {
52     if ( xEnv.is() )
53     {
54         uno::Reference<
55             task::XInteractionHandler > xIH = xEnv->getInteractionHandler();
56         if ( xIH.is() )
57         {
58             rtl::Reference< ucbhelper::InteractionRequest > xRequest
59                 = new ucbhelper::InteractionRequest( rException );
60 
61             uno::Sequence< uno::Reference< task::XInteractionContinuation > >
62                 aContinuations( 1 );
63             aContinuations[ 0 ]
64                 = new ucbhelper::InteractionAbort( xRequest.get() );
65 
66             xRequest->setContinuations( aContinuations );
67 
68             xIH->handle( xRequest.get() );
69 
70             rtl::Reference< ucbhelper::InteractionContinuation > xSelection
71                 = xRequest->getSelection();
72 
73             if ( xSelection.is() )
74                 throw ucb::CommandFailedException(
75                                     rtl::OUString(),
76                                     uno::Reference< uno::XInterface >(),
77                                     rException );
78         }
79     }
80 
81     cppu::throwException( rException );
82 
83     OSL_ENSURE( sal_False, "Return from cppu::throwException call!!!" );
84     throw uno::RuntimeException();
85 }
86 
87 
88 //=========================================================================
89 void cancelCommandExecution( const ucb::IOErrorCode eError,
90                              const uno::Sequence< uno::Any > & rArgs,
91                              const uno::Reference<
92                                 ucb::XCommandEnvironment > & xEnv,
93                              const rtl::OUString & rMessage,
94                              const uno::Reference<
95                                     ucb::XCommandProcessor > & xContext )
96 {
97     rtl::Reference< ucbhelper::SimpleIOErrorRequest > xRequest
98         = new ucbhelper::SimpleIOErrorRequest(
99                                     eError, rArgs, rMessage, xContext );
100     if ( xEnv.is() )
101     {
102         uno::Reference<
103             task::XInteractionHandler > xIH = xEnv->getInteractionHandler();
104         if ( xIH.is() )
105         {
106             xIH->handle( xRequest.get() );
107 
108             rtl::Reference< ucbhelper::InteractionContinuation > xSelection
109                 = xRequest->getSelection();
110 
111             if ( xSelection.is() )
112                 throw ucb::CommandFailedException( rtl::OUString(),
113                                                    xContext,
114                                                    xRequest->getRequest() );
115         }
116     }
117 
118     cppu::throwException( xRequest->getRequest() );
119 
120     OSL_ENSURE( sal_False, "Return from cppu::throwException call!!!" );
121     throw uno::RuntimeException();
122 }
123 
124 }
125