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;
37 
38  //intercept standard IO error exception (local file and WebDAV)
39  aInterceptedRequest.Handle = HANDLE_INTERACTIVEIOEXCEPTION;
40  aInterceptedRequest.Request <<= css::ucb::InteractiveIOException();
42  lInterceptions.push_back(aInterceptedRequest);
43 
44  //intercept internal error
45  aInterceptedRequest.Handle = HANDLE_UNSUPPORTEDDATASINKEXCEPTION;
46  aInterceptedRequest.Request <<= css::ucb::UnsupportedDataSinkException();
48  lInterceptions.push_back(aInterceptedRequest);
49 
50  //intercept network error exception (WebDAV ucp provider)
51  aInterceptedRequest.Handle = HANDLE_INTERACTIVENETWORKEXCEPTION;
52  aInterceptedRequest.Request <<= css::ucb::InteractiveNetworkException();
54  lInterceptions.push_back(aInterceptedRequest);
55 
56  //intercept certificate validation request (WebDAV ucp provider)
57  aInterceptedRequest.Handle = HANDLE_CERTIFICATEREQUEST;
58  aInterceptedRequest.Request <<= css::ucb::CertificateValidationRequest();
60  lInterceptions.push_back(aInterceptedRequest);
61 
62  //intercept authentication request (WebDAV ucp provider)
63  aInterceptedRequest.Handle = HANDLE_AUTHENTICATIONREQUEST;
64  aInterceptedRequest.Request <<= css::ucb::AuthenticationRequest();
66  lInterceptions.push_back(aInterceptedRequest);
67 
68  setInterceptedHandler(xHandler);
69  setInterceptions(lInterceptions);
70 }
71 
73 
75  const ::ucbhelper::InterceptedInteraction::InterceptedRequest& aRequest,
76  const css::uno::Reference<css::task::XInteractionRequest>& xRequest)
77 {
78  bool bAbort = false;
79  switch (aRequest.Handle)
80  {
81  case HANDLE_UNSUPPORTEDDATASINKEXCEPTION:
82  case HANDLE_INTERACTIVENETWORKEXCEPTION:
83  case HANDLE_INTERACTIVEIOEXCEPTION:
84  {
85  bAbort = true;
86  }
87  break;
88 
89  case HANDLE_CERTIFICATEREQUEST:
90  {
91  // use default internal handler.
92  if (m_xInterceptedHandler.is())
93  {
94  m_xInterceptedHandler->handle(xRequest);
95  return ::ucbhelper::InterceptedInteraction::E_INTERCEPTED;
96  }
97  else
98  bAbort = true;
99  break;
100  }
101 
102  case HANDLE_AUTHENTICATIONREQUEST:
103  {
104  // use default internal handler.
105  if (m_xInterceptedHandler.is())
106  {
107  m_xInterceptedHandler->handle(xRequest);
108  return ::ucbhelper::InterceptedInteraction::E_INTERCEPTED;
109  }
110  else //simply abort
111  bAbort = true;
112  }
113  break;
114  }
115 
116  // handle interaction by ourself, by not doing
117  // any selection...
118  if (bAbort)
119  {
120  css::uno::Reference<css::task::XInteractionContinuation> xAbort
122  xRequest->getContinuations(), cppu::UnoType<css::task::XInteractionAbort>::get());
123  if (!xAbort.is())
124  return ::ucbhelper::InterceptedInteraction::E_NO_CONTINUATION_FOUND;
125  return ::ucbhelper::InterceptedInteraction::E_INTERCEPTED;
126  }
127 
128  return ::ucbhelper::InterceptedInteraction::E_INTERCEPTED;
129 }
130 }
131 
132 /* 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
css::uno::Type const & get()
void setInterceptions(const ::std::vector< InterceptedRequest > &lInterceptions)
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.