2010-10-14 08:27:31 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-11-15 17:28:16 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2005-07-07 12:10:20 +00:00
|
|
|
|
2010-04-09 11:05:09 +02:00
|
|
|
#include <svtools/svtools.hrc>
|
2005-07-07 12:10:20 +00:00
|
|
|
#include <tools/resid.hxx>
|
|
|
|
#include <com/sun/star/task/XInteractionContinuation.hpp>
|
|
|
|
#include <com/sun/star/task/XInteractionAbort.hpp>
|
|
|
|
#include <com/sun/star/task/XInteractionRetry.hpp>
|
|
|
|
#include <com/sun/star/java/JavaNotFoundException.hpp>
|
|
|
|
#include <com/sun/star/java/InvalidJavaSettingsException.hpp>
|
|
|
|
#include <com/sun/star/java/JavaDisabledException.hpp>
|
|
|
|
#include <com/sun/star/java/JavaVMCreationFailureException.hpp>
|
|
|
|
#include <com/sun/star/java/RestartRequiredException.hpp>
|
|
|
|
#include <vcl/svapp.hxx>
|
|
|
|
#include <vcl/msgbox.hxx>
|
2010-10-16 03:20:00 -05:00
|
|
|
#include <osl/mutex.hxx>
|
2005-07-07 12:10:20 +00:00
|
|
|
#include <tools/string.hxx>
|
|
|
|
#include <tools/rcid.h>
|
|
|
|
#include <jvmfwk/framework.h>
|
|
|
|
|
2012-04-25 15:33:16 +01:00
|
|
|
#include <svtools/svtresid.hxx>
|
2007-06-27 20:47:35 +00:00
|
|
|
#include <svtools/javainteractionhandler.hxx>
|
|
|
|
#include <svtools/javacontext.hxx>
|
2005-07-07 12:10:20 +00:00
|
|
|
|
|
|
|
using namespace com::sun::star::uno;
|
|
|
|
using namespace com::sun::star::task;
|
|
|
|
|
|
|
|
namespace svt
|
|
|
|
{
|
|
|
|
|
|
|
|
JavaInteractionHandler::JavaInteractionHandler(bool bReportErrorOnce) :
|
|
|
|
m_aRefCount(0),
|
|
|
|
m_bShowErrorsOnce(bReportErrorOnce),
|
|
|
|
m_bJavaDisabled_Handled(false),
|
|
|
|
m_bInvalidSettings_Handled(false),
|
|
|
|
m_bJavaNotFound_Handled(false),
|
|
|
|
m_bVMCreationFailure_Handled(false),
|
|
|
|
m_bRestartRequired_Handled(false),
|
|
|
|
m_nResult_JavaDisabled(RET_NO)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
JavaInteractionHandler::~JavaInteractionHandler()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Any SAL_CALL JavaInteractionHandler::queryInterface(const Type& aType )
|
|
|
|
throw (RuntimeException)
|
|
|
|
{
|
|
|
|
if (aType == getCppuType(reinterpret_cast<Reference<XInterface>*>(0)))
|
|
|
|
return Any( static_cast<XInterface*>(this), aType);
|
|
|
|
else if (aType == getCppuType(reinterpret_cast<Reference<XInteractionHandler>*>(0)))
|
|
|
|
return Any( static_cast<XInteractionHandler*>(this), aType);
|
|
|
|
return Any();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SAL_CALL JavaInteractionHandler::acquire( ) throw ()
|
|
|
|
{
|
2012-09-22 01:51:12 -05:00
|
|
|
osl_atomic_increment( &m_aRefCount );
|
2005-07-07 12:10:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SAL_CALL JavaInteractionHandler::release( ) throw ()
|
|
|
|
{
|
2012-09-22 01:51:12 -05:00
|
|
|
if (! osl_atomic_decrement( &m_aRefCount ))
|
2005-07-07 12:10:20 +00:00
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SAL_CALL JavaInteractionHandler::handle( const Reference< XInteractionRequest >& Request ) throw (RuntimeException)
|
|
|
|
{
|
|
|
|
Any anyExc = Request->getRequest();
|
|
|
|
Sequence< Reference< XInteractionContinuation > > aSeqCont = Request->getContinuations();
|
|
|
|
|
|
|
|
Reference< XInteractionAbort > abort;
|
|
|
|
Reference< XInteractionRetry > retry;
|
|
|
|
sal_Int32 i;
|
|
|
|
|
|
|
|
for ( i = 0; i < aSeqCont.getLength(); i++ )
|
|
|
|
{
|
|
|
|
abort = Reference< XInteractionAbort>::query( aSeqCont[i]);
|
|
|
|
if ( abort.is() )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
for ( i= 0; i < aSeqCont.getLength(); i++)
|
|
|
|
{
|
|
|
|
retry= Reference<XInteractionRetry>::query( aSeqCont[i]);
|
|
|
|
if ( retry.is() )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
com::sun::star::java::JavaNotFoundException e1;
|
|
|
|
com::sun::star::java::InvalidJavaSettingsException e2;
|
|
|
|
com::sun::star::java::JavaDisabledException e3;
|
|
|
|
com::sun::star::java::JavaVMCreationFailureException e4;
|
|
|
|
com::sun::star::java::RestartRequiredException e5;
|
|
|
|
// Try to recover the Exception type in the any and
|
|
|
|
// react accordingly.
|
2010-11-05 10:31:15 +08:00
|
|
|
sal_uInt16 nResult = RET_CANCEL;
|
2005-07-07 12:10:20 +00:00
|
|
|
|
|
|
|
if ( anyExc >>= e1 )
|
|
|
|
{
|
|
|
|
if( ! (m_bShowErrorsOnce && m_bJavaNotFound_Handled))
|
|
|
|
{
|
|
|
|
// No suitable JRE found
|
2010-10-13 01:47:23 -05:00
|
|
|
SolarMutexGuard aSolarGuard;
|
2005-07-07 12:10:20 +00:00
|
|
|
m_bJavaNotFound_Handled = true;
|
2010-08-09 17:39:22 +02:00
|
|
|
WarningBox aWarningBox( NULL, SvtResId( WARNINGBOX_JAVANOTFOUND ) );
|
2012-06-25 23:10:14 +01:00
|
|
|
aWarningBox.SetText(SvtResId(STR_WARNING_JAVANOTFOUND).toString());
|
2005-07-07 12:10:20 +00:00
|
|
|
nResult = aWarningBox.Execute();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nResult = RET_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ( anyExc >>= e2 )
|
|
|
|
{
|
|
|
|
if( !(m_bShowErrorsOnce && m_bInvalidSettings_Handled))
|
|
|
|
{
|
|
|
|
// javavendors.xml was updated and Java has not been configured yet
|
2010-10-13 01:47:23 -05:00
|
|
|
SolarMutexGuard aSolarGuard;
|
2005-07-07 12:10:20 +00:00
|
|
|
m_bInvalidSettings_Handled = true;
|
2012-04-03 16:22:01 +02:00
|
|
|
#ifdef MACOSX
|
|
|
|
WarningBox aWarningBox( NULL, SvtResId( WARNINGBOX_INVALIDJAVASETTINGS_MAC ) );
|
|
|
|
#else
|
2010-08-09 17:39:22 +02:00
|
|
|
WarningBox aWarningBox( NULL, SvtResId( WARNINGBOX_INVALIDJAVASETTINGS ) );
|
2012-04-03 16:22:01 +02:00
|
|
|
#endif
|
2012-06-25 23:10:14 +01:00
|
|
|
aWarningBox.SetText(SvtResId(STR_WARNING_INVALIDJAVASETTINGS).toString());
|
2005-07-07 12:10:20 +00:00
|
|
|
nResult = aWarningBox.Execute();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nResult = RET_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ( anyExc >>= e3 )
|
|
|
|
{
|
|
|
|
if( !(m_bShowErrorsOnce && m_bJavaDisabled_Handled))
|
|
|
|
{
|
2010-10-13 01:47:23 -05:00
|
|
|
SolarMutexGuard aSolarGuard;
|
2005-07-07 12:10:20 +00:00
|
|
|
m_bJavaDisabled_Handled = true;
|
|
|
|
// Java disabled. Give user a chance to enable Java inside Office.
|
2010-08-09 17:39:22 +02:00
|
|
|
QueryBox aQueryBox( NULL, SvtResId( QBX_JAVADISABLED ) );
|
2012-06-25 23:10:14 +01:00
|
|
|
aQueryBox.SetText(SvtResId( STR_QUESTION_JAVADISABLED ).toString());
|
2005-07-07 12:10:20 +00:00
|
|
|
nResult = aQueryBox.Execute();
|
|
|
|
if ( nResult == RET_YES )
|
|
|
|
{
|
|
|
|
jfw_setEnabled(sal_True);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_nResult_JavaDisabled = nResult;
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nResult = m_nResult_JavaDisabled;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ( anyExc >>= e4 )
|
|
|
|
{
|
|
|
|
if( !(m_bShowErrorsOnce && m_bVMCreationFailure_Handled))
|
|
|
|
{
|
|
|
|
// Java not correctly installed, or damaged
|
2010-10-13 01:47:23 -05:00
|
|
|
SolarMutexGuard aSolarGuard;
|
2005-07-07 12:10:20 +00:00
|
|
|
m_bVMCreationFailure_Handled = true;
|
2012-04-03 16:22:01 +02:00
|
|
|
#ifdef MACOSX
|
|
|
|
ErrorBox aErrorBox( NULL, SvtResId( ERRORBOX_JVMCREATIONFAILED_MAC ) );
|
|
|
|
#else
|
2010-08-09 17:39:22 +02:00
|
|
|
ErrorBox aErrorBox( NULL, SvtResId( ERRORBOX_JVMCREATIONFAILED ) );
|
2012-04-03 16:22:01 +02:00
|
|
|
#endif
|
2012-06-25 23:10:14 +01:00
|
|
|
aErrorBox.SetText(SvtResId( STR_ERROR_JVMCREATIONFAILED ).toString());
|
2005-07-07 12:10:20 +00:00
|
|
|
nResult = aErrorBox.Execute();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nResult = RET_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ( anyExc >>= e5 )
|
|
|
|
{
|
|
|
|
if( !(m_bShowErrorsOnce && m_bRestartRequired_Handled))
|
|
|
|
{
|
|
|
|
// a new JRE was selected, but office needs to be restarted
|
|
|
|
//before it can be used.
|
2010-10-13 01:47:23 -05:00
|
|
|
SolarMutexGuard aSolarGuard;
|
2005-07-07 12:10:20 +00:00
|
|
|
m_bRestartRequired_Handled = true;
|
2010-08-09 17:39:22 +02:00
|
|
|
ErrorBox aErrorBox(NULL, SvtResId( ERRORBOX_RESTARTREQUIRED ) );
|
2012-06-25 23:10:14 +01:00
|
|
|
aErrorBox.SetText(SvtResId( STR_ERROR_RESTARTREQUIRED ).toString());
|
2005-07-07 12:10:20 +00:00
|
|
|
nResult = aErrorBox.Execute();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nResult = RET_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( nResult == RET_CANCEL || nResult == RET_NO)
|
|
|
|
{
|
|
|
|
// Unknown exception type or user wants to cancel
|
|
|
|
if ( abort.is() )
|
|
|
|
abort->select();
|
|
|
|
}
|
|
|
|
else // nResult == RET_OK
|
|
|
|
{
|
|
|
|
// User selected OK => retry Java usage
|
|
|
|
if ( retry.is() )
|
|
|
|
retry->select();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2010-10-14 08:27:31 +02:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|