merged tag ooo/OOO330_m14
[LibreOffice.git] / comphelper / source / misc / stillreadwriteinteraction.cxx
blob9054f0754b5e5ee3adebc214e6e6f2b92c048eef
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_comphelper.hxx"
30 #include <comphelper/stillreadwriteinteraction.hxx>
32 #ifndef __COM_SUN_STAR_UCB_INTERACTIVEIOEXCEPTION_HPP__
33 #include <com/sun/star/ucb/InteractiveIOException.hpp>
34 #endif
36 #ifndef __COM_SUN_STAR_TASK_XINTERACTIONABORT_HPP__
37 #include <com/sun/star/task/XInteractionAbort.hpp>
38 #endif
40 #ifndef __COM_SUN_STAR_UCB_UNSUPPORTEDDATASINKEXCEPTION_HPP__
41 #include <com/sun/star/ucb/UnsupportedDataSinkException.hpp>
42 #endif
44 namespace comphelper{
46 namespace css = ::com::sun::star;
48 StillReadWriteInteraction::StillReadWriteInteraction(const css::uno::Reference< css::task::XInteractionHandler >& xHandler)
49 : m_bUsed (sal_False)
50 , m_bHandledByMySelf (sal_False)
51 , m_bHandledByInternalHandler(sal_False)
53 ::std::vector< ::ucbhelper::InterceptedInteraction::InterceptedRequest > lInterceptions;
54 ::ucbhelper::InterceptedInteraction::InterceptedRequest aInterceptedRequest;
56 aInterceptedRequest.Handle = HANDLE_INTERACTIVEIOEXCEPTION;
57 aInterceptedRequest.Request <<= css::ucb::InteractiveIOException();
58 aInterceptedRequest.Continuation = ::getCppuType(static_cast< css::uno::Reference< css::task::XInteractionAbort >* >(0));
59 aInterceptedRequest.MatchExact = sal_False;
60 lInterceptions.push_back(aInterceptedRequest);
62 aInterceptedRequest.Handle = HANDLE_UNSUPPORTEDDATASINKEXCEPTION;
63 aInterceptedRequest.Request <<= css::ucb::UnsupportedDataSinkException();
64 aInterceptedRequest.Continuation = ::getCppuType(static_cast< css::uno::Reference< css::task::XInteractionAbort >* >(0));
65 aInterceptedRequest.MatchExact = sal_False;
66 lInterceptions.push_back(aInterceptedRequest);
68 setInterceptedHandler(xHandler);
69 setInterceptions(lInterceptions);
72 void StillReadWriteInteraction::resetInterceptions()
74 setInterceptions(::std::vector< ::ucbhelper::InterceptedInteraction::InterceptedRequest >());
77 void StillReadWriteInteraction::resetErrorStates()
79 m_bUsed = sal_False;
80 m_bHandledByMySelf = sal_False;
81 m_bHandledByInternalHandler = sal_False;
84 sal_Bool StillReadWriteInteraction::wasWriteError()
86 return (m_bUsed && m_bHandledByMySelf);
89 ucbhelper::InterceptedInteraction::EInterceptionState StillReadWriteInteraction::intercepted(const ::ucbhelper::InterceptedInteraction::InterceptedRequest& aRequest,
90 const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionRequest >& xRequest)
92 // we are used!
93 m_bUsed = sal_True;
95 // check if its a real interception - might some parameters are not the right ones ...
96 sal_Bool bAbort = sal_False;
97 switch(aRequest.Handle)
99 case HANDLE_INTERACTIVEIOEXCEPTION:
101 css::ucb::InteractiveIOException exIO;
102 xRequest->getRequest() >>= exIO;
103 bAbort = (
104 (exIO.Code == css::ucb::IOErrorCode_ACCESS_DENIED )
105 || (exIO.Code == css::ucb::IOErrorCode_LOCKING_VIOLATION )
106 || (exIO.Code == css::ucb::IOErrorCode_NOT_EXISTING )
107 #ifdef MACOSX
108 // this is a workaround for MAC, on this platform if the file is locked
109 // the returned error code looks to be wrong
110 || (exIO.Code == css::ucb::IOErrorCode_GENERAL )
111 #endif
114 break;
116 case HANDLE_UNSUPPORTEDDATASINKEXCEPTION:
118 bAbort = sal_True;
120 break;
123 // handle interaction by ourself
124 if (bAbort)
126 m_bHandledByMySelf = sal_True;
127 css::uno::Reference< css::task::XInteractionContinuation > xAbort = ::ucbhelper::InterceptedInteraction::extractContinuation(
128 xRequest->getContinuations(),
129 ::getCppuType(static_cast< css::uno::Reference< css::task::XInteractionAbort >* >(0)));
130 if (!xAbort.is())
131 return ::ucbhelper::InterceptedInteraction::E_NO_CONTINUATION_FOUND;
132 xAbort->select();
133 return ::ucbhelper::InterceptedInteraction::E_INTERCEPTED;
136 // Otherwhise use internal handler.
137 if (m_xInterceptedHandler.is())
139 m_bHandledByInternalHandler = sal_True;
140 m_xInterceptedHandler->handle(xRequest);
142 return ::ucbhelper::InterceptedInteraction::E_INTERCEPTED;