1dde7d3faSAndrew Rist /**************************************************************
2dde7d3faSAndrew Rist *
3dde7d3faSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4dde7d3faSAndrew Rist * or more contributor license agreements. See the NOTICE file
5dde7d3faSAndrew Rist * distributed with this work for additional information
6dde7d3faSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7dde7d3faSAndrew Rist * to you under the Apache License, Version 2.0 (the
8dde7d3faSAndrew Rist * "License"); you may not use this file except in compliance
9dde7d3faSAndrew Rist * with the License. You may obtain a copy of the License at
10dde7d3faSAndrew Rist *
11dde7d3faSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12dde7d3faSAndrew Rist *
13dde7d3faSAndrew Rist * Unless required by applicable law or agreed to in writing,
14dde7d3faSAndrew Rist * software distributed under the License is distributed on an
15dde7d3faSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16dde7d3faSAndrew Rist * KIND, either express or implied. See the License for the
17dde7d3faSAndrew Rist * specific language governing permissions and limitations
18dde7d3faSAndrew Rist * under the License.
19dde7d3faSAndrew Rist *
20dde7d3faSAndrew Rist *************************************************************/
21dde7d3faSAndrew Rist
22dde7d3faSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_comphelper.hxx"
26cdf0e10cSrcweir #include <comphelper/stillreadwriteinteraction.hxx>
27cdf0e10cSrcweir
28cdf0e10cSrcweir #ifndef __COM_SUN_STAR_UCB_INTERACTIVEIOEXCEPTION_HPP__
29cdf0e10cSrcweir #include <com/sun/star/ucb/InteractiveIOException.hpp>
30cdf0e10cSrcweir #endif
31cdf0e10cSrcweir
32cdf0e10cSrcweir #ifndef __COM_SUN_STAR_TASK_XINTERACTIONABORT_HPP__
33cdf0e10cSrcweir #include <com/sun/star/task/XInteractionAbort.hpp>
34cdf0e10cSrcweir #endif
35cdf0e10cSrcweir
36cdf0e10cSrcweir #ifndef __COM_SUN_STAR_UCB_UNSUPPORTEDDATASINKEXCEPTION_HPP__
37cdf0e10cSrcweir #include <com/sun/star/ucb/UnsupportedDataSinkException.hpp>
38cdf0e10cSrcweir #endif
39cdf0e10cSrcweir
409c0c1533SAndrea Pescetti #include <com/sun/star/ucb/AuthenticationRequest.hpp>
419c0c1533SAndrea Pescetti
42cdf0e10cSrcweir namespace comphelper{
43cdf0e10cSrcweir
44cdf0e10cSrcweir namespace css = ::com::sun::star;
45cdf0e10cSrcweir
StillReadWriteInteraction(const css::uno::Reference<css::task::XInteractionHandler> & xHandler,const css::uno::Reference<css::task::XInteractionHandler> & xAuthenticationHandler)469c0c1533SAndrea Pescetti StillReadWriteInteraction::StillReadWriteInteraction(const css::uno::Reference< css::task::XInteractionHandler >& xHandler,
479c0c1533SAndrea Pescetti const css::uno::Reference< css::task::XInteractionHandler >& xAuthenticationHandler)
48cdf0e10cSrcweir : m_bUsed (sal_False)
49cdf0e10cSrcweir , m_bHandledByMySelf (sal_False)
50cdf0e10cSrcweir , m_bHandledByInternalHandler(sal_False)
519c0c1533SAndrea Pescetti , m_xAuthenticationHandler(xAuthenticationHandler)
52cdf0e10cSrcweir {
53cdf0e10cSrcweir ::std::vector< ::ucbhelper::InterceptedInteraction::InterceptedRequest > lInterceptions;
54cdf0e10cSrcweir ::ucbhelper::InterceptedInteraction::InterceptedRequest aInterceptedRequest;
55cdf0e10cSrcweir
56cdf0e10cSrcweir aInterceptedRequest.Handle = HANDLE_INTERACTIVEIOEXCEPTION;
57cdf0e10cSrcweir aInterceptedRequest.Request <<= css::ucb::InteractiveIOException();
58cdf0e10cSrcweir aInterceptedRequest.Continuation = ::getCppuType(static_cast< css::uno::Reference< css::task::XInteractionAbort >* >(0));
59cdf0e10cSrcweir aInterceptedRequest.MatchExact = sal_False;
60cdf0e10cSrcweir lInterceptions.push_back(aInterceptedRequest);
61cdf0e10cSrcweir
62cdf0e10cSrcweir aInterceptedRequest.Handle = HANDLE_UNSUPPORTEDDATASINKEXCEPTION;
63cdf0e10cSrcweir aInterceptedRequest.Request <<= css::ucb::UnsupportedDataSinkException();
64cdf0e10cSrcweir aInterceptedRequest.Continuation = ::getCppuType(static_cast< css::uno::Reference< css::task::XInteractionAbort >* >(0));
65cdf0e10cSrcweir aInterceptedRequest.MatchExact = sal_False;
66cdf0e10cSrcweir lInterceptions.push_back(aInterceptedRequest);
679c0c1533SAndrea Pescetti
689c0c1533SAndrea Pescetti aInterceptedRequest.Handle = HANDLE_AUTHENTICATIONREQUESTEXCEPTION;
699c0c1533SAndrea Pescetti aInterceptedRequest.Request <<= css::ucb::AuthenticationRequest();
709c0c1533SAndrea Pescetti aInterceptedRequest.Continuation = ::getCppuType(static_cast< css::uno::Reference< css::task::XInteractionAbort >* >(0));
719c0c1533SAndrea Pescetti aInterceptedRequest.MatchExact = sal_False;
729c0c1533SAndrea Pescetti lInterceptions.push_back(aInterceptedRequest);
739c0c1533SAndrea Pescetti
74cdf0e10cSrcweir setInterceptedHandler(xHandler);
75cdf0e10cSrcweir setInterceptions(lInterceptions);
76cdf0e10cSrcweir }
77cdf0e10cSrcweir
resetInterceptions()78cdf0e10cSrcweir void StillReadWriteInteraction::resetInterceptions()
79cdf0e10cSrcweir {
80cdf0e10cSrcweir setInterceptions(::std::vector< ::ucbhelper::InterceptedInteraction::InterceptedRequest >());
81cdf0e10cSrcweir }
82cdf0e10cSrcweir
resetErrorStates()83cdf0e10cSrcweir void StillReadWriteInteraction::resetErrorStates()
84cdf0e10cSrcweir {
85cdf0e10cSrcweir m_bUsed = sal_False;
86cdf0e10cSrcweir m_bHandledByMySelf = sal_False;
87cdf0e10cSrcweir m_bHandledByInternalHandler = sal_False;
88cdf0e10cSrcweir }
89cdf0e10cSrcweir
wasWriteError()90cdf0e10cSrcweir sal_Bool StillReadWriteInteraction::wasWriteError()
91cdf0e10cSrcweir {
92cdf0e10cSrcweir return (m_bUsed && m_bHandledByMySelf);
93cdf0e10cSrcweir }
94cdf0e10cSrcweir
intercepted(const::ucbhelper::InterceptedInteraction::InterceptedRequest & aRequest,const::com::sun::star::uno::Reference<::com::sun::star::task::XInteractionRequest> & xRequest)95cdf0e10cSrcweir ucbhelper::InterceptedInteraction::EInterceptionState StillReadWriteInteraction::intercepted(const ::ucbhelper::InterceptedInteraction::InterceptedRequest& aRequest,
96cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionRequest >& xRequest)
97cdf0e10cSrcweir {
98cdf0e10cSrcweir // we are used!
99cdf0e10cSrcweir m_bUsed = sal_True;
100cdf0e10cSrcweir
101cdf0e10cSrcweir // check if its a real interception - might some parameters are not the right ones ...
102cdf0e10cSrcweir sal_Bool bAbort = sal_False;
103cdf0e10cSrcweir switch(aRequest.Handle)
104cdf0e10cSrcweir {
105cdf0e10cSrcweir case HANDLE_INTERACTIVEIOEXCEPTION:
106cdf0e10cSrcweir {
107cdf0e10cSrcweir css::ucb::InteractiveIOException exIO;
108cdf0e10cSrcweir xRequest->getRequest() >>= exIO;
109cdf0e10cSrcweir bAbort = (
110cdf0e10cSrcweir (exIO.Code == css::ucb::IOErrorCode_ACCESS_DENIED )
111cdf0e10cSrcweir || (exIO.Code == css::ucb::IOErrorCode_LOCKING_VIOLATION )
112cdf0e10cSrcweir || (exIO.Code == css::ucb::IOErrorCode_NOT_EXISTING )
113cdf0e10cSrcweir #ifdef MACOSX
114cdf0e10cSrcweir // this is a workaround for MAC, on this platform if the file is locked
115cdf0e10cSrcweir // the returned error code looks to be wrong
116cdf0e10cSrcweir || (exIO.Code == css::ucb::IOErrorCode_GENERAL )
117cdf0e10cSrcweir #endif
118cdf0e10cSrcweir );
119cdf0e10cSrcweir }
120cdf0e10cSrcweir break;
121cdf0e10cSrcweir
122cdf0e10cSrcweir case HANDLE_UNSUPPORTEDDATASINKEXCEPTION:
123cdf0e10cSrcweir {
124cdf0e10cSrcweir bAbort = sal_True;
125cdf0e10cSrcweir }
126cdf0e10cSrcweir break;
1279c0c1533SAndrea Pescetti case HANDLE_AUTHENTICATIONREQUESTEXCEPTION:
1289c0c1533SAndrea Pescetti {
1299c0c1533SAndrea Pescetti //use internal authentication dedicated handler and return
1309c0c1533SAndrea Pescetti if (m_xAuthenticationHandler.is())
1319c0c1533SAndrea Pescetti {
1329c0c1533SAndrea Pescetti m_xAuthenticationHandler->handle(xRequest);
1339c0c1533SAndrea Pescetti return ::ucbhelper::InterceptedInteraction::E_INTERCEPTED;
1349c0c1533SAndrea Pescetti }
1359c0c1533SAndrea Pescetti else //simply abort
1369c0c1533SAndrea Pescetti bAbort = sal_True;;
1379c0c1533SAndrea Pescetti }
1389c0c1533SAndrea Pescetti break;
139cdf0e10cSrcweir }
140cdf0e10cSrcweir
141cdf0e10cSrcweir // handle interaction by ourself
142cdf0e10cSrcweir if (bAbort)
143cdf0e10cSrcweir {
144cdf0e10cSrcweir m_bHandledByMySelf = sal_True;
145cdf0e10cSrcweir css::uno::Reference< css::task::XInteractionContinuation > xAbort = ::ucbhelper::InterceptedInteraction::extractContinuation(
146cdf0e10cSrcweir xRequest->getContinuations(),
147cdf0e10cSrcweir ::getCppuType(static_cast< css::uno::Reference< css::task::XInteractionAbort >* >(0)));
148cdf0e10cSrcweir if (!xAbort.is())
149cdf0e10cSrcweir return ::ucbhelper::InterceptedInteraction::E_NO_CONTINUATION_FOUND;
150cdf0e10cSrcweir xAbort->select();
151cdf0e10cSrcweir return ::ucbhelper::InterceptedInteraction::E_INTERCEPTED;
152cdf0e10cSrcweir }
153cdf0e10cSrcweir
154*4e7d57d8Smseidel // Otherwise use internal handler.
155cdf0e10cSrcweir if (m_xInterceptedHandler.is())
156cdf0e10cSrcweir {
157cdf0e10cSrcweir m_bHandledByInternalHandler = sal_True;
158cdf0e10cSrcweir m_xInterceptedHandler->handle(xRequest);
159cdf0e10cSrcweir }
160cdf0e10cSrcweir return ::ucbhelper::InterceptedInteraction::E_INTERCEPTED;
161cdf0e10cSrcweir }
162cdf0e10cSrcweir }
163