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