26#include <com/sun/star/beans/NamedValue.hpp>
27#include <com/sun/star/container/XContainer.hpp>
28#include <com/sun/star/java/JavaNotFoundException.hpp>
29#include <com/sun/star/java/InvalidJavaSettingsException.hpp>
30#include <com/sun/star/java/RestartRequiredException.hpp>
31#include <com/sun/star/java/JavaDisabledException.hpp>
32#include <com/sun/star/java/JavaVMCreationFailureException.hpp>
33#include <com/sun/star/lang/DisposedException.hpp>
34#include <com/sun/star/lang/IllegalArgumentException.hpp>
35#include <com/sun/star/lang/XMultiComponentFactory.hpp>
36#include <com/sun/star/lang/XMultiServiceFactory.hpp>
37#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
38#include <com/sun/star/registry/XRegistryKey.hpp>
39#include <com/sun/star/registry/XSimpleRegistry.hpp>
40#include <com/sun/star/task/XInteractionHandler.hpp>
41#include <com/sun/star/uno/Exception.hpp>
42#include <com/sun/star/uno/Reference.hxx>
43#include <com/sun/star/uno/RuntimeException.hpp>
44#include <com/sun/star/uno/Sequence.hxx>
45#include <com/sun/star/uno/XComponentContext.hpp>
46#include <com/sun/star/uno/XCurrentContext.hpp>
47#include <com/sun/star/uno/XInterface.hpp>
48#include <com/sun/star/util/theMacroExpander.hpp>
57#include <rtl/process.h>
58#include <rtl/ustring.hxx>
61#include <uno/current_context.hxx>
62#include <jvmfwk/framework.hxx>
105class NoJavaIniException:
public css::uno::Exception
109typedef std::stack< jvmaccess::VirtualMachine::AttachGuard * > GuardStack;
113static void destroyAttachGuards(
void *
pData)
115 GuardStack * pStack =
static_cast< GuardStack *
>(
pData);
116 if (pStack !=
nullptr)
118 while (!pStack->empty())
120 delete pStack->top();
129bool askForRetry(css::uno::Any
const & rException)
131 css::uno::Reference< css::uno::XCurrentContext > xContext(
132 css::uno::getCurrentContext());
135 css::uno::Reference< css::task::XInteractionHandler > xHandler;
136 xContext->getValueByName(
"java-vm.interaction-handler")
142 xHandler->handle(xRequest);
143 return xRequest->retry();
153 const css::uno::Reference<css::lang::XMultiComponentFactory> &
xSMgr,
154 const css::uno::Reference<css::uno::XComponentContext> &xCtx )
156 css::uno::Reference<css::uno::XInterface> xConfRegistry =
xSMgr->createInstanceWithContext(
157 "com.sun.star.configuration.ConfigurationRegistry",
159 if(!xConfRegistry.is())
throw css::uno::RuntimeException(
"javavm.cxx: couldn't get ConfigurationRegistry",
nullptr);
161 css::uno::Reference<css::registry::XSimpleRegistry> xConfRegistry_simple(xConfRegistry, css::uno::UNO_QUERY_THROW);
162 xConfRegistry_simple->open(
"org.openoffice.Inet",
true,
false);
163 css::uno::Reference<css::registry::XRegistryKey> xRegistryRootKey = xConfRegistry_simple->getRootKey();
166 css::uno::Reference<css::registry::XRegistryKey> proxyEnable= xRegistryRootKey->openKey(
"Settings/ooInetProxyType");
167 if( proxyEnable.is() && 0 != proxyEnable->getLongValue())
170 css::uno::Reference<css::registry::XRegistryKey> ftpProxy_name = xRegistryRootKey->openKey(
"Settings/ooInetFTPProxyName");
171 if(ftpProxy_name.is() && !ftpProxy_name->getStringValue().isEmpty()) {
172 OUString ftpHost =
"ftp.proxyHost=" + ftpProxy_name->getStringValue();
175 css::uno::Reference<css::registry::XRegistryKey> ftpProxy_port = xRegistryRootKey->openKey(
"Settings/ooInetFTPProxyPort");
176 if(ftpProxy_port.is() && ftpProxy_port->getLongValue()) {
177 OUString ftpPort =
"ftp.proxyPort=" + OUString::number(ftpProxy_port->getLongValue());
185 css::uno::Reference<css::registry::XRegistryKey> httpProxy_name = xRegistryRootKey->openKey(
"Settings/ooInetHTTPProxyName");
186 if(httpProxy_name.is() && !httpProxy_name->getStringValue().isEmpty()) {
187 OUString httpHost =
"http.proxyHost=" + httpProxy_name->getStringValue();
190 css::uno::Reference<css::registry::XRegistryKey> httpProxy_port = xRegistryRootKey->openKey(
"Settings/ooInetHTTPProxyPort");
191 if(httpProxy_port.is() && httpProxy_port->getLongValue()) {
192 OUString httpPort =
"http.proxyPort=" + OUString::number(httpProxy_port->getLongValue());
200 css::uno::Reference<css::registry::XRegistryKey> httpsProxy_name = xRegistryRootKey->openKey(
"Settings/ooInetHTTPSProxyName");
201 if(httpsProxy_name.is() && !httpsProxy_name->getStringValue().isEmpty()) {
202 OUString httpsHost =
"https.proxyHost=" + httpsProxy_name->getStringValue();
205 css::uno::Reference<css::registry::XRegistryKey> httpsProxy_port = xRegistryRootKey->openKey(
"Settings/ooInetHTTPSProxyPort");
206 if(httpsProxy_port.is() && httpsProxy_port->getLongValue()) {
207 OUString httpsPort =
"https.proxyPort=" + OUString::number(httpsProxy_port->getLongValue());
215 css::uno::Reference<css::registry::XRegistryKey> nonProxies_name = xRegistryRootKey->openKey(
"Settings/ooInetNoProxy");
216 if(nonProxies_name.is() && !nonProxies_name->getStringValue().isEmpty()) {
217 OUString
value = nonProxies_name->getStringValue();
221 OUString httpNonProxyHosts =
"http.nonProxyHosts=" +
value;
222 OUString ftpNonProxyHosts =
"ftp.nonProxyHosts=" +
value;
228 xConfRegistry_simple->close();
232void getDefaultLocaleFromConfig(
234 const css::uno::Reference<css::lang::XMultiComponentFactory> &
xSMgr,
235 const css::uno::Reference<css::uno::XComponentContext> &xCtx )
237 css::uno::Reference<css::uno::XInterface> xConfRegistry =
238 xSMgr->createInstanceWithContext(
"com.sun.star.configuration.ConfigurationRegistry", xCtx );
239 if(!xConfRegistry.is())
240 throw css::uno::RuntimeException(
241 "javavm.cxx: couldn't get ConfigurationRegistry",
nullptr);
243 css::uno::Reference<css::registry::XSimpleRegistry> xConfRegistry_simple(
244 xConfRegistry, css::uno::UNO_QUERY_THROW);
245 xConfRegistry_simple->open(
"org.openoffice.Setup",
true,
false);
246 css::uno::Reference<css::registry::XRegistryKey> xRegistryRootKey = xConfRegistry_simple->getRootKey();
255 css::uno::Reference<css::registry::XRegistryKey> xUILocale = xRegistryRootKey->openKey(
"L10N/ooLocale");
256 if(xUILocale.is() && !xUILocale->getStringValue().isEmpty()) {
257 LanguageTag aLanguageTag( xUILocale->getStringValue());
266 if(!language.isEmpty()) {
267 OUString prop =
"user.language=" + language;
273 OUString prop =
"user.script=" +
script;
277 if(!country.isEmpty()) {
278 OUString prop =
"user.country=" + country;
283 if(!language.isEmpty()) {
284 OUString prop =
"user.language.display=" + language;
289 OUString prop =
"user.script.display=" +
script;
293 if(!country.isEmpty()) {
294 OUString prop =
"user.country.display=" + country;
300 css::uno::Reference<css::registry::XRegistryKey> xLocale = xRegistryRootKey->openKey(
"L10N/ooSetupSystemLocale");
301 if(xLocale.is() && !xLocale->getStringValue().isEmpty()) {
302 LanguageTag aLanguageTag( xLocale->getStringValue());
312 if(!language.isEmpty()) {
313 OUString prop =
"user.language.format=" + language;
318 OUString prop =
"user.script.format=" +
script;
322 if(!country.isEmpty()) {
323 OUString prop =
"user.country.format=" + country;
328 xConfRegistry_simple->close();
332void getJavaPropsFromSafetySettings(
334 const css::uno::Reference<css::lang::XMultiComponentFactory> &
xSMgr,
335 const css::uno::Reference<css::uno::XComponentContext> &xCtx)
337 css::uno::Reference<css::uno::XInterface> xConfRegistry =
338 xSMgr->createInstanceWithContext(
339 "com.sun.star.configuration.ConfigurationRegistry",
341 if(!xConfRegistry.is())
342 throw css::uno::RuntimeException(
343 "javavm.cxx: couldn't get ConfigurationRegistry",
nullptr);
345 css::uno::Reference<css::registry::XSimpleRegistry> xConfRegistry_simple(
346 xConfRegistry, css::uno::UNO_QUERY_THROW);
347 xConfRegistry_simple->open(
348 "org.openoffice.Office.Java",
350 css::uno::Reference<css::registry::XRegistryKey> xRegistryRootKey =
351 xConfRegistry_simple->getRootKey();
353 if (xRegistryRootKey.is())
355 css::uno::Reference<css::registry::XRegistryKey> key_NetAccess= xRegistryRootKey->openKey(
"VirtualMachine/NetAccess");
356 if (key_NetAccess.is())
358 sal_Int32 val= key_NetAccess->getLongValue();
362 case 0: sVal =
"host";
364 case 1: sVal =
"unrestricted";
366 case 3: sVal =
"none";
369 OUString sProperty =
"appletviewer.security.mode=" + sVal;
372 css::uno::Reference<css::registry::XRegistryKey> key_CheckSecurity= xRegistryRootKey->openKey(
373 "VirtualMachine/Security");
374 if( key_CheckSecurity.is())
376 bool val =
static_cast<bool>(key_CheckSecurity->getLongValue());
377 OUString sProperty(
"stardiv.security.disableSecurity=");
379 sProperty +=
"false";
385 xConfRegistry_simple->close();
396 time_t clock = time(
nullptr);
398 tmData = localtime(&clock);
400 char *
p = tmData->tm_zone;
401#elif defined(_MSC_VER)
402 char *
p = _tzname[0];
405 char *
p = tzname[0];
410 pjvm->
pushProp(
"user.timezone=ECT");
414void initVMConfiguration(
416 const css::uno::Reference<css::lang::XMultiComponentFactory> &
xSMgr,
417 const css::uno::Reference<css::uno::XComponentContext > &xCtx)
421 getINetPropsFromConfig(&jvm,
xSMgr, xCtx);
423 catch(
const css::uno::Exception & exception) {
424 SAL_INFO(
"stoc",
"can not get INETProps because of " << exception);
428 getDefaultLocaleFromConfig(&jvm,
xSMgr,xCtx);
430 catch(
const css::uno::Exception & exception) {
431 SAL_INFO(
"stoc",
"can not get locale because of " << exception);
436 getJavaPropsFromSafetySettings(&jvm,
xSMgr, xCtx);
438 catch(
const css::uno::Exception & exception) {
439 SAL_INFO(
"stoc",
"couldn't get safety settings because of " << exception);
448 if (getenv(
"STOC_FORCE_SYSTEM_LAF"))
449 pjvm->
pushProp(
"swing.systemlaf=javax.swing.plaf.metal.MetalLookAndFeel");
454class DetachCurrentThread {
456 explicit DetachCurrentThread(JavaVM * jvm): m_jvm(jvm) {}
458 ~DetachCurrentThread() {
459 if (m_jvm->DetachCurrentThread() != 0) {
464 DetachCurrentThread(
const DetachCurrentThread&) =
delete;
465 DetachCurrentThread& operator=(
const DetachCurrentThread&) =
delete;
473JavaVirtualMachine::JavaVirtualMachine(
474 css::uno::Reference< css::uno::XComponentContext > xContext):
479 m_aAttachGuards(destroyAttachGuards)
488 throw css::lang::DisposedException(
491 throw css::uno::RuntimeException(
492 "bad call to initialize",
494 css::beans::NamedValue val;
495 if (rArguments.getLength() == 1 && (rArguments[0] >>= val) && val.Name ==
"UnoVirtualMachine" )
499 "Pointer cannot be represented as sal_Int64");
500 sal_Int64 nPointer =
reinterpret_cast< sal_Int64
>(
502 val.Value >>= nPointer;
508 "Pointer cannot be represented as sal_Int64");
509 sal_Int64 nPointer =
reinterpret_cast< sal_Int64
>(
511 if (rArguments.getLength() == 1)
512 rArguments[0] >>= nPointer;
520 throw css::lang::WrappedTargetRuntimeException(
521 "jvmaccess::UnoVirtualMachine::CreationException",
527 throw css::lang::IllegalArgumentException(
528 "sequence of exactly one any containing either (a) a"
529 " com.sun.star.beans.NamedValue with Name"
530 " \"UnoVirtualMachine\" and Value a hyper representing a"
531 " non-null pointer to a jvmaccess:UnoVirtualMachine, or (b)"
532 " a hyper representing a non-null pointer to a"
533 " jvmaccess::VirtualMachine required",
541 return "com.sun.star.comp.stoc.JavaVirtualMachine";
550css::uno::Sequence< OUString > SAL_CALL
553 return {
"com.sun.star.java.JavaVirtualMachine" };
556css::uno::Any SAL_CALL
561 throw css::lang::DisposedException(
563 css::uno::Sequence< sal_Int8 > aId(16);
564 rtl_getGlobalProcessId(
reinterpret_cast< sal_uInt8 *
>(aId.getArray()));
566 RETURN_JAVAVM, RETURN_VIRTUALMACHINE, RETURN_UNOVIRTUALMACHINE };
567 ReturnType returnType =
568 rProcessId.getLength() == 17 && rProcessId[16] == 0
569 ? RETURN_VIRTUALMACHINE
570 : rProcessId.getLength() == 17 && rProcessId[16] == 1
571 ? RETURN_UNOVIRTUALMACHINE
573 css::uno::Sequence< sal_Int8 > aProcessId(rProcessId);
574 if (returnType != RETURN_JAVAVM)
575 aProcessId.realloc(16);
576 if (aId != aProcessId)
577 return css::uno::Any();
579 std::unique_ptr<JavaInfo> info;
583 initVMConfiguration(&aJvm,
m_xContext->getServiceManager(),
586 std::vector<OUString> options;
587 options.reserve(
props.size());
588 for (
auto const&
i :
props)
590 options.push_back(
i.startsWith(
"-") ?
i :
"-D" +
i);
593 JNIEnv * pMainThreadEnv =
nullptr;
596 if (getenv(
"STOC_FORCE_NO_JRE"))
602 bool bStarted =
false;
611 if (getenv(
"STOC_FORCE_NO_JRE"))
623 css::java::JavaNotFoundException exc(
624 "JavaVirtualMachine::getJavaVM failed because"
625 " No suitable JRE found!",
627 askForRetry(css::uno::Any(exc));
628 return css::uno::Any();
633 throw css::uno::RuntimeException(
634 "[JavaVirtualMachine]:An unexpected error occurred"
635 " while searching for a Java, " + OUString::number(errFind),
nullptr);
644 css::java::InvalidJavaSettingsException exc(
645 "JavaVirtualMachine::getJavaVM failed because"
646 " Java settings have changed!",
648 askForRetry(css::uno::Any(exc));
649 return css::uno::Any();
654 return css::uno::Any();
660 css::java::JavaDisabledException exc(
661 "JavaVirtualMachine::getJavaVM failed because Java is disabled!",
663 if( ! askForRetry(css::uno::Any(exc)))
664 return css::uno::Any();
673 std::unique_ptr<JavaInfo> aJavaInfo;
697 css::java::JavaVMCreationFailureException exc(
698 "JavaVirtualMachine::getJavaVM failed because Java is defective!",
700 askForRetry(css::uno::Any(exc));
701 return css::uno::Any();
714 css::java::RestartRequiredException exc(
715 "JavaVirtualMachine::getJavaVM failed because "
716 "Office must be restarted before Java can be used!",
718 askForRetry(css::uno::Any(exc));
719 return css::uno::Any();
724 throw css::uno::RuntimeException(
725 "[JavaVirtualMachine]:An unexpected error occurred"
726 " while starting Java!",
nullptr);
736 m_pJavaVm, JNI_VERSION_1_2,
true, pMainThreadEnv);
753 throw css::lang::WrappedTargetRuntimeException(
754 "jvmaccess::VirtualMachine::AttachGuard::CreationException occurred",
758 switch (returnType) {
761 throw css::uno::RuntimeException(
762 "JavaVirtualMachine service was initialized in a way"
763 " that the requested JavaVM pointer is not available",
766 return css::uno::Any(
reinterpret_cast< sal_IntPtr
>(
m_pJavaVm));
767 case RETURN_VIRTUALMACHINE:
769 return css::uno::Any(
770 reinterpret_cast< sal_Int64
>(
772 case RETURN_UNOVIRTUALMACHINE:
774 return css::uno::Any(
783 throw css::lang::DisposedException(
784 OUString(), getXWeak());
793 throw css::lang::DisposedException(
794 OUString(), getXWeak());
800 bool bEnabled =
false;
802 throw css::uno::RuntimeException();
810 throw css::lang::DisposedException(
811 OUString(), getXWeak());
816 return pStack !=
nullptr && !pStack->empty();
823 throw css::lang::DisposedException(
826 throw css::uno::RuntimeException(
827 "JavaVirtualMachine::registerThread: null VirtualMachine",
831 if (pStack ==
nullptr)
833 pStack =
new GuardStack;
845 throw css::lang::WrappedTargetRuntimeException(
846 "JavaVirtualMachine::registerThread: jvmaccess::"
847 "VirtualMachine::AttachGuard::CreationException",
856 throw css::lang::DisposedException(
859 throw css::uno::RuntimeException(
860 "JavaVirtualMachine::revokeThread: null VirtualMachine",
864 if (pStack ==
nullptr || pStack->empty())
865 throw css::uno::RuntimeException(
866 "JavaVirtualMachine::revokeThread: no matching registerThread",
868 delete pStack->top();
883 css::container::ContainerEvent
const &)
887 css::container::ContainerEvent
const &)
896 css::container::ContainerEvent
const & rEvent)
905 rEvent.Accessor >>= aAccessor;
906 OUString aPropertyName;
907 OUString aPropertyName2;
908 OUString aPropertyValue;
909 bool bSecurityChanged =
false;
910 if ( aAccessor ==
"ooInetProxyType" )
914 rEvent.Element >>=
value;
918 else if ( aAccessor ==
"ooInetHTTPProxyName" )
920 aPropertyName =
"http.proxyHost";
921 rEvent.Element >>= aPropertyValue;
923 else if ( aAccessor ==
"ooInetHTTPProxyPort" )
925 aPropertyName =
"http.proxyPort";
927 rEvent.Element >>=
n;
928 aPropertyValue = OUString::number(
n);
930 else if ( aAccessor ==
"ooInetHTTPSProxyName" )
932 aPropertyName =
"https.proxyHost";
933 rEvent.Element >>= aPropertyValue;
935 else if ( aAccessor ==
"ooInetHTTPSProxyPort" )
937 aPropertyName =
"https.proxyPort";
939 rEvent.Element >>=
n;
940 aPropertyValue = OUString::number(
n);
942 else if ( aAccessor ==
"ooInetFTPProxyName" )
944 aPropertyName =
"ftp.proxyHost";
945 rEvent.Element >>= aPropertyValue;
947 else if ( aAccessor ==
"ooInetFTPProxyPort" )
949 aPropertyName =
"ftp.proxyPort";
951 rEvent.Element >>=
n;
952 aPropertyValue = OUString::number(
n);
954 else if ( aAccessor ==
"ooInetNoProxy" )
956 aPropertyName =
"http.nonProxyHosts";
957 aPropertyName2 =
"ftp.nonProxyHosts";
958 rEvent.Element >>= aPropertyValue;
959 aPropertyValue = aPropertyValue.replace(
';',
'|');
961 else if ( aAccessor ==
"NetAccess" )
963 aPropertyName =
"appletviewer.security.mode";
965 if (rEvent.Element >>=
n)
969 aPropertyValue =
"host";
972 aPropertyValue =
"unrestricted";
975 aPropertyValue =
"none";
980 bSecurityChanged =
true;
982 else if ( aAccessor ==
"Security" )
984 aPropertyName =
"stardiv.security.disableSecurity";
986 if (rEvent.Element >>= b)
988 aPropertyValue =
"false";
990 aPropertyValue =
"true";
993 bSecurityChanged =
true;
1005 if (!xVirtualMachine.is())
1016 jclass jcSystem= pJNIEnv->FindClass(
"java/lang/System");
1017 if(pJNIEnv->ExceptionOccurred())
throw css::uno::RuntimeException(
"JNI:FindClass java/lang/System",
nullptr);
1018 jmethodID jmSetProps= pJNIEnv->GetStaticMethodID( jcSystem,
"setProperty",
"(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;");
1019 if(pJNIEnv->ExceptionOccurred())
throw css::uno::RuntimeException(
"JNI:GetStaticMethodID java.lang.System.setProperty",
nullptr);
1021 jstring jsPropName= pJNIEnv->NewString(
reinterpret_cast<jchar
const *
>(aPropertyName.getStr()), aPropertyName.getLength());
1022 if(pJNIEnv->ExceptionOccurred())
throw css::uno::RuntimeException(
"JNI:NewString",
nullptr);
1026 aPropertyValue= aPropertyValue.trim();
1027 if( aPropertyValue.isEmpty() ||
1028 ( ( aPropertyName ==
"ftp.proxyPort" || aPropertyName ==
"http.proxyPort" ) && aPropertyValue ==
"0" )
1032 jmethodID jmGetProps= pJNIEnv->GetStaticMethodID( jcSystem,
"getProperties",
"()Ljava/util/Properties;");
1033 if(pJNIEnv->ExceptionOccurred())
throw css::uno::RuntimeException(
"JNI:GetStaticMethodID java.lang.System.getProperties",
nullptr);
1034 jobject joProperties= pJNIEnv->CallStaticObjectMethod( jcSystem, jmGetProps);
1035 if(pJNIEnv->ExceptionOccurred())
throw css::uno::RuntimeException(
"JNI:CallStaticObjectMethod java.lang.System.getProperties",
nullptr);
1037 jclass jcProperties= pJNIEnv->FindClass(
"java/util/Properties");
1038 if(pJNIEnv->ExceptionOccurred())
throw css::uno::RuntimeException(
"JNI:FindClass java/util/Properties",
nullptr);
1039 jmethodID jmRemove= pJNIEnv->GetMethodID( jcProperties,
"remove",
"(Ljava/lang/Object;)Ljava/lang/Object;");
1040 if(pJNIEnv->ExceptionOccurred())
throw css::uno::RuntimeException(
"JNI:GetMethodID java.util.Properties.remove",
nullptr);
1041 pJNIEnv->CallObjectMethod( joProperties, jmRemove, jsPropName);
1045 if (!aPropertyName2.isEmpty())
1047 jstring jsPropName2= pJNIEnv->NewString(
reinterpret_cast<jchar
const *
>(aPropertyName2.getStr()), aPropertyName2.getLength());
1048 if(pJNIEnv->ExceptionOccurred())
throw css::uno::RuntimeException(
"JNI:NewString",
nullptr);
1049 pJNIEnv->CallObjectMethod( joProperties, jmRemove, jsPropName2);
1055 jstring jsPropValue= pJNIEnv->NewString(
reinterpret_cast<jchar
const *
>(aPropertyValue.getStr()), aPropertyValue.getLength());
1056 if(pJNIEnv->ExceptionOccurred())
throw css::uno::RuntimeException(
"JNI:NewString",
nullptr);
1057 pJNIEnv->CallStaticObjectMethod( jcSystem, jmSetProps, jsPropName, jsPropValue);
1058 if(pJNIEnv->ExceptionOccurred())
throw css::uno::RuntimeException(
"JNI:CallStaticObjectMethod java.lang.System.setProperty",
nullptr);
1062 if (!aPropertyName2.isEmpty())
1064 jstring jsPropName2= pJNIEnv->NewString(
reinterpret_cast<jchar
const *
>(aPropertyName2.getStr()), aPropertyName2.getLength());
1065 if(pJNIEnv->ExceptionOccurred())
throw css::uno::RuntimeException(
"JNI:NewString",
nullptr);
1066 jsPropValue= pJNIEnv->NewString(
reinterpret_cast<jchar
const *
>(aPropertyValue.getStr()), aPropertyValue.getLength());
1067 if(pJNIEnv->ExceptionOccurred())
throw css::uno::RuntimeException(
"JNI:NewString",
nullptr);
1068 pJNIEnv->CallStaticObjectMethod( jcSystem, jmSetProps, jsPropName2, jsPropValue);
1069 if(pJNIEnv->ExceptionOccurred())
throw css::uno::RuntimeException(
"JNI:CallStaticObjectMethod java.lang.System.setProperty",
nullptr);
1076 if (bSecurityChanged)
1078 jmethodID jmGetSecur= pJNIEnv->GetStaticMethodID( jcSystem,
"getSecurityManager",
"()Ljava/lang/SecurityManager;");
1079 if(pJNIEnv->ExceptionOccurred())
throw css::uno::RuntimeException(
"JNI:GetStaticMethodID java.lang.System.getSecurityManager",
nullptr);
1080 jobject joSecur= pJNIEnv->CallStaticObjectMethod( jcSystem, jmGetSecur);
1081 if (joSecur !=
nullptr)
1091 jclass jcSec= pJNIEnv->GetObjectClass( joSecur);
1092 jclass jcClass= pJNIEnv->FindClass(
"java/lang/Class");
1093 if(pJNIEnv->ExceptionOccurred())
throw css::uno::RuntimeException(
"JNI:FindClass java.lang.Class",
nullptr);
1094 jmethodID jmName= pJNIEnv->GetMethodID( jcClass,
"getName",
"()Ljava/lang/String;");
1095 if(pJNIEnv->ExceptionOccurred())
throw css::uno::RuntimeException(
"JNI:GetMethodID java.lang.Class.getName",
nullptr);
1096 jstring jsClass=
static_cast<jstring
>(pJNIEnv->CallObjectMethod( jcSec, jmName));
1097 const jchar* jcharName= pJNIEnv->GetStringChars( jsClass,
nullptr);
1100 bIsSandbox =
sName ==
"com.sun.star.lib.sandbox.SandboxSecurity";
1101 pJNIEnv->ReleaseStringChars( jsClass, jcharName);
1106 jmethodID jmReset= pJNIEnv->GetMethodID( jcSec,
"reset",
"()V");
1107 if(pJNIEnv->ExceptionOccurred())
throw css::uno::RuntimeException(
"JNI:GetMethodID com.sun.star.lib.sandbox.SandboxSecurity.reset",
nullptr);
1108 pJNIEnv->CallVoidMethod( joSecur, jmReset);
1109 if(pJNIEnv->ExceptionOccurred())
throw css::uno::RuntimeException(
"JNI:CallVoidMethod com.sun.star.lib.sandbox.SandboxSecurity.reset",
nullptr);
1117 throw css::lang::WrappedTargetRuntimeException(
1118 "jvmaccess::VirtualMachine::AttachGuard::CreationException",
1119 getXWeak(), anyEx );
1131 catch (css::uno::Exception &)
1133 OSL_FAIL(
"com.sun.star.uno.Exception caught");
1141 catch (css::uno::Exception &)
1143 OSL_FAIL(
"com.sun.star.uno.Exception caught");
1149 css::uno::Reference< css::container::XContainer > xContainer1;
1150 css::uno::Reference< css::container::XContainer > xContainer2;
1159 if (xContainer1.is())
1160 xContainer1->removeContainerListener(
this);
1161 if (xContainer2.is())
1162 xContainer2->removeContainerListener(
this);
1175 css::uno::Reference< css::lang::XMultiServiceFactory > xConfigProvider(
1177 "/singletons/com.sun.star.configuration.theDefaultProvider"),
1178 css::uno::UNO_QUERY);
1180 if (xConfigProvider.is())
1186 {
"nodepath", css::uno::Any(OUString(
"org.openoffice.Inet/Settings"))},
1187 {
"depth", css::uno::Any(sal_Int32(-1))}
1190 xConfigProvider->createInstanceWithArguments(
1191 "com.sun.star.configuration.ConfigurationAccess",
1193 css::uno::UNO_QUERY);
1201 {
"nodepath", css::uno::Any(OUString(
"org.openoffice.Office.Java/VirtualMachine"))},
1202 {
"depth", css::uno::Any(sal_Int32(-1))}
1205 xConfigProvider->createInstanceWithArguments(
1206 "com.sun.star.configuration.ConfigurationAccess",
1208 css::uno::UNO_QUERY);
1213 }
catch(
const css::uno::Exception & e)
1215 SAL_INFO(
"stoc",
"could not set up listener for Configuration because of >" << e <<
"<");
1233 OUString sFtpProxyHost(
"ftp.proxyHost");
1234 OUString sFtpProxyPort(
"ftp.proxyPort");
1235 OUString sFtpNonProxyHosts (
"ftp.nonProxyHosts");
1236 OUString sHttpProxyHost(
"http.proxyHost");
1237 OUString sHttpProxyPort(
"http.proxyPort");
1238 OUString sHttpNonProxyHosts(
"http.nonProxyHosts");
1241 jstring jsFtpProxyHost= pJNIEnv->NewString(
reinterpret_cast<jchar
const *
>(sFtpProxyHost.getStr()), sFtpProxyHost.getLength());
1242 if(pJNIEnv->ExceptionOccurred())
throw css::uno::RuntimeException(
"JNI:NewString",
nullptr);
1243 jstring jsFtpProxyPort= pJNIEnv->NewString(
reinterpret_cast<jchar
const *
>(sFtpProxyPort.getStr()), sFtpProxyPort.getLength());
1244 if(pJNIEnv->ExceptionOccurred())
throw css::uno::RuntimeException(
"JNI:NewString",
nullptr);
1245 jstring jsFtpNonProxyHosts= pJNIEnv->NewString(
reinterpret_cast<jchar
const *
>(sFtpNonProxyHosts.getStr()), sFtpNonProxyHosts.getLength());
1246 if(pJNIEnv->ExceptionOccurred())
throw css::uno::RuntimeException(
"JNI:NewString",
nullptr);
1247 jstring jsHttpProxyHost= pJNIEnv->NewString(
reinterpret_cast<jchar
const *
>(sHttpProxyHost.getStr()), sHttpProxyHost.getLength());
1248 if(pJNIEnv->ExceptionOccurred())
throw css::uno::RuntimeException(
"JNI:NewString",
nullptr);
1249 jstring jsHttpProxyPort= pJNIEnv->NewString(
reinterpret_cast<jchar
const *
>(sHttpProxyPort.getStr()), sHttpProxyPort.getLength());
1250 if(pJNIEnv->ExceptionOccurred())
throw css::uno::RuntimeException(
"JNI:NewString",
nullptr);
1251 jstring jsHttpNonProxyHosts= pJNIEnv->NewString(
reinterpret_cast<jchar
const *
>(sHttpNonProxyHosts.getStr()), sHttpNonProxyHosts.getLength());
1252 if(pJNIEnv->ExceptionOccurred())
throw css::uno::RuntimeException(
"JNI:NewString",
nullptr);
1255 jclass jcSystem= pJNIEnv->FindClass(
"java/lang/System");
1256 if(pJNIEnv->ExceptionOccurred())
throw css::uno::RuntimeException(
"JNI:FindClass java/lang/System",
nullptr);
1257 jmethodID jmSetProps= pJNIEnv->GetStaticMethodID( jcSystem,
"setProperty",
"(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;");
1258 if(pJNIEnv->ExceptionOccurred())
throw css::uno::RuntimeException(
"JNI:GetStaticMethodID java.lang.System.setProperty",
nullptr);
1261 jmethodID jmGetProps= pJNIEnv->GetStaticMethodID( jcSystem,
"getProperties",
"()Ljava/util/Properties;");
1262 if(pJNIEnv->ExceptionOccurred())
throw css::uno::RuntimeException(
"JNI:GetStaticMethodID java.lang.System.getProperties",
nullptr);
1263 jobject joProperties= pJNIEnv->CallStaticObjectMethod( jcSystem, jmGetProps);
1264 if(pJNIEnv->ExceptionOccurred())
throw css::uno::RuntimeException(
"JNI:CallStaticObjectMethod java.lang.System.getProperties",
nullptr);
1266 jclass jcProperties= pJNIEnv->FindClass(
"java/util/Properties");
1267 if(pJNIEnv->ExceptionOccurred())
throw css::uno::RuntimeException(
"JNI:FindClass java/util/Properties",
nullptr);
1274 const ::std::vector< OUString> & Props = jvm.
getProperties();
1276 for(
auto& prop : Props)
1278 sal_Int32
index= prop.indexOf(
'=');
1279 std::u16string_view propName= prop.subView( 0,
index);
1280 OUString propValue= prop.copy(
index + 1);
1282 if( propName == sFtpProxyHost)
1284 jstring jsVal= pJNIEnv->NewString(
reinterpret_cast<jchar
const *
>(propValue.getStr()), propValue.getLength());
1285 if(pJNIEnv->ExceptionOccurred())
throw css::uno::RuntimeException(
"JNI:NewString",
nullptr);
1286 pJNIEnv->CallStaticObjectMethod( jcSystem, jmSetProps, jsFtpProxyHost, jsVal);
1287 if(pJNIEnv->ExceptionOccurred())
throw css::uno::RuntimeException(
"JNI:CallStaticObjectMethod java.lang.System.setProperty",
nullptr);
1289 else if( propName == sFtpProxyPort)
1291 jstring jsVal= pJNIEnv->NewString(
reinterpret_cast<jchar
const *
>(propValue.getStr()), propValue.getLength());
1292 if(pJNIEnv->ExceptionOccurred())
throw css::uno::RuntimeException(
"JNI:NewString",
nullptr);
1293 pJNIEnv->CallStaticObjectMethod( jcSystem, jmSetProps, jsFtpProxyPort, jsVal);
1294 if(pJNIEnv->ExceptionOccurred())
throw css::uno::RuntimeException(
"JNI:CallStaticObjectMethod java.lang.System.setProperty",
nullptr);
1296 else if( propName == sFtpNonProxyHosts)
1298 jstring jsVal= pJNIEnv->NewString(
reinterpret_cast<jchar
const *
>(propValue.getStr()), propValue.getLength());
1299 if(pJNIEnv->ExceptionOccurred())
throw css::uno::RuntimeException(
"JNI:NewString",
nullptr);
1300 pJNIEnv->CallStaticObjectMethod( jcSystem, jmSetProps, jsFtpNonProxyHosts, jsVal);
1301 if(pJNIEnv->ExceptionOccurred())
throw css::uno::RuntimeException(
"JNI:CallStaticObjectMethod java.lang.System.setProperty",
nullptr);
1303 else if( propName == sHttpProxyHost)
1305 jstring jsVal= pJNIEnv->NewString(
reinterpret_cast<jchar
const *
>(propValue.getStr()), propValue.getLength());
1306 if(pJNIEnv->ExceptionOccurred())
throw css::uno::RuntimeException(
"JNI:NewString",
nullptr);
1307 pJNIEnv->CallStaticObjectMethod( jcSystem, jmSetProps, jsHttpProxyHost, jsVal);
1308 if(pJNIEnv->ExceptionOccurred())
throw css::uno::RuntimeException(
"JNI:CallStaticObjectMethod java.lang.System.setProperty",
nullptr);
1310 else if( propName == sHttpProxyPort)
1312 jstring jsVal= pJNIEnv->NewString(
reinterpret_cast<jchar
const *
>(propValue.getStr()), propValue.getLength());
1313 if(pJNIEnv->ExceptionOccurred())
throw css::uno::RuntimeException(
"JNI:NewString",
nullptr);
1314 pJNIEnv->CallStaticObjectMethod( jcSystem, jmSetProps, jsHttpProxyPort, jsVal);
1315 if(pJNIEnv->ExceptionOccurred())
throw css::uno::RuntimeException(
"JNI:CallStaticObjectMethod java.lang.System.setProperty",
nullptr);
1317 else if( propName == sHttpNonProxyHosts)
1319 jstring jsVal= pJNIEnv->NewString(
reinterpret_cast<jchar
const *
>(propValue.getStr()), propValue.getLength());
1320 if(pJNIEnv->ExceptionOccurred())
throw css::uno::RuntimeException(
"JNI:NewString",
nullptr);
1321 pJNIEnv->CallStaticObjectMethod( jcSystem, jmSetProps, jsHttpNonProxyHosts, jsVal);
1322 if(pJNIEnv->ExceptionOccurred())
throw css::uno::RuntimeException(
"JNI:CallStaticObjectMethod java.lang.System.setProperty",
nullptr);
1329 jmethodID jmRemove= pJNIEnv->GetMethodID( jcProperties,
"remove",
"(Ljava/lang/Object;)Ljava/lang/Object;");
1330 if(pJNIEnv->ExceptionOccurred())
throw css::uno::RuntimeException(
"JNI:GetMethodID java.util.Property.remove",
nullptr);
1331 pJNIEnv->CallObjectMethod( joProperties, jmRemove, jsFtpProxyHost);
1332 pJNIEnv->CallObjectMethod( joProperties, jmRemove, jsFtpProxyPort);
1333 pJNIEnv->CallObjectMethod( joProperties, jmRemove, jsFtpNonProxyHosts);
1334 pJNIEnv->CallObjectMethod( joProperties, jmRemove, jsHttpProxyHost);
1335 pJNIEnv->CallObjectMethod( joProperties, jmRemove, jsHttpProxyPort);
1336 pJNIEnv->CallObjectMethod( joProperties, jmRemove, jsHttpNonProxyHosts);
1340 catch (css::uno::RuntimeException &)
1342 OSL_FAIL(
"RuntimeException");
1346 OSL_FAIL(
"jvmaccess::VirtualMachine::AttachGuard::CreationException");
1351 css::uno::Reference< css::util::XMacroExpander > exp = css::util::theMacroExpander::get(
m_xContext);
1354 baseUrl = exp->expandMacros(
"$URE_INTERNAL_JAVA_DIR/");
1355 }
catch (css::lang::IllegalArgumentException &) {
1357 throw css::lang::WrappedTargetRuntimeException(
1358 "css::lang::IllegalArgumentException",
1359 getXWeak(), anyEx );
1363 classPath = exp->expandMacros(
"$URE_INTERNAL_JAVA_CLASSPATH");
1364 }
catch (css::lang::IllegalArgumentException &) {}
1365 jclass class_URLClassLoader = environment->FindClass(
1366 "java/net/URLClassLoader");
1367 if (class_URLClassLoader ==
nullptr) {
1370 jmethodID ctor_URLClassLoader = environment->GetMethodID(
1371 class_URLClassLoader,
"<init>",
"([Ljava/net/URL;)V");
1372 if (ctor_URLClassLoader ==
nullptr) {
1375 jclass class_URL = environment->FindClass(
"java/net/URL");
1376 if (class_URL ==
nullptr) {
1379 jmethodID ctor_URL_1 = environment->GetMethodID(
1380 class_URL,
"<init>",
"(Ljava/lang/String;)V");
1381 if (ctor_URL_1 ==
nullptr) {
1385 args[0].l = environment->NewString(
1386 reinterpret_cast< jchar
const *
>(baseUrl.getStr()),
1387 static_cast< jsize
>(baseUrl.getLength()));
1388 if (
args[0].l ==
nullptr) {
1391 jobject
base = environment->NewObjectA(class_URL, ctor_URL_1,
args);
1392 if (
base ==
nullptr) {
1395 jmethodID ctor_URL_2 = environment->GetMethodID(
1396 class_URL,
"<init>",
"(Ljava/net/URL;Ljava/lang/String;)V");
1397 if (ctor_URL_2 ==
nullptr) {
1402 if (classpath ==
nullptr) {
1406 args[1].l = environment->NewStringUTF(
"unoloader.jar");
1407 if (
args[1].l ==
nullptr) {
1410 args[0].l = environment->NewObjectA(class_URL, ctor_URL_2,
args);
1411 if (
args[0].l ==
nullptr) {
1414 args[0].l = environment->NewObjectArray(1, class_URL,
args[0].l);
1415 if (
args[0].l ==
nullptr) {
1418 jobject cl1 = environment->NewObjectA(
1419 class_URLClassLoader, ctor_URLClassLoader,
args);
1420 if (cl1 ==
nullptr) {
1423 jmethodID method_loadClass = environment->GetMethodID(
1424 class_URLClassLoader,
"loadClass",
1425 "(Ljava/lang/String;)Ljava/lang/Class;");
1426 if (method_loadClass ==
nullptr) {
1429 args[0].l = environment->NewStringUTF(
1430 "com.sun.star.lib.unoloader.UnoClassLoader");
1431 if (
args[0].l ==
nullptr) {
1434 jclass class_UnoClassLoader =
static_cast< jclass
>(
1435 environment->CallObjectMethodA(cl1, method_loadClass,
args));
1436 if (class_UnoClassLoader ==
nullptr) {
1439 jmethodID ctor_UnoClassLoader = environment->GetMethodID(
1440 class_UnoClassLoader,
"<init>",
1441 "(Ljava/net/URL;[Ljava/net/URL;Ljava/lang/ClassLoader;)V");
1442 if (ctor_UnoClassLoader ==
nullptr) {
1446 args[1].l = classpath;
1448 jobject cl2 = environment->NewObjectA(
1449 class_UnoClassLoader, ctor_UnoClassLoader,
args);
1450 if (cl2 ==
nullptr) {
1458 throw css::lang::WrappedTargetRuntimeException(
1459 "jvmaccess::UnoVirtualMachine::CreationException",
1460 getXWeak(), anyEx );
1466 environment->ExceptionDescribe();
1468 environment->ExceptionClear();
1470 throw css::uno::RuntimeException(
1471 "JNI exception occurred",
1476extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
1478 css::uno::XComponentContext* context , css::uno::Sequence<css::uno::Any>
const&)
Reference< XComponentContext > m_xContext
void getIsoLanguageScriptCountry(OUString &rLanguage, OUString &rScript, OUString &rCountry) const
mutable::osl::Mutex m_aMutex
JNIEnv * getEnvironment() const
void pushProp(const OUString &uString)
const ::std::vector< OUString > & getProperties() const
virtual void SAL_CALL elementInserted(css::container::ContainerEvent const &rEvent) override
virtual sal_Bool SAL_CALL isThreadAttached() override
virtual void SAL_CALL elementReplaced(css::container::ContainerEvent const &rEvent) override
virtual void SAL_CALL revokeThread() override
virtual ~JavaVirtualMachine() override
void handleJniException(JNIEnv *environment)
virtual void SAL_CALL elementRemoved(css::container::ContainerEvent const &rEvent) override
virtual void SAL_CALL registerThread() override
rtl::Reference< jvmaccess::VirtualMachine > m_xVirtualMachine
css::uno::Reference< css::container::XContainer > m_xJavaConfiguration
rtl::Reference< jvmaccess::UnoVirtualMachine > m_xUnoVirtualMachine
void registerConfigChangesListener()
virtual sal_Bool SAL_CALL supportsService(OUString const &rServiceName) override
virtual OUString SAL_CALL getImplementationName() override
css::uno::Reference< css::uno::XComponentContext > m_xContext
virtual css::uno::Any SAL_CALL getJavaVM(css::uno::Sequence< sal_Int8 > const &rProcessId) override
virtual sal_Bool SAL_CALL isVMEnabled() override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual void SAL_CALL disposing() override
css::uno::Reference< css::container::XContainer > m_xInetConfiguration
void setINetSettingsInVM(bool set_reset)
osl::ThreadData m_aAttachGuards
virtual void SAL_CALL initialize(css::uno::Sequence< css::uno::Any > const &rArguments) override
virtual sal_Bool SAL_CALL isVMStarted() override
void setUpUnoVirtualMachine(JNIEnv *environment)
Reference< XMultiServiceFactory > xSMgr
javaFrameworkError jfw_findAndSelectJRE(std::unique_ptr< JavaInfo > *pInfo)
javaFrameworkError jfw_getSelectedJRE(std::unique_ptr< JavaInfo > *ppInfo)
javaFrameworkError jfw_startVM(JavaInfo const *pInfo, std::vector< OUString > const &arOptions, JavaVM **ppVM, JNIEnv **ppEnv)
javaFrameworkError jfw_getEnabled(bool *pbEnabled)
javaFrameworkError jfw_existJRE(const JavaInfo *pInfo, bool *exist)
#define JFW_REQUIRE_NEEDRESTART
Sequence< PropertyValue > aArguments
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * stoc_JavaVM_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
#define SAL_INFO(area, stream)
std::unique_ptr< sal_Int32[]> pData
bool IsContextFlagActive(const OUString &sName)
css::uno::Sequence< css::uno::Any > InitAnyPropertySequence(::std::initializer_list< ::std::pair< OUString, css::uno::Any > > vInit)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
Any SAL_CALL getCaughtException()
JVMACCESS_DLLPUBLIC jobjectArray translateToUrls(css::uno::Reference< css::uno::XComponentContext > const &context, JNIEnv *environment, std::u16string_view classPath)
TransliterationModules tm