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 //=========================================================================
cancelCommandExecution(const uno::Any & rException,const uno::Reference<ucb::XCommandEnvironment> & xEnv)48 void cancelCommandExecution( const uno::Any & rException,
49                              const uno::Reference<
50                                         ucb::XCommandEnvironment > & xEnv )
51     throw( uno::Exception )
52 {
53     if ( xEnv.is() )
54     {
55         uno::Reference<
56             task::XInteractionHandler > xIH = xEnv->getInteractionHandler();
57         if ( xIH.is() )
58         {
59             rtl::Reference< ucbhelper::InteractionRequest > xRequest
60                 = new ucbhelper::InteractionRequest( rException );
61 
62             uno::Sequence< uno::Reference< task::XInteractionContinuation > >
63                 aContinuations( 1 );
64             aContinuations[ 0 ]
65                 = new ucbhelper::InteractionAbort( xRequest.get() );
66 
67             xRequest->setContinuations( aContinuations );
68 
69             xIH->handle( xRequest.get() );
70 
71             rtl::Reference< ucbhelper::InteractionContinuation > xSelection
72 				= xRequest->getSelection();
73 
74             if ( xSelection.is() )
75                 throw ucb::CommandFailedException(
76                                     rtl::OUString(),
77                                     uno::Reference< uno::XInterface >(),
78                                     rException );
79         }
80     }
81 
82     cppu::throwException( rException );
83 
84     OSL_ENSURE( sal_False, "Return from cppu::throwException call!!!" );
85     throw uno::RuntimeException();
86 }
87 
88 
89 //=========================================================================
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)90 void cancelCommandExecution( const ucb::IOErrorCode eError,
91                              const uno::Sequence< uno::Any > & rArgs,
92                              const uno::Reference<
93                                 ucb::XCommandEnvironment > & xEnv,
94                              const rtl::OUString & rMessage,
95                              const uno::Reference<
96                                     ucb::XCommandProcessor > & xContext )
97     throw( uno::Exception )
98 {
99     rtl::Reference< ucbhelper::SimpleIOErrorRequest > xRequest
100         = new ucbhelper::SimpleIOErrorRequest(
101                                     eError, rArgs, rMessage, xContext );
102     if ( xEnv.is() )
103     {
104         uno::Reference<
105             task::XInteractionHandler > xIH = xEnv->getInteractionHandler();
106         if ( xIH.is() )
107         {
108             xIH->handle( xRequest.get() );
109 
110             rtl::Reference< ucbhelper::InteractionContinuation > xSelection
111 				= xRequest->getSelection();
112 
113             if ( xSelection.is() )
114                 throw ucb::CommandFailedException( rtl::OUString(),
115                                                    xContext,
116                                                    xRequest->getRequest() );
117         }
118     }
119 
120     cppu::throwException( xRequest->getRequest() );
121 
122     OSL_ENSURE( sal_False, "Return from cppu::throwException call!!!" );
123     throw uno::RuntimeException();
124 }
125 
126 }
127