Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <svtools/svtools.hrc>
30 : : #include <tools/resid.hxx>
31 : : #include <com/sun/star/task/XInteractionContinuation.hpp>
32 : : #include <com/sun/star/task/XInteractionAbort.hpp>
33 : : #include <com/sun/star/task/XInteractionRetry.hpp>
34 : : #include <com/sun/star/java/JavaNotFoundException.hpp>
35 : : #include <com/sun/star/java/InvalidJavaSettingsException.hpp>
36 : : #include <com/sun/star/java/JavaDisabledException.hpp>
37 : : #include <com/sun/star/java/JavaVMCreationFailureException.hpp>
38 : : #include <com/sun/star/java/RestartRequiredException.hpp>
39 : : #include <vcl/svapp.hxx>
40 : : #include <vcl/msgbox.hxx>
41 : : #include <osl/mutex.hxx>
42 : : #include <tools/string.hxx>
43 : : #include <tools/rcid.h>
44 : : #include <jvmfwk/framework.h>
45 : :
46 : : #include <svtools/svtresid.hxx>
47 : : #include <svtools/javainteractionhandler.hxx>
48 : : #include <svtools/javacontext.hxx>
49 : :
50 : : using namespace com::sun::star::uno;
51 : : using namespace com::sun::star::task;
52 : :
53 : : namespace svt
54 : : {
55 : :
56 : 0 : JavaInteractionHandler::JavaInteractionHandler(bool bReportErrorOnce) :
57 : : m_aRefCount(0),
58 : : m_bShowErrorsOnce(bReportErrorOnce),
59 : : m_bJavaDisabled_Handled(false),
60 : : m_bInvalidSettings_Handled(false),
61 : : m_bJavaNotFound_Handled(false),
62 : : m_bVMCreationFailure_Handled(false),
63 : : m_bRestartRequired_Handled(false),
64 : 0 : m_nResult_JavaDisabled(RET_NO)
65 : : {
66 : 0 : }
67 : :
68 : 0 : JavaInteractionHandler::~JavaInteractionHandler()
69 : : {
70 [ # # ]: 0 : }
71 : :
72 : 0 : Any SAL_CALL JavaInteractionHandler::queryInterface(const Type& aType )
73 : : throw (RuntimeException)
74 : : {
75 [ # # ]: 0 : if (aType == getCppuType(reinterpret_cast<Reference<XInterface>*>(0)))
76 : 0 : return Any( static_cast<XInterface*>(this), aType);
77 [ # # ]: 0 : else if (aType == getCppuType(reinterpret_cast<Reference<XInteractionHandler>*>(0)))
78 : 0 : return Any( static_cast<XInteractionHandler*>(this), aType);
79 : 0 : return Any();
80 : : }
81 : :
82 : 0 : void SAL_CALL JavaInteractionHandler::acquire( ) throw ()
83 : : {
84 : 0 : osl_incrementInterlockedCount( &m_aRefCount );
85 : 0 : }
86 : :
87 : 0 : void SAL_CALL JavaInteractionHandler::release( ) throw ()
88 : : {
89 [ # # ]: 0 : if (! osl_decrementInterlockedCount( &m_aRefCount ))
90 [ # # ]: 0 : delete this;
91 : 0 : }
92 : :
93 : :
94 : 0 : void SAL_CALL JavaInteractionHandler::handle( const Reference< XInteractionRequest >& Request ) throw (RuntimeException)
95 : : {
96 [ # # ][ # # ]: 0 : Any anyExc = Request->getRequest();
97 [ # # ][ # # ]: 0 : Sequence< Reference< XInteractionContinuation > > aSeqCont = Request->getContinuations();
98 : :
99 : 0 : Reference< XInteractionAbort > abort;
100 : 0 : Reference< XInteractionRetry > retry;
101 : : sal_Int32 i;
102 : :
103 [ # # ]: 0 : for ( i = 0; i < aSeqCont.getLength(); i++ )
104 : : {
105 [ # # ][ # # ]: 0 : abort = Reference< XInteractionAbort>::query( aSeqCont[i]);
[ # # ]
106 [ # # ]: 0 : if ( abort.is() )
107 : 0 : break;
108 : : }
109 : :
110 [ # # ]: 0 : for ( i= 0; i < aSeqCont.getLength(); i++)
111 : : {
112 [ # # ][ # # ]: 0 : retry= Reference<XInteractionRetry>::query( aSeqCont[i]);
[ # # ]
113 [ # # ]: 0 : if ( retry.is() )
114 : 0 : break;
115 : : }
116 : :
117 [ # # ]: 0 : com::sun::star::java::JavaNotFoundException e1;
118 [ # # ]: 0 : com::sun::star::java::InvalidJavaSettingsException e2;
119 [ # # ]: 0 : com::sun::star::java::JavaDisabledException e3;
120 [ # # ]: 0 : com::sun::star::java::JavaVMCreationFailureException e4;
121 [ # # ]: 0 : com::sun::star::java::RestartRequiredException e5;
122 : : // Try to recover the Exception type in the any and
123 : : // react accordingly.
124 : 0 : sal_uInt16 nResult = RET_CANCEL;
125 : :
126 [ # # ][ # # ]: 0 : if ( anyExc >>= e1 )
127 : : {
128 [ # # ][ # # ]: 0 : if( ! (m_bShowErrorsOnce && m_bJavaNotFound_Handled))
129 : : {
130 : : // No suitable JRE found
131 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
132 : 0 : m_bJavaNotFound_Handled = true;
133 [ # # ][ # # ]: 0 : WarningBox aWarningBox( NULL, SvtResId( WARNINGBOX_JAVANOTFOUND ) );
134 [ # # ][ # # ]: 0 : aWarningBox.SetText(SvtResId(STR_WARNING_JAVANOTFOUND).toString());
[ # # ][ # # ]
[ # # ]
135 [ # # ][ # # ]: 0 : nResult = aWarningBox.Execute();
[ # # ]
136 : : }
137 : : else
138 : : {
139 : 0 : nResult = RET_OK;
140 : : }
141 : : }
142 [ # # ][ # # ]: 0 : else if ( anyExc >>= e2 )
143 : : {
144 [ # # ][ # # ]: 0 : if( !(m_bShowErrorsOnce && m_bInvalidSettings_Handled))
145 : : {
146 : : // javavendors.xml was updated and Java has not been configured yet
147 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
148 : 0 : m_bInvalidSettings_Handled = true;
149 : : #ifdef MACOSX
150 : : WarningBox aWarningBox( NULL, SvtResId( WARNINGBOX_INVALIDJAVASETTINGS_MAC ) );
151 : : #else
152 [ # # ][ # # ]: 0 : WarningBox aWarningBox( NULL, SvtResId( WARNINGBOX_INVALIDJAVASETTINGS ) );
153 : : #endif
154 [ # # ][ # # ]: 0 : aWarningBox.SetText(SvtResId(STR_WARNING_INVALIDJAVASETTINGS).toString());
[ # # ][ # # ]
[ # # ]
155 [ # # ][ # # ]: 0 : nResult = aWarningBox.Execute();
[ # # ]
156 : : }
157 : : else
158 : : {
159 : 0 : nResult = RET_OK;
160 : : }
161 : : }
162 [ # # ][ # # ]: 0 : else if ( anyExc >>= e3 )
163 : : {
164 [ # # ][ # # ]: 0 : if( !(m_bShowErrorsOnce && m_bJavaDisabled_Handled))
165 : : {
166 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
167 : 0 : m_bJavaDisabled_Handled = true;
168 : : // Java disabled. Give user a chance to enable Java inside Office.
169 [ # # ][ # # ]: 0 : QueryBox aQueryBox( NULL, SvtResId( QBX_JAVADISABLED ) );
170 [ # # ][ # # ]: 0 : aQueryBox.SetText(SvtResId( STR_QUESTION_JAVADISABLED ).toString());
[ # # ][ # # ]
[ # # ]
171 [ # # ]: 0 : nResult = aQueryBox.Execute();
172 [ # # ]: 0 : if ( nResult == RET_YES )
173 : : {
174 [ # # ]: 0 : jfw_setEnabled(sal_True);
175 : : }
176 : :
177 [ # # ][ # # ]: 0 : m_nResult_JavaDisabled = nResult;
178 : :
179 : : }
180 : : else
181 : : {
182 : 0 : nResult = m_nResult_JavaDisabled;
183 : : }
184 : : }
185 [ # # ][ # # ]: 0 : else if ( anyExc >>= e4 )
186 : : {
187 [ # # ][ # # ]: 0 : if( !(m_bShowErrorsOnce && m_bVMCreationFailure_Handled))
188 : : {
189 : : // Java not correctly installed, or damaged
190 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
191 : 0 : m_bVMCreationFailure_Handled = true;
192 : : #ifdef MACOSX
193 : : ErrorBox aErrorBox( NULL, SvtResId( ERRORBOX_JVMCREATIONFAILED_MAC ) );
194 : : #else
195 [ # # ][ # # ]: 0 : ErrorBox aErrorBox( NULL, SvtResId( ERRORBOX_JVMCREATIONFAILED ) );
196 : : #endif
197 [ # # ][ # # ]: 0 : aErrorBox.SetText(SvtResId( STR_ERROR_JVMCREATIONFAILED ).toString());
[ # # ][ # # ]
[ # # ]
198 [ # # ][ # # ]: 0 : nResult = aErrorBox.Execute();
[ # # ]
199 : : }
200 : : else
201 : : {
202 : 0 : nResult = RET_OK;
203 : : }
204 : : }
205 [ # # ][ # # ]: 0 : else if ( anyExc >>= e5 )
206 : : {
207 [ # # ][ # # ]: 0 : if( !(m_bShowErrorsOnce && m_bRestartRequired_Handled))
208 : : {
209 : : // a new JRE was selected, but office needs to be restarted
210 : : //before it can be used.
211 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
212 : 0 : m_bRestartRequired_Handled = true;
213 [ # # ][ # # ]: 0 : ErrorBox aErrorBox(NULL, SvtResId( ERRORBOX_RESTARTREQUIRED ) );
214 [ # # ][ # # ]: 0 : aErrorBox.SetText(SvtResId( STR_ERROR_RESTARTREQUIRED ).toString());
[ # # ][ # # ]
[ # # ]
215 [ # # ][ # # ]: 0 : nResult = aErrorBox.Execute();
[ # # ]
216 : : }
217 : : else
218 : : {
219 : 0 : nResult = RET_OK;
220 : : }
221 : : }
222 : :
223 [ # # ][ # # ]: 0 : if ( nResult == RET_CANCEL || nResult == RET_NO)
224 : : {
225 : : // Unknown exception type or user wants to cancel
226 [ # # ]: 0 : if ( abort.is() )
227 [ # # ][ # # ]: 0 : abort->select();
228 : : }
229 : : else // nResult == RET_OK
230 : : {
231 : : // User selected OK => retry Java usage
232 [ # # ]: 0 : if ( retry.is() )
233 [ # # ][ # # ]: 0 : retry->select();
234 [ # # ][ # # ]: 0 : }
[ # # ][ # # ]
[ # # ][ # # ]
235 : 0 : }
236 : :
237 : : }
238 : :
239 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|