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