LCOV - code coverage report
Current view: top level - uui/source - iahndl.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 8 600 1.3 %
Date: 2014-04-11 Functions: 3 30 10.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <memory>
      21             : 
      22             : #include "com/sun/star/awt/XWindow.hpp"
      23             : #include "com/sun/star/beans/PropertyValue.hpp"
      24             : #include "com/sun/star/configuration/theDefaultProvider.hpp"
      25             : #include "com/sun/star/configuration/backend/MergeRecoveryRequest.hpp"
      26             : #include "com/sun/star/configuration/backend/StratumCreationException.hpp"
      27             : #include "com/sun/star/container/XHierarchicalNameAccess.hpp"
      28             : #include "com/sun/star/document/BrokenPackageRequest.hpp"
      29             : #include "com/sun/star/task/DocumentMacroConfirmationRequest.hpp"
      30             : #include "com/sun/star/java/WrongJavaVersionException.hpp"
      31             : #include "com/sun/star/lang/XInitialization.hpp"
      32             : #include "com/sun/star/lang/XMultiServiceFactory.hpp"
      33             : #include "com/sun/star/script/ModuleSizeExceededRequest.hpp"
      34             : #include "com/sun/star/task/ErrorCodeIOException.hpp"
      35             : #include "com/sun/star/task/ErrorCodeRequest.hpp"
      36             : #include "com/sun/star/task/FutureDocumentVersionProductUpdateRequest.hpp"
      37             : #include "com/sun/star/task/InteractionHandler.hpp"
      38             : #include "com/sun/star/task/XInteractionAbort.hpp"
      39             : #include "com/sun/star/task/XInteractionApprove.hpp"
      40             : #include "com/sun/star/task/XInteractionAskLater.hpp"
      41             : #include "com/sun/star/task/XInteractionDisapprove.hpp"
      42             : #include "com/sun/star/task/XInteractionHandler2.hpp"
      43             : #include "com/sun/star/task/XInteractionRequest.hpp"
      44             : #include "com/sun/star/task/XInteractionRetry.hpp"
      45             : #include "com/sun/star/ucb/InteractiveAppException.hpp"
      46             : #include "com/sun/star/ucb/InteractiveLockingLockedException.hpp"
      47             : #include "com/sun/star/ucb/InteractiveLockingNotLockedException.hpp"
      48             : #include "com/sun/star/ucb/InteractiveLockingLockExpiredException.hpp"
      49             : #include "com/sun/star/ucb/InteractiveNetworkConnectException.hpp"
      50             : #include "com/sun/star/ucb/InteractiveNetworkOffLineException.hpp"
      51             : #include "com/sun/star/ucb/InteractiveNetworkReadException.hpp"
      52             : #include "com/sun/star/ucb/InteractiveNetworkResolveNameException.hpp"
      53             : #include "com/sun/star/ucb/InteractiveNetworkWriteException.hpp"
      54             : #include "com/sun/star/ucb/InteractiveWrongMediumException.hpp"
      55             : #include "com/sun/star/ucb/NameClashException.hpp"
      56             : #include "com/sun/star/ucb/NameClashResolveRequest.hpp"
      57             : #include "com/sun/star/ucb/UnsupportedNameClashException.hpp"
      58             : #include "com/sun/star/ucb/XInteractionReplaceExistingData.hpp"
      59             : #include "com/sun/star/ucb/XInteractionSupplyName.hpp"
      60             : #include "com/sun/star/xforms/InvalidDataOnSubmitException.hpp"
      61             : #include "com/sun/star/loader/CannotActivateFactoryException.hpp"
      62             : 
      63             : #include <rtl/strbuf.hxx>
      64             : #include "osl/conditn.hxx"
      65             : #include "tools/rcid.h"
      66             : #include "tools/errinf.hxx"
      67             : #include "osl/mutex.hxx"
      68             : #include "osl/thread.hxx"
      69             : #include "tools/diagnose_ex.h"
      70             : #include "comphelper/documentconstants.hxx"
      71             : #include "svtools/sfxecode.hxx"
      72             : #include "vcl/msgbox.hxx"
      73             : #include "vcl/svapp.hxx"
      74             : #include "unotools/configmgr.hxx"
      75             : #include "toolkit/helper/vclunohelper.hxx"
      76             : #include "comphelper/processfactory.hxx"
      77             : #include "comphelper/namedvaluecollection.hxx"
      78             : #include "typelib/typedescription.hxx"
      79             : #include "unotools/confignode.hxx"
      80             : 
      81             : #include "ids.hrc"
      82             : 
      83             : #include "getcontinuations.hxx"
      84             : #include "secmacrowarnings.hxx"
      85             : #include "newerverwarn.hxx"
      86             : 
      87             : #include "iahndl.hxx"
      88             : #include "nameclashdlg.hxx"
      89             : 
      90             : #include <boost/scoped_ptr.hpp>
      91             : 
      92             : using ::com::sun::star::uno::Sequence;
      93             : using ::com::sun::star::uno::UNO_QUERY;
      94             : using ::com::sun::star::uno::Reference;
      95             : using ::com::sun::star::task::XInteractionContinuation;
      96             : using ::com::sun::star::task::XInteractionAbort;
      97             : using ::com::sun::star::task::XInteractionApprove;
      98             : using ::com::sun::star::task::XInteractionAskLater;
      99             : using ::com::sun::star::task::FutureDocumentVersionProductUpdateRequest;
     100             : using ::com::sun::star::uno::XInterface;
     101             : using ::com::sun::star::lang::XInitialization;
     102             : using ::com::sun::star::uno::UNO_QUERY_THROW;
     103             : using ::com::sun::star::task::InteractionHandler;
     104             : using ::com::sun::star::task::XInteractionHandler2;
     105             : using ::com::sun::star::uno::Exception;
     106             : using ::com::sun::star::uno::Any;
     107             : using ::com::sun::star::task::XInteractionRequest;
     108             : using ::com::sun::star::lang::XMultiServiceFactory;
     109             : 
     110             : using namespace ::com::sun::star;
     111             : 
     112             : namespace {
     113             : 
     114           0 : class HandleData : public osl::Condition
     115             : {
     116             : public:
     117           0 :     HandleData(
     118             :         uno::Reference< task::XInteractionRequest > const & rRequest)
     119             :         : osl::Condition(),
     120             :           m_rRequest(rRequest),
     121           0 :           bHandled( false )
     122             :     {
     123           0 :     }
     124             :     uno::Reference< task::XInteractionRequest > m_rRequest;
     125             :     bool                                        bHandled;
     126             :     beans::Optional< OUString >            m_aResult;
     127             : };
     128             : 
     129             : } /* namespace */
     130             : 
     131         449 : UUIInteractionHelper::UUIInteractionHelper(
     132             :     uno::Reference< uno::XComponentContext > const & rxContext,
     133             :     uno::Reference< awt::XWindow > const & rxWindowParam,
     134             :     const OUString & rContextParam)
     135             :     SAL_THROW(()):
     136             :         m_xContext(rxContext),
     137             :         m_xWindowParam(rxWindowParam),
     138         449 :         m_aContextParam(rContextParam)
     139             : {
     140         449 : }
     141             : 
     142         453 : UUIInteractionHelper::UUIInteractionHelper(
     143             :     uno::Reference< uno::XComponentContext > const & rxContext)
     144             :     SAL_THROW(()):
     145         453 :         m_xContext(rxContext)
     146             : {
     147         453 : }
     148             : 
     149         900 : UUIInteractionHelper::~UUIInteractionHelper()
     150             : {
     151         900 : }
     152             : 
     153             : long
     154           0 : UUIInteractionHelper::handlerequest(
     155             :     void* pHandleData, void* pInteractionHelper)
     156             : {
     157             :     HandleData* pHND
     158           0 :         = static_cast< HandleData * >(pHandleData);
     159             :     UUIInteractionHelper* pUUI
     160           0 :         = static_cast< UUIInteractionHelper * >(pInteractionHelper);
     161           0 :     bool bDummy = false;
     162           0 :     OUString aDummy;
     163             :     pHND->bHandled
     164           0 :         = pUUI->handleRequest_impl(pHND->m_rRequest, false, bDummy, aDummy);
     165           0 :     pHND->set();
     166           0 :     return 0;
     167             : }
     168             : 
     169             : bool
     170           0 : UUIInteractionHelper::handleRequest(
     171             :     uno::Reference< task::XInteractionRequest > const & rRequest)
     172             :     SAL_THROW((uno::RuntimeException))
     173             : {
     174           0 :     Application* pApp = 0;
     175           0 :     if(
     176             :         // be aware,it is the same type
     177             :         static_cast< oslThreadIdentifier >(
     178           0 :             Application::GetMainThreadIdentifier())
     179           0 :         != osl::Thread::getCurrentIdentifier()
     180           0 :         &&
     181             :         (pApp = GetpApp())
     182             :         != 0
     183             :     ) {
     184             :         // we are not in the main thread, let it handle that stuff
     185           0 :         HandleData aHD(rRequest);
     186           0 :         Link aLink(&aHD,handlerequest);
     187           0 :         pApp->PostUserEvent(aLink,this);
     188           0 :         sal_uLong locks = Application::ReleaseSolarMutex();
     189           0 :         aHD.wait();
     190           0 :         Application::AcquireSolarMutex(locks);
     191           0 :         return aHD.bHandled;
     192             :     }
     193             :     else
     194             :     {
     195           0 :         bool bDummy = false;
     196           0 :         OUString aDummy;
     197           0 :         return handleRequest_impl(rRequest, false, bDummy, aDummy);
     198             :     }
     199             : }
     200             : 
     201             : long
     202           0 : UUIInteractionHelper::getstringfromrequest(
     203             :     void* pHandleData,void* pInteractionHelper)
     204             : {
     205           0 :     HandleData* pHND = (HandleData*) pHandleData;
     206           0 :     UUIInteractionHelper* pUUI = (UUIInteractionHelper*) pInteractionHelper;
     207           0 :     pHND->m_aResult = pUUI->getStringFromRequest_impl(pHND->m_rRequest);
     208           0 :     pHND->set();
     209           0 :     return 0;
     210             : }
     211             : 
     212             : beans::Optional< OUString >
     213           0 : UUIInteractionHelper::getStringFromRequest_impl(
     214             :     uno::Reference< task::XInteractionRequest > const & rRequest)
     215             :     SAL_THROW((uno::RuntimeException))
     216             : {
     217           0 :     bool bSuccess = false;
     218           0 :     OUString aMessage;
     219           0 :     handleRequest_impl(rRequest, true, bSuccess, aMessage);
     220             : 
     221             :     OSL_ENSURE(bSuccess ||
     222             :                !isInformationalErrorMessageRequest(
     223             :                    rRequest->getContinuations()),
     224             :                "Interaction request is a candidate for a string representation."
     225             :                "Please implement!");
     226             : 
     227           0 :     return beans::Optional< OUString >(bSuccess, aMessage);
     228             : }
     229             : 
     230             : beans::Optional< OUString >
     231           0 : UUIInteractionHelper::getStringFromRequest(
     232             :     uno::Reference< task::XInteractionRequest > const & rRequest)
     233             :     SAL_THROW((uno::RuntimeException))
     234             : {
     235           0 :     Application* pApp = 0;
     236           0 :     if(
     237             :         // be aware,it is the same type
     238             :         static_cast< oslThreadIdentifier >(
     239           0 :             Application::GetMainThreadIdentifier())
     240           0 :         != osl::Thread::getCurrentIdentifier()
     241           0 :         &&
     242             :         (pApp = GetpApp())
     243             :         != 0
     244             :     ) {
     245             :         // we are not in the main thread, let it handle that stuff
     246           0 :         HandleData aHD(rRequest);
     247           0 :         Link aLink(&aHD,getstringfromrequest);
     248           0 :         pApp->PostUserEvent(aLink,this);
     249           0 :         sal_uLong locks = Application::ReleaseSolarMutex();
     250           0 :         aHD.wait();
     251           0 :         Application::AcquireSolarMutex(locks);
     252           0 :         return aHD.m_aResult;
     253             :     }
     254             :     else
     255           0 :         return getStringFromRequest_impl(rRequest);
     256             : }
     257             : 
     258             : OUString
     259           0 : UUIInteractionHelper::replaceMessageWithArguments(
     260             :     const OUString& _aMessage,
     261             :     std::vector< OUString > const & rArguments )
     262             : {
     263           0 :     OUString aMessage = _aMessage;
     264           0 :     for (sal_Int32 i = 0;;)
     265             :     {
     266           0 :         i = aMessage.indexOf("$(ARG", i);
     267           0 :         if (i == -1)
     268           0 :             break;
     269           0 :         if (aMessage.getLength() - i >= RTL_CONSTASCII_LENGTH("$(ARGx)")
     270           0 :             && aMessage[i + RTL_CONSTASCII_LENGTH("$(ARGx")] == ')')
     271             :         {
     272           0 :             sal_Unicode c = aMessage[i + RTL_CONSTASCII_LENGTH("$(ARG")];
     273           0 :             if (c >= '1' && c <= '2')
     274             :             {
     275             :                 std::vector< OUString >::size_type nIndex
     276             :                     = static_cast< std::vector< OUString >::size_type >(
     277           0 :                         c - '1');
     278           0 :                 if (nIndex < rArguments.size())
     279             :                 {
     280             :                     aMessage
     281           0 :                         = aMessage.replaceAt(i,
     282           0 :                                              RTL_CONSTASCII_LENGTH("$(ARGx)"),
     283           0 :                                              rArguments[nIndex]);
     284           0 :                     i += rArguments[nIndex].getLength();
     285           0 :                     continue;
     286             :                 }
     287             :             }
     288             :         }
     289           0 :         ++i;
     290           0 :     }
     291             : 
     292           0 :     return aMessage;
     293             : }
     294             : 
     295             : bool
     296           0 : UUIInteractionHelper::isInformationalErrorMessageRequest(
     297             :     uno::Sequence< uno::Reference< task::XInteractionContinuation > > const &
     298             :         rContinuations)
     299             : {
     300             :     // Only requests with a single continuation (user has no choice, request
     301             :     // is just informational)
     302           0 :     if (rContinuations.getLength() != 1 )
     303           0 :         return false;
     304             : 
     305             :     // user can only abort or approve, all other continuations are not
     306             :     // considered to be informational.
     307             :     uno::Reference< task::XInteractionApprove > xApprove(
     308           0 :         rContinuations[0], uno::UNO_QUERY);
     309           0 :     if (xApprove.is())
     310           0 :         return true;
     311             : 
     312             :     uno::Reference< task::XInteractionAbort > xAbort(
     313           0 :         rContinuations[0], uno::UNO_QUERY);
     314           0 :     if (xAbort.is())
     315           0 :         return true;
     316             : 
     317           0 :     return false;
     318             : }
     319             : 
     320             : bool
     321           0 : UUIInteractionHelper::tryOtherInteractionHandler(
     322             :     uno::Reference< task::XInteractionRequest > const & rRequest)
     323             :     SAL_THROW((uno::RuntimeException))
     324             : {
     325           0 :     InteractionHandlerDataList dataList;
     326           0 :     getInteractionHandlerList(dataList);
     327             : 
     328           0 :     InteractionHandlerDataList::const_iterator aEnd(dataList.end());
     329           0 :     for (InteractionHandlerDataList::const_iterator aIt(dataList.begin());
     330             :          aIt != aEnd;
     331             :          ++aIt)
     332             :     {
     333           0 :         if ( handleCustomRequest( rRequest, aIt->ServiceName ) )
     334           0 :             return true;
     335             :     }
     336           0 :     return false;
     337             : }
     338             : 
     339             : namespace
     340             : {
     341             : 
     342           0 :     static bool lcl_matchesRequest( const Any& i_rRequest, const OUString& i_rTypeName, const OUString& i_rPropagation )
     343             :     {
     344           0 :         const ::com::sun::star::uno::TypeDescription aTypeDesc( i_rTypeName );
     345           0 :         const typelib_TypeDescription* pTypeDesc = aTypeDesc.get();
     346           0 :         if ( !pTypeDesc || !pTypeDesc->pWeakRef )
     347             :         {
     348             : #if OSL_DEBUG_LEVEL > 0
     349             :             OStringBuffer aMessage;
     350             :             aMessage.append( "no type found for '" );
     351             :             aMessage.append( OUStringToOString( i_rTypeName, RTL_TEXTENCODING_UTF8 ) );
     352             :             aMessage.append( "'" );
     353             :             OSL_FAIL( aMessage.makeStringAndClear().getStr() );
     354             : #endif
     355           0 :             return false;
     356             :         }
     357           0 :         const ::com::sun::star::uno::Type aType( pTypeDesc->pWeakRef );
     358             : 
     359           0 :         const bool bExactMatch = i_rPropagation.equalsAscii( "named-only" );
     360           0 :         if ( bExactMatch )
     361           0 :             return i_rRequest.getValueType().equals( aType );
     362             : 
     363           0 :         return i_rRequest.isExtractableTo( aType );
     364             :     }
     365             : }
     366             : 
     367             : 
     368           0 : bool UUIInteractionHelper::handleCustomRequest( const Reference< XInteractionRequest >& i_rRequest, const OUString& i_rServiceName ) const
     369             : {
     370             :     try
     371             :     {
     372           0 :         Reference< XInteractionHandler2 > xHandler( m_xContext->getServiceManager()->createInstanceWithContext( i_rServiceName, m_xContext ), UNO_QUERY_THROW );
     373             : 
     374           0 :         Reference< XInitialization > xHandlerInit( xHandler, UNO_QUERY );
     375           0 :         if ( xHandlerInit.is() )
     376             :         {
     377           0 :             ::comphelper::NamedValueCollection aInitArgs;
     378           0 :             aInitArgs.put( "Parent", getParentXWindow() );
     379           0 :             xHandlerInit->initialize( aInitArgs.getWrappedPropertyValues() );
     380             :         }
     381             : 
     382           0 :         if ( xHandler->handleInteractionRequest( i_rRequest ) )
     383           0 :             return true;
     384             :     }
     385           0 :     catch( const Exception& )
     386             :     {
     387             :         DBG_UNHANDLED_EXCEPTION();
     388             :     }
     389           0 :     return false;
     390             : }
     391             : 
     392             : 
     393           0 : bool UUIInteractionHelper::handleTypedHandlerImplementations( Reference< XInteractionRequest > const & rRequest )
     394             : {
     395             :     // the request
     396           0 :     const Any aRequest( rRequest->getRequest() );
     397             : 
     398           0 :     const StringHashMap::const_iterator aCacheHitTest = m_aTypedCustomHandlers.find( aRequest.getValueTypeName() );
     399           0 :     if ( aCacheHitTest != m_aTypedCustomHandlers.end() )
     400           0 :         return handleCustomRequest( rRequest, aCacheHitTest->second );
     401             : 
     402             :     // the base registration node for "typed" interaction handlers
     403             :     const ::utl::OConfigurationTreeRoot aConfigRoot( ::utl::OConfigurationTreeRoot::createWithComponentContext(
     404             :         m_xContext,
     405             :         OUString( "/org.openoffice.Interaction/InteractionHandlers" ),
     406             :         -1,
     407             :         ::utl::OConfigurationTreeRoot::CM_READONLY
     408           0 :     ) );
     409             : 
     410             :     // loop through all registered implementations
     411           0 :     const Sequence< OUString > aRegisteredHandlers( aConfigRoot.getNodeNames() );
     412           0 :     const OUString* pHandlerName = aRegisteredHandlers.getConstArray();
     413           0 :     const OUString* pHandlersEnd = aRegisteredHandlers.getConstArray() + aRegisteredHandlers.getLength();
     414           0 :     for ( ; pHandlerName != pHandlersEnd; ++pHandlerName )
     415             :     {
     416           0 :         const ::utl::OConfigurationNode aHandlerNode( aConfigRoot.openNode( *pHandlerName ) );
     417           0 :         const ::utl::OConfigurationNode aTypesNode( aHandlerNode.openNode( "HandledRequestTypes" ) );
     418             : 
     419             :         // loop through all the types which the current handler is registered for
     420           0 :         const Sequence< OUString > aHandledTypes( aTypesNode.getNodeNames() );
     421           0 :         const OUString* pType = aHandledTypes.getConstArray();
     422           0 :         const OUString* pTypesEnd = aHandledTypes.getConstArray() + aHandledTypes.getLength();
     423           0 :         for ( ; pType != pTypesEnd; ++pType )
     424             :         {
     425             :             // the UNO type is the node name
     426           0 :             ::utl::OConfigurationNode aType( aTypesNode.openNode( *pType ) );
     427             :             // and there's a child denoting how the responsibility propagates
     428           0 :             OUString sPropagation;
     429           0 :             OSL_VERIFY( aType.getNodeValue( "Propagation" ) >>= sPropagation );
     430           0 :             if ( lcl_matchesRequest( aRequest, *pType, sPropagation ) )
     431             :             {
     432             :                 // retrieve the service/implementation name of the handler
     433           0 :                 OUString sServiceName;
     434           0 :                 OSL_VERIFY( aHandlerNode.getNodeValue( "ServiceName" ) >>= sServiceName );
     435             :                 // cache the information who feels responsible for requests of this type
     436           0 :                 m_aTypedCustomHandlers[ aRequest.getValueTypeName() ] = sServiceName;
     437             :                 // actually handle the request
     438           0 :                 return handleCustomRequest( rRequest, sServiceName );
     439             :             }
     440           0 :         }
     441           0 :     }
     442             : 
     443           0 :     return false;
     444             : }
     445             : 
     446             : bool
     447           0 : UUIInteractionHelper::handleRequest_impl(
     448             :     uno::Reference< task::XInteractionRequest > const & rRequest,
     449             :     bool bObtainErrorStringOnly,
     450             :     bool & bHasErrorString,
     451             :     OUString & rErrorString)
     452             :     SAL_THROW((uno::RuntimeException))
     453             : {
     454             :     try
     455             :     {
     456           0 :         if (!rRequest.is())
     457           0 :             return false;
     458             : 
     459           0 :         uno::Any aAnyRequest(rRequest->getRequest());
     460             : 
     461           0 :         script::ModuleSizeExceededRequest aModSizeException;
     462           0 :         if (aAnyRequest >>= aModSizeException )
     463             :         {
     464           0 :             ErrCode nErrorCode = ERRCODE_UUI_IO_MODULESIZEEXCEEDED;
     465           0 :             std::vector< OUString > aArguments;
     466             :             uno::Sequence< OUString > sModules
     467           0 :                 = aModSizeException.Names;
     468           0 :             if ( sModules.getLength() )
     469             :             {
     470           0 :                 OUString aName;
     471           0 :                 for ( sal_Int32 index=0; index< sModules.getLength(); ++index )
     472             :                 {
     473           0 :                     if ( index )
     474           0 :                         aName = aName + OUString( ',' ) + sModules[index];
     475             :                     else
     476           0 :                         aName = sModules[index]; // 1st name
     477             :                 }
     478           0 :                 aArguments.push_back( aName );
     479             :             }
     480             :             handleErrorHandlerRequest( task::InteractionClassification_WARNING,
     481             :                                        nErrorCode,
     482             :                                        aArguments,
     483           0 :                                        rRequest->getContinuations(),
     484             :                                        bObtainErrorStringOnly,
     485             :                                        bHasErrorString,
     486           0 :                                        rErrorString);
     487           0 :             return true;
     488             :         }
     489             : 
     490           0 :         ucb::NameClashException aNCException;
     491           0 :         if (aAnyRequest >>= aNCException)
     492             :         {
     493           0 :             ErrCode nErrorCode = ERRCODE_UUI_IO_TARGETALREADYEXISTS;
     494           0 :             std::vector< OUString > aArguments;
     495             : 
     496           0 :             if( !aNCException.Name.isEmpty() )
     497             :             {
     498           0 :                 nErrorCode = ERRCODE_UUI_IO_ALREADYEXISTS;
     499           0 :                 aArguments.push_back( aNCException.Name );
     500             :             }
     501             : 
     502             :             handleErrorHandlerRequest( aNCException.Classification,
     503             :                                        nErrorCode,
     504             :                                        aArguments,
     505           0 :                                        rRequest->getContinuations(),
     506             :                                        bObtainErrorStringOnly,
     507             :                                        bHasErrorString,
     508           0 :                                        rErrorString);
     509           0 :             return true;
     510             :         }
     511             : 
     512           0 :         ucb::UnsupportedNameClashException aUORequest;
     513           0 :         if (aAnyRequest >>= aUORequest)
     514             :         {
     515           0 :             ErrCode nErrorCode = ERRCODE_UUI_IO_UNSUPPORTEDOVERWRITE;
     516           0 :             std::vector< OUString > aArguments;
     517             : 
     518           0 :             uno::Reference< task::XInteractionApprove > xApprove;
     519           0 :             uno::Reference< task::XInteractionDisapprove > xDisapprove;
     520             :             getContinuations(
     521           0 :                 rRequest->getContinuations(), &xApprove, &xDisapprove);
     522             : 
     523           0 :             if ( xApprove.is() && xDisapprove.is() )
     524             :             {
     525             :                 handleErrorHandlerRequest( task::InteractionClassification_QUERY,
     526             :                                            nErrorCode,
     527             :                                            aArguments,
     528           0 :                                            rRequest->getContinuations(),
     529             :                                            bObtainErrorStringOnly,
     530             :                                            bHasErrorString,
     531           0 :                                            rErrorString);
     532             :             }
     533           0 :             return true;
     534             :         }
     535             : 
     536           0 :         if ( handleInteractiveIOException( rRequest,
     537             :                                            bObtainErrorStringOnly,
     538             :                                            bHasErrorString,
     539           0 :                                            rErrorString ) )
     540           0 :             return true;
     541             : 
     542           0 :         ucb::InteractiveAppException aAppException;
     543           0 :         if (aAnyRequest >>= aAppException)
     544             :         {
     545           0 :             std::vector< OUString > aArguments;
     546             :             handleErrorHandlerRequest( aAppException.Classification,
     547             :                                        aAppException.Code,
     548             :                                        aArguments,
     549           0 :                                        rRequest->getContinuations(),
     550             :                                        bObtainErrorStringOnly,
     551             :                                        bHasErrorString,
     552           0 :                                        rErrorString);
     553           0 :             return true;
     554             :         }
     555             : 
     556           0 :         ucb::InteractiveNetworkException aNetworkException;
     557           0 :         if (aAnyRequest >>= aNetworkException)
     558             :         {
     559             :             ErrCode nErrorCode;
     560           0 :             std::vector< OUString > aArguments;
     561           0 :             ucb::InteractiveNetworkOffLineException aOffLineException;
     562           0 :             ucb::InteractiveNetworkResolveNameException aResolveNameException;
     563           0 :             ucb::InteractiveNetworkConnectException aConnectException;
     564           0 :             ucb::InteractiveNetworkReadException aReadException;
     565           0 :             ucb::InteractiveNetworkWriteException aWriteException;
     566           0 :             if (aAnyRequest >>= aOffLineException)
     567           0 :                 nErrorCode = ERRCODE_INET_OFFLINE;
     568           0 :             else if (aAnyRequest >>= aResolveNameException)
     569             :             {
     570           0 :                 nErrorCode = ERRCODE_INET_NAME_RESOLVE;
     571           0 :                 aArguments.push_back(aResolveNameException.Server);
     572             :             }
     573           0 :             else if (aAnyRequest >>= aConnectException)
     574             :             {
     575           0 :                 nErrorCode = ERRCODE_INET_CONNECT;
     576           0 :                 aArguments.push_back(aConnectException.Server);
     577             :             }
     578           0 :             else if (aAnyRequest >>= aReadException)
     579             :             {
     580           0 :                 nErrorCode = ERRCODE_INET_READ;
     581           0 :                 aArguments.push_back(aReadException.Diagnostic);
     582             :             }
     583           0 :             else if (aAnyRequest >>= aWriteException)
     584             :             {
     585           0 :                 nErrorCode = ERRCODE_INET_WRITE;
     586           0 :                 aArguments.push_back(aWriteException.Diagnostic);
     587             :             }
     588             :             else
     589           0 :                 nErrorCode = ERRCODE_INET_GENERAL;
     590             : 
     591             :             handleErrorHandlerRequest(aNetworkException.Classification,
     592             :                                       nErrorCode,
     593             :                                       aArguments,
     594           0 :                                       rRequest->getContinuations(),
     595             :                                       bObtainErrorStringOnly,
     596             :                                       bHasErrorString,
     597           0 :                                       rErrorString);
     598           0 :             return true;
     599             :         }
     600             : 
     601           0 :         ucb::InteractiveWrongMediumException aWrongMediumException;
     602           0 :         if (aAnyRequest >>= aWrongMediumException)
     603             :         {
     604           0 :             sal_Int32 nMedium = 0;
     605           0 :             aWrongMediumException.Medium >>= nMedium;
     606           0 :             std::vector< OUString > aArguments;
     607           0 :             aArguments.push_back(OUString::number(nMedium + 1));
     608             :             handleErrorHandlerRequest(aWrongMediumException.Classification,
     609             :                                       ERRCODE_UUI_WRONGMEDIUM,
     610             :                                       aArguments,
     611           0 :                                       rRequest->getContinuations(),
     612             :                                       bObtainErrorStringOnly,
     613             :                                       bHasErrorString,
     614           0 :                                       rErrorString);
     615           0 :             return true;
     616             :         }
     617             : 
     618           0 :         java::WrongJavaVersionException aWrongJavaVersionException;
     619           0 :         if (aAnyRequest >>= aWrongJavaVersionException)
     620             :         {
     621             :             ErrCode nErrorCode;
     622           0 :             std::vector< OUString > aArguments;
     623           0 :             if (aWrongJavaVersionException.DetectedVersion.isEmpty())
     624           0 :                 if (aWrongJavaVersionException.LowestSupportedVersion.isEmpty())
     625           0 :                     nErrorCode = ERRCODE_UUI_WRONGJAVA;
     626             :                 else
     627             :                 {
     628           0 :                     nErrorCode = ERRCODE_UUI_WRONGJAVA_MIN;
     629           0 :                     aArguments.push_back(aWrongJavaVersionException.LowestSupportedVersion);
     630             :                 }
     631           0 :             else if (aWrongJavaVersionException.LowestSupportedVersion.isEmpty())
     632             :             {
     633           0 :                 nErrorCode = ERRCODE_UUI_WRONGJAVA_VERSION;
     634           0 :                 aArguments.push_back(aWrongJavaVersionException.DetectedVersion);
     635             :             }
     636             :             else
     637             :             {
     638           0 :                 nErrorCode = ERRCODE_UUI_WRONGJAVA_VERSION_MIN;
     639           0 :                 aArguments.reserve(2);
     640           0 :                 aArguments.push_back(aWrongJavaVersionException.DetectedVersion);
     641           0 :                 aArguments.push_back(aWrongJavaVersionException.LowestSupportedVersion);
     642             :             }
     643             :             handleErrorHandlerRequest(task::InteractionClassification_ERROR,
     644             :                                       nErrorCode,
     645             :                                       aArguments,
     646           0 :                                       rRequest->getContinuations(),
     647             :                                       bObtainErrorStringOnly,
     648             :                                       bHasErrorString,
     649           0 :                                       rErrorString);
     650           0 :             return true;
     651             :         }
     652             : 
     653           0 :         configuration::backend::MergeRecoveryRequest aMergeRecoveryRequest;
     654           0 :         if (aAnyRequest >>= aMergeRecoveryRequest)
     655             :         {
     656             :             ErrCode nErrorCode = aMergeRecoveryRequest.IsRemovalRequest
     657             :                 ? ERRCODE_UUI_CONFIGURATION_BROKENDATA_WITHREMOVE
     658           0 :                 : ERRCODE_UUI_CONFIGURATION_BROKENDATA_NOREMOVE;
     659             : 
     660           0 :             std::vector< OUString > aArguments;
     661           0 :             aArguments.push_back(aMergeRecoveryRequest.ErrorLayerId);
     662             : 
     663             :             handleErrorHandlerRequest(task::InteractionClassification_ERROR,
     664             :                                       nErrorCode,
     665             :                                       aArguments,
     666           0 :                                       rRequest->getContinuations(),
     667             :                                       bObtainErrorStringOnly,
     668             :                                       bHasErrorString,
     669           0 :                                       rErrorString);
     670           0 :             return true;
     671             :         }
     672             : 
     673             :         configuration::backend::StratumCreationException
     674           0 :             aStratumCreationException;
     675             : 
     676           0 :         if (aAnyRequest >>= aStratumCreationException)
     677             :         {
     678           0 :             const ErrCode nErrorCode = ERRCODE_UUI_CONFIGURATION_BACKENDMISSING;
     679             : 
     680           0 :             OUString aStratum = aStratumCreationException.StratumData;
     681           0 :             if (aStratum.isEmpty())
     682           0 :                 aStratum = aStratumCreationException.StratumService;
     683             : 
     684           0 :             std::vector< OUString > aArguments;
     685           0 :             aArguments.push_back(aStratum);
     686             : 
     687             :             handleErrorHandlerRequest(task::InteractionClassification_ERROR,
     688             :                                       nErrorCode,
     689             :                                       aArguments,
     690           0 :                                       rRequest->getContinuations(),
     691             :                                       bObtainErrorStringOnly,
     692             :                                       bHasErrorString,
     693           0 :                                       rErrorString);
     694           0 :             return true;
     695             :         }
     696             : 
     697           0 :         xforms::InvalidDataOnSubmitException aInvalidDataOnSubmitException;
     698           0 :         if (aAnyRequest >>= aInvalidDataOnSubmitException)
     699             :         {
     700             :             const ErrCode nErrorCode =
     701           0 :                 ERRCODE_UUI_INVALID_XFORMS_SUBMISSION_DATA;
     702             : 
     703           0 :             std::vector< OUString > aArguments;
     704             : 
     705             :             handleErrorHandlerRequest(task::InteractionClassification_QUERY,
     706             :                                       nErrorCode,
     707             :                                       aArguments,
     708           0 :                                       rRequest->getContinuations(),
     709             :                                       bObtainErrorStringOnly,
     710             :                                       bHasErrorString,
     711           0 :                                       rErrorString);
     712           0 :             return true;
     713             :         }
     714             : 
     715           0 :         ucb::InteractiveLockingLockedException aLLException;
     716           0 :         if (aAnyRequest >>= aLLException)
     717             :         {
     718             :             ErrCode nErrorCode = aLLException.SelfOwned
     719           0 :                 ? ERRCODE_UUI_LOCKING_LOCKED_SELF : ERRCODE_UUI_LOCKING_LOCKED;
     720           0 :             std::vector< OUString > aArguments;
     721           0 :             aArguments.push_back( aLLException.Url );
     722             : 
     723             :             handleErrorHandlerRequest( aLLException.Classification,
     724             :                                        nErrorCode,
     725             :                                        aArguments,
     726           0 :                                        rRequest->getContinuations(),
     727             :                                        bObtainErrorStringOnly,
     728             :                                        bHasErrorString,
     729           0 :                                        rErrorString );
     730           0 :             return true;
     731             :         }
     732             : 
     733           0 :         ucb::InteractiveLockingNotLockedException aLNLException;
     734           0 :         if (aAnyRequest >>= aLNLException)
     735             :         {
     736           0 :             ErrCode nErrorCode = ERRCODE_UUI_LOCKING_NOT_LOCKED;
     737           0 :             std::vector< OUString > aArguments;
     738           0 :             aArguments.push_back( aLNLException.Url );
     739             : 
     740             :             handleErrorHandlerRequest( aLNLException.Classification,
     741             :                                        nErrorCode,
     742             :                                        aArguments,
     743           0 :                                        rRequest->getContinuations(),
     744             :                                        bObtainErrorStringOnly,
     745             :                                        bHasErrorString,
     746           0 :                                        rErrorString );
     747           0 :             return true;
     748             :         }
     749             : 
     750           0 :         ucb::InteractiveLockingLockExpiredException aLLEException;
     751           0 :         if (aAnyRequest >>= aLLEException)
     752             :         {
     753           0 :             ErrCode nErrorCode = ERRCODE_UUI_LOCKING_LOCK_EXPIRED;
     754           0 :             std::vector< OUString > aArguments;
     755           0 :             aArguments.push_back( aLLEException.Url );
     756             : 
     757             :             handleErrorHandlerRequest( aLLEException.Classification,
     758             :                                        nErrorCode,
     759             :                                        aArguments,
     760           0 :                                        rRequest->getContinuations(),
     761             :                                        bObtainErrorStringOnly,
     762             :                                        bHasErrorString,
     763           0 :                                        rErrorString );
     764           0 :             return true;
     765             :         }
     766             : 
     767           0 :         document::BrokenPackageRequest aBrokenPackageRequest;
     768           0 :         if (aAnyRequest >>= aBrokenPackageRequest)
     769             :         {
     770           0 :             std::vector< OUString > aArguments;
     771             : 
     772           0 :             if( !aBrokenPackageRequest.aName.isEmpty() )
     773           0 :                 aArguments.push_back( aBrokenPackageRequest.aName );
     774             : 
     775             :             handleBrokenPackageRequest( aArguments,
     776           0 :                                         rRequest->getContinuations(),
     777             :                                         bObtainErrorStringOnly,
     778             :                                         bHasErrorString,
     779           0 :                                         rErrorString );
     780           0 :             return true;
     781             :         }
     782             : 
     783           0 :         task::ErrorCodeRequest aErrorCodeRequest;
     784           0 :         if (aAnyRequest >>= aErrorCodeRequest)
     785             :         {
     786             :             // Sucky special handling for xlsx macro filter warning
     787           0 :             if ( (sal_uInt32)ERRCODE_SFX_VBASIC_CANTSAVE_STORAGE == (sal_uInt32)aErrorCodeRequest.ErrCode)
     788             :             {
     789           0 :                 std::vector< OUString > aArguments;
     790             :                 handleErrorHandlerRequest( task::InteractionClassification_WARNING,
     791             :                                        ERRCODE_UUI_IO_WARN_CANTSAVE_MACROS,
     792             :                                        aArguments,
     793           0 :                                        rRequest->getContinuations(),
     794             :                                        bObtainErrorStringOnly,
     795             :                                        bHasErrorString,
     796           0 :                                        rErrorString);
     797             :             }
     798             :             else
     799             :             {
     800             :                 handleGenericErrorRequest( aErrorCodeRequest.ErrCode,
     801           0 :                                        rRequest->getContinuations(),
     802             :                                        bObtainErrorStringOnly,
     803             :                                        bHasErrorString,
     804           0 :                                        rErrorString);
     805             :             }
     806           0 :             return true;
     807             :         }
     808             : 
     809           0 :         task::ErrorCodeIOException aErrorCodeIOException;
     810           0 :         if (aAnyRequest >>= aErrorCodeIOException)
     811             :         {
     812             :             handleGenericErrorRequest( aErrorCodeIOException.ErrCode,
     813           0 :                                        rRequest->getContinuations(),
     814             :                                        bObtainErrorStringOnly,
     815             :                                        bHasErrorString,
     816           0 :                                        rErrorString);
     817           0 :             return true;
     818             :         }
     819             : 
     820           0 :         loader::CannotActivateFactoryException aCannotActivateFactoryException;
     821           0 :         if (aAnyRequest >>= aCannotActivateFactoryException)
     822             :         {
     823           0 :             ErrCode nErrorCode = ERRCODE_UUI_CANNOT_ACTIVATE_FACTORY;
     824           0 :             std::vector< OUString > aArguments;
     825           0 :             aArguments.push_back( aCannotActivateFactoryException.Message );
     826             : 
     827             :             handleErrorHandlerRequest( task::InteractionClassification_ERROR,
     828             :                                        nErrorCode,
     829             :                                        aArguments,
     830           0 :                                        rRequest->getContinuations(),
     831             :                                        bObtainErrorStringOnly,
     832             :                                        bHasErrorString,
     833           0 :                                        rErrorString );
     834           0 :             return true;
     835             :         }
     836             : 
     837             : 
     838             : 
     839             :         // Handle requests which do not have a plain string representation.
     840             : 
     841           0 :         if (!bObtainErrorStringOnly)
     842             :         {
     843           0 :             if ( handleAuthenticationRequest( rRequest ) )
     844           0 :                 return true;
     845             : 
     846           0 :             if ( handleCertificateValidationRequest( rRequest ) )
     847           0 :                 return true;
     848             : 
     849           0 :             ucb::NameClashResolveRequest aNameClashResolveRequest;
     850           0 :             if (aAnyRequest >>= aNameClashResolveRequest)
     851             :             {
     852             :                 handleNameClashResolveRequest(aNameClashResolveRequest,
     853           0 :                                               rRequest->getContinuations());
     854           0 :                 return true;
     855             :             }
     856             : 
     857           0 :             if ( handleMasterPasswordRequest( rRequest ) )
     858           0 :                 return true;
     859             : 
     860           0 :             if ( handlePasswordRequest( rRequest ) )
     861           0 :                 return true;
     862             : 
     863           0 :             if ( handleNoSuchFilterRequest( rRequest ) )
     864           0 :                 return true;
     865             : 
     866           0 :             if ( handleAmbigousFilterRequest( rRequest ) )
     867           0 :                 return true;
     868             : 
     869           0 :             if ( handleFilterOptionsRequest( rRequest ) )
     870           0 :                 return true;
     871             : 
     872           0 :             if ( handleLockedDocumentRequest( rRequest ) )
     873           0 :                 return true;
     874             : 
     875           0 :             if ( handleChangedByOthersRequest( rRequest ) )
     876           0 :                 return true;
     877             : 
     878           0 :             if ( handleLockFileIgnoreRequest( rRequest ) )
     879           0 :                 return true;
     880             : 
     881           0 :             task::DocumentMacroConfirmationRequest aMacroConfirmRequest;
     882           0 :             if (aAnyRequest >>= aMacroConfirmRequest)
     883             :             {
     884             :                 handleMacroConfirmRequest(
     885             :                     aMacroConfirmRequest.DocumentURL,
     886             :                     aMacroConfirmRequest.DocumentStorage,
     887           0 :                     !aMacroConfirmRequest.DocumentVersion.isEmpty() ? aMacroConfirmRequest.DocumentVersion : ODFVER_012_TEXT,
     888             :                     aMacroConfirmRequest.DocumentSignatureInformation,
     889           0 :                     rRequest->getContinuations());
     890           0 :                 return true;
     891             :             }
     892             : 
     893             :             task::FutureDocumentVersionProductUpdateRequest
     894           0 :                 aProductUpdateRequest;
     895           0 :             if (aAnyRequest >>= aProductUpdateRequest)
     896             :             {
     897             :                 handleFutureDocumentVersionUpdateRequest(
     898             :                     aProductUpdateRequest,
     899           0 :                     rRequest->getContinuations());
     900           0 :                 return true;
     901             :             }
     902             : 
     903             : 
     904             :             // Last chance: interaction handlers registered in the configuration
     905             : 
     906             : 
     907             :             // typed InteractionHandlers (ooo.Interactions)
     908           0 :             if ( handleTypedHandlerImplementations( rRequest ) )
     909           0 :                 return true;
     910             : 
     911             :             // legacy configuration (ooo.ucb.InteractionHandlers)
     912           0 :             if (tryOtherInteractionHandler( rRequest ))
     913           0 :                 return true;
     914             :         }
     915             : 
     916             :         // Not handled.
     917           0 :         return false;
     918             :     }
     919           0 :     catch (std::bad_alloc const &)
     920             :     {
     921             :         throw uno::RuntimeException("out of memory",
     922           0 :             uno::Reference< uno::XInterface >());
     923             :     }
     924           0 :     catch( const uno::RuntimeException& )
     925             :     {
     926           0 :         throw;  // allowed to leave here
     927             :     }
     928           0 :     catch( const uno::Exception& )
     929             :     {
     930             :         DBG_UNHANDLED_EXCEPTION();
     931             :     }
     932           0 :     return false;
     933             : }
     934             : 
     935             : void
     936           0 : UUIInteractionHelper::getInteractionHandlerList(
     937             :     InteractionHandlerDataList &rdataList)
     938             :     SAL_THROW((uno::RuntimeException))
     939             : {
     940             :     try
     941             :     {
     942             :         uno::Reference< lang::XMultiServiceFactory > xConfigProv =
     943           0 :             configuration::theDefaultProvider::get( m_xContext );
     944             : 
     945           0 :         OUStringBuffer aFullPath;
     946             :         aFullPath.appendAscii(
     947           0 :             "/org.openoffice.ucb.InteractionHandler/InteractionHandlers" );
     948             : 
     949           0 :         uno::Sequence< uno::Any > aArguments( 1 );
     950           0 :         beans::PropertyValue      aProperty;
     951           0 :         aProperty.Name = "nodepath";
     952           0 :         aProperty.Value <<= aFullPath.makeStringAndClear();
     953           0 :         aArguments[ 0 ] <<= aProperty;
     954             : 
     955             :         uno::Reference< uno::XInterface > xInterface(
     956           0 :                 xConfigProv->createInstanceWithArguments(
     957           0 :                     "com.sun.star.configuration.ConfigurationAccess" , aArguments ) );
     958             : 
     959           0 :         if ( !xInterface.is() )
     960             :             throw uno::RuntimeException("unable to instanciate config access",
     961           0 :                 uno::Reference< uno::XInterface >());
     962             : 
     963             :         uno::Reference< container::XNameAccess > xNameAccess(
     964           0 :             xInterface, uno::UNO_QUERY );
     965           0 :         if ( !xNameAccess.is() )
     966             :             throw uno::RuntimeException(OUString(
     967             :                     "config access does not implement XNameAccess"),
     968           0 :                 uno::Reference< uno::XInterface >());
     969             : 
     970           0 :         uno::Sequence< OUString > aElems = xNameAccess->getElementNames();
     971           0 :         const OUString* pElems = aElems.getConstArray();
     972           0 :         sal_Int32 nCount = aElems.getLength();
     973             : 
     974           0 :         if ( nCount > 0 )
     975             :         {
     976             :             uno::Reference< container::XHierarchicalNameAccess >
     977           0 :                                 xHierNameAccess( xInterface, uno::UNO_QUERY );
     978             : 
     979           0 :             if ( !xHierNameAccess.is() )
     980             :                 throw uno::RuntimeException(OUString(
     981             :                     "config access does not implement XHierarchicalNameAccess"),
     982           0 :                     uno::Reference< uno::XInterface >());
     983             : 
     984             :             // Iterate over children.
     985           0 :             for ( sal_Int32 n = 0; n < nCount; ++n )
     986             :             {
     987           0 :                 OUStringBuffer aElemBuffer;
     988           0 :                 aElemBuffer.appendAscii( "['" );
     989           0 :                 aElemBuffer.append( pElems[ n ] );
     990             : 
     991             :                 try
     992             :                 {
     993           0 :                     InteractionHandlerData aInfo;
     994             : 
     995             :                     // Obtain service name.
     996           0 :                     OUStringBuffer aKeyBuffer = aElemBuffer;
     997           0 :                     aKeyBuffer.appendAscii( "']/ServiceName" );
     998             : 
     999           0 :                     OUString aValue;
    1000           0 :                     if ( !( xHierNameAccess->getByHierarchicalName(
    1001           0 :                                 aKeyBuffer.makeStringAndClear() ) >>= aValue ) )
    1002             :                     {
    1003             :                         OSL_FAIL( "GetInteractionHandlerList - "
    1004             :                                     "Error getting item value!" );
    1005           0 :                         continue;
    1006             :                     }
    1007             : 
    1008           0 :                     aInfo.ServiceName = aValue;
    1009             : 
    1010             :                     // Append info to list.
    1011           0 :                     rdataList.push_back( aInfo );
    1012             :                 }
    1013           0 :                 catch ( container::NoSuchElementException& )
    1014             :                 {
    1015             :                     // getByHierarchicalName
    1016             : 
    1017             :                     OSL_FAIL( "GetInteractionHandlerList - "
    1018             :                                 "caught NoSuchElementException!" );
    1019             :                 }
    1020           0 :             }
    1021           0 :         }
    1022             :     }
    1023           0 :     catch ( uno::RuntimeException const & )
    1024             :     {
    1025           0 :         throw;
    1026             :     }
    1027           0 :     catch ( uno::Exception const & )
    1028             :     {
    1029             :         OSL_FAIL( "GetInteractionHandlerList - Caught Exception!" );
    1030             :     }
    1031           0 : }
    1032             : 
    1033             : Window *
    1034           0 : UUIInteractionHelper::getParentProperty()
    1035             :     SAL_THROW(())
    1036             : {
    1037           0 :     uno::Reference< awt::XWindow > xWindow = getParentXWindow();
    1038           0 :     if ( xWindow.is() )
    1039           0 :         return VCLUnoHelper::GetWindow(xWindow);
    1040             : 
    1041           0 :     return 0;
    1042             : }
    1043             : 
    1044             : uno::Reference< awt::XWindow>
    1045           0 : UUIInteractionHelper::getParentXWindow() const
    1046             :     SAL_THROW(())
    1047             : {
    1048           0 :     return m_xWindowParam;
    1049             : }
    1050             : 
    1051             : OUString
    1052           0 : UUIInteractionHelper::getContextProperty()
    1053             :     SAL_THROW(())
    1054             : {
    1055           0 :     return m_aContextParam;
    1056             : }
    1057             : 
    1058             : uno::Reference< task::XInteractionHandler2 >
    1059           0 : UUIInteractionHelper::getInteractionHandler()
    1060             :     SAL_THROW((uno::RuntimeException))
    1061             : {
    1062             :     return InteractionHandler::createWithParentAndContext(
    1063             :         m_xContext, m_xWindowParam,
    1064           0 :         m_aContextParam);
    1065             : }
    1066             : 
    1067             : namespace {
    1068             : 
    1069             : sal_uInt16
    1070           0 : executeMessageBox(
    1071             :     Window * pParent,
    1072             :     OUString const & rTitle,
    1073             :     OUString const & rMessage,
    1074             :     WinBits nButtonMask )
    1075             :     SAL_THROW((uno::RuntimeException))
    1076             : {
    1077           0 :     SolarMutexGuard aGuard;
    1078             : 
    1079           0 :     MessBox xBox( pParent, nButtonMask, rTitle, rMessage );
    1080             : 
    1081           0 :     sal_uInt16 aResult = xBox.Execute();
    1082           0 :     switch( aResult )
    1083             :     {
    1084             :     case RET_OK:
    1085           0 :         aResult = ERRCODE_BUTTON_OK;
    1086           0 :         break;
    1087             :     case RET_CANCEL:
    1088           0 :         aResult = ERRCODE_BUTTON_CANCEL;
    1089           0 :         break;
    1090             :     case RET_YES:
    1091           0 :         aResult = ERRCODE_BUTTON_YES;
    1092           0 :         break;
    1093             :     case RET_NO:
    1094           0 :         aResult = ERRCODE_BUTTON_NO;
    1095           0 :         break;
    1096             :     case RET_RETRY:
    1097           0 :         aResult = ERRCODE_BUTTON_RETRY;
    1098           0 :         break;
    1099             :     }
    1100             : 
    1101           0 :     return aResult;
    1102             : }
    1103             : 
    1104           0 : NameClashResolveDialogResult executeSimpleNameClashResolveDialog( Window *pParent,
    1105             :                                                                   OUString const & rTargetFolderURL,
    1106             :                                                                   OUString const & rClashingName,
    1107             :                                                                   OUString & rProposedNewName,
    1108             :                                                                   bool bAllowOverwrite )
    1109             : {
    1110           0 :     boost::scoped_ptr< ResMgr > xManager( ResMgr::CreateResMgr( "uui" ) );
    1111           0 :     if ( !xManager.get() )
    1112           0 :         return ABORT;
    1113             : 
    1114             :     NameClashDialog aDialog( pParent, xManager.get(), rTargetFolderURL,
    1115           0 :                              rClashingName, rProposedNewName, bAllowOverwrite );
    1116             : 
    1117           0 :     NameClashResolveDialogResult eResult = (NameClashResolveDialogResult) aDialog.Execute();
    1118           0 :     rProposedNewName = aDialog.getNewName();
    1119           0 :     return eResult;
    1120             : }
    1121             : 
    1122             : } // namespace
    1123             : 
    1124             : void
    1125           0 : UUIInteractionHelper::handleNameClashResolveRequest(
    1126             :     ucb::NameClashResolveRequest const & rRequest,
    1127             :     uno::Sequence< uno::Reference<
    1128             :         task::XInteractionContinuation > > const & rContinuations)
    1129             :   SAL_THROW((uno::RuntimeException))
    1130             : {
    1131             :     OSL_ENSURE(!rRequest.TargetFolderURL.isEmpty(),
    1132             :         "NameClashResolveRequest must not contain empty TargetFolderURL" );
    1133             : 
    1134             :     OSL_ENSURE(!rRequest.ClashingName.isEmpty(),
    1135             :         "NameClashResolveRequest must not contain empty ClashingName" );
    1136             : 
    1137           0 :     uno::Reference< task::XInteractionAbort > xAbort;
    1138           0 :     uno::Reference< ucb::XInteractionSupplyName > xSupplyName;
    1139           0 :     uno::Reference< ucb::XInteractionReplaceExistingData > xReplaceExistingData;
    1140             :     getContinuations(
    1141           0 :         rContinuations, &xAbort, &xSupplyName, &xReplaceExistingData);
    1142             : 
    1143             :     OSL_ENSURE( xAbort.is(),
    1144             :         "NameClashResolveRequest must contain Abort continuation" );
    1145             : 
    1146             :     OSL_ENSURE( xSupplyName.is(),
    1147             :         "NameClashResolveRequest must contain SupplyName continuation" );
    1148             : 
    1149           0 :     NameClashResolveDialogResult eResult = ABORT;
    1150           0 :     OUString aProposedNewName( rRequest.ProposedNewName );
    1151             : 
    1152             :     eResult = executeSimpleNameClashResolveDialog( getParentProperty(),
    1153             :                     rRequest.TargetFolderURL,
    1154             :                     rRequest.ClashingName,
    1155             :                     aProposedNewName,
    1156           0 :                     xReplaceExistingData.is() );
    1157             : 
    1158           0 :     switch ( eResult )
    1159             :     {
    1160             :     case ABORT:
    1161           0 :         xAbort->select();
    1162           0 :         break;
    1163             : 
    1164             :     case RENAME:
    1165           0 :         xSupplyName->setName( aProposedNewName );
    1166           0 :         xSupplyName->select();
    1167           0 :         break;
    1168             : 
    1169             :     case OVERWRITE:
    1170             :         OSL_ENSURE(
    1171             :             xReplaceExistingData.is(),
    1172             :             "Invalid NameClashResolveDialogResult: OVERWRITE - "
    1173             :             "No ReplaceExistingData continuation available!" );
    1174           0 :         xReplaceExistingData->select();
    1175           0 :         break;
    1176           0 :     }
    1177           0 : }
    1178             : 
    1179             : void
    1180           0 : UUIInteractionHelper::handleGenericErrorRequest(
    1181             :     sal_Int32 nErrorCode,
    1182             :     uno::Sequence< uno::Reference<
    1183             :         task::XInteractionContinuation > > const & rContinuations,
    1184             :     bool bObtainErrorStringOnly,
    1185             :     bool & bHasErrorString,
    1186             :     OUString & rErrorString)
    1187             :     SAL_THROW((uno::RuntimeException))
    1188             : {
    1189           0 :     if (bObtainErrorStringOnly)
    1190             :     {
    1191           0 :         bHasErrorString = isInformationalErrorMessageRequest(rContinuations);
    1192           0 :         if (bHasErrorString)
    1193             :         {
    1194           0 :             OUString aErrorString;
    1195           0 :             ErrorHandler::GetErrorString(nErrorCode, aErrorString);
    1196           0 :             rErrorString = aErrorString;
    1197             :         }
    1198             :     }
    1199             :     else
    1200             :     {
    1201           0 :         uno::Reference< task::XInteractionAbort > xAbort;
    1202           0 :         uno::Reference< task::XInteractionApprove > xApprove;
    1203           0 :         getContinuations(rContinuations, &xApprove, &xAbort);
    1204             : 
    1205             :         // Note: It's important to convert the transported long to the
    1206             :         // required  unsigned long value. Otherwhise using as flag field
    1207             :         // can fail ...
    1208           0 :         ErrCode  nError   = static_cast< ErrCode >(nErrorCode);
    1209           0 :         sal_Bool bWarning = !ERRCODE_TOERROR(nError);
    1210             : 
    1211           0 :         if ( nError == ERRCODE_SFX_BROKENSIGNATURE
    1212           0 :              || nError == ERRCODE_SFX_INCOMPLETE_ENCRYPTION )
    1213             :         {
    1214             :             // the security warning box needs a special title
    1215           0 :             OUString aErrorString;
    1216           0 :             ErrorHandler::GetErrorString( nErrorCode, aErrorString );
    1217             : 
    1218             :             boost::scoped_ptr< ResMgr > xManager(
    1219           0 :                 ResMgr::CreateResMgr( "uui" ) );
    1220           0 :             OUString aTitle( utl::ConfigManager::getProductName() );
    1221             : 
    1222             :             OUString aErrTitle
    1223             :                   = ResId( nError == ERRCODE_SFX_BROKENSIGNATURE
    1224             :                                        ? STR_WARNING_BROKENSIGNATURE_TITLE
    1225             :                                        : STR_WARNING_INCOMPLETE_ENCRYPTION_TITLE,
    1226           0 :                                    *xManager.get() ).toString();
    1227             : 
    1228           0 :             if ( !aTitle.isEmpty() && !aErrTitle.isEmpty() )
    1229           0 :                 aTitle += " - " ;
    1230           0 :             aTitle += aErrTitle;
    1231             : 
    1232             :             executeMessageBox(
    1233           0 :                 getParentProperty(), aTitle, aErrorString, WB_OK );
    1234             :         }
    1235             :         else
    1236           0 :             ErrorHandler::HandleError(nErrorCode);
    1237             : 
    1238           0 :         if (xApprove.is() && bWarning)
    1239           0 :             xApprove->select();
    1240           0 :         else if (xAbort.is())
    1241           0 :             xAbort->select();
    1242             :     }
    1243           0 : }
    1244             : 
    1245             : void
    1246           0 : UUIInteractionHelper::handleMacroConfirmRequest(
    1247             :     const OUString& aDocumentURL,
    1248             :     const uno::Reference< embed::XStorage >& xZipStorage,
    1249             :     const OUString& aDocumentVersion,
    1250             :     const uno::Sequence< security::DocumentSignatureInformation > aSignInfo,
    1251             :     uno::Sequence< uno::Reference< task::XInteractionContinuation > > const &
    1252             :         rContinuations )
    1253             :     SAL_THROW((uno::RuntimeException))
    1254             : {
    1255           0 :     uno::Reference< task::XInteractionAbort > xAbort;
    1256           0 :     uno::Reference< task::XInteractionApprove > xApprove;
    1257           0 :     getContinuations( rContinuations, &xApprove, &xAbort );
    1258             : 
    1259           0 :     bool bApprove = false;
    1260             : 
    1261           0 :     boost::scoped_ptr< ResMgr > pResMgr( ResMgr::CreateResMgr( "uui" ) );
    1262           0 :     if ( pResMgr.get() )
    1263             :     {
    1264           0 :         bool bShowSignatures = aSignInfo.getLength() > 0;
    1265             :         MacroWarning aWarning(
    1266           0 :             getParentProperty(), bShowSignatures, *pResMgr.get() );
    1267             : 
    1268           0 :         aWarning.SetDocumentURL( aDocumentURL );
    1269           0 :         if ( aSignInfo.getLength() > 1 )
    1270             :         {
    1271           0 :             aWarning.SetStorage( xZipStorage, aDocumentVersion, aSignInfo );
    1272             :         }
    1273           0 :         else if ( aSignInfo.getLength() == 1 )
    1274             :         {
    1275           0 :             aWarning.SetCertificate( aSignInfo[ 0 ].Signer );
    1276             :         }
    1277             : 
    1278           0 :         bApprove = aWarning.Execute() == RET_OK;
    1279             :     }
    1280             : 
    1281           0 :     if ( bApprove && xApprove.is() )
    1282           0 :         xApprove->select();
    1283           0 :     else if ( xAbort.is() )
    1284           0 :         xAbort->select();
    1285           0 : }
    1286             : 
    1287             : void
    1288           0 : UUIInteractionHelper::handleFutureDocumentVersionUpdateRequest(
    1289             :     const task::FutureDocumentVersionProductUpdateRequest& _rRequest,
    1290             :     uno::Sequence< uno::Reference< task::XInteractionContinuation > > const &
    1291             :         rContinuations )
    1292             :     SAL_THROW((uno::RuntimeException))
    1293             : {
    1294           0 :     uno::Reference< task::XInteractionAbort > xAbort;
    1295           0 :     uno::Reference< task::XInteractionApprove > xApprove;
    1296           0 :     uno::Reference< task::XInteractionAskLater > xAskLater;
    1297           0 :     getContinuations( rContinuations, &xApprove, &xAbort, &xAskLater );
    1298             : 
    1299           0 :     short nResult = RET_CANCEL;
    1300             : 
    1301             :     static bool s_bDeferredToNextSession = false;
    1302             :     // TODO: this static variable is somewhat hacky. Formerly (before the dialog was moved from SFX2 to the
    1303             :     // interaction handler implementation), this was stored in SFX_APP()'s impl structure, in member
    1304             :     // bODFVersionWarningLater. Of course, we do not have access to it here.
    1305             : 
    1306             :     // A proper solution which I would envision would be:
    1307             :     // - There's a central implementation (this one here) of css.task.InteractionHandler
    1308             :     // - There's a configuration which maps UNO names to service names
    1309             :     // - If the handler is confronted with a request, it tries to find the name of the UNO structure describing
    1310             :     //   the request in the said configuration.
    1311             :     //   - If an entry is found, then
    1312             :     //     - the respective service is instantiated
    1313             :     //     - the component is queried for css.task.XInteractionHandler, and the request is delegated
    1314             :     //   - if no entry is found, then the request is silenced (with calling the AbortContinuation, if possible)
    1315             :     // This way, the FutureDocumentVersionProductUpdateRequest could be handled in SFX (or any other
    1316             :     // suitable place), again, and we would only have one place where we remember the s_bDeferredToNextSession
    1317             :     // flag.
    1318             : 
    1319             :     // Note: The above pattern has been implemented in CWS autorecovery. Now the remaining task is to move the
    1320             :     // handling of this interaction to SFX, again.
    1321             : 
    1322           0 :     if ( !s_bDeferredToNextSession )
    1323             :     {
    1324           0 :         boost::scoped_ptr< ResMgr > pResMgr( ResMgr::CreateResMgr( "uui" ) );
    1325           0 :         if ( pResMgr.get() )
    1326             :         {
    1327             :             ::uui::NewerVersionWarningDialog aDialog(
    1328             :                 getParentProperty(),
    1329             :                 _rRequest.DocumentODFVersion,
    1330           0 :                 *pResMgr.get() );
    1331           0 :             nResult = aDialog.Execute();
    1332           0 :         }
    1333             :     }
    1334             : 
    1335           0 :     switch ( nResult )
    1336             :     {
    1337             :     case RET_OK:
    1338           0 :         if ( xApprove.is() )
    1339           0 :             xApprove->select();
    1340           0 :         break;
    1341             :     case RET_CANCEL:
    1342           0 :         if ( xAbort.is() )
    1343           0 :             xAbort->select();
    1344           0 :         break;
    1345             :     case RET_ASK_LATER:
    1346           0 :         if ( xAskLater.is() )
    1347           0 :             xAskLater->select();
    1348           0 :         s_bDeferredToNextSession = true;
    1349           0 :         break;
    1350             :     default:
    1351             :         OSL_FAIL( "UUIInteractionHelper::handleFutureDocumentVersionUpdateRequest: "
    1352             :                     "unexpected dialog return value!" );
    1353           0 :         break;
    1354           0 :     }
    1355           0 : }
    1356             : 
    1357             : void
    1358           0 : UUIInteractionHelper::handleBrokenPackageRequest(
    1359             :     std::vector< OUString > const & rArguments,
    1360             :     uno::Sequence< uno::Reference< task::XInteractionContinuation > > const &
    1361             :         rContinuations,
    1362             :     bool bObtainErrorStringOnly,
    1363             :     bool & bHasErrorString,
    1364             :     OUString & rErrorString)
    1365             :     SAL_THROW((uno::RuntimeException))
    1366             : {
    1367           0 :     if (bObtainErrorStringOnly)
    1368             :     {
    1369           0 :         bHasErrorString = isInformationalErrorMessageRequest(rContinuations);
    1370           0 :         if (!bHasErrorString)
    1371           0 :             return;
    1372             :     }
    1373             : 
    1374           0 :     uno::Reference< task::XInteractionApprove > xApprove;
    1375           0 :     uno::Reference< task::XInteractionDisapprove > xDisapprove;
    1376           0 :     uno::Reference< task::XInteractionAbort > xAbort;
    1377           0 :     getContinuations(rContinuations, &xApprove, &xDisapprove, &xAbort);
    1378             : 
    1379             :     ErrCode nErrorCode;
    1380           0 :     if( xApprove.is() && xDisapprove.is() )
    1381             :     {
    1382           0 :         nErrorCode = ERRCODE_UUI_IO_BROKENPACKAGE;
    1383             :     }
    1384           0 :     else if ( xAbort.is() )
    1385             :     {
    1386           0 :         nErrorCode = ERRCODE_UUI_IO_BROKENPACKAGE_CANTREPAIR;
    1387             :     }
    1388             :     else
    1389           0 :         return;
    1390             : 
    1391           0 :     OUString aMessage;
    1392             :     {
    1393           0 :         SolarMutexGuard aGuard;
    1394           0 :         boost::scoped_ptr< ResMgr > xManager(ResMgr::CreateResMgr("uui"));
    1395           0 :         if (!xManager.get())
    1396           0 :             return;
    1397             : 
    1398           0 :         ResId aResId( RID_UUI_ERRHDL, *xManager.get() );
    1399           0 :         if ( !ErrorResource(aResId).getString(nErrorCode, aMessage) )
    1400           0 :             return;
    1401             :     }
    1402             : 
    1403           0 :     aMessage = replaceMessageWithArguments( aMessage, rArguments );
    1404             : 
    1405           0 :     if (bObtainErrorStringOnly)
    1406             :     {
    1407           0 :         rErrorString = aMessage;
    1408           0 :         return;
    1409             :     }
    1410             : 
    1411             :     WinBits nButtonMask;
    1412           0 :     if( xApprove.is() && xDisapprove.is() )
    1413             :     {
    1414           0 :         nButtonMask = WB_YES_NO | WB_DEF_YES;
    1415             :     }
    1416           0 :     else if ( xAbort.is() )
    1417             :     {
    1418           0 :         nButtonMask = WB_OK;
    1419             :     }
    1420             :     else
    1421           0 :         return;
    1422             : 
    1423             :     OUString title(
    1424           0 :         utl::ConfigManager::getProductName() +
    1425           0 :         OUString( " " ) +
    1426           0 :         utl::ConfigManager::getProductVersion() );
    1427             : 
    1428           0 :     switch (
    1429           0 :         executeMessageBox( getParentProperty(), title, aMessage, nButtonMask ) )
    1430             :     {
    1431             :     case ERRCODE_BUTTON_OK:
    1432             :         OSL_ENSURE( xAbort.is(), "unexpected situation" );
    1433           0 :         if (xAbort.is())
    1434           0 :             xAbort->select();
    1435           0 :         break;
    1436             : 
    1437             :     case ERRCODE_BUTTON_NO:
    1438             :         OSL_ENSURE(xDisapprove.is(), "unexpected situation");
    1439           0 :         if (xDisapprove.is())
    1440           0 :             xDisapprove->select();
    1441           0 :         break;
    1442             : 
    1443             :     case ERRCODE_BUTTON_YES:
    1444             :         OSL_ENSURE(xApprove.is(), "unexpected situation");
    1445           0 :         if (xApprove.is())
    1446           0 :             xApprove->select();
    1447           0 :         break;
    1448           0 :     }
    1449             : }
    1450             : 
    1451             : 
    1452             : // ErrorResource Implementation
    1453             : 
    1454             : 
    1455             : bool
    1456           0 : ErrorResource::getString(ErrCode nErrorCode, OUString &rString)
    1457             :     const SAL_THROW(())
    1458             : {
    1459             :     ResId aResId(static_cast< sal_uInt16 >(nErrorCode & ERRCODE_RES_MASK),
    1460           0 :                  *m_pResMgr);
    1461           0 :     aResId.SetRT(RSC_STRING);
    1462           0 :     if (!IsAvailableRes(aResId))
    1463           0 :         return false;
    1464           0 :     aResId.SetAutoRelease(false);
    1465           0 :     rString = aResId.toString();
    1466           0 :     m_pResMgr->PopContext();
    1467           0 :     return true;
    1468             : }
    1469             : 
    1470             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10