LCOV - code coverage report
Current view: top level - svtools/source/java - javainteractionhandler.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 85 1.2 %
Date: 2014-11-03 Functions: 2 9 22.2 %
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 <svtools/svtools.hrc>
      21             : #include <tools/resid.hxx>
      22             : #include <com/sun/star/task/XInteractionContinuation.hpp>
      23             : #include <com/sun/star/task/XInteractionAbort.hpp>
      24             : #include <com/sun/star/task/XInteractionRetry.hpp>
      25             : #include <com/sun/star/java/JavaNotFoundException.hpp>
      26             : #include <com/sun/star/java/InvalidJavaSettingsException.hpp>
      27             : #include <com/sun/star/java/JavaDisabledException.hpp>
      28             : #include <com/sun/star/java/JavaVMCreationFailureException.hpp>
      29             : #include <com/sun/star/java/RestartRequiredException.hpp>
      30             : #include <comphelper/processfactory.hxx>
      31             : #include <vcl/layout.hxx>
      32             : #include <vcl/svapp.hxx>
      33             : #include <osl/mutex.hxx>
      34             : #include <tools/rcid.h>
      35             : #include <jvmfwk/framework.h>
      36             : 
      37             : #include <svtools/restartdialog.hxx>
      38             : #include <svtools/svtresid.hxx>
      39             : #include <svtools/javainteractionhandler.hxx>
      40             : #include <svtools/javacontext.hxx>
      41             : 
      42             : using namespace com::sun::star::uno;
      43             : using namespace com::sun::star::task;
      44             : 
      45             : namespace svt
      46             : {
      47             : 
      48           0 : JavaInteractionHandler::JavaInteractionHandler(bool bReportErrorOnce) :
      49             :     m_aRefCount(0),
      50             :     m_bShowErrorsOnce(bReportErrorOnce),
      51             :     m_bJavaDisabled_Handled(false),
      52             :     m_bInvalidSettings_Handled(false),
      53             :     m_bJavaNotFound_Handled(false),
      54             :     m_bVMCreationFailure_Handled(false),
      55             :     m_bRestartRequired_Handled(false),
      56           0 :     m_nResult_JavaDisabled(RET_NO)
      57             : {
      58           0 : }
      59             : 
      60           0 : JavaInteractionHandler::~JavaInteractionHandler()
      61             : {
      62           0 : }
      63             : 
      64           0 : Any SAL_CALL JavaInteractionHandler::queryInterface(const Type& aType )
      65             :     throw (RuntimeException, std::exception)
      66             : {
      67           0 :     if (aType == cppu::UnoType<XInterface>::get())
      68           0 :         return Any( static_cast<XInterface*>(this), aType);
      69           0 :     else if (aType == cppu::UnoType<XInteractionHandler>::get())
      70           0 :         return Any( static_cast<XInteractionHandler*>(this), aType);
      71           0 :     return Any();
      72             : }
      73             : 
      74           0 : void SAL_CALL JavaInteractionHandler::acquire(  ) throw ()
      75             : {
      76           0 :     osl_atomic_increment( &m_aRefCount );
      77           0 : }
      78             : 
      79           0 : void SAL_CALL JavaInteractionHandler::release(  ) throw ()
      80             : {
      81           0 :     if (! osl_atomic_decrement( &m_aRefCount ))
      82           0 :         delete this;
      83           0 : }
      84             : 
      85             : 
      86           0 : void SAL_CALL JavaInteractionHandler::handle( const Reference< XInteractionRequest >& Request ) throw (RuntimeException, std::exception)
      87             : {
      88           0 :     Any anyExc = Request->getRequest();
      89           0 :     Sequence< Reference< XInteractionContinuation > > aSeqCont = Request->getContinuations();
      90             : 
      91           0 :     Reference< XInteractionAbort > abort;
      92           0 :     Reference< XInteractionRetry > retry;
      93             :     sal_Int32 i;
      94             : 
      95           0 :     for ( i = 0; i < aSeqCont.getLength(); i++ )
      96             :     {
      97           0 :         abort = Reference< XInteractionAbort>::query( aSeqCont[i]);
      98           0 :         if ( abort.is() )
      99           0 :             break;
     100             :     }
     101             : 
     102           0 :     for ( i= 0; i < aSeqCont.getLength(); i++)
     103             :     {
     104           0 :         retry= Reference<XInteractionRetry>::query( aSeqCont[i]);
     105           0 :         if ( retry.is() )
     106           0 :             break;
     107             :     }
     108             : 
     109           0 :     com::sun::star::java::JavaNotFoundException e1;
     110           0 :     com::sun::star::java::InvalidJavaSettingsException e2;
     111           0 :      com::sun::star::java::JavaDisabledException                e3;
     112           0 :     com::sun::star::java::JavaVMCreationFailureException    e4;
     113           0 :     com::sun::star::java::RestartRequiredException e5;
     114             :     // Try to recover the Exception type in the any and
     115             :     // react accordingly.
     116           0 :     sal_uInt16      nResult = RET_CANCEL;
     117             : 
     118           0 :     if ( anyExc >>= e1 )
     119             :     {
     120           0 :         if( ! (m_bShowErrorsOnce && m_bJavaNotFound_Handled))
     121             :         {
     122             :            // No suitable JRE found
     123           0 :             SolarMutexGuard aSolarGuard;
     124           0 :             m_bJavaNotFound_Handled = true;
     125           0 :             MessageDialog aWarningBox(NULL, SvtResId(STR_WARNING_JAVANOTFOUND), VCL_MESSAGE_WARNING);
     126           0 :             aWarningBox.SetText(SvtResId(STR_WARNING_JAVANOTFOUND_TITLE));
     127           0 :             nResult = aWarningBox.Execute();
     128             :         }
     129             :         else
     130             :         {
     131           0 :             nResult = RET_OK;
     132             :         }
     133             :     }
     134           0 :     else if ( anyExc >>= e2 )
     135             :     {
     136           0 :         if( !(m_bShowErrorsOnce && m_bInvalidSettings_Handled))
     137             :         {
     138             :            // javavendors.xml was updated and Java has not been configured yet
     139           0 :             SolarMutexGuard aSolarGuard;
     140           0 :             m_bInvalidSettings_Handled = true;
     141             : #ifdef MACOSX
     142             :             MessageDialog aWarningBox(NULL, SvtResId(STR_WARNING_INVALIDJAVASETTINGS_MAC), VCL_MESSAGE_WARNING);
     143             : #else
     144           0 :             MessageDialog aWarningBox(NULL, SvtResId(STR_WARNING_INVALIDJAVASETTINGS), VCL_MESSAGE_WARNING);
     145             : #endif
     146           0 :             aWarningBox.SetText(SvtResId(STR_WARNING_INVALIDJAVASETTINGS_TITLE));
     147           0 :             nResult = aWarningBox.Execute();
     148             :         }
     149             :         else
     150             :         {
     151           0 :             nResult = RET_OK;
     152             :         }
     153             :     }
     154           0 :     else if ( anyExc >>= e3 )
     155             :     {
     156           0 :         if( !(m_bShowErrorsOnce && m_bJavaDisabled_Handled))
     157             :         {
     158           0 :             SolarMutexGuard aSolarGuard;
     159           0 :             m_bJavaDisabled_Handled = true;
     160             :             // Java disabled. Give user a chance to enable Java inside Office.
     161             :             MessageDialog aQueryBox(NULL, "JavaDisabledDialog",
     162           0 :                                     "svt/ui/javadisableddialog.ui");
     163           0 :             nResult = aQueryBox.Execute();
     164           0 :             if ( nResult == RET_YES )
     165             :             {
     166           0 :                 jfw_setEnabled(sal_True);
     167             :             }
     168             : 
     169           0 :             m_nResult_JavaDisabled = nResult;
     170             : 
     171             :         }
     172             :         else
     173             :         {
     174           0 :             nResult = m_nResult_JavaDisabled;
     175             :         }
     176             :     }
     177           0 :     else if ( anyExc >>= e4 )
     178             :     {
     179           0 :         if( !(m_bShowErrorsOnce && m_bVMCreationFailure_Handled))
     180             :         {
     181             :             // Java not correctly installed, or damaged
     182           0 :             SolarMutexGuard aSolarGuard;
     183           0 :             m_bVMCreationFailure_Handled = true;
     184             : #ifdef MACOSX
     185             :             MessageDialog aErrorBox(NULL, SvtResId(STR_ERROR_JVMCREATIONFAILED_MAC));
     186             : #else
     187           0 :             MessageDialog aErrorBox(NULL, SvtResId(STR_ERROR_JVMCREATIONFAILED));
     188             : #endif
     189           0 :             aErrorBox.SetText(SvtResId(STR_ERROR_JVMCREATIONFAILED_TITLE));
     190           0 :             nResult = aErrorBox.Execute();
     191             :         }
     192             :         else
     193             :         {
     194           0 :             nResult = RET_OK;
     195             :         }
     196             :     }
     197           0 :     else if ( anyExc >>= e5 )
     198             :     {
     199           0 :         if( !(m_bShowErrorsOnce && m_bRestartRequired_Handled))
     200             :         {
     201             :             // a new JRE was selected, but office needs to be restarted
     202             :             //before it can be used.
     203           0 :             SolarMutexGuard aSolarGuard;
     204           0 :             m_bRestartRequired_Handled = true;
     205             :             svtools::executeRestartDialog(
     206             :                 comphelper::getProcessComponentContext(), 0,
     207           0 :                 svtools::RESTART_REASON_JAVA);
     208             :         }
     209           0 :         nResult = RET_OK;
     210             :     }
     211             : 
     212           0 :     if ( nResult == RET_CANCEL || nResult == RET_NO)
     213             :     {
     214             :         // Unknown exception type or user wants to cancel
     215           0 :         if ( abort.is() )
     216           0 :             abort->select();
     217             :     }
     218             :     else // nResult == RET_OK
     219             :     {
     220             :         // User selected OK => retry Java usage
     221           0 :         if ( retry.is() )
     222           0 :             retry->select();
     223           0 :     }
     224           0 : }
     225             : 
     226        1227 : }
     227             : 
     228             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10