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