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 static const sal_Int32 HANDLE_INTERACTIVEIOEXCEPTION = 0;
24 static const sal_Int32 HANDLE_UNSUPPORTEDDATASINKEXCEPTION = 1;
26 static const sal_Int32 HANDLE_INTERACTIVENETWORKEXCEPTION = 2;
28 static const sal_Int32 HANDLE_CERTIFICATEREQUEST = 3;
30 static 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 {
74 }
75 
77  const ::ucbhelper::InterceptedInteraction::InterceptedRequest& aRequest,
78  const css::uno::Reference< css::task::XInteractionRequest >& xRequest)
79 {
80  bool bAbort = false;
81  switch(aRequest.Handle)
82  {
83  case HANDLE_UNSUPPORTEDDATASINKEXCEPTION:
84  case HANDLE_INTERACTIVENETWORKEXCEPTION:
85  case HANDLE_INTERACTIVEIOEXCEPTION:
86  {
87  bAbort = true;
88  }
89  break;
90 
91  case HANDLE_CERTIFICATEREQUEST:
92  {
93  // use default internal handler.
94  if (m_xInterceptedHandler.is())
95  {
96  m_xInterceptedHandler->handle(xRequest);
97  return ::ucbhelper::InterceptedInteraction::E_INTERCEPTED;
98  }
99  else
100  bAbort = true;
101  break;
102  }
103 
104  case HANDLE_AUTHENTICATIONREQUEST:
105  {
106  // use default internal handler.
107  if (m_xInterceptedHandler.is())
108  {
109  m_xInterceptedHandler->handle(xRequest);
110  return ::ucbhelper::InterceptedInteraction::E_INTERCEPTED;
111  }
112  else //simply abort
113  bAbort = true;
114  }
115  break;
116  }
117 
118  // handle interaction by ourself, by not doing
119  // any selection...
120  if (bAbort)
121  {
122  css::uno::Reference< css::task::XInteractionContinuation > xAbort =
124  xRequest->getContinuations(),
126  if (!xAbort.is())
127  return ::ucbhelper::InterceptedInteraction::E_NO_CONTINUATION_FOUND;
128  return ::ucbhelper::InterceptedInteraction::E_INTERCEPTED;
129  }
130 
131  return ::ucbhelper::InterceptedInteraction::E_INTERCEPTED;
132 }
133 }
134 
135 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static 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)
static 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)
static 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
static const sal_Int32 HANDLE_AUTHENTICATIONREQUEST
Will handle com::sun::star::ucb::AuthenticationRequest.
static const sal_Int32 HANDLE_INTERACTIVENETWORKEXCEPTION
Will handle com::sun::star::ucb::InteractiveNetworkException.