1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
37 #include <svtools/restartdialog.hxx>
38 #include <svtools/svtresid.hxx>
39 #include <svtools/javainteractionhandler.hxx>
40 #include <svtools/javacontext.hxx>
42 using namespace com::sun::star::uno
;
43 using namespace com::sun::star::task
;
48 JavaInteractionHandler::JavaInteractionHandler(bool bReportErrorOnce
) :
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 m_nResult_JavaDisabled(RET_NO
)
60 JavaInteractionHandler::~JavaInteractionHandler()
64 Any SAL_CALL
JavaInteractionHandler::queryInterface(const Type
& aType
)
65 throw (RuntimeException
, std::exception
)
67 if (aType
== cppu::UnoType
<XInterface
>::get())
68 return Any( static_cast<XInterface
*>(this), aType
);
69 else if (aType
== cppu::UnoType
<XInteractionHandler
>::get())
70 return Any( static_cast<XInteractionHandler
*>(this), aType
);
74 void SAL_CALL
JavaInteractionHandler::acquire( ) throw ()
76 osl_atomic_increment( &m_aRefCount
);
79 void SAL_CALL
JavaInteractionHandler::release( ) throw ()
81 if (! osl_atomic_decrement( &m_aRefCount
))
86 void SAL_CALL
JavaInteractionHandler::handle( const Reference
< XInteractionRequest
>& Request
) throw (RuntimeException
, std::exception
)
88 Any anyExc
= Request
->getRequest();
89 Sequence
< Reference
< XInteractionContinuation
> > aSeqCont
= Request
->getContinuations();
91 Reference
< XInteractionAbort
> abort
;
92 Reference
< XInteractionRetry
> retry
;
95 for ( i
= 0; i
< aSeqCont
.getLength(); i
++ )
97 abort
= Reference
< XInteractionAbort
>::query( aSeqCont
[i
]);
102 for ( i
= 0; i
< aSeqCont
.getLength(); i
++)
104 retry
= Reference
<XInteractionRetry
>::query( aSeqCont
[i
]);
109 com::sun::star::java::JavaNotFoundException e1
;
110 com::sun::star::java::InvalidJavaSettingsException e2
;
111 com::sun::star::java::JavaDisabledException e3
;
112 com::sun::star::java::JavaVMCreationFailureException e4
;
113 com::sun::star::java::RestartRequiredException e5
;
114 // Try to recover the Exception type in the any and
115 // react accordingly.
116 sal_uInt16 nResult
= RET_CANCEL
;
120 if( ! (m_bShowErrorsOnce
&& m_bJavaNotFound_Handled
))
122 // No suitable JRE found
123 SolarMutexGuard aSolarGuard
;
124 m_bJavaNotFound_Handled
= true;
125 ScopedVclPtrInstance
< MessageDialog
> aWarningBox(nullptr, SvtResId(STR_WARNING_JAVANOTFOUND
), VCL_MESSAGE_WARNING
);
126 aWarningBox
->SetText(SvtResId(STR_WARNING_JAVANOTFOUND_TITLE
));
127 nResult
= aWarningBox
->Execute();
134 else if ( anyExc
>>= e2
)
136 if( !(m_bShowErrorsOnce
&& m_bInvalidSettings_Handled
))
138 // javavendors.xml was updated and Java has not been configured yet
139 SolarMutexGuard aSolarGuard
;
140 m_bInvalidSettings_Handled
= true;
142 ScopedVclPtrInstance
< MessageDialog
> aWarningBox(nullptr, SvtResId(STR_WARNING_INVALIDJAVASETTINGS_MAC
), VCL_MESSAGE_WARNING
);
144 ScopedVclPtrInstance
< MessageDialog
> aWarningBox(nullptr, SvtResId(STR_WARNING_INVALIDJAVASETTINGS
), VCL_MESSAGE_WARNING
);
146 aWarningBox
->SetText(SvtResId(STR_WARNING_INVALIDJAVASETTINGS_TITLE
));
147 nResult
= aWarningBox
->Execute();
154 else if ( anyExc
>>= e3
)
156 if( !(m_bShowErrorsOnce
&& m_bJavaDisabled_Handled
))
158 SolarMutexGuard aSolarGuard
;
159 m_bJavaDisabled_Handled
= true;
160 // Java disabled. Give user a chance to enable Java inside Office.
161 ScopedVclPtrInstance
<MessageDialog
> aQueryBox(nullptr , "JavaDisabledDialog",
162 "svt/ui/javadisableddialog.ui");
163 nResult
= aQueryBox
->Execute();
164 if ( nResult
== RET_YES
)
166 jfw_setEnabled(sal_True
);
169 m_nResult_JavaDisabled
= nResult
;
174 nResult
= m_nResult_JavaDisabled
;
177 else if ( anyExc
>>= e4
)
179 if( !(m_bShowErrorsOnce
&& m_bVMCreationFailure_Handled
))
181 // Java not correctly installed, or damaged
182 SolarMutexGuard aSolarGuard
;
183 m_bVMCreationFailure_Handled
= true;
185 ScopedVclPtrInstance
< MessageDialog
> aErrorBox(nullptr, SvtResId(STR_ERROR_JVMCREATIONFAILED_MAC
));
187 ScopedVclPtrInstance
< MessageDialog
> aErrorBox(nullptr, SvtResId(STR_ERROR_JVMCREATIONFAILED
));
189 aErrorBox
->SetText(SvtResId(STR_ERROR_JVMCREATIONFAILED_TITLE
));
190 nResult
= aErrorBox
->Execute();
197 else if ( anyExc
>>= e5
)
199 if( !(m_bShowErrorsOnce
&& m_bRestartRequired_Handled
))
201 // a new JRE was selected, but office needs to be restarted
202 //before it can be used.
203 SolarMutexGuard aSolarGuard
;
204 m_bRestartRequired_Handled
= true;
205 svtools::executeRestartDialog(
206 comphelper::getProcessComponentContext(), 0,
207 svtools::RESTART_REASON_JAVA
);
212 if ( nResult
== RET_CANCEL
|| nResult
== RET_NO
)
214 // Unknown exception type or user wants to cancel
218 else // nResult == RET_OK
220 // User selected OK => retry Java usage
228 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */