From 940b4d1848e8c70ab7642901a68594e8016caffc Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 27 Apr 2024 18:51:28 +0200 Subject: Adding upstream version 1:7.0.4. Signed-off-by: Daniel Baumann --- svtools/source/java/javacontext.cxx | 85 +++++++++ svtools/source/java/javainteractionhandler.cxx | 252 +++++++++++++++++++++++++ 2 files changed, 337 insertions(+) create mode 100644 svtools/source/java/javacontext.cxx create mode 100644 svtools/source/java/javainteractionhandler.cxx (limited to 'svtools/source/java') diff --git a/svtools/source/java/javacontext.cxx b/svtools/source/java/javacontext.cxx new file mode 100644 index 000000000..f961453f6 --- /dev/null +++ b/svtools/source/java/javacontext.cxx @@ -0,0 +1,85 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 . + */ + +#include +#include +#include +#include + +using namespace com::sun::star::uno; +using namespace com::sun::star::task; +namespace svt +{ + +JavaContext::JavaContext( const Reference< XCurrentContext > & ctx) + : m_aRefCount(0), + m_xNextContext( ctx ) +{ +} + +JavaContext::~JavaContext() +{ +} + +Any SAL_CALL JavaContext::queryInterface(const Type& aType ) +{ + if (aType == cppu::UnoType::get()) + return Any(Reference(static_cast(this))); + else if (aType == cppu::UnoType::get()) + return Any(Reference( static_cast(this))); + return Any(); +} + +void SAL_CALL JavaContext::acquire( ) throw () +{ + osl_atomic_increment( &m_aRefCount ); +} + +void SAL_CALL JavaContext::release( ) throw () +{ + if (! osl_atomic_decrement( &m_aRefCount )) + delete this; +} + +Any SAL_CALL JavaContext::getValueByName( const OUString& Name) +{ + Any retVal; + + if ( Name == JAVA_INTERACTION_HANDLER_NAME ) + { + { + osl::MutexGuard aGuard(osl::Mutex::getGlobalMutex()); + if (!m_xHandler.is()) + m_xHandler.set( new JavaInteractionHandler ); + } + retVal <<= m_xHandler; + + } + else if( m_xNextContext.is() ) + { + // Call next context in chain if found + retVal = m_xNextContext->getValueByName( Name ); + } + return retVal; +} + + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svtools/source/java/javainteractionhandler.cxx b/svtools/source/java/javainteractionhandler.cxx new file mode 100644 index 000000000..9dff4a57e --- /dev/null +++ b/svtools/source/java/javainteractionhandler.cxx @@ -0,0 +1,252 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 . + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +using namespace com::sun::star::uno; +using namespace com::sun::star::task; + +namespace +{ +static struct JavaEvents { + bool bDisabledHandled : 1; + bool bInvalidSettingsHandled : 1; + bool bNotFoundHandled : 1; + bool bVMCreationFailureHandled : 1; + bool bRestartRequiredHandled : 1; + sal_uInt16 nResult_JavaDisabled = RET_NO; + JavaEvents() + : bDisabledHandled(false) + , bInvalidSettingsHandled(false) + , bNotFoundHandled(false) + , bVMCreationFailureHandled(false) + , bRestartRequiredHandled(false) + {} +} g_JavaEvents; +} + +namespace svt +{ + +JavaInteractionHandler::JavaInteractionHandler() : + m_aRefCount(0) +{ +} + +JavaInteractionHandler::~JavaInteractionHandler() +{ +} + +Any SAL_CALL JavaInteractionHandler::queryInterface(const Type& aType ) +{ + if (aType == cppu::UnoType::get()) + return Any( static_cast(this), aType); + else if (aType == cppu::UnoType::get()) + return Any( static_cast(this), aType); + return Any(); +} + +void SAL_CALL JavaInteractionHandler::acquire( ) throw () +{ + osl_atomic_increment( &m_aRefCount ); +} + +void SAL_CALL JavaInteractionHandler::release( ) throw () +{ + if (! osl_atomic_decrement( &m_aRefCount )) + delete this; +} + +void SAL_CALL JavaInteractionHandler::handle( const Reference< XInteractionRequest >& Request ) +{ + Any anyExc = Request->getRequest(); + const Sequence< Reference< XInteractionContinuation > > aSeqCont = Request->getContinuations(); + + Reference< XInteractionAbort > abort; + Reference< XInteractionRetry > retry; + + for ( const auto& rCont : aSeqCont ) + { + abort.set( rCont, UNO_QUERY ); + if ( abort.is() ) + break; + } + + for ( const auto& rCont : aSeqCont ) + { + retry.set( rCont, UNO_QUERY ); + if ( retry.is() ) + break; + } + + css::java::JavaNotFoundException e1; + css::java::InvalidJavaSettingsException e2; + css::java::JavaDisabledException e3; + css::java::JavaVMCreationFailureException e4; + css::java::RestartRequiredException e5; + // Try to recover the Exception type in the any and + // react accordingly. + sal_uInt16 nResult = RET_CANCEL; + + if ( anyExc >>= e1 ) + { + SolarMutexGuard aSolarGuard; + if( !g_JavaEvents.bNotFoundHandled ) + { + // No suitable JRE found + g_JavaEvents.bNotFoundHandled = true; +#if defined( MACOSX ) + std::unique_ptr xWarningBox(Application::CreateMessageDialog(nullptr, + VclMessageType::Warning, VclButtonsType::Ok, SvtResId(STR_WARNING_JAVANOTFOUND_MAC))); +#elif defined( _WIN32 ) + std::unique_ptr xWarningBox(Application::CreateMessageDialog(nullptr, + VclMessageType::Warning, VclButtonsType::Ok, SvtResId(STR_WARNING_JAVANOTFOUND_WIN))); + OUString sPrimTex = xWarningBox->get_primary_text(); +#if defined( _WIN64 ) + xWarningBox->set_primary_text(sPrimTex.replaceAll( "%BITNESS", "64" )); +#else + xWarningBox->set_primary_text(sPrimTex.replaceAll( "%BITNESS", "32" )); +#endif +#else + std::unique_ptr xWarningBox(Application::CreateMessageDialog(nullptr, + VclMessageType::Warning, VclButtonsType::Ok, SvtResId(STR_WARNING_JAVANOTFOUND))); +#endif + xWarningBox->set_title(SvtResId(STR_WARNING_JAVANOTFOUND_TITLE)); + nResult = xWarningBox->run(); + } + else + { + nResult = RET_OK; + } + } + else if ( anyExc >>= e2 ) + { + SolarMutexGuard aSolarGuard; + if( !g_JavaEvents.bInvalidSettingsHandled ) + { + // javavendors.xml was updated and Java has not been configured yet + g_JavaEvents.bInvalidSettingsHandled = true; +#ifdef MACOSX + OUString sWarning(SvtResId(STR_WARNING_INVALIDJAVASETTINGS_MAC)); +#else + OUString sWarning(SvtResId(STR_WARNING_INVALIDJAVASETTINGS)); +#endif + std::unique_ptr xWarningBox(Application::CreateMessageDialog(nullptr, + VclMessageType::Warning, VclButtonsType::Ok, sWarning)); + xWarningBox->set_title(SvtResId(STR_WARNING_INVALIDJAVASETTINGS_TITLE)); + nResult = xWarningBox->run(); + } + else + { + nResult = RET_OK; + } + } + else if ( anyExc >>= e3 ) + { + SolarMutexGuard aSolarGuard; + if( !g_JavaEvents.bDisabledHandled ) + { + g_JavaEvents.bDisabledHandled = true; + // Java disabled. Give user a chance to enable Java inside Office. + std::unique_ptr xBuilder(Application::CreateBuilder(nullptr, "svt/ui/javadisableddialog.ui")); + std::unique_ptr xQueryBox(xBuilder->weld_message_dialog("JavaDisabledDialog")); + nResult = xQueryBox->run(); + if ( nResult == RET_YES ) + { + jfw_setEnabled(true); + } + + g_JavaEvents.nResult_JavaDisabled = nResult; + + } + else + { + nResult = g_JavaEvents.nResult_JavaDisabled; + } + } + else if ( anyExc >>= e4 ) + { + SolarMutexGuard aSolarGuard; + if( !g_JavaEvents.bVMCreationFailureHandled ) + { + // Java not correctly installed, or damaged + g_JavaEvents.bVMCreationFailureHandled = true; +#ifdef MACOSX + OUString sWarning(SvtResId(STR_ERROR_JVMCREATIONFAILED_MAC)); +#else + OUString sWarning(SvtResId(STR_ERROR_JVMCREATIONFAILED)); +#endif + std::unique_ptr xErrorBox(Application::CreateMessageDialog(nullptr, + VclMessageType::Warning, VclButtonsType::Ok, sWarning)); + xErrorBox->set_title(SvtResId(STR_ERROR_JVMCREATIONFAILED_TITLE)); + nResult = xErrorBox->run(); + } + else + { + nResult = RET_OK; + } + } + else if ( anyExc >>= e5 ) + { + SolarMutexGuard aSolarGuard; + if( !g_JavaEvents.bRestartRequiredHandled ) + { + // a new JRE was selected, but office needs to be restarted + //before it can be used. + g_JavaEvents.bRestartRequiredHandled = true; + svtools::executeRestartDialog( + comphelper::getProcessComponentContext(), nullptr, + svtools::RESTART_REASON_JAVA); + } + 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(); + } +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit v1.2.3