cool#10610 Ensure the parent-child relations of comments.
[LibreOffice.git] / jvmfwk / plugins / sunmajor / pluginlib / util_cocoa.mm
blob8c745f8d98dbe135b97d0988c2f48083f4a26912
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 #include <rtl/ustring.hxx>
5 #include <premac.h>
6 #import <Foundation/Foundation.h>
7 #include <postmac.h>
9 #import "util_cocoa.hxx"
11 using namespace rtl;
13 bool JvmfwkUtil_isLoadableJVM( OUString const & aURL )
15     bool bRet = false;
17     if ( aURL.getLength() )
18     {
19         NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init];
21         NSString *pString = [NSString stringWithCharacters:reinterpret_cast<unichar const *>(aURL.getStr()) length:aURL.getLength()];
22         if ( pString )
23         {
24             // Ignore all but Oracle's JDK as loading Apple's Java and Oracle's
25             // JRE will cause macOS's JavaVM framework to display a dialog and
26             // invoke exit() when loaded via JNI on macOS 10.10
27             NSURL *pURL = [NSURL URLWithString:pString];
28             if ( pURL )
29                 pURL = [pURL filePathURL];
30             if ( pURL )
31                 pURL = [pURL URLByStandardizingPath];
32             if ( pURL )
33                 pURL = [pURL URLByResolvingSymlinksInPath];
35             while ( pURL )
36             {
37                 // Check if this is a valid bundle
38                 NSNumber *pDir = nil;
39                 NSURL *pContentsURL = [pURL URLByAppendingPathComponent:@"Contents"];
40                 if ( pContentsURL && [pContentsURL getResourceValue:&pDir forKey:NSURLIsDirectoryKey error:nil] && pDir && [pDir boolValue] )
41                 {
42                     NSBundle *pBundle = [NSBundle bundleWithURL:pURL];
43                     if ( pBundle )
44                     {
45                         // Make sure that this bundle's Info.plist has the
46                         // proper JVM keys to supports loading via JNI. If
47                         // this bundle is a valid JVM and these keys
48                         // are missing, loading the JVM will cause macOS's
49                         // JavaVM framework to display a dialog and invoke
50                         // exit() when loaded via JNI on macOS 10.10.
51                         NSDictionary *pInfo = [pBundle infoDictionary];
52                         if ( pInfo )
53                         {
54                             NSDictionary *pJavaVM = [pInfo objectForKey:@"JavaVM"];
55                             if ( pJavaVM && [pJavaVM isKindOfClass:[NSDictionary class]] )
56                             {
57                                 NSArray *pJVMCapabilities = [pJavaVM objectForKey:@"JVMCapabilities"];
58                                 if ( pJVMCapabilities )
59                                 {
60                                     if ( [pJVMCapabilities indexOfObjectIdenticalTo:@"JNI"] == NSNotFound )
61                                     {
62                                         if ( [pJVMCapabilities isKindOfClass:[NSMutableArray class]] )
63                                         {
64                                             [static_cast<NSMutableArray *>(pJVMCapabilities) addObject:@"JNI"];
65                                             bRet = true;
66                                         }
67                                         else if ( [pJavaVM isKindOfClass:[NSMutableDictionary class]] )
68                                         {
69                                             NSMutableArray *pNewJVMCapabilities = [NSMutableArray arrayWithCapacity:[pJVMCapabilities count] + 1];
70                                             if ( pNewJVMCapabilities )
71                                             {
72                                                 [pNewJVMCapabilities addObject:@"JNI"];
73                                                 [static_cast<NSMutableDictionary *>(pJavaVM) setObject:pNewJVMCapabilities forKey:@"JVMCapabilities"];
74                                                 bRet = true;
75                                             }
76                                         }
77                                     }
78                                     else
79                                     {
80                                         bRet = true;
81                                     }
82                                 }
83                             }
84                         }
85                     }
86                 }
88                 NSURL *pOldURL = pURL;
89                 pURL = [pURL URLByDeletingLastPathComponent];
90                 if ( pURL )
91                 {
92                     pURL = [pURL URLByStandardizingPath];
93                     if ( pURL )
94                     {
95                         pURL = [pURL URLByResolvingSymlinksInPath];
96                         if ( pURL && [pURL isEqual:pOldURL] )
97                             pURL = nil;
98                     }
99                 }
100             }
101         }
103         [pPool release];
104     }
106     return bRet;
109 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */