Branch data 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 : :
21 : : #include "javavm.hxx"
22 : :
23 : : #include "interact.hxx"
24 : : #include "jvmargs.hxx"
25 : :
26 : : #include "com/sun/star/beans/NamedValue.hpp"
27 : : #include "com/sun/star/beans/PropertyState.hpp"
28 : : #include "com/sun/star/beans/PropertyValue.hpp"
29 : : #include "com/sun/star/container/XContainer.hpp"
30 : : #include "com/sun/star/java/JavaNotFoundException.hpp"
31 : : #include "com/sun/star/java/InvalidJavaSettingsException.hpp"
32 : : #include "com/sun/star/java/RestartRequiredException.hpp"
33 : : #include "com/sun/star/java/JavaDisabledException.hpp"
34 : : #include "com/sun/star/java/JavaVMCreationFailureException.hpp"
35 : : #include "com/sun/star/lang/DisposedException.hpp"
36 : : #include "com/sun/star/lang/IllegalArgumentException.hpp"
37 : : #include "com/sun/star/lang/XEventListener.hpp"
38 : : #include "com/sun/star/lang/XMultiComponentFactory.hpp"
39 : : #include "com/sun/star/lang/XSingleComponentFactory.hpp"
40 : : #include "com/sun/star/lang/WrappedTargetRuntimeException.hpp"
41 : : #include "com/sun/star/registry/XRegistryKey.hpp"
42 : : #include "com/sun/star/registry/XSimpleRegistry.hpp"
43 : : #include "com/sun/star/task/XInteractionHandler.hpp"
44 : : #include "com/sun/star/uno/Exception.hpp"
45 : : #include "com/sun/star/uno/Reference.hxx"
46 : : #include "com/sun/star/uno/RuntimeException.hpp"
47 : : #include "com/sun/star/uno/Sequence.hxx"
48 : : #include "com/sun/star/uno/XComponentContext.hpp"
49 : : #include "com/sun/star/uno/XCurrentContext.hpp"
50 : : #include "com/sun/star/uno/XInterface.hpp"
51 : : #include "com/sun/star/util/XMacroExpander.hpp"
52 : : #include "com/sun/star/container/XNameAccess.hpp"
53 : : #include "cppuhelper/exc_hlp.hxx"
54 : : #include "cppuhelper/factory.hxx"
55 : : #include "cppuhelper/implbase1.hxx"
56 : : #include "cppuhelper/implementationentry.hxx"
57 : : #include "jvmaccess/classpath.hxx"
58 : : #include "jvmaccess/unovirtualmachine.hxx"
59 : : #include "jvmaccess/virtualmachine.hxx"
60 : : #include "osl/file.hxx"
61 : : #include "osl/thread.h"
62 : : #include "rtl/bootstrap.hxx"
63 : : #include "rtl/process.h"
64 : : #include "rtl/string.h"
65 : : #include "rtl/ustrbuf.hxx"
66 : : #include "rtl/ustring.h"
67 : : #include "rtl/ustring.hxx"
68 : : #include "rtl/uri.hxx"
69 : : #include "sal/types.h"
70 : : #include "uno/current_context.hxx"
71 : : #include "uno/environment.h"
72 : : #include "uno/lbnames.h"
73 : : #include "jvmfwk/framework.h"
74 : : #include "jni.h"
75 : :
76 : : #include <stack>
77 : : #include <string.h>
78 : : #include <time.h>
79 : : #include <memory>
80 : : #include <vector>
81 : : #include "boost/scoped_array.hpp"
82 : : #define OUSTR(x) rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( x ))
83 : :
84 : : // Properties of the javavm can be put
85 : : // as a komma separated list in this
86 : : // environment variable
87 : : #define PROPERTIES_ENV "OO_JAVA_PROPERTIES"
88 : : #ifdef UNIX
89 : : #define INI_FILE "javarc"
90 : : #ifdef MACOSX
91 : : #define DEF_JAVALIB "JavaVM.framework"
92 : : #else
93 : : #define DEF_JAVALIB "libjvm.so"
94 : : #endif
95 : : #define TIMEZONE "MEZ"
96 : : #else
97 : : #define INI_FILE "java.ini"
98 : : #define DEF_JAVALIB "jvm.dll"
99 : : #define TIMEZONE "MET"
100 : : #endif
101 : :
102 : : /* Within this implementation of the com.sun.star.java.JavaVirtualMachine
103 : : * service and com.sun.star.java.theJavaVirtualMachine singleton, the method
104 : : * com.sun.star.java.XJavaVM.getJavaVM relies on the following:
105 : : * 1 The string "$URE_INTERNAL_JAVA_DIR/" is expanded via the
106 : : * com.sun.star.util.theMacroExpander singleton into an internal (see the
107 : : * com.sun.star.uri.ExternalUriReferenceTranslator service), hierarchical URI
108 : : * reference relative to which the URE JAR files can be addressed.
109 : : * 2 The string "$URE_INTERNAL_JAVA_CLASSPATH" is either not expandable via the
110 : : * com.sun.star.util.theMacroExpander singleton
111 : : * (com.sun.star.lang.IllegalArgumentException), or is expanded via the
112 : : * com.sun.star.util.theMacroExpander singleton into a list of zero or more
113 : : * internal (see the com.sun.star.uri.ExternalUriReferenceTranslator service)
114 : : * URIs, where any space characters (U+0020) are ignored (and, in particular,
115 : : * separate adjacent URIs).
116 : : * If either of these requirements is not met, getJavaVM raises a
117 : : * com.sun.star.uno.RuntimeException.
118 : : */
119 : :
120 : : namespace css = com::sun::star;
121 : :
122 : : using stoc_javavm::JavaVirtualMachine;
123 : :
124 : : namespace {
125 : :
126 : :
127 : :
128 : : class NoJavaIniException: public css::uno::Exception
129 : : {
130 : : };
131 : :
132 : : class SingletonFactory:
133 : : private cppu::WeakImplHelper1< css::lang::XEventListener >
134 : : {
135 : : public:
136 : : static css::uno::Reference< css::uno::XInterface > getSingleton(
137 : : css::uno::Reference< css::uno::XComponentContext > const & rContext);
138 : :
139 : : private:
140 : : SingletonFactory(SingletonFactory &); // not implemented
141 : : void operator =(SingletonFactory); // not implemented
142 : :
143 : 4 : inline SingletonFactory() {}
144 : :
145 [ - + ]: 8 : virtual inline ~SingletonFactory() {}
146 : :
147 : : virtual void SAL_CALL disposing(css::lang::EventObject const &)
148 : : throw (css::uno::RuntimeException);
149 : :
150 : : static void dispose();
151 : :
152 : : // TODO ok to keep these static?
153 : : static osl::Mutex m_aMutex;
154 : : static css::uno::Reference< css::uno::XInterface > m_xSingleton;
155 : : static bool m_bDisposed;
156 : : };
157 : :
158 : 4 : css::uno::Reference< css::uno::XInterface > SingletonFactory::getSingleton(
159 : : css::uno::Reference< css::uno::XComponentContext > const & rContext)
160 : : {
161 : 4 : css::uno::Reference< css::uno::XInterface > xSingleton;
162 : 4 : css::uno::Reference< css::lang::XComponent > xComponent;
163 : : {
164 [ + - ]: 4 : osl::MutexGuard aGuard(m_aMutex);
165 [ + - ]: 4 : if (!m_xSingleton.is())
166 : : {
167 [ - + ]: 4 : if (m_bDisposed)
168 [ # # ]: 0 : throw css::lang::DisposedException();
169 : : xComponent = css::uno::Reference< css::lang::XComponent >(
170 [ + - ][ + - ]: 4 : rContext, css::uno::UNO_QUERY_THROW);
171 : : m_xSingleton = static_cast< cppu::OWeakObject * >(
172 [ + - ][ + - ]: 4 : new JavaVirtualMachine(rContext));
173 : : }
174 [ + - ][ + - ]: 4 : xSingleton = m_xSingleton;
175 : : }
176 [ + - ]: 4 : if (xComponent.is())
177 : : try
178 : : {
179 [ + - ][ + - ]: 4 : xComponent->addEventListener(new SingletonFactory);
[ + - ][ + - ]
[ + - ]
180 : : }
181 : 0 : catch (...)
182 : : {
183 [ # # ]: 0 : dispose();
184 : 0 : throw;
185 : : }
186 : 4 : return xSingleton;
187 : : }
188 : :
189 : 4 : void SAL_CALL SingletonFactory::disposing(css::lang::EventObject const &)
190 : : throw (css::uno::RuntimeException)
191 : : {
192 : 4 : dispose();
193 : 4 : }
194 : :
195 : 4 : void SingletonFactory::dispose()
196 : : {
197 : 4 : css::uno::Reference< css::lang::XComponent > xComponent;
198 : : {
199 [ + - ]: 4 : osl::MutexGuard aGuard(m_aMutex);
200 : : xComponent = css::uno::Reference< css::lang::XComponent >(
201 [ + - ][ + - ]: 4 : m_xSingleton, css::uno::UNO_QUERY);
202 : 4 : m_xSingleton.clear();
203 [ + - ]: 4 : m_bDisposed = true;
204 : : }
205 [ + - ]: 4 : if (xComponent.is())
206 [ + - ][ + - ]: 4 : xComponent->dispose();
207 : 4 : }
208 : :
209 : 4 : osl::Mutex SingletonFactory::m_aMutex;
210 : 4 : css::uno::Reference< css::uno::XInterface > SingletonFactory::m_xSingleton;
211 : : bool SingletonFactory::m_bDisposed = false;
212 : :
213 : 4 : rtl::OUString serviceGetImplementationName()
214 : : {
215 : : return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
216 : 4 : "com.sun.star.comp.stoc.JavaVirtualMachine"));
217 : : }
218 : :
219 : 4 : css::uno::Sequence< rtl::OUString > serviceGetSupportedServiceNames()
220 : : {
221 : : rtl::OUString aServiceName(
222 [ + - ]: 4 : RTL_CONSTASCII_USTRINGPARAM("com.sun.star.java.JavaVirtualMachine"));
223 [ + - ]: 4 : return css::uno::Sequence< rtl::OUString >(&aServiceName, 1);
224 : : }
225 : :
226 : 4 : css::uno::Reference< css::uno::XInterface > SAL_CALL serviceCreateInstance(
227 : : css::uno::Reference< css::uno::XComponentContext > const & rContext)
228 : : SAL_THROW((css::uno::Exception))
229 : : {
230 : : // Only one single instance of this service is ever constructed, and is
231 : : // available until the component context used to create this instance is
232 : : // disposed. Afterwards, this function throws a DisposedException (as do
233 : : // all relevant methods on the single service instance).
234 : 4 : return SingletonFactory::getSingleton(rContext);
235 : : }
236 : :
237 : : cppu::ImplementationEntry const aServiceImplementation[]
238 : : = { { serviceCreateInstance,
239 : : serviceGetImplementationName,
240 : : serviceGetSupportedServiceNames,
241 : : cppu::createSingleComponentFactory,
242 : : 0, 0 },
243 : : { 0, 0, 0, 0, 0, 0 } };
244 : :
245 : : typedef std::stack< jvmaccess::VirtualMachine::AttachGuard * > GuardStack;
246 : :
247 : : extern "C" {
248 : :
249 : 0 : static void destroyAttachGuards(void * pData)
250 : : {
251 : 0 : GuardStack * pStack = static_cast< GuardStack * >(pData);
252 [ # # ]: 0 : if (pStack != 0)
253 : : {
254 [ # # ]: 0 : while (!pStack->empty())
255 : : {
256 [ # # ]: 0 : delete pStack->top();
257 : 0 : pStack->pop();
258 : : }
259 [ # # ]: 0 : delete pStack;
260 : : }
261 : 0 : }
262 : :
263 : : }
264 : :
265 : 0 : bool askForRetry(css::uno::Any const & rException)
266 : : {
267 : : css::uno::Reference< css::uno::XCurrentContext > xContext(
268 [ # # ]: 0 : css::uno::getCurrentContext());
269 [ # # ]: 0 : if (xContext.is())
270 : : {
271 : 0 : css::uno::Reference< css::task::XInteractionHandler > xHandler;
272 [ # # ]: 0 : xContext->getValueByName(rtl::OUString(
273 : : RTL_CONSTASCII_USTRINGPARAM(
274 : 0 : "java-vm.interaction-handler")))
275 [ # # ][ # # ]: 0 : >>= xHandler;
[ # # ]
276 [ # # ]: 0 : if (xHandler.is())
277 : : {
278 : : rtl::Reference< stoc_javavm::InteractionRequest > xRequest(
279 [ # # ]: 0 : new stoc_javavm::InteractionRequest(rException));
280 [ # # ][ # # ]: 0 : xHandler->handle(xRequest.get());
[ # # ][ # # ]
281 [ # # ]: 0 : return xRequest->retry();
282 [ # # ]: 0 : }
283 : : }
284 : 0 : return false;
285 : : }
286 : :
287 : : // Only gets the properties if the "Proxy Server" entry in the option dialog is
288 : : // set to manual (i.e. not to none)
289 : 4 : void getINetPropsFromConfig(stoc_javavm::JVM * pjvm,
290 : : const css::uno::Reference<css::lang::XMultiComponentFactory> & xSMgr,
291 : : const css::uno::Reference<css::uno::XComponentContext> &xCtx ) throw (css::uno::Exception)
292 : : {
293 [ + - ]: 4 : css::uno::Reference<css::uno::XInterface> xConfRegistry = xSMgr->createInstanceWithContext(
294 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.configuration.ConfigurationRegistry")),
295 [ + - ][ + - ]: 4 : xCtx );
296 [ # # ][ # # ]: 4 : if(!xConfRegistry.is()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("javavm.cxx: couldn't get ConfigurationRegistry")), 0);
[ # # ][ - + ]
297 : :
298 [ + - ]: 4 : css::uno::Reference<css::registry::XSimpleRegistry> xConfRegistry_simple(xConfRegistry, css::uno::UNO_QUERY);
299 [ - + ][ # # ]: 4 : if(!xConfRegistry_simple.is()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("javavm.cxx: couldn't get ConfigurationRegistry")), 0);
[ # # ][ # # ]
300 : :
301 [ + - ][ + - ]: 4 : xConfRegistry_simple->open(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("org.openoffice.Inet")), sal_True, sal_False);
[ + - ]
302 [ + - ][ + - ]: 4 : css::uno::Reference<css::registry::XRegistryKey> xRegistryRootKey = xConfRegistry_simple->getRootKey();
303 : :
304 : : // if ooInetProxyType is not 0 then read the settings
305 [ + - ][ + - ]: 4 : css::uno::Reference<css::registry::XRegistryKey> proxyEnable= xRegistryRootKey->openKey(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Settings/ooInetProxyType")));
[ + - ]
306 [ + - ][ + - ]: 4 : if( proxyEnable.is() && 0 != proxyEnable->getLongValue())
[ + - ][ + - ]
[ + - ]
307 : : {
308 : : // read ftp proxy name
309 [ + - ][ + - ]: 4 : css::uno::Reference<css::registry::XRegistryKey> ftpProxy_name = xRegistryRootKey->openKey(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Settings/ooInetFTPProxyName")));
[ + - ]
310 [ + - ][ + - ]: 4 : if(ftpProxy_name.is() && !ftpProxy_name->getStringValue().isEmpty()) {
[ - + ][ + - ]
[ - + # # ]
[ + - ]
311 [ # # ]: 0 : rtl::OUString ftpHost = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ftp.proxyHost="));
312 [ # # ][ # # ]: 0 : ftpHost += ftpProxy_name->getStringValue();
313 : :
314 : : // read ftp proxy port
315 [ # # ][ # # ]: 0 : css::uno::Reference<css::registry::XRegistryKey> ftpProxy_port = xRegistryRootKey->openKey(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Settings/ooInetFTPProxyPort")));
[ # # ]
316 [ # # ][ # # ]: 0 : if(ftpProxy_port.is() && ftpProxy_port->getLongValue()) {
[ # # ][ # # ]
[ # # ]
317 [ # # ]: 0 : rtl::OUString ftpPort = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ftp.proxyPort="));
318 [ # # ][ # # ]: 0 : ftpPort += rtl::OUString::valueOf(ftpProxy_port->getLongValue());
319 : :
320 [ # # ]: 0 : pjvm->pushProp(ftpHost);
321 [ # # ]: 0 : pjvm->pushProp(ftpPort);
322 : 0 : }
323 : : }
324 : :
325 : : // read http proxy name
326 [ + - ][ + - ]: 4 : css::uno::Reference<css::registry::XRegistryKey> httpProxy_name = xRegistryRootKey->openKey(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Settings/ooInetHTTPProxyName")));
[ + - ]
327 [ + - ][ + - ]: 4 : if(httpProxy_name.is() && !httpProxy_name->getStringValue().isEmpty()) {
[ - + ][ + - ]
[ - + # # ]
[ + - ]
328 [ # # ]: 0 : rtl::OUString httpHost = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("http.proxyHost="));
329 [ # # ][ # # ]: 0 : httpHost += httpProxy_name->getStringValue();
330 : :
331 : : // read http proxy port
332 [ # # ][ # # ]: 0 : css::uno::Reference<css::registry::XRegistryKey> httpProxy_port = xRegistryRootKey->openKey(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Settings/ooInetHTTPProxyPort")));
[ # # ]
333 [ # # ][ # # ]: 0 : if(httpProxy_port.is() && httpProxy_port->getLongValue()) {
[ # # ][ # # ]
[ # # ]
334 [ # # ]: 0 : rtl::OUString httpPort = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("http.proxyPort="));
335 [ # # ][ # # ]: 0 : httpPort += rtl::OUString::valueOf(httpProxy_port->getLongValue());
336 : :
337 [ # # ]: 0 : pjvm->pushProp(httpHost);
338 [ # # ]: 0 : pjvm->pushProp(httpPort);
339 : 0 : }
340 : : }
341 : :
342 : : // read https proxy name
343 [ + - ][ + - ]: 4 : css::uno::Reference<css::registry::XRegistryKey> httpsProxy_name = xRegistryRootKey->openKey(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Settings/ooInetHTTPSProxyName")));
[ + - ]
344 [ + - ][ + - ]: 4 : if(httpsProxy_name.is() && !httpsProxy_name->getStringValue().isEmpty()) {
[ - + ][ + - ]
[ - + # # ]
[ + - ]
345 [ # # ]: 0 : rtl::OUString httpsHost = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("https.proxyHost="));
346 [ # # ][ # # ]: 0 : httpsHost += httpsProxy_name->getStringValue();
347 : :
348 : : // read https proxy port
349 [ # # ][ # # ]: 0 : css::uno::Reference<css::registry::XRegistryKey> httpsProxy_port = xRegistryRootKey->openKey(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Settings/ooInetHTTPSProxyPort")));
[ # # ]
350 [ # # ][ # # ]: 0 : if(httpsProxy_port.is() && httpsProxy_port->getLongValue()) {
[ # # ][ # # ]
[ # # ]
351 [ # # ]: 0 : rtl::OUString httpsPort = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("https.proxyPort="));
352 [ # # ][ # # ]: 0 : httpsPort += rtl::OUString::valueOf(httpsProxy_port->getLongValue());
353 : :
354 [ # # ]: 0 : pjvm->pushProp(httpsHost);
355 [ # # ]: 0 : pjvm->pushProp(httpsPort);
356 : 0 : }
357 : : }
358 : :
359 : : // read nonProxyHosts
360 [ + - ][ + - ]: 4 : css::uno::Reference<css::registry::XRegistryKey> nonProxies_name = xRegistryRootKey->openKey(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Settings/ooInetNoProxy")));
[ + - ]
361 [ + - ][ + - ]: 4 : if(nonProxies_name.is() && !nonProxies_name->getStringValue().isEmpty()) {
[ - + ][ + - ]
[ - + # # ]
[ + - ]
362 [ # # ]: 0 : rtl::OUString httpNonProxyHosts = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("http.nonProxyHosts="));
363 [ # # ]: 0 : rtl::OUString ftpNonProxyHosts= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ftp.nonProxyHosts="));
364 [ # # ][ # # ]: 0 : rtl::OUString value= nonProxies_name->getStringValue();
365 : : // replace the separator ";" by "|"
366 : 0 : value= value.replace((sal_Unicode)';', (sal_Unicode)'|');
367 : :
368 : 0 : httpNonProxyHosts += value;
369 : 0 : ftpNonProxyHosts += value;
370 : :
371 [ # # ]: 0 : pjvm->pushProp(httpNonProxyHosts);
372 [ # # ]: 0 : pjvm->pushProp(ftpNonProxyHosts);
373 : 4 : }
374 : :
375 : : // read socks settings
376 : : /* Reference<XRegistryKey> socksProxy_name = xRegistryRootKey->openKey(OUSTR("Settings/ooInetSOCKSProxyName"));
377 : : if (socksProxy_name.is() && httpProxy_name->getStringValue().getLength()) {
378 : : OUString socksHost = OUSTR("socksProxyHost=");
379 : : socksHost += socksProxy_name->getStringValue();
380 : :
381 : : // read http proxy port
382 : : Reference<XRegistryKey> socksProxy_port = xRegistryRootKey->openKey(OUSTR("Settings/ooInetSOCKSProxyPort"));
383 : : if (socksProxy_port.is() && socksProxy_port->getLongValue()) {
384 : : OUString socksPort = OUSTR("socksProxyPort=");
385 : : socksPort += OUString::valueOf(socksProxy_port->getLongValue());
386 : :
387 : : pjvm->pushProp(socksHost);
388 : : pjvm->pushProp(socksPort);
389 : : }
390 : : }
391 : : */ }
392 [ + - ][ + - ]: 4 : xConfRegistry_simple->close();
393 : 4 : }
394 : :
395 : 4 : void getDefaultLocaleFromConfig(
396 : : stoc_javavm::JVM * pjvm,
397 : : const css::uno::Reference<css::lang::XMultiComponentFactory> & xSMgr,
398 : : const css::uno::Reference<css::uno::XComponentContext> &xCtx ) throw(css::uno::Exception)
399 : : {
400 : : css::uno::Reference<css::uno::XInterface> xConfRegistry =
401 [ + - ]: 4 : xSMgr->createInstanceWithContext(
402 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
403 [ + - ][ + - ]: 4 : "com.sun.star.configuration.ConfigurationRegistry")), xCtx );
404 [ - + ]: 4 : if(!xConfRegistry.is())
405 : : throw css::uno::RuntimeException(
406 [ # # ][ # # ]: 0 : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("javavm.cxx: couldn't get ConfigurationRegistry")), 0);
[ # # ]
407 : :
408 : : css::uno::Reference<css::registry::XSimpleRegistry> xConfRegistry_simple(
409 [ + - ]: 4 : xConfRegistry, css::uno::UNO_QUERY);
410 [ - + ]: 4 : if(!xConfRegistry_simple.is())
411 : : throw css::uno::RuntimeException(
412 [ # # ][ # # ]: 0 : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("javavm.cxx: couldn't get ConfigurationRegistry")), 0);
[ # # ]
413 : :
414 [ + - ][ + - ]: 4 : xConfRegistry_simple->open(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("org.openoffice.Setup")), sal_True, sal_False);
[ + - ]
415 [ + - ][ + - ]: 4 : css::uno::Reference<css::registry::XRegistryKey> xRegistryRootKey = xConfRegistry_simple->getRootKey();
416 : :
417 : : // read locale
418 [ + - ][ + - ]: 4 : css::uno::Reference<css::registry::XRegistryKey> locale = xRegistryRootKey->openKey(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("L10N/ooLocale")));
[ + - ]
419 [ + - ][ + - ]: 4 : if(locale.is() && !locale->getStringValue().isEmpty()) {
[ + - ][ + - ]
[ + - # # ]
[ + - ]
420 : 4 : rtl::OUString language;
421 : 4 : rtl::OUString country;
422 : :
423 [ + - ][ + - ]: 4 : sal_Int32 index = locale->getStringValue().indexOf((sal_Unicode) '-');
424 : :
425 [ + - ]: 4 : if(index >= 0) {
426 [ + - ][ + - ]: 4 : language = locale->getStringValue().copy(0, index);
427 [ + - ][ + - ]: 4 : country = locale->getStringValue().copy(index + 1);
428 : :
429 [ + - ]: 4 : if(!language.isEmpty()) {
430 [ + - ]: 4 : rtl::OUString prop(RTL_CONSTASCII_USTRINGPARAM("user.language="));
431 : 4 : prop += language;
432 : :
433 [ + - ]: 4 : pjvm->pushProp(prop);
434 : : }
435 : :
436 [ + - ]: 4 : if(!country.isEmpty()) {
437 [ + - ]: 4 : rtl::OUString prop(RTL_CONSTASCII_USTRINGPARAM("user.country="));
438 : 4 : prop += country;
439 : :
440 [ + - ]: 4 : pjvm->pushProp(prop);
441 : : }
442 : 4 : }
443 : : }
444 : :
445 [ + - ][ + - ]: 4 : xConfRegistry_simple->close();
446 : 4 : }
447 : :
448 : :
449 : :
450 : 4 : void getJavaPropsFromSafetySettings(
451 : : stoc_javavm::JVM * pjvm,
452 : : const css::uno::Reference<css::lang::XMultiComponentFactory> & xSMgr,
453 : : const css::uno::Reference<css::uno::XComponentContext> &xCtx) throw(css::uno::Exception)
454 : : {
455 : : css::uno::Reference<css::uno::XInterface> xConfRegistry =
456 [ + - ]: 4 : xSMgr->createInstanceWithContext(
457 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
458 : : "com.sun.star.configuration.ConfigurationRegistry")),
459 [ + - ][ + - ]: 4 : xCtx);
460 [ - + ]: 4 : if(!xConfRegistry.is())
461 : : throw css::uno::RuntimeException(
462 [ # # ][ # # ]: 0 : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("javavm.cxx: couldn't get ConfigurationRegistry")), 0);
[ # # ]
463 : :
464 : : css::uno::Reference<css::registry::XSimpleRegistry> xConfRegistry_simple(
465 [ + - ]: 4 : xConfRegistry, css::uno::UNO_QUERY);
466 [ - + ]: 4 : if(!xConfRegistry_simple.is())
467 : : throw css::uno::RuntimeException(
468 [ # # ][ # # ]: 0 : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("javavm.cxx: couldn't get ConfigurationRegistry")), 0);
[ # # ]
469 : :
470 [ + - ]: 4 : xConfRegistry_simple->open(
471 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("org.openoffice.Office.Java")),
472 [ + - ][ + - ]: 4 : sal_True, sal_False);
473 : : css::uno::Reference<css::registry::XRegistryKey> xRegistryRootKey =
474 [ + - ][ + - ]: 4 : xConfRegistry_simple->getRootKey();
475 : :
476 [ + - ]: 4 : if (xRegistryRootKey.is())
477 : : {
478 [ + - ][ + - ]: 4 : css::uno::Reference<css::registry::XRegistryKey> key_NetAccess= xRegistryRootKey->openKey(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("VirtualMachine/NetAccess")));
[ + - ]
479 [ + - ]: 4 : if (key_NetAccess.is())
480 : : {
481 [ + - ][ - + ]: 4 : sal_Int32 val= key_NetAccess->getLongValue();
482 : 0 : rtl::OUString sVal;
483 [ # # # # ]: 0 : switch( val)
484 : : {
485 [ # # ]: 0 : case 0: sVal= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("host"));
486 : 0 : break;
487 [ # # ]: 0 : case 1: sVal= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("unrestricted"));
488 : 0 : break;
489 [ # # ]: 0 : case 3: sVal= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("none"));
490 : 0 : break;
491 : : }
492 [ # # ]: 0 : rtl::OUString sProperty( RTL_CONSTASCII_USTRINGPARAM("appletviewer.security.mode="));
493 : 0 : sProperty= sProperty + sVal;
494 [ # # ]: 4 : pjvm->pushProp(sProperty);
495 : : }
496 [ # # ]: 0 : css::uno::Reference<css::registry::XRegistryKey> key_CheckSecurity= xRegistryRootKey->openKey(
497 [ # # ][ # # ]: 0 : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("VirtualMachine/Security")));
498 [ # # ]: 0 : if( key_CheckSecurity.is())
499 : : {
500 [ # # ][ # # ]: 0 : sal_Bool val= (sal_Bool) key_CheckSecurity->getLongValue();
501 [ # # ]: 0 : rtl::OUString sProperty(RTL_CONSTASCII_USTRINGPARAM("stardiv.security.disableSecurity="));
502 [ # # ]: 0 : if( val)
503 [ # # ]: 0 : sProperty= sProperty + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("false"));
504 : : else
505 [ # # ]: 0 : sProperty= sProperty + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("true"));
506 [ # # ]: 0 : pjvm->pushProp( sProperty);
507 : 4 : }
508 : : }
509 [ # # ][ # # ]: 4 : xConfRegistry_simple->close();
510 : 0 : }
511 : :
512 : 4 : static void setTimeZone(stoc_javavm::JVM * pjvm) throw() {
513 : : /* A Bug in the Java function
514 : : ** struct Hjava_util_Properties * java_lang_System_initProperties(
515 : : ** struct Hjava_lang_System *this,
516 : : ** struct Hjava_util_Properties *props);
517 : : ** This function doesn't detect MEZ, MET or "W. Europe Standard Time"
518 : : */
519 : : struct tm *tmData;
520 : 4 : time_t clock = time(NULL);
521 : 4 : tzset();
522 : 4 : tmData = localtime(&clock);
523 : : #ifdef MACOSX
524 : : char * p = tmData->tm_zone;
525 : : #else
526 : 4 : char * p = tzname[0];
527 : : (void)tmData;
528 : : #endif
529 : :
530 [ - + ]: 4 : if (!strcmp(TIMEZONE, p))
531 [ # # ][ # # ]: 0 : pjvm->pushProp(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("user.timezone=ECT")));
532 : 4 : }
533 : :
534 : 4 : void initVMConfiguration(
535 : : stoc_javavm::JVM * pjvm,
536 : : const css::uno::Reference<css::lang::XMultiComponentFactory> & xSMgr,
537 : : const css::uno::Reference<css::uno::XComponentContext > &xCtx) throw(css::uno::Exception)
538 : : {
539 : 4 : stoc_javavm::JVM jvm;
540 : : try {
541 [ + - ]: 4 : getINetPropsFromConfig(&jvm, xSMgr, xCtx);
542 : : }
543 [ # # # # ]: 0 : catch(const css::uno::Exception & exception) {
544 : : #if OSL_DEBUG_LEVEL > 1
545 : : rtl::OString message = rtl::OUStringToOString(exception.Message, RTL_TEXTENCODING_ASCII_US);
546 : : OSL_TRACE("javavm.cxx: can not get INetProps cause of >%s<", message.getStr());
547 : : #else
548 : : (void) exception; // unused
549 : : #endif
550 : : }
551 : :
552 : : try {
553 [ + - ]: 4 : getDefaultLocaleFromConfig(&jvm, xSMgr,xCtx);
554 : : }
555 [ - + ][ # # ]: 4 : catch(const css::uno::Exception & exception) {
556 : : #if OSL_DEBUG_LEVEL > 1
557 : : rtl::OString message = rtl::OUStringToOString(exception.Message, RTL_TEXTENCODING_ASCII_US);
558 : : OSL_TRACE("javavm.cxx: can not get locale cause of >%s<", message.getStr());
559 : : #else
560 : : (void) exception; // unused
561 : : #endif
562 : : }
563 : :
564 : : try
565 : : {
566 [ - + ]: 4 : getJavaPropsFromSafetySettings(&jvm, xSMgr, xCtx);
567 : : }
568 [ + - ]: 4 : catch(const css::uno::Exception & exception) {
569 : : #if OSL_DEBUG_LEVEL > 1
570 : : rtl::OString message = rtl::OUStringToOString(exception.Message, RTL_TEXTENCODING_ASCII_US);
571 : : OSL_TRACE("javavm.cxx: couldn't get safety settings because of >%s<", message.getStr());
572 : : #else
573 : : (void) exception; // unused
574 : : #endif
575 : : }
576 : :
577 [ + - ]: 4 : *pjvm= jvm;
578 : 4 : setTimeZone(pjvm);
579 : :
580 [ # # ]: 4 : }
581 : :
582 : : class DetachCurrentThread {
583 : : public:
584 : 4 : explicit DetachCurrentThread(JavaVM * jvm): m_jvm(jvm) {}
585 : :
586 : 4 : ~DetachCurrentThread() {
587 : 4 : if (m_jvm->DetachCurrentThread() != 0) {
588 : : OSL_ASSERT(false);
589 : : }
590 : 4 : }
591 : :
592 : : private:
593 : : DetachCurrentThread(DetachCurrentThread &); // not defined
594 : : void operator =(DetachCurrentThread &); // not defined
595 : :
596 : : JavaVM * m_jvm;
597 : : };
598 : :
599 : : }
600 : :
601 : 4 : extern "C" SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory(sal_Char const * pImplName,
602 : : void * pServiceManager,
603 : : void * pRegistryKey)
604 : : {
605 : : return cppu::component_getFactoryHelper(pImplName, pServiceManager,
606 : : pRegistryKey,
607 : 4 : aServiceImplementation);
608 : : }
609 : :
610 : : // There is no component_canUnload, as the library cannot be unloaded.
611 : :
612 : 4 : JavaVirtualMachine::JavaVirtualMachine(
613 : : css::uno::Reference< css::uno::XComponentContext > const & rContext):
614 : : JavaVirtualMachine_Impl(*static_cast< osl::Mutex * >(this)),
615 : : m_xContext(rContext),
616 : : m_bDisposed(false),
617 : : m_pJavaVm(0),
618 : : m_bDontCreateJvm(false),
619 [ + - ]: 4 : m_aAttachGuards(destroyAttachGuards) // TODO check for validity
620 : 4 : {}
621 : :
622 : : void SAL_CALL
623 : 0 : JavaVirtualMachine::initialize(css::uno::Sequence< css::uno::Any > const &
624 : : rArguments)
625 : : throw (css::uno::Exception)
626 : : {
627 [ # # ]: 0 : osl::MutexGuard aGuard(*this);
628 [ # # ]: 0 : if (m_bDisposed)
629 : : throw css::lang::DisposedException(
630 [ # # ][ # # ]: 0 : rtl::OUString(), static_cast< cppu::OWeakObject * >(this));
631 [ # # ]: 0 : if (m_xUnoVirtualMachine.is())
632 : : throw css::uno::RuntimeException(
633 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
634 : : "bad call to initialize")),
635 [ # # ][ # # ]: 0 : static_cast< cppu::OWeakObject * >(this));
[ # # ]
636 : 0 : css::beans::NamedValue val;
637 [ # # ][ # # ]: 0 : if (rArguments.getLength() == 1 && (rArguments[0] >>= val) && val.Name == "UnoVirtualMachine" )
[ # # ][ # # ]
[ # # ]
638 : : {
639 : : OSL_ENSURE(
640 : : sizeof (sal_Int64) >= sizeof (jvmaccess::UnoVirtualMachine *),
641 : : "Pointer cannot be represented as sal_Int64");
642 : : sal_Int64 nPointer = reinterpret_cast< sal_Int64 >(
643 : 0 : static_cast< jvmaccess::UnoVirtualMachine * >(0));
644 : 0 : val.Value >>= nPointer;
645 : : m_xUnoVirtualMachine =
646 [ # # ]: 0 : reinterpret_cast< jvmaccess::UnoVirtualMachine * >(nPointer);
647 : : } else {
648 : : OSL_ENSURE(
649 : : sizeof (sal_Int64) >= sizeof (jvmaccess::VirtualMachine *),
650 : : "Pointer cannot be represented as sal_Int64");
651 : : sal_Int64 nPointer = reinterpret_cast< sal_Int64 >(
652 : 0 : static_cast< jvmaccess::VirtualMachine * >(0));
653 [ # # ]: 0 : if (rArguments.getLength() == 1)
654 : 0 : rArguments[0] >>= nPointer;
655 : : rtl::Reference< jvmaccess::VirtualMachine > vm(
656 [ # # ]: 0 : reinterpret_cast< jvmaccess::VirtualMachine * >(nPointer));
657 [ # # ]: 0 : if (vm.is()) {
658 : : try {
659 [ # # ][ # # ]: 0 : m_xUnoVirtualMachine = new jvmaccess::UnoVirtualMachine(vm, 0);
[ # # ]
660 [ # # ]: 0 : } catch (jvmaccess::UnoVirtualMachine::CreationException &) {
661 : : throw css::uno::RuntimeException(
662 : : rtl::OUString(
663 : : RTL_CONSTASCII_USTRINGPARAM(
664 : : "jvmaccess::UnoVirtualMachine::CreationException")),
665 [ # # # # : 0 : static_cast< cppu::OWeakObject * >(this));
# # ]
666 : : }
667 [ # # ]: 0 : }
668 : : }
669 [ # # ]: 0 : if (!m_xUnoVirtualMachine.is()) {
670 : : throw css::lang::IllegalArgumentException(
671 : : rtl::OUString(
672 : : RTL_CONSTASCII_USTRINGPARAM(
673 : : "sequence of exactly one any containing either (a) a"
674 : : " com.sun.star.beans.NamedValue with Name"
675 : : " \"UnoVirtualMachine\" and Value a hyper representing a"
676 : : " non-null pointer to a jvmaccess:UnoVirtualMachine, or (b)"
677 : : " a hyper representing a non-null pointer to a"
678 : : " jvmaccess::VirtualMachine required")),
679 [ # # ][ # # ]: 0 : static_cast< cppu::OWeakObject * >(this), 0);
[ # # ]
680 : : }
681 [ # # ][ # # ]: 0 : m_xVirtualMachine = m_xUnoVirtualMachine->getVirtualMachine();
[ # # ][ # # ]
682 : 0 : }
683 : :
684 : 0 : rtl::OUString SAL_CALL JavaVirtualMachine::getImplementationName()
685 : : throw (css::uno::RuntimeException)
686 : : {
687 : 0 : return serviceGetImplementationName();
688 : : }
689 : :
690 : : sal_Bool SAL_CALL
691 : 0 : JavaVirtualMachine::supportsService(rtl::OUString const & rServiceName)
692 : : throw (css::uno::RuntimeException)
693 : : {
694 [ # # ]: 0 : css::uno::Sequence< rtl::OUString > aNames(getSupportedServiceNames());
695 [ # # ]: 0 : for (sal_Int32 i = 0; i < aNames.getLength(); ++i)
696 [ # # ][ # # ]: 0 : if (aNames[i] == rServiceName)
697 : 0 : return true;
698 [ # # ]: 0 : return false;
699 : : }
700 : :
701 : : css::uno::Sequence< rtl::OUString > SAL_CALL
702 : 0 : JavaVirtualMachine::getSupportedServiceNames()
703 : : throw (css::uno::RuntimeException)
704 : : {
705 : 0 : return serviceGetSupportedServiceNames();
706 : : }
707 : :
708 : : css::uno::Any SAL_CALL
709 : 4 : JavaVirtualMachine::getJavaVM(css::uno::Sequence< sal_Int8 > const & rProcessId)
710 : : throw (css::uno::RuntimeException)
711 : : {
712 [ + - ]: 4 : osl::MutexGuard aGuard(*this);
713 [ - + ]: 4 : if (m_bDisposed)
714 : : throw css::lang::DisposedException(
715 [ # # ][ # # ]: 0 : rtl::OUString(), static_cast< cppu::OWeakObject * >(this));
716 [ + - ]: 4 : css::uno::Sequence< sal_Int8 > aId(16);
717 [ + - ][ + - ]: 4 : rtl_getGlobalProcessId(reinterpret_cast< sal_uInt8 * >(aId.getArray()));
718 : : enum ReturnType {
719 : : RETURN_JAVAVM, RETURN_VIRTUALMACHINE, RETURN_UNOVIRTUALMACHINE };
720 : : ReturnType returnType =
721 : 8 : rProcessId.getLength() == 17 && rProcessId[16] == 0
722 : : ? RETURN_VIRTUALMACHINE
723 : 8 : : rProcessId.getLength() == 17 && rProcessId[16] == 1
724 : : ? RETURN_UNOVIRTUALMACHINE
725 [ + - + - : 16 : : RETURN_JAVAVM;
+ - + - ]
726 [ + - ]: 4 : css::uno::Sequence< sal_Int8 > aProcessId(rProcessId);
727 [ + - ]: 4 : if (returnType != RETURN_JAVAVM)
728 [ + - ]: 4 : aProcessId.realloc(16);
729 [ + - ][ - + ]: 4 : if (aId != aProcessId)
730 : 0 : return css::uno::Any();
731 : :
732 [ + - ]: 4 : while (!m_xVirtualMachine.is()) // retry until successful
733 : : {
734 : : // This is the second attempt to create Java. m_bDontCreateJvm is
735 : : // set which means instantiating the JVM might crash.
736 [ - + ]: 4 : if (m_bDontCreateJvm)
737 : : //throw css::uno::RuntimeException();
738 : 0 : return css::uno::Any();
739 : :
740 : 4 : stoc_javavm::JVM aJvm;
741 [ + - ]: 4 : initVMConfiguration(&aJvm, m_xContext->getServiceManager(),
742 [ + - ][ + - ]: 4 : m_xContext);
743 : : //Create the JavaVMOption array
744 [ + - ]: 4 : const std::vector<rtl::OUString> & props = aJvm.getProperties();
745 : : boost::scoped_array<JavaVMOption> sarOptions(
746 [ + - ]: 4 : new JavaVMOption[props.size()]);
747 : 4 : JavaVMOption * arOptions = sarOptions.get();
748 : : //Create an array that contains the strings which are passed
749 : : //into the options
750 : : boost::scoped_array<rtl::OString> sarPropStrings(
751 [ + + ][ + - ]: 12 : new rtl::OString[props.size()]);
752 : 4 : rtl::OString * arPropStrings = sarPropStrings.get();
753 : :
754 : 4 : rtl::OString sJavaOption("-");
755 : : typedef std::vector<rtl::OUString>::const_iterator cit;
756 : 4 : int index = 0;
757 [ + - ][ + + ]: 12 : for (cit i = props.begin(); i != props.end(); ++i)
758 : : {
759 : : rtl::OString sOption = rtl::OUStringToOString(
760 [ + - ][ + - ]: 8 : *i, osl_getThreadTextEncoding());
761 : :
762 [ + - ]: 8 : if (!sOption.matchIgnoreAsciiCase(sJavaOption, 0))
763 : 8 : arPropStrings[index]= rtl::OString("-D") + sOption;
764 : : else
765 : 0 : arPropStrings[index] = sOption;
766 : :
767 : 8 : arOptions[index].optionString = (sal_Char*)arPropStrings[index].getStr();
768 : 8 : arOptions[index].extraInfo = 0;
769 : 8 : index ++;
770 : 8 : }
771 : :
772 : 4 : JNIEnv * pMainThreadEnv = 0;
773 : 4 : javaFrameworkError errcode = JFW_E_NONE;
774 : :
775 [ - + ]: 4 : if (getenv("STOC_FORCE_NO_JRE"))
776 : 0 : errcode = JFW_E_NO_SELECT;
777 : : else
778 : : errcode = jfw_startVM(arOptions, index, & m_pJavaVm,
779 [ + - ]: 4 : & pMainThreadEnv);
780 : :
781 : 4 : bool bStarted = false;
782 [ + - - - : 4 : switch (errcode)
- - - - ]
783 : : {
784 : 4 : case JFW_E_NONE: bStarted = true; break;
785 : : case JFW_E_NO_SELECT:
786 : : {
787 : : // No Java configured. We silenty run the java configuration
788 : : // Java.
789 [ # # ]: 0 : javaFrameworkError errFind = jfw_findAndSelectJRE( NULL );
790 [ # # ]: 0 : if (getenv("STOC_FORCE_NO_JRE"))
791 : 0 : errFind = JFW_E_NO_JAVA_FOUND;
792 [ # # ]: 0 : if (errFind == JFW_E_NONE)
793 : : {
794 : 0 : continue;
795 : : }
796 [ # # ]: 0 : else if (errFind == JFW_E_NO_JAVA_FOUND)
797 : : {
798 : :
799 : : //Warning MessageBox:
800 : : //%PRODUCTNAME requires a Java runtime environment (JRE) to perform this task.
801 : : //Please install a JRE and restart %PRODUCTNAME.
802 : : css::java::JavaNotFoundException exc(
803 : : rtl::OUString(
804 : : RTL_CONSTASCII_USTRINGPARAM(
805 : : "JavaVirtualMachine::getJavaVM failed because"
806 : : " No suitable JRE found!")),
807 [ # # ][ # # ]: 0 : static_cast< cppu::OWeakObject * >(this));
[ # # ]
808 [ # # ][ # # ]: 0 : askForRetry(css::uno::makeAny(exc));
809 [ # # ]: 0 : return css::uno::Any();
810 : : }
811 : : else
812 : : {
813 : : //An unexpected error occurred
814 : : throw css::uno::RuntimeException(
815 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
816 : : "[JavaVirtualMachine]:An unexpected error occurred"
817 [ # # ][ # # ]: 0 : " while searching for a Java!")), 0);
[ # # ]
818 : : }
819 : : }
820 : : case JFW_E_INVALID_SETTINGS:
821 : : {
822 : : //Warning MessageBox:
823 : : // The %PRODUCTNAME configuration has been changed. Under Tools
824 : : // - Options - %PRODUCTNAME - Java, select the Java runtime environment
825 : : // you want to have used by %PRODUCTNAME.
826 : : css::java::InvalidJavaSettingsException exc(
827 : : rtl::OUString(
828 : : RTL_CONSTASCII_USTRINGPARAM(
829 : : "JavaVirtualMachine::getJavaVM failed because"
830 : : " Java settings have changed!")),
831 [ # # ][ # # ]: 0 : static_cast< cppu::OWeakObject * >(this));
[ # # ]
832 [ # # ][ # # ]: 0 : askForRetry(css::uno::makeAny(exc));
833 [ # # ]: 0 : return css::uno::Any();
834 : : }
835 : : case JFW_E_JAVA_DISABLED:
836 : : {
837 : : //QueryBox:
838 : : //%PRODUCTNAME requires a Java runtime environment (JRE) to perform
839 : : //this task. However, use of a JRE has been disabled. Do you want to
840 : : //enable the use of a JRE now?
841 : : css::java::JavaDisabledException exc(
842 : : rtl::OUString(
843 : : RTL_CONSTASCII_USTRINGPARAM(
844 : : "JavaVirtualMachine::getJavaVM failed because"
845 : : " Java is disabled!")),
846 [ # # ][ # # ]: 0 : static_cast< cppu::OWeakObject * >(this));
[ # # ]
847 [ # # ][ # # ]: 0 : if( ! askForRetry(css::uno::makeAny(exc)))
[ # # ]
848 : 0 : return css::uno::Any();
849 [ # # ][ # # ]: 0 : continue;
850 : : }
851 : : case JFW_E_VM_CREATION_FAILED:
852 : : {
853 : : //If the creation failed because the JRE has been uninstalled then
854 : : //we search another one. As long as there is a javaldx, we should
855 : : //never come into this situation. javaldx checks alway if the JRE
856 : : //still exist.
857 : 0 : JavaInfo * pJavaInfo = NULL;
858 [ # # ][ # # ]: 0 : if (JFW_E_NONE == jfw_getSelectedJRE(&pJavaInfo))
859 : : {
860 : 0 : sal_Bool bExist = sal_False;
861 [ # # ][ # # ]: 0 : if (JFW_E_NONE == jfw_existJRE(pJavaInfo, &bExist))
862 : : {
863 [ # # ][ # # ]: 0 : if (bExist == sal_False
864 : 0 : && ! (pJavaInfo->nRequirements & JFW_REQUIRE_NEEDRESTART))
865 : : {
866 [ # # ]: 0 : javaFrameworkError errFind = jfw_findAndSelectJRE( NULL );
867 [ # # ]: 0 : if (errFind == JFW_E_NONE)
868 : : {
869 : 0 : continue;
870 : : }
871 : : }
872 : : }
873 : : }
874 : :
875 [ # # ]: 0 : jfw_freeJavaInfo(pJavaInfo);
876 : : //
877 : : //Error: %PRODUCTNAME requires a Java
878 : : //runtime environment (JRE) to perform this task. The selected JRE
879 : : //is defective. Please select another version or install a new JRE
880 : : //and select it under Tools - Options - %PRODUCTNAME - Java.
881 : : css::java::JavaVMCreationFailureException exc(
882 : : rtl::OUString(
883 : : RTL_CONSTASCII_USTRINGPARAM(
884 : : "JavaVirtualMachine::getJavaVM failed because"
885 : : " Java is defective!")),
886 [ # # ][ # # ]: 0 : static_cast< cppu::OWeakObject * >(this), 0);
[ # # ]
887 [ # # ][ # # ]: 0 : askForRetry(css::uno::makeAny(exc));
888 [ # # ]: 0 : return css::uno::Any();
889 : : }
890 : : case JFW_E_RUNNING_JVM:
891 : : {
892 : : //This service should make sure that we do not start java twice.
893 : : OSL_ASSERT(0);
894 : 0 : break;
895 : : }
896 : : case JFW_E_NEED_RESTART:
897 : : {
898 : : //Error:
899 : : //For the selected Java runtime environment to work properly,
900 : : //%PRODUCTNAME must be restarted. Please restart %PRODUCTNAME now.
901 : : css::java::RestartRequiredException exc(
902 : : rtl::OUString(
903 : : RTL_CONSTASCII_USTRINGPARAM(
904 : : "JavaVirtualMachine::getJavaVM failed because"
905 : : "Office must be restarted before Java can be used!")),
906 [ # # ][ # # ]: 0 : static_cast< cppu::OWeakObject * >(this));
[ # # ]
907 [ # # ][ # # ]: 0 : askForRetry(css::uno::makeAny(exc));
908 [ # # ]: 0 : return css::uno::Any();
909 : : }
910 : : default:
911 : : //RuntimeException: error is somewhere in the java framework.
912 : : //An unexpected error occurred
913 : : throw css::uno::RuntimeException(
914 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
915 : : "[JavaVirtualMachine]:An unexpected error occurred"
916 [ # # ][ # # ]: 0 : " while starting Java!")), 0);
[ # # ]
917 : : }
918 : :
919 [ + - ]: 4 : if (bStarted)
920 : : {
921 : : {
922 : 4 : DetachCurrentThread detach(m_pJavaVm);
923 : : // necessary to make debugging work; this thread will be
924 : : // suspended when the destructor of detach returns
925 : : m_xVirtualMachine = new jvmaccess::VirtualMachine(
926 [ + - ][ + - ]: 4 : m_pJavaVm, JNI_VERSION_1_2, true, pMainThreadEnv);
[ + - ]
927 [ + - ][ + - ]: 4 : setUpUnoVirtualMachine(pMainThreadEnv);
928 : : }
929 : : // Listen for changes in the configuration (e.g. proxy settings):
930 : : // TODO this is done too late; changes to the configuration done
931 : : // after the above call to initVMConfiguration are lost
932 [ + - ]: 4 : registerConfigChangesListener();
933 : :
934 : : break;
935 : : }
936 [ - - + - ]: 4 : }
[ + - ]
[ - - + - ]
[ + - ]
[ - - + - ]
[ - - - + ]
937 [ - + ]: 4 : if (!m_xUnoVirtualMachine.is()) {
938 : : try {
939 [ # # ]: 0 : jvmaccess::VirtualMachine::AttachGuard guard(m_xVirtualMachine);
940 [ # # ][ # # ]: 0 : setUpUnoVirtualMachine(guard.getEnvironment());
941 [ # # ]: 0 : } catch (jvmaccess::VirtualMachine::AttachGuard::CreationException &) {
942 : : throw css::uno::RuntimeException(
943 : : rtl::OUString(
944 : : RTL_CONSTASCII_USTRINGPARAM(
945 : : "jvmaccess::VirtualMachine::AttachGuard::"
946 : : "CreationException occurred")),
947 [ # # # # : 0 : static_cast< cppu::OWeakObject * >(this));
# # ]
948 : : }
949 : : }
950 [ - - + ]: 4 : switch (returnType) {
951 : : default: // RETURN_JAVAVM
952 [ # # ]: 0 : if (m_pJavaVm == 0) {
953 : : throw css::uno::RuntimeException(
954 : : rtl::OUString(
955 : : RTL_CONSTASCII_USTRINGPARAM(
956 : : "JavaVirtualMachine service was initialized in a way"
957 : : " that the requested JavaVM pointer is not available")),
958 [ # # ][ # # ]: 0 : static_cast< cppu::OWeakObject * >(this));
[ # # ]
959 : : }
960 [ # # ]: 0 : return css::uno::makeAny(reinterpret_cast< sal_IntPtr >(m_pJavaVm));
961 : : case RETURN_VIRTUALMACHINE:
962 : : OSL_ASSERT(sizeof (sal_Int64) >= sizeof (jvmaccess::VirtualMachine *));
963 : : return css::uno::makeAny(
964 : : reinterpret_cast< sal_Int64 >(
965 [ # # ][ # # ]: 0 : m_xUnoVirtualMachine->getVirtualMachine().get()));
[ # # ]
966 : : case RETURN_UNOVIRTUALMACHINE:
967 : : OSL_ASSERT(sizeof (sal_Int64) >= sizeof (jvmaccess::VirtualMachine *));
968 : : return css::uno::makeAny(
969 [ + - ]: 4 : reinterpret_cast< sal_Int64 >(m_xUnoVirtualMachine.get()));
970 [ + - ][ + - ]: 4 : }
[ + - ]
971 : : }
972 : :
973 : 0 : sal_Bool SAL_CALL JavaVirtualMachine::isVMStarted()
974 : : throw (css::uno::RuntimeException)
975 : : {
976 [ # # ]: 0 : osl::MutexGuard aGuard(*this);
977 [ # # ]: 0 : if (m_bDisposed)
978 : : throw css::lang::DisposedException(
979 [ # # ][ # # ]: 0 : rtl::OUString(), static_cast< cppu::OWeakObject * >(this));
980 [ # # ]: 0 : return m_xUnoVirtualMachine.is();
981 : : }
982 : :
983 : 0 : sal_Bool SAL_CALL JavaVirtualMachine::isVMEnabled()
984 : : throw (css::uno::RuntimeException)
985 : : {
986 : : {
987 [ # # ]: 0 : osl::MutexGuard aGuard(*this);
988 [ # # ]: 0 : if (m_bDisposed)
989 : : throw css::lang::DisposedException(
990 [ # # ][ # # ]: 0 : rtl::OUString(), static_cast< cppu::OWeakObject * >(this));
[ # # ]
991 : : }
992 : : // stoc_javavm::JVM aJvm;
993 : : // initVMConfiguration(&aJvm, m_xContext->getServiceManager(), m_xContext);
994 : : // return aJvm.isEnabled();
995 : : //ToDo
996 : 0 : sal_Bool bEnabled = sal_False;
997 [ # # ][ # # ]: 0 : if (jfw_getEnabled( & bEnabled) != JFW_E_NONE)
998 [ # # ]: 0 : throw css::uno::RuntimeException();
999 : 0 : return bEnabled;
1000 : : }
1001 : :
1002 : 0 : sal_Bool SAL_CALL JavaVirtualMachine::isThreadAttached()
1003 : : throw (css::uno::RuntimeException)
1004 : : {
1005 [ # # ]: 0 : osl::MutexGuard aGuard(*this);
1006 [ # # ]: 0 : if (m_bDisposed)
1007 : : throw css::lang::DisposedException(
1008 [ # # ][ # # ]: 0 : rtl::OUString(), static_cast< cppu::OWeakObject * >(this));
1009 : : // TODO isThreadAttached only returns true if the thread was attached via
1010 : : // registerThread:
1011 : : GuardStack * pStack
1012 [ # # ]: 0 : = static_cast< GuardStack * >(m_aAttachGuards.getData());
1013 [ # # ][ # # ]: 0 : return pStack != 0 && !pStack->empty();
[ # # ][ # # ]
1014 : : }
1015 : :
1016 : 0 : void SAL_CALL JavaVirtualMachine::registerThread()
1017 : : throw (css::uno::RuntimeException)
1018 : : {
1019 [ # # ]: 0 : osl::MutexGuard aGuard(*this);
1020 [ # # ]: 0 : if (m_bDisposed)
1021 : : throw css::lang::DisposedException(
1022 [ # # ][ # # ]: 0 : rtl::OUString(), static_cast< cppu::OWeakObject * >(this));
1023 [ # # ]: 0 : if (!m_xUnoVirtualMachine.is())
1024 : : throw css::uno::RuntimeException(
1025 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
1026 : : "JavaVirtualMachine::registerThread:"
1027 : : " null VirtualMachine")),
1028 [ # # ][ # # ]: 0 : static_cast< cppu::OWeakObject * >(this));
[ # # ]
1029 : : GuardStack * pStack
1030 [ # # ]: 0 : = static_cast< GuardStack * >(m_aAttachGuards.getData());
1031 [ # # ]: 0 : if (pStack == 0)
1032 : : {
1033 [ # # ][ # # ]: 0 : pStack = new GuardStack;
[ # # ]
1034 [ # # ]: 0 : m_aAttachGuards.setData(pStack);
1035 : : }
1036 : : try
1037 : : {
1038 : : pStack->push(
1039 : : new jvmaccess::VirtualMachine::AttachGuard(
1040 [ # # ][ # # ]: 0 : m_xUnoVirtualMachine->getVirtualMachine()));
[ # # ][ # # ]
[ # # ]
1041 : : }
1042 [ # # ]: 0 : catch (jvmaccess::VirtualMachine::AttachGuard::CreationException &)
1043 : : {
1044 : : throw css::uno::RuntimeException(
1045 : : rtl::OUString(
1046 : : RTL_CONSTASCII_USTRINGPARAM(
1047 : : "JavaVirtualMachine::registerThread: jvmaccess::"
1048 : : "VirtualMachine::AttachGuard::CreationException")),
1049 [ # # # # : 0 : static_cast< cppu::OWeakObject * >(this));
# # ]
1050 [ # # ]: 0 : }
1051 : 0 : }
1052 : :
1053 : 0 : void SAL_CALL JavaVirtualMachine::revokeThread()
1054 : : throw (css::uno::RuntimeException)
1055 : : {
1056 [ # # ]: 0 : osl::MutexGuard aGuard(*this);
1057 [ # # ]: 0 : if (m_bDisposed)
1058 : : throw css::lang::DisposedException(
1059 [ # # ][ # # ]: 0 : rtl::OUString(), static_cast< cppu::OWeakObject * >(this));
1060 [ # # ]: 0 : if (!m_xUnoVirtualMachine.is())
1061 : : throw css::uno::RuntimeException(
1062 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
1063 : : "JavaVirtualMachine::revokeThread:"
1064 : : " null VirtualMachine")),
1065 [ # # ][ # # ]: 0 : static_cast< cppu::OWeakObject * >(this));
[ # # ]
1066 : : GuardStack * pStack
1067 [ # # ]: 0 : = static_cast< GuardStack * >(m_aAttachGuards.getData());
1068 [ # # ][ # # ]: 0 : if (pStack == 0 || pStack->empty())
[ # # ][ # # ]
1069 : : throw css::uno::RuntimeException(
1070 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
1071 : : "JavaVirtualMachine::revokeThread:"
1072 : : " no matching registerThread")),
1073 [ # # ][ # # ]: 0 : static_cast< cppu::OWeakObject * >(this));
[ # # ]
1074 [ # # ][ # # ]: 0 : delete pStack->top();
[ # # ]
1075 [ # # ][ # # ]: 0 : pStack->pop();
1076 : 0 : }
1077 : :
1078 : : void SAL_CALL
1079 : 0 : JavaVirtualMachine::disposing(css::lang::EventObject const & rSource)
1080 : : throw (css::uno::RuntimeException)
1081 : : {
1082 [ # # ]: 0 : osl::MutexGuard aGuard(*this);
1083 [ # # ][ # # ]: 0 : if (rSource.Source == m_xInetConfiguration)
1084 : 0 : m_xInetConfiguration.clear();
1085 [ # # ][ # # ]: 0 : if (rSource.Source == m_xJavaConfiguration)
1086 [ # # ]: 0 : m_xJavaConfiguration.clear();
1087 : 0 : }
1088 : :
1089 : 0 : void SAL_CALL JavaVirtualMachine::elementInserted(
1090 : : css::container::ContainerEvent const &)
1091 : : throw (css::uno::RuntimeException)
1092 : 0 : {}
1093 : :
1094 : 0 : void SAL_CALL JavaVirtualMachine::elementRemoved(
1095 : : css::container::ContainerEvent const &)
1096 : : throw (css::uno::RuntimeException)
1097 : 0 : {}
1098 : :
1099 : : // If a user changes the setting, for example for proxy settings, then this
1100 : : // function will be called from the configuration manager. Even if the .xml
1101 : : // file does not contain an entry yet and that entry has to be inserted, this
1102 : : // function will be called. We call java.lang.System.setProperty for the new
1103 : : // values.
1104 : 0 : void SAL_CALL JavaVirtualMachine::elementReplaced(
1105 : : css::container::ContainerEvent const & rEvent)
1106 : : throw (css::uno::RuntimeException)
1107 : : {
1108 : : // TODO Using the new value stored in rEvent is wrong here. If two threads
1109 : : // receive different elementReplaced calls in quick succession, it is
1110 : : // unspecified which changes the JVM's system properties last. A correct
1111 : : // solution must atomically (i.e., protected by a mutex) read the latest
1112 : : // value from the configuration and set it as a system property at the JVM.
1113 : :
1114 : 0 : rtl::OUString aAccessor;
1115 : 0 : rEvent.Accessor >>= aAccessor;
1116 : 0 : rtl::OUString aPropertyName;
1117 : 0 : rtl::OUString aPropertyName2;
1118 : 0 : rtl::OUString aPropertyValue;
1119 : 0 : bool bSecurityChanged = false;
1120 [ # # ]: 0 : if ( aAccessor == "ooInetProxyType" )
1121 : : {
1122 : : // Proxy none, manually
1123 : 0 : sal_Int32 value = 0;
1124 : 0 : rEvent.Element >>= value;
1125 [ # # ]: 0 : setINetSettingsInVM(value != 0);
1126 : : return;
1127 : : }
1128 [ # # ]: 0 : else if ( aAccessor == "ooInetHTTPProxyName" )
1129 : : {
1130 : : aPropertyName = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
1131 [ # # ]: 0 : "http.proxyHost"));
1132 : 0 : rEvent.Element >>= aPropertyValue;
1133 : : }
1134 [ # # ]: 0 : else if ( aAccessor == "ooInetHTTPProxyPort" )
1135 : : {
1136 : : aPropertyName
1137 [ # # ]: 0 : = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("http.proxyPort"));
1138 : 0 : sal_Int32 n = 0;
1139 : 0 : rEvent.Element >>= n;
1140 : 0 : aPropertyValue = rtl::OUString::valueOf(n);
1141 : : }
1142 [ # # ]: 0 : else if ( aAccessor == "ooInetHTTPSProxyName" )
1143 : : {
1144 : : aPropertyName = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
1145 [ # # ]: 0 : "https.proxyHost"));
1146 : 0 : rEvent.Element >>= aPropertyValue;
1147 : : }
1148 [ # # ]: 0 : else if ( aAccessor == "ooInetHTTPSProxyPort" )
1149 : : {
1150 : : aPropertyName
1151 [ # # ]: 0 : = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("https.proxyPort"));
1152 : 0 : sal_Int32 n = 0;
1153 : 0 : rEvent.Element >>= n;
1154 : 0 : aPropertyValue = rtl::OUString::valueOf(n);
1155 : : }
1156 [ # # ]: 0 : else if ( aAccessor == "ooInetFTPProxyName" )
1157 : : {
1158 : : aPropertyName = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
1159 [ # # ]: 0 : "ftp.proxyHost"));
1160 : 0 : rEvent.Element >>= aPropertyValue;
1161 : : }
1162 [ # # ]: 0 : else if ( aAccessor == "ooInetFTPProxyPort" )
1163 : : {
1164 : : aPropertyName = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
1165 [ # # ]: 0 : "ftp.proxyPort"));
1166 : 0 : sal_Int32 n = 0;
1167 : 0 : rEvent.Element >>= n;
1168 : 0 : aPropertyValue = rtl::OUString::valueOf(n);
1169 : : }
1170 [ # # ]: 0 : else if ( aAccessor == "ooInetNoProxy" )
1171 : : {
1172 : : aPropertyName = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
1173 [ # # ]: 0 : "http.nonProxyHosts"));
1174 : : aPropertyName2 = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
1175 [ # # ]: 0 : "ftp.nonProxyHosts"));
1176 : 0 : rEvent.Element >>= aPropertyValue;
1177 : 0 : aPropertyValue = aPropertyValue.replace(';', '|');
1178 : : }
1179 [ # # ]: 0 : else if ( aAccessor == "NetAccess" )
1180 : : {
1181 : : aPropertyName = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
1182 [ # # ]: 0 : "appletviewer.security.mode"));
1183 : 0 : sal_Int32 n = 0;
1184 [ # # ]: 0 : if (rEvent.Element >>= n)
1185 [ # # # # ]: 0 : switch (n)
1186 : : {
1187 : : case 0:
1188 : : aPropertyValue = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
1189 [ # # ]: 0 : "host"));
1190 : 0 : break;
1191 : : case 1:
1192 : : aPropertyValue = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
1193 [ # # ]: 0 : "unrestricted"));
1194 : 0 : break;
1195 : : case 3:
1196 : : aPropertyValue = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
1197 [ # # ]: 0 : "none"));
1198 : 0 : break;
1199 : : }
1200 : : else
1201 : : return;
1202 : 0 : bSecurityChanged = true;
1203 : : }
1204 [ # # ]: 0 : else if ( aAccessor == "Security" )
1205 : : {
1206 : : aPropertyName = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
1207 [ # # ]: 0 : "stardiv.security.disableSecurity"));
1208 : 0 : sal_Bool b = sal_Bool();
1209 [ # # ]: 0 : if (rEvent.Element >>= b)
1210 [ # # ]: 0 : if (b)
1211 : : aPropertyValue = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
1212 [ # # ]: 0 : "false"));
1213 : : else
1214 : : aPropertyValue = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
1215 [ # # ]: 0 : "true"));
1216 : : else
1217 : : return;
1218 : 0 : bSecurityChanged = true;
1219 : : }
1220 : : else
1221 : : return;
1222 : :
1223 : 0 : rtl::Reference< jvmaccess::VirtualMachine > xVirtualMachine;
1224 : : {
1225 [ # # ]: 0 : osl::MutexGuard aGuard(*this);
1226 [ # # ]: 0 : if (m_xUnoVirtualMachine.is()) {
1227 [ # # ][ # # ]: 0 : xVirtualMachine = m_xUnoVirtualMachine->getVirtualMachine();
[ # # ]
1228 [ # # ]: 0 : }
1229 : : }
1230 [ # # ]: 0 : if (xVirtualMachine.is())
1231 : : {
1232 : : try
1233 : : {
1234 : : jvmaccess::VirtualMachine::AttachGuard aAttachGuard(
1235 [ # # ]: 0 : xVirtualMachine);
1236 : 0 : JNIEnv * pJNIEnv = aAttachGuard.getEnvironment();
1237 : :
1238 : : // call java.lang.System.setProperty
1239 : : // String setProperty( String key, String value)
1240 [ # # ]: 0 : jclass jcSystem= pJNIEnv->FindClass("java/lang/System");
1241 [ # # ][ # # ]: 0 : if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:FindClass java/lang/System")), 0);
[ # # ][ # # ]
[ # # ]
1242 [ # # ]: 0 : jmethodID jmSetProps= pJNIEnv->GetStaticMethodID( jcSystem, "setProperty","(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;");
1243 [ # # ][ # # ]: 0 : if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:GetStaticMethodID java.lang.System.setProperty")), 0);
[ # # ][ # # ]
[ # # ]
1244 : :
1245 [ # # ]: 0 : jstring jsPropName= pJNIEnv->NewString( aPropertyName.getStr(), aPropertyName.getLength());
1246 [ # # ][ # # ]: 0 : if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:NewString")), 0);
[ # # ][ # # ]
[ # # ]
1247 : :
1248 : : // remove the property if it does not have a value ( user left the dialog field empty)
1249 : : // or if the port is set to 0
1250 : 0 : aPropertyValue= aPropertyValue.trim();
1251 [ # # ][ # # : 0 : if( aPropertyValue.isEmpty() ||
# # # # #
# ]
1252 : 0 : ( ( aPropertyName == "ftp.proxyPort" || aPropertyName == "http.proxyPort" /*|| aPropertyName == "socksProxyPort"*/ ) && aPropertyValue == "0" )
1253 : : )
1254 : : {
1255 : : // call java.lang.System.getProperties
1256 [ # # ]: 0 : jmethodID jmGetProps= pJNIEnv->GetStaticMethodID( jcSystem, "getProperties","()Ljava/util/Properties;");
1257 [ # # ][ # # ]: 0 : if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:GetStaticMethodID java.lang.System.getProperties")), 0);
[ # # ][ # # ]
[ # # ]
1258 [ # # ]: 0 : jobject joProperties= pJNIEnv->CallStaticObjectMethod( jcSystem, jmGetProps);
1259 [ # # ][ # # ]: 0 : if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:CallStaticObjectMethod java.lang.System.getProperties")), 0);
[ # # ][ # # ]
[ # # ]
1260 : : // call java.util.Properties.remove
1261 [ # # ]: 0 : jclass jcProperties= pJNIEnv->FindClass("java/util/Properties");
1262 [ # # ][ # # ]: 0 : if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:FindClass java/util/Properties")), 0);
[ # # ][ # # ]
[ # # ]
1263 [ # # ]: 0 : jmethodID jmRemove= pJNIEnv->GetMethodID( jcProperties, "remove", "(Ljava/lang/Object;)Ljava/lang/Object;");
1264 [ # # ][ # # ]: 0 : if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:GetMethodID java.util.Properties.remove")), 0);
[ # # ][ # # ]
[ # # ]
1265 [ # # ]: 0 : pJNIEnv->CallObjectMethod( joProperties, jmRemove, jsPropName);
1266 : :
1267 : : // special calse for ftp.nonProxyHosts and http.nonProxyHosts. The office only
1268 : : // has a value for two java properties
1269 [ # # ]: 0 : if (!aPropertyName2.isEmpty())
1270 : : {
1271 [ # # ]: 0 : jstring jsPropName2= pJNIEnv->NewString( aPropertyName2.getStr(), aPropertyName2.getLength());
1272 [ # # ][ # # ]: 0 : if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:NewString")), 0);
[ # # ][ # # ]
[ # # ]
1273 [ # # ]: 0 : pJNIEnv->CallObjectMethod( joProperties, jmRemove, jsPropName2);
1274 : : }
1275 : : }
1276 : : else
1277 : : {
1278 : : // Change the Value of the property
1279 [ # # ]: 0 : jstring jsPropValue= pJNIEnv->NewString( aPropertyValue.getStr(), aPropertyValue.getLength());
1280 [ # # ][ # # ]: 0 : if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:NewString")), 0);
[ # # ][ # # ]
[ # # ]
1281 [ # # ]: 0 : pJNIEnv->CallStaticObjectMethod( jcSystem, jmSetProps, jsPropName, jsPropValue);
1282 [ # # ][ # # ]: 0 : if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:CallStaticObjectMethod java.lang.System.setProperty")), 0);
[ # # ][ # # ]
[ # # ]
1283 : :
1284 : : // special calse for ftp.nonProxyHosts and http.nonProxyHosts. The office only
1285 : : // has a value for two java properties
1286 [ # # ]: 0 : if (!aPropertyName2.isEmpty())
1287 : : {
1288 [ # # ]: 0 : jstring jsPropName2= pJNIEnv->NewString( aPropertyName2.getStr(), aPropertyName2.getLength());
1289 [ # # ][ # # ]: 0 : if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:NewString")), 0);
[ # # ][ # # ]
[ # # ]
1290 [ # # ]: 0 : jsPropValue= pJNIEnv->NewString( aPropertyValue.getStr(), aPropertyValue.getLength());
1291 [ # # ][ # # ]: 0 : if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:NewString")), 0);
[ # # ][ # # ]
[ # # ]
1292 [ # # ]: 0 : pJNIEnv->CallStaticObjectMethod( jcSystem, jmSetProps, jsPropName2, jsPropValue);
1293 [ # # ][ # # ]: 0 : if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:CallStaticObjectMethod java.lang.System.setProperty")), 0);
[ # # ][ # # ]
[ # # ]
1294 : : }
1295 : : }
1296 : :
1297 : : // If the settings for Security and NetAccess changed then we have to notify the SandboxSecurity
1298 : : // SecurityManager
1299 : : // call System.getSecurityManager()
1300 [ # # ]: 0 : if (bSecurityChanged)
1301 : : {
1302 [ # # ]: 0 : jmethodID jmGetSecur= pJNIEnv->GetStaticMethodID( jcSystem,"getSecurityManager","()Ljava/lang/SecurityManager;");
1303 [ # # ][ # # ]: 0 : if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:GetStaticMethodID java.lang.System.getSecurityManager")), 0);
[ # # ][ # # ]
[ # # ]
1304 [ # # ]: 0 : jobject joSecur= pJNIEnv->CallStaticObjectMethod( jcSystem, jmGetSecur);
1305 [ # # ]: 0 : if (joSecur != 0)
1306 : : {
1307 : : // Make sure the SecurityManager is our SandboxSecurity
1308 : : // FindClass("com.sun.star.lib.sandbox.SandboxSecurityManager" only worked at the first time
1309 : : // this code was executed. Maybe it is a security feature. However, all attempts to debug the
1310 : : // SandboxSecurity class (maybe the VM invokes checkPackageAccess) failed.
1311 : : // jclass jcSandboxSec= pJNIEnv->FindClass("com.sun.star.lib.sandbox.SandboxSecurity");
1312 : : // if(pJNIEnv->ExceptionOccurred()) throw RuntimeException(OUSTR("JNI:FindClass com.sun.star.lib.sandbox.SandboxSecurity"), Reference<XInterface>());
1313 : : // jboolean bIsSand= pJNIEnv->IsInstanceOf( joSecur, jcSandboxSec);
1314 : : // The SecurityManagers class Name must be com.sun.star.lib.sandbox.SandboxSecurity
1315 [ # # ]: 0 : jclass jcSec= pJNIEnv->GetObjectClass( joSecur);
1316 [ # # ]: 0 : jclass jcClass= pJNIEnv->FindClass("java/lang/Class");
1317 [ # # ][ # # ]: 0 : if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:FindClass java.lang.Class")), 0);
[ # # ][ # # ]
[ # # ]
1318 [ # # ]: 0 : jmethodID jmName= pJNIEnv->GetMethodID( jcClass,"getName","()Ljava/lang/String;");
1319 [ # # ][ # # ]: 0 : if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:GetMethodID java.lang.Class.getName")), 0);
[ # # ][ # # ]
[ # # ]
1320 [ # # ]: 0 : jstring jsClass= (jstring) pJNIEnv->CallObjectMethod( jcSec, jmName);
1321 [ # # ]: 0 : const jchar* jcharName= pJNIEnv->GetStringChars( jsClass, NULL);
1322 : 0 : rtl::OUString sName( jcharName);
1323 : : jboolean bIsSandbox;
1324 [ # # ]: 0 : if ( sName == "com.sun.star.lib.sandbox.SandboxSecurity" )
1325 : 0 : bIsSandbox= JNI_TRUE;
1326 : : else
1327 : 0 : bIsSandbox= JNI_FALSE;
1328 [ # # ]: 0 : pJNIEnv->ReleaseStringChars( jsClass, jcharName);
1329 : :
1330 [ # # ]: 0 : if (bIsSandbox == JNI_TRUE)
1331 : : {
1332 : : // call SandboxSecurity.reset
1333 [ # # ]: 0 : jmethodID jmReset= pJNIEnv->GetMethodID( jcSec,"reset","()V");
1334 [ # # ][ # # ]: 0 : if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:GetMethodID com.sun.star.lib.sandbox.SandboxSecurity.reset")), 0);
[ # # ][ # # ]
[ # # ]
1335 [ # # ]: 0 : pJNIEnv->CallVoidMethod( joSecur, jmReset);
1336 [ # # ][ # # ]: 0 : if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:CallVoidMethod com.sun.star.lib.sandbox.SandboxSecurity.reset")), 0);
[ # # ][ # # ]
[ # # ]
1337 : 0 : }
1338 : : }
1339 [ # # ]: 0 : }
1340 : : }
1341 [ # # ]: 0 : catch (jvmaccess::VirtualMachine::AttachGuard::CreationException &)
1342 : : {
1343 : : throw css::uno::RuntimeException(
1344 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
1345 : : "jvmaccess::VirtualMachine::AttachGuard::"
1346 : : "CreationException")),
1347 [ # # # # : 0 : 0);
# # ]
1348 : : }
1349 [ # # ][ # # ]: 0 : }
[ # # ][ # # ]
[ # # ]
1350 : : }
1351 : :
1352 [ + - ][ + - ]: 4 : JavaVirtualMachine::~JavaVirtualMachine()
[ + - ][ + - ]
1353 : : {
1354 [ - + ]: 4 : if (m_xInetConfiguration.is())
1355 : : // We should never get here, but just in case...
1356 : : try
1357 : : {
1358 [ # # ][ # # ]: 0 : m_xInetConfiguration->removeContainerListener(this);
[ # # ][ # # ]
1359 : : }
1360 [ # # ]: 0 : catch (css::uno::Exception &)
1361 : : {
1362 : : OSL_FAIL("com.sun.star.uno.Exception caught");
1363 : : }
1364 [ - + ]: 4 : if (m_xJavaConfiguration.is())
1365 : : // We should never get here, but just in case...
1366 : : try
1367 : : {
1368 [ # # ][ # # ]: 0 : m_xJavaConfiguration->removeContainerListener(this);
[ # # ][ # # ]
1369 : : }
1370 [ # # ]: 0 : catch (css::uno::Exception &)
1371 : : {
1372 : : OSL_FAIL("com.sun.star.uno.Exception caught");
1373 : : }
1374 [ - + ]: 8 : }
1375 : :
1376 : 4 : void SAL_CALL JavaVirtualMachine::disposing()
1377 : : {
1378 : 4 : css::uno::Reference< css::container::XContainer > xContainer1;
1379 : 4 : css::uno::Reference< css::container::XContainer > xContainer2;
1380 : : {
1381 [ + - ]: 4 : osl::MutexGuard aGuard(*this);
1382 : 4 : m_bDisposed = true;
1383 [ + - ]: 4 : xContainer1 = m_xInetConfiguration;
1384 : 4 : m_xInetConfiguration.clear();
1385 [ + - ]: 4 : xContainer2 = m_xJavaConfiguration;
1386 [ + - ]: 4 : m_xJavaConfiguration.clear();
1387 : : }
1388 [ + - ]: 4 : if (xContainer1.is())
1389 [ + - ][ + - ]: 4 : xContainer1->removeContainerListener(this);
[ + - ]
1390 [ + - ]: 4 : if (xContainer2.is())
1391 [ + - ][ + - ]: 4 : xContainer2->removeContainerListener(this);
[ + - ]
1392 : 4 : }
1393 : :
1394 : : /*We listen to changes in the configuration. For example, the user changes the proxy
1395 : : settings in the options dialog (menu tools). Then we are notified of this change and
1396 : : if the java vm is already running we change the properties (System.lang.System.setProperties)
1397 : : through JNI.
1398 : : To receive notifications this class implements XContainerListener.
1399 : : */
1400 : 4 : void JavaVirtualMachine::registerConfigChangesListener()
1401 : : {
1402 : : try
1403 : : {
1404 : : css::uno::Reference< css::lang::XMultiServiceFactory > xConfigProvider(
1405 [ + - ][ + - ]: 8 : m_xContext->getServiceManager()->createInstanceWithContext( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
[ + - ]
1406 [ + - ][ + - ]: 4 : "com.sun.star.configuration.ConfigurationProvider")), m_xContext), css::uno::UNO_QUERY);
[ + - ]
1407 : :
1408 [ + - ]: 4 : if (xConfigProvider.is())
1409 : : {
1410 : : // We register this instance as listener to changes in org.openoffice.Inet/Settings
1411 : : // arguments for ConfigurationAccess
1412 [ + - ]: 4 : css::uno::Sequence< css::uno::Any > aArguments(2);
1413 [ + - ]: 4 : aArguments[0] <<= css::beans::PropertyValue(
1414 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("nodepath")),
1415 : : 0,
1416 : : css::uno::makeAny(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("org.openoffice.Inet/Settings"))),
1417 [ + - ][ + - ]: 8 : css::beans::PropertyState_DIRECT_VALUE);
[ + - ][ + - ]
1418 : : // depth: -1 means unlimited
1419 [ + - ]: 4 : aArguments[1] <<= css::beans::PropertyValue(
1420 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("depth")),
1421 : : 0,
1422 : : css::uno::makeAny( (sal_Int32)-1),
1423 [ + - ][ + - ]: 8 : css::beans::PropertyState_DIRECT_VALUE);
[ + - ]
1424 : :
1425 : : m_xInetConfiguration
1426 : : = css::uno::Reference< css::container::XContainer >(
1427 [ + - ]: 4 : xConfigProvider->createInstanceWithArguments(
1428 : : rtl::OUString(
1429 : : RTL_CONSTASCII_USTRINGPARAM(
1430 : : "com.sun.star.configuration.ConfigurationAccess")),
1431 : 4 : aArguments),
1432 [ + - ][ + - ]: 4 : css::uno::UNO_QUERY);
[ + - ][ + - ]
1433 : :
1434 [ + - ]: 4 : if (m_xInetConfiguration.is())
1435 [ + - ][ + - ]: 4 : m_xInetConfiguration->addContainerListener(this);
[ + - ]
1436 : :
1437 : : // now register as listener to changes in org.openoffice.Java/VirtualMachine
1438 [ + - ]: 4 : css::uno::Sequence< css::uno::Any > aArguments2(2);
1439 [ + - ]: 4 : aArguments2[0] <<= css::beans::PropertyValue(
1440 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("nodepath")),
1441 : : 0,
1442 : : css::uno::makeAny(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("org.openoffice.Office.Java/VirtualMachine"))),
1443 [ + - ][ + - ]: 8 : css::beans::PropertyState_DIRECT_VALUE);
[ + - ][ + - ]
1444 : : // depth: -1 means unlimited
1445 [ + - ]: 4 : aArguments2[1] <<= css::beans::PropertyValue(
1446 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("depth")),
1447 : : 0,
1448 : : css::uno::makeAny( (sal_Int32)-1),
1449 [ + - ][ + - ]: 8 : css::beans::PropertyState_DIRECT_VALUE);
[ + - ]
1450 : :
1451 : : m_xJavaConfiguration
1452 : : = css::uno::Reference< css::container::XContainer >(
1453 [ + - ]: 4 : xConfigProvider->createInstanceWithArguments(
1454 : : rtl::OUString(
1455 : : RTL_CONSTASCII_USTRINGPARAM(
1456 : : "com.sun.star.configuration.ConfigurationAccess")),
1457 : 4 : aArguments2),
1458 [ + - ][ + - ]: 4 : css::uno::UNO_QUERY);
[ + - ][ + - ]
1459 : :
1460 [ + - ]: 4 : if (m_xJavaConfiguration.is())
1461 [ + - ][ + - ]: 4 : m_xJavaConfiguration->addContainerListener(this);
[ + - ][ + - ]
[ + - ]
1462 [ # # ]: 4 : }
1463 : 0 : }catch(const css::uno::Exception & e)
1464 : : {
1465 : : #if OSL_DEBUG_LEVEL > 1
1466 : : rtl::OString message = rtl::OUStringToOString(e.Message, RTL_TEXTENCODING_ASCII_US);
1467 : : OSL_TRACE("javavm.cxx: could not set up listener for Configuration because of >%s<", message.getStr());
1468 : : #else
1469 : : (void) e; // unused
1470 : : #endif
1471 : : }
1472 : 4 : }
1473 : :
1474 : : // param true: all Inet setting are set as Java Properties on a live VM.
1475 : : // false: the Java net properties are set to empty value.
1476 : 0 : void JavaVirtualMachine::setINetSettingsInVM(bool set_reset)
1477 : : {
1478 [ # # ]: 0 : osl::MutexGuard aGuard(*this);
1479 : : try
1480 : : {
1481 [ # # ]: 0 : if (m_xUnoVirtualMachine.is())
1482 : : {
1483 : : jvmaccess::VirtualMachine::AttachGuard aAttachGuard(
1484 [ # # ][ # # ]: 0 : m_xUnoVirtualMachine->getVirtualMachine());
[ # # ]
1485 : 0 : JNIEnv * pJNIEnv = aAttachGuard.getEnvironment();
1486 : :
1487 : : // The Java Properties
1488 [ # # ]: 0 : rtl::OUString sFtpProxyHost(RTL_CONSTASCII_USTRINGPARAM("ftp.proxyHost") );
1489 [ # # ]: 0 : rtl::OUString sFtpProxyPort(RTL_CONSTASCII_USTRINGPARAM("ftp.proxyPort") );
1490 [ # # ]: 0 : rtl::OUString sFtpNonProxyHosts (RTL_CONSTASCII_USTRINGPARAM("ftp.nonProxyHosts"));
1491 [ # # ]: 0 : rtl::OUString sHttpProxyHost(RTL_CONSTASCII_USTRINGPARAM("http.proxyHost") );
1492 [ # # ]: 0 : rtl::OUString sHttpProxyPort(RTL_CONSTASCII_USTRINGPARAM("http.proxyPort") );
1493 [ # # ]: 0 : rtl::OUString sHttpNonProxyHosts(RTL_CONSTASCII_USTRINGPARAM("http.nonProxyHosts"));
1494 : :
1495 : : // creat Java Properties as JNI strings
1496 [ # # ]: 0 : jstring jsFtpProxyHost= pJNIEnv->NewString( sFtpProxyHost.getStr(), sFtpProxyHost.getLength());
1497 [ # # ][ # # ]: 0 : if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:NewString")), 0);
[ # # ][ # # ]
[ # # ]
1498 [ # # ]: 0 : jstring jsFtpProxyPort= pJNIEnv->NewString( sFtpProxyPort.getStr(), sFtpProxyPort.getLength());
1499 [ # # ][ # # ]: 0 : if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:NewString")), 0);
[ # # ][ # # ]
[ # # ]
1500 [ # # ]: 0 : jstring jsFtpNonProxyHosts= pJNIEnv->NewString( sFtpNonProxyHosts.getStr(), sFtpNonProxyHosts.getLength());
1501 [ # # ][ # # ]: 0 : if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:NewString")), 0);
[ # # ][ # # ]
[ # # ]
1502 [ # # ]: 0 : jstring jsHttpProxyHost= pJNIEnv->NewString( sHttpProxyHost.getStr(), sHttpProxyHost.getLength());
1503 [ # # ][ # # ]: 0 : if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:NewString")), 0);
[ # # ][ # # ]
[ # # ]
1504 [ # # ]: 0 : jstring jsHttpProxyPort= pJNIEnv->NewString( sHttpProxyPort.getStr(), sHttpProxyPort.getLength());
1505 [ # # ][ # # ]: 0 : if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:NewString")), 0);
[ # # ][ # # ]
[ # # ]
1506 [ # # ]: 0 : jstring jsHttpNonProxyHosts= pJNIEnv->NewString( sHttpNonProxyHosts.getStr(), sHttpNonProxyHosts.getLength());
1507 [ # # ][ # # ]: 0 : if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:NewString")), 0);
[ # # ][ # # ]
[ # # ]
1508 : :
1509 : : // prepare java.lang.System.setProperty
1510 [ # # ]: 0 : jclass jcSystem= pJNIEnv->FindClass("java/lang/System");
1511 [ # # ][ # # ]: 0 : if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:FindClass java/lang/System")), 0);
[ # # ][ # # ]
[ # # ]
1512 [ # # ]: 0 : jmethodID jmSetProps= pJNIEnv->GetStaticMethodID( jcSystem, "setProperty","(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;");
1513 [ # # ][ # # ]: 0 : if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:GetStaticMethodID java.lang.System.setProperty")), 0);
[ # # ][ # # ]
[ # # ]
1514 : :
1515 : : // call java.lang.System.getProperties
1516 [ # # ]: 0 : jmethodID jmGetProps= pJNIEnv->GetStaticMethodID( jcSystem, "getProperties","()Ljava/util/Properties;");
1517 [ # # ][ # # ]: 0 : if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:GetStaticMethodID java.lang.System.getProperties")), 0);
[ # # ][ # # ]
[ # # ]
1518 [ # # ]: 0 : jobject joProperties= pJNIEnv->CallStaticObjectMethod( jcSystem, jmGetProps);
1519 [ # # ][ # # ]: 0 : if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:CallStaticObjectMethod java.lang.System.getProperties")), 0);
[ # # ][ # # ]
[ # # ]
1520 : : // prepare java.util.Properties.remove
1521 [ # # ]: 0 : jclass jcProperties= pJNIEnv->FindClass("java/util/Properties");
1522 [ # # ][ # # ]: 0 : if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:FindClass java/util/Properties")), 0);
[ # # ][ # # ]
[ # # ]
1523 : :
1524 [ # # ]: 0 : if (set_reset)
1525 : : {
1526 : : // Set all network properties with the VM
1527 : 0 : JVM jvm;
1528 [ # # ][ # # ]: 0 : getINetPropsFromConfig( &jvm, m_xContext->getServiceManager(), m_xContext);
[ # # ]
1529 [ # # ]: 0 : const ::std::vector< rtl::OUString> & Props = jvm.getProperties();
1530 : : typedef ::std::vector< rtl::OUString >::const_iterator C_IT;
1531 : :
1532 [ # # ][ # # ]: 0 : for( C_IT i= Props.begin(); i != Props.end(); ++i)
1533 : : {
1534 : 0 : rtl::OUString prop= *i;
1535 : 0 : sal_Int32 index= prop.indexOf( (sal_Unicode)'=');
1536 : 0 : rtl::OUString propName= prop.copy( 0, index);
1537 : 0 : rtl::OUString propValue= prop.copy( index + 1);
1538 : :
1539 [ # # ]: 0 : if( propName.equals( sFtpProxyHost))
1540 : : {
1541 [ # # ]: 0 : jstring jsVal= pJNIEnv->NewString( propValue.getStr(), propValue.getLength());
1542 [ # # ][ # # ]: 0 : if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:NewString")), 0);
[ # # ][ # # ]
[ # # ]
1543 [ # # ]: 0 : pJNIEnv->CallStaticObjectMethod( jcSystem, jmSetProps, jsFtpProxyHost, jsVal);
1544 [ # # ][ # # ]: 0 : if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:CallStaticObjectMethod java.lang.System.setProperty")), 0);
[ # # ][ # # ]
[ # # ]
1545 : : }
1546 [ # # ]: 0 : else if( propName.equals( sFtpProxyPort))
1547 : : {
1548 [ # # ]: 0 : jstring jsVal= pJNIEnv->NewString( propValue.getStr(), propValue.getLength());
1549 [ # # ][ # # ]: 0 : if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:NewString")), 0);
[ # # ][ # # ]
[ # # ]
1550 [ # # ]: 0 : pJNIEnv->CallStaticObjectMethod( jcSystem, jmSetProps, jsFtpProxyPort, jsVal);
1551 [ # # ][ # # ]: 0 : if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:CallStaticObjectMethod java.lang.System.setProperty")), 0);
[ # # ][ # # ]
[ # # ]
1552 : : }
1553 [ # # ]: 0 : else if( propName.equals( sFtpNonProxyHosts))
1554 : : {
1555 [ # # ]: 0 : jstring jsVal= pJNIEnv->NewString( propValue.getStr(), propValue.getLength());
1556 [ # # ][ # # ]: 0 : if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:NewString")), 0);
[ # # ][ # # ]
[ # # ]
1557 [ # # ]: 0 : pJNIEnv->CallStaticObjectMethod( jcSystem, jmSetProps, jsFtpNonProxyHosts, jsVal);
1558 [ # # ][ # # ]: 0 : if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:CallStaticObjectMethod java.lang.System.setProperty")), 0);
[ # # ][ # # ]
[ # # ]
1559 : : }
1560 [ # # ]: 0 : else if( propName.equals( sHttpProxyHost))
1561 : : {
1562 [ # # ]: 0 : jstring jsVal= pJNIEnv->NewString( propValue.getStr(), propValue.getLength());
1563 [ # # ][ # # ]: 0 : if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:NewString")), 0);
[ # # ][ # # ]
[ # # ]
1564 [ # # ]: 0 : pJNIEnv->CallStaticObjectMethod( jcSystem, jmSetProps, jsHttpProxyHost, jsVal);
1565 [ # # ][ # # ]: 0 : if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:CallStaticObjectMethod java.lang.System.setProperty")), 0);
[ # # ][ # # ]
[ # # ]
1566 : : }
1567 [ # # ]: 0 : else if( propName.equals( sHttpProxyPort))
1568 : : {
1569 [ # # ]: 0 : jstring jsVal= pJNIEnv->NewString( propValue.getStr(), propValue.getLength());
1570 [ # # ][ # # ]: 0 : if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:NewString")), 0);
[ # # ][ # # ]
[ # # ]
1571 [ # # ]: 0 : pJNIEnv->CallStaticObjectMethod( jcSystem, jmSetProps, jsHttpProxyPort, jsVal);
1572 [ # # ][ # # ]: 0 : if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:CallStaticObjectMethod java.lang.System.setProperty")), 0);
[ # # ][ # # ]
[ # # ]
1573 : : }
1574 [ # # ]: 0 : else if( propName.equals( sHttpNonProxyHosts))
1575 : : {
1576 [ # # ]: 0 : jstring jsVal= pJNIEnv->NewString( propValue.getStr(), propValue.getLength());
1577 [ # # ][ # # ]: 0 : if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:NewString")), 0);
[ # # ][ # # ]
[ # # ]
1578 [ # # ]: 0 : pJNIEnv->CallStaticObjectMethod( jcSystem, jmSetProps, jsHttpNonProxyHosts, jsVal);
1579 [ # # ][ # # ]: 0 : if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:CallStaticObjectMethod java.lang.System.setProperty")), 0);
[ # # ][ # # ]
[ # # ]
1580 : : }
1581 : 0 : }
1582 : : }
1583 : : else
1584 : : {
1585 : : // call java.util.Properties.remove
1586 [ # # ]: 0 : jmethodID jmRemove= pJNIEnv->GetMethodID( jcProperties, "remove", "(Ljava/lang/Object;)Ljava/lang/Object;");
1587 [ # # ][ # # ]: 0 : if(pJNIEnv->ExceptionOccurred()) throw css::uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JNI:GetMethodID java.util.Property.remove")), 0);
[ # # ][ # # ]
[ # # ]
1588 [ # # ]: 0 : pJNIEnv->CallObjectMethod( joProperties, jmRemove, jsFtpProxyHost);
1589 [ # # ]: 0 : pJNIEnv->CallObjectMethod( joProperties, jmRemove, jsFtpProxyPort);
1590 [ # # ]: 0 : pJNIEnv->CallObjectMethod( joProperties, jmRemove, jsFtpNonProxyHosts);
1591 [ # # ]: 0 : pJNIEnv->CallObjectMethod( joProperties, jmRemove, jsHttpProxyHost);
1592 [ # # ]: 0 : pJNIEnv->CallObjectMethod( joProperties, jmRemove, jsHttpProxyPort);
1593 [ # # ]: 0 : pJNIEnv->CallObjectMethod( joProperties, jmRemove, jsHttpNonProxyHosts);
1594 [ # # ]: 0 : }
[ # # # ]
1595 : : }
1596 : : }
1597 [ # # ]: 0 : catch (css::uno::RuntimeException &)
1598 : : {
1599 : : OSL_FAIL("RuntimeException");
1600 : : }
1601 [ # # ]: 0 : catch (jvmaccess::VirtualMachine::AttachGuard::CreationException &)
1602 : : {
1603 : : OSL_FAIL("jvmaccess::VirtualMachine::AttachGuard::CreationException");
1604 [ # # ]: 0 : }
1605 : 0 : }
1606 : :
1607 : 4 : void JavaVirtualMachine::setUpUnoVirtualMachine(JNIEnv * environment) {
1608 : 4 : css::uno::Reference< css::util::XMacroExpander > exp;
1609 [ + - - + ]: 16 : if (!(m_xContext->getValueByName(
[ - + ][ + - ]
1610 : : rtl::OUString(
1611 : : RTL_CONSTASCII_USTRINGPARAM(
1612 : 4 : "/singletons/com.sun.star.util.theMacroExpander")))
1613 [ + - ][ + - ]: 8 : >>= exp)
[ + - ][ + - ]
[ + - ]
[ # # # # ]
1614 : 4 : || !exp.is())
1615 : : {
1616 : : throw css::uno::RuntimeException(
1617 : : rtl::OUString(
1618 : : RTL_CONSTASCII_USTRINGPARAM(
1619 : : "component context fails to supply singleton"
1620 : : " com.sun.star.util.theMacroExpander of type"
1621 : : " com.sun.star.util.XMacroExpander")),
1622 [ # # ][ # # ]: 0 : m_xContext);
1623 : : }
1624 : 4 : rtl::OUString baseUrl;
1625 : : try {
1626 [ + - ]: 4 : baseUrl = exp->expandMacros(
1627 : : rtl::OUString(
1628 [ + - ][ + - ]: 4 : RTL_CONSTASCII_USTRINGPARAM("$URE_INTERNAL_JAVA_DIR/")));
1629 [ # # ]: 0 : } catch (css::lang::IllegalArgumentException &) {
1630 : : throw css::uno::RuntimeException(
1631 : : rtl::OUString(
1632 : : RTL_CONSTASCII_USTRINGPARAM(
1633 : : "com::sun::star::lang::IllegalArgumentException")),
1634 [ # # # # : 0 : static_cast< cppu::OWeakObject * >(this));
# # ]
1635 : : }
1636 : 4 : rtl::OUString classPath;
1637 : : try {
1638 [ + - ]: 4 : classPath = exp->expandMacros(
1639 : : rtl::OUString(
1640 [ + - ][ + - ]: 4 : RTL_CONSTASCII_USTRINGPARAM("$URE_INTERNAL_JAVA_CLASSPATH")));
[ # # ]
1641 [ # # ]: 0 : } catch (css::lang::IllegalArgumentException &) {}
1642 : : jclass class_URLClassLoader = environment->FindClass(
1643 [ + - ]: 4 : "java/net/URLClassLoader");
1644 [ - + ]: 4 : if (class_URLClassLoader == 0) {
1645 [ # # ]: 0 : handleJniException(environment);
1646 : : }
1647 : : jmethodID ctor_URLClassLoader = environment->GetMethodID(
1648 [ + - ]: 4 : class_URLClassLoader, "<init>", "([Ljava/net/URL;)V");
1649 [ - + ]: 4 : if (ctor_URLClassLoader == 0) {
1650 [ # # ]: 0 : handleJniException(environment);
1651 : : }
1652 [ + - ]: 4 : jclass class_URL = environment->FindClass("java/net/URL");
1653 [ - + ]: 4 : if (class_URL == 0) {
1654 [ # # ]: 0 : handleJniException(environment);
1655 : : }
1656 : : jmethodID ctor_URL_1 = environment->GetMethodID(
1657 [ + - ]: 4 : class_URL, "<init>", "(Ljava/lang/String;)V");
1658 [ - + ]: 4 : if (ctor_URL_1 == 0) {
1659 [ # # ]: 0 : handleJniException(environment);
1660 : : }
1661 : : jvalue args[3];
1662 : : args[0].l = environment->NewString(
1663 : : static_cast< jchar const * >(baseUrl.getStr()),
1664 [ + - ]: 4 : static_cast< jsize >(baseUrl.getLength()));
1665 [ - + ]: 4 : if (args[0].l == 0) {
1666 [ # # ]: 0 : handleJniException(environment);
1667 : : }
1668 [ + - ]: 4 : jobject base = environment->NewObjectA(class_URL, ctor_URL_1, args);
1669 [ - + ]: 4 : if (base == 0) {
1670 [ # # ]: 0 : handleJniException(environment);
1671 : : }
1672 : : jmethodID ctor_URL_2 = environment->GetMethodID(
1673 [ + - ]: 4 : class_URL, "<init>", "(Ljava/net/URL;Ljava/lang/String;)V");
1674 [ - + ]: 4 : if (ctor_URL_2 == 0) {
1675 [ # # ]: 0 : handleJniException(environment);
1676 : : }
1677 : : jobjectArray classpath = jvmaccess::ClassPath::translateToUrls(
1678 [ + - ]: 4 : m_xContext, environment, classPath);
1679 [ - + ]: 4 : if (classpath == 0) {
1680 [ # # ]: 0 : handleJniException(environment);
1681 : : }
1682 : 4 : args[0].l = base;
1683 [ + - ]: 4 : args[1].l = environment->NewStringUTF("unoloader.jar");
1684 [ - + ]: 4 : if (args[1].l == 0) {
1685 [ # # ]: 0 : handleJniException(environment);
1686 : : }
1687 [ + - ]: 4 : args[0].l = environment->NewObjectA(class_URL, ctor_URL_2, args);
1688 [ - + ]: 4 : if (args[0].l == 0) {
1689 [ # # ]: 0 : handleJniException(environment);
1690 : : }
1691 [ + - ]: 4 : args[0].l = environment->NewObjectArray(1, class_URL, args[0].l);
1692 [ - + ]: 4 : if (args[0].l == 0) {
1693 [ # # ]: 0 : handleJniException(environment);
1694 : : }
1695 : : jobject cl1 = environment->NewObjectA(
1696 [ + - ]: 4 : class_URLClassLoader, ctor_URLClassLoader, args);
1697 [ - + ]: 4 : if (cl1 == 0) {
1698 [ # # ]: 0 : handleJniException(environment);
1699 : : }
1700 : : jmethodID method_loadClass = environment->GetMethodID(
1701 : : class_URLClassLoader, "loadClass",
1702 [ + - ]: 4 : "(Ljava/lang/String;)Ljava/lang/Class;");
1703 [ - + ]: 4 : if (method_loadClass == 0) {
1704 [ # # ]: 0 : handleJniException(environment);
1705 : : }
1706 : : args[0].l = environment->NewStringUTF(
1707 [ + - ]: 4 : "com.sun.star.lib.unoloader.UnoClassLoader");
1708 [ - + ]: 4 : if (args[0].l == 0) {
1709 [ # # ]: 0 : handleJniException(environment);
1710 : : }
1711 : : jclass class_UnoClassLoader = static_cast< jclass >(
1712 [ + - ]: 4 : environment->CallObjectMethodA(cl1, method_loadClass, args));
1713 [ - + ]: 4 : if (class_UnoClassLoader == 0) {
1714 [ # # ]: 0 : handleJniException(environment);
1715 : : }
1716 : : jmethodID ctor_UnoClassLoader = environment->GetMethodID(
1717 : : class_UnoClassLoader, "<init>",
1718 [ + - ]: 4 : "(Ljava/net/URL;[Ljava/net/URL;Ljava/lang/ClassLoader;)V");
1719 [ - + ]: 4 : if (ctor_UnoClassLoader == 0) {
1720 [ # # ]: 0 : handleJniException(environment);
1721 : : }
1722 : 4 : args[0].l = base;
1723 : 4 : args[1].l = classpath;
1724 : 4 : args[2].l = cl1;
1725 : : jobject cl2 = environment->NewObjectA(
1726 [ + - ]: 4 : class_UnoClassLoader, ctor_UnoClassLoader, args);
1727 [ - + ]: 4 : if (cl2 == 0) {
1728 [ # # ]: 0 : handleJniException(environment);
1729 : : }
1730 : : try {
1731 : : m_xUnoVirtualMachine = new jvmaccess::UnoVirtualMachine(
1732 [ + - ][ + - ]: 4 : m_xVirtualMachine, cl2);
[ + - ]
1733 [ # # ]: 0 : } catch (jvmaccess::UnoVirtualMachine::CreationException &) {
1734 : : throw css::uno::RuntimeException(
1735 : : rtl::OUString(
1736 : : RTL_CONSTASCII_USTRINGPARAM(
1737 : : "jvmaccess::UnoVirtualMachine::CreationException")),
1738 [ # # # # : 0 : static_cast< cppu::OWeakObject * >(this));
# # ]
1739 : 4 : }
1740 : 4 : }
1741 : :
1742 : 0 : void JavaVirtualMachine::handleJniException(JNIEnv * environment) {
1743 : 0 : environment->ExceptionClear();
1744 : : throw css::uno::RuntimeException(
1745 : : rtl::OUString(
1746 : : RTL_CONSTASCII_USTRINGPARAM("JNI exception occurred")),
1747 [ # # ][ # # ]: 0 : static_cast< cppu::OWeakObject * >(this));
[ # # ]
1748 [ + - ][ + - ]: 12 : }
1749 : :
1750 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|