1*ac9096f4SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*ac9096f4SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*ac9096f4SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*ac9096f4SAndrew Rist  * distributed with this work for additional information
6*ac9096f4SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*ac9096f4SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*ac9096f4SAndrew Rist  * "License"); you may not use this file except in compliance
9*ac9096f4SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*ac9096f4SAndrew Rist  *
11*ac9096f4SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*ac9096f4SAndrew Rist  *
13*ac9096f4SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*ac9096f4SAndrew Rist  * software distributed under the License is distributed on an
15*ac9096f4SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ac9096f4SAndrew Rist  * KIND, either express or implied.  See the License for the
17*ac9096f4SAndrew Rist  * specific language governing permissions and limitations
18*ac9096f4SAndrew Rist  * under the License.
19*ac9096f4SAndrew Rist  *
20*ac9096f4SAndrew Rist  *************************************************************/
21*ac9096f4SAndrew Rist 
22*ac9096f4SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_ucbhelper.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir /**************************************************************************
28cdf0e10cSrcweir 								TODO
29cdf0e10cSrcweir  **************************************************************************
30cdf0e10cSrcweir 
31cdf0e10cSrcweir  *************************************************************************/
32cdf0e10cSrcweir #include <osl/diagnose.h>
33cdf0e10cSrcweir #include <cppuhelper/exc_hlp.hxx>
34cdf0e10cSrcweir #include <com/sun/star/ucb/CommandFailedException.hpp>
35cdf0e10cSrcweir #include <com/sun/star/ucb/XCommandEnvironment.hpp>
36cdf0e10cSrcweir #ifndef _UCBHELPER_INTERACTIONREQUEST_HXX
37cdf0e10cSrcweir #include <ucbhelper/interactionrequest.hxx>
38cdf0e10cSrcweir #endif
39cdf0e10cSrcweir #include <ucbhelper/cancelcommandexecution.hxx>
40cdf0e10cSrcweir #include <ucbhelper/simpleioerrorrequest.hxx>
41cdf0e10cSrcweir 
42cdf0e10cSrcweir using namespace com::sun::star;
43cdf0e10cSrcweir 
44cdf0e10cSrcweir namespace ucbhelper
45cdf0e10cSrcweir {
46cdf0e10cSrcweir 
47cdf0e10cSrcweir //=========================================================================
cancelCommandExecution(const uno::Any & rException,const uno::Reference<ucb::XCommandEnvironment> & xEnv)48cdf0e10cSrcweir void cancelCommandExecution( const uno::Any & rException,
49cdf0e10cSrcweir                              const uno::Reference<
50cdf0e10cSrcweir                                         ucb::XCommandEnvironment > & xEnv )
51cdf0e10cSrcweir     throw( uno::Exception )
52cdf0e10cSrcweir {
53cdf0e10cSrcweir     if ( xEnv.is() )
54cdf0e10cSrcweir     {
55cdf0e10cSrcweir         uno::Reference<
56cdf0e10cSrcweir             task::XInteractionHandler > xIH = xEnv->getInteractionHandler();
57cdf0e10cSrcweir         if ( xIH.is() )
58cdf0e10cSrcweir         {
59cdf0e10cSrcweir             rtl::Reference< ucbhelper::InteractionRequest > xRequest
60cdf0e10cSrcweir                 = new ucbhelper::InteractionRequest( rException );
61cdf0e10cSrcweir 
62cdf0e10cSrcweir             uno::Sequence< uno::Reference< task::XInteractionContinuation > >
63cdf0e10cSrcweir                 aContinuations( 1 );
64cdf0e10cSrcweir             aContinuations[ 0 ]
65cdf0e10cSrcweir                 = new ucbhelper::InteractionAbort( xRequest.get() );
66cdf0e10cSrcweir 
67cdf0e10cSrcweir             xRequest->setContinuations( aContinuations );
68cdf0e10cSrcweir 
69cdf0e10cSrcweir             xIH->handle( xRequest.get() );
70cdf0e10cSrcweir 
71cdf0e10cSrcweir             rtl::Reference< ucbhelper::InteractionContinuation > xSelection
72cdf0e10cSrcweir 				= xRequest->getSelection();
73cdf0e10cSrcweir 
74cdf0e10cSrcweir             if ( xSelection.is() )
75cdf0e10cSrcweir                 throw ucb::CommandFailedException(
76cdf0e10cSrcweir                                     rtl::OUString(),
77cdf0e10cSrcweir                                     uno::Reference< uno::XInterface >(),
78cdf0e10cSrcweir                                     rException );
79cdf0e10cSrcweir         }
80cdf0e10cSrcweir     }
81cdf0e10cSrcweir 
82cdf0e10cSrcweir     cppu::throwException( rException );
83cdf0e10cSrcweir 
84cdf0e10cSrcweir     OSL_ENSURE( sal_False, "Return from cppu::throwException call!!!" );
85cdf0e10cSrcweir     throw uno::RuntimeException();
86cdf0e10cSrcweir }
87cdf0e10cSrcweir 
88cdf0e10cSrcweir 
89cdf0e10cSrcweir //=========================================================================
cancelCommandExecution(const ucb::IOErrorCode eError,const uno::Sequence<uno::Any> & rArgs,const uno::Reference<ucb::XCommandEnvironment> & xEnv,const rtl::OUString & rMessage,const uno::Reference<ucb::XCommandProcessor> & xContext)90cdf0e10cSrcweir void cancelCommandExecution( const ucb::IOErrorCode eError,
91cdf0e10cSrcweir                              const uno::Sequence< uno::Any > & rArgs,
92cdf0e10cSrcweir                              const uno::Reference<
93cdf0e10cSrcweir                                 ucb::XCommandEnvironment > & xEnv,
94cdf0e10cSrcweir                              const rtl::OUString & rMessage,
95cdf0e10cSrcweir                              const uno::Reference<
96cdf0e10cSrcweir                                     ucb::XCommandProcessor > & xContext )
97cdf0e10cSrcweir     throw( uno::Exception )
98cdf0e10cSrcweir {
99cdf0e10cSrcweir     rtl::Reference< ucbhelper::SimpleIOErrorRequest > xRequest
100cdf0e10cSrcweir         = new ucbhelper::SimpleIOErrorRequest(
101cdf0e10cSrcweir                                     eError, rArgs, rMessage, xContext );
102cdf0e10cSrcweir     if ( xEnv.is() )
103cdf0e10cSrcweir     {
104cdf0e10cSrcweir         uno::Reference<
105cdf0e10cSrcweir             task::XInteractionHandler > xIH = xEnv->getInteractionHandler();
106cdf0e10cSrcweir         if ( xIH.is() )
107cdf0e10cSrcweir         {
108cdf0e10cSrcweir             xIH->handle( xRequest.get() );
109cdf0e10cSrcweir 
110cdf0e10cSrcweir             rtl::Reference< ucbhelper::InteractionContinuation > xSelection
111cdf0e10cSrcweir 				= xRequest->getSelection();
112cdf0e10cSrcweir 
113cdf0e10cSrcweir             if ( xSelection.is() )
114cdf0e10cSrcweir                 throw ucb::CommandFailedException( rtl::OUString(),
115cdf0e10cSrcweir                                                    xContext,
116cdf0e10cSrcweir                                                    xRequest->getRequest() );
117cdf0e10cSrcweir         }
118cdf0e10cSrcweir     }
119cdf0e10cSrcweir 
120cdf0e10cSrcweir     cppu::throwException( xRequest->getRequest() );
121cdf0e10cSrcweir 
122cdf0e10cSrcweir     OSL_ENSURE( sal_False, "Return from cppu::throwException call!!!" );
123cdf0e10cSrcweir     throw uno::RuntimeException();
124cdf0e10cSrcweir }
125cdf0e10cSrcweir 
126cdf0e10cSrcweir }
127