1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #include <comphelper/simplefileaccessinteraction.hxx>
11 #include <com/sun/star/task/XInteractionAbort.hpp>
12 #include <com/sun/star/task/XInteractionApprove.hpp>
13 #include <com/sun/star/ucb/AuthenticationRequest.hpp>
14 #include <com/sun/star/ucb/CertificateValidationRequest.hpp>
15 #include <com/sun/star/ucb/InteractiveIOException.hpp>
16 #include <com/sun/star/ucb/InteractiveNetworkException.hpp>
17 #include <com/sun/star/ucb/UnsupportedDataSinkException.hpp>
21 /// Will handle com::sun::star::ucb::InteractiveIOException and derived classes
22 const sal_Int32 HANDLE_INTERACTIVEIOEXCEPTION
= 0;
23 /// Will handle com::sun::star::ucb::UnsupportedDataSinkException
24 const sal_Int32 HANDLE_UNSUPPORTEDDATASINKEXCEPTION
= 1;
25 /// Will handle com::sun::star::ucb::InteractiveNetworkException
26 const sal_Int32 HANDLE_INTERACTIVENETWORKEXCEPTION
= 2;
27 /// Will handle com::sun::star::ucb::CertificateValidationRequest
28 const sal_Int32 HANDLE_CERTIFICATEREQUEST
= 3;
29 /// Will handle com::sun::star::ucb::AuthenticationRequest
30 const sal_Int32 HANDLE_AUTHENTICATIONREQUEST
= 4;
32 SimpleFileAccessInteraction::SimpleFileAccessInteraction(
33 const css::uno::Reference
<css::task::XInteractionHandler
>& xHandler
)
35 std::vector
<::ucbhelper::InterceptedInteraction::InterceptedRequest
> lInterceptions
{
36 { //intercept standard IO error exception (local file and WebDAV)
37 css::uno::Any(css::ucb::InteractiveIOException()),
38 cppu::UnoType
<css::task::XInteractionAbort
>::get(), HANDLE_INTERACTIVEIOEXCEPTION
},
39 { //intercept internal error
40 css::uno::Any(css::ucb::UnsupportedDataSinkException()),
41 cppu::UnoType
<css::task::XInteractionAbort
>::get(), HANDLE_UNSUPPORTEDDATASINKEXCEPTION
},
43 //intercept network error exception (WebDAV ucp provider)
44 css::uno::Any(css::ucb::InteractiveNetworkException()),
45 cppu::UnoType
<css::task::XInteractionAbort
>::get(),
46 HANDLE_INTERACTIVENETWORKEXCEPTION
,
48 { //intercept certificate validation request (WebDAV ucp provider)
49 css::uno::Any(css::ucb::CertificateValidationRequest()),
50 cppu::UnoType
<css::task::XInteractionAbort
>::get(), HANDLE_CERTIFICATEREQUEST
},
51 { //intercept authentication request (WebDAV ucp provider)
52 css::uno::Any(css::ucb::AuthenticationRequest()),
53 cppu::UnoType
<css::task::XInteractionApprove
>::get(), HANDLE_AUTHENTICATIONREQUEST
}
56 setInterceptedHandler(xHandler
);
57 setInterceptions(std::move(lInterceptions
));
60 SimpleFileAccessInteraction::~SimpleFileAccessInteraction() {}
62 ucbhelper::InterceptedInteraction::EInterceptionState
SimpleFileAccessInteraction::intercepted(
63 const ::ucbhelper::InterceptedInteraction::InterceptedRequest
& aRequest
,
64 const css::uno::Reference
<css::task::XInteractionRequest
>& xRequest
)
67 switch (aRequest
.Handle
)
69 case HANDLE_UNSUPPORTEDDATASINKEXCEPTION
:
70 case HANDLE_INTERACTIVENETWORKEXCEPTION
:
71 case HANDLE_INTERACTIVEIOEXCEPTION
:
77 case HANDLE_CERTIFICATEREQUEST
:
79 // use default internal handler.
80 if (m_xInterceptedHandler
.is())
82 m_xInterceptedHandler
->handle(xRequest
);
83 return ::ucbhelper::InterceptedInteraction::E_INTERCEPTED
;
90 case HANDLE_AUTHENTICATIONREQUEST
:
92 // use default internal handler.
93 if (m_xInterceptedHandler
.is())
95 m_xInterceptedHandler
->handle(xRequest
);
96 return ::ucbhelper::InterceptedInteraction::E_INTERCEPTED
;
104 // handle interaction by ourself, by not doing
108 css::uno::Reference
<css::task::XInteractionContinuation
> xAbort
109 = ::ucbhelper::InterceptedInteraction::extractContinuation(
110 xRequest
->getContinuations(), cppu::UnoType
<css::task::XInteractionAbort
>::get());
112 return ::ucbhelper::InterceptedInteraction::E_NO_CONTINUATION_FOUND
;
113 return ::ucbhelper::InterceptedInteraction::E_INTERCEPTED
;
116 return ::ucbhelper::InterceptedInteraction::E_INTERCEPTED
;
120 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */