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