LibreOffice Module comphelper (master)  1
simplefileaccessinteraction.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  */
9 
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>
18 
19 namespace comphelper
20 {
22 const sal_Int32 HANDLE_INTERACTIVEIOEXCEPTION = 0;
28 const sal_Int32 HANDLE_CERTIFICATEREQUEST = 3;
30 const sal_Int32 HANDLE_AUTHENTICATIONREQUEST = 4;
31 
33  const css::uno::Reference<css::task::XInteractionHandler>& xHandler)
34 {
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 },
42  {
43  //intercept network error exception (WebDAV ucp provider)
44  css::uno::Any(css::ucb::InteractiveNetworkException()),
47  },
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 }
54  };
55 
56  setInterceptedHandler(xHandler);
57  setInterceptions(std::move(lInterceptions));
58 }
59 
61 
63  const ::ucbhelper::InterceptedInteraction::InterceptedRequest& aRequest,
64  const css::uno::Reference<css::task::XInteractionRequest>& xRequest)
65 {
66  bool bAbort = false;
67  switch (aRequest.Handle)
68  {
69  case HANDLE_UNSUPPORTEDDATASINKEXCEPTION:
70  case HANDLE_INTERACTIVENETWORKEXCEPTION:
71  case HANDLE_INTERACTIVEIOEXCEPTION:
72  {
73  bAbort = true;
74  }
75  break;
76 
77  case HANDLE_CERTIFICATEREQUEST:
78  {
79  // use default internal handler.
80  if (m_xInterceptedHandler.is())
81  {
82  m_xInterceptedHandler->handle(xRequest);
83  return ::ucbhelper::InterceptedInteraction::E_INTERCEPTED;
84  }
85  else
86  bAbort = true;
87  break;
88  }
89 
90  case HANDLE_AUTHENTICATIONREQUEST:
91  {
92  // use default internal handler.
93  if (m_xInterceptedHandler.is())
94  {
95  m_xInterceptedHandler->handle(xRequest);
96  return ::ucbhelper::InterceptedInteraction::E_INTERCEPTED;
97  }
98  else //simply abort
99  bAbort = true;
100  }
101  break;
102  }
103 
104  // handle interaction by ourself, by not doing
105  // any selection...
106  if (bAbort)
107  {
108  css::uno::Reference<css::task::XInteractionContinuation> xAbort
110  xRequest->getContinuations(), cppu::UnoType<css::task::XInteractionAbort>::get());
111  if (!xAbort.is())
112  return ::ucbhelper::InterceptedInteraction::E_NO_CONTINUATION_FOUND;
113  return ::ucbhelper::InterceptedInteraction::E_INTERCEPTED;
114  }
115 
116  return ::ucbhelper::InterceptedInteraction::E_INTERCEPTED;
117 }
118 }
119 
120 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const sal_Int32 HANDLE_UNSUPPORTEDDATASINKEXCEPTION
Will handle com::sun::star::ucb::UnsupportedDataSinkException.
static css::uno::Reference< css::task::XInteractionContinuation > extractContinuation(const css::uno::Sequence< css::uno::Reference< css::task::XInteractionContinuation > > &lContinuations, const css::uno::Type &aType)
SimpleFileAccessInteraction(const css::uno::Reference< css::task::XInteractionHandler > &xHandler)
const sal_Int32 HANDLE_INTERACTIVEIOEXCEPTION
Will handle com::sun::star::ucb::InteractiveIOException and derived classes.
virtual ucbhelper::InterceptedInteraction::EInterceptionState intercepted(const ::ucbhelper::InterceptedInteraction::InterceptedRequest &aRequest, const css::uno::Reference< css::task::XInteractionRequest > &xRequest) override
void setInterceptions(::std::vector< InterceptedRequest > &&lInterceptions)
css::uno::Type const & get()
const sal_Int32 HANDLE_CERTIFICATEREQUEST
Will handle com::sun::star::ucb::CertificateValidationRequest.
void setInterceptedHandler(const css::uno::Reference< css::task::XInteractionHandler > &xInterceptedHandler)
css::uno::Reference< css::task::XInteractionHandler > m_xInterceptedHandler
const sal_Int32 HANDLE_AUTHENTICATIONREQUEST
Will handle com::sun::star::ucb::AuthenticationRequest.
const sal_Int32 HANDLE_INTERACTIVENETWORKEXCEPTION
Will handle com::sun::star::ucb::InteractiveNetworkException.