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

Generated by: LCOV version 1.10