< prev index next >

src/java.desktop/macosx/native/libosxui/AquaFileView.m

Print this page
rev 54096 : 8259651: [macOS] Replace JNF_COCOA_ENTER/EXIT macros
rev 54098 : 8260616: Removing remaining JNF dependencies in the java.desktop module
8259729: Missed JNFInstanceOf -> IsInstanceOf conversion


   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 
  27 #include <jni_util.h>
  28 
  29 #import "com_apple_laf_AquaFileView.h"
  30 
  31 #import <sys/param.h> // for MAXPATHLEN
  32 #import <CoreFoundation/CoreFoundation.h>
  33 #import <JavaNativeFoundation/JavaNativeFoundation.h>
  34 
  35 /*
  36  * Class:     com_apple_laf_AquaFileView
  37  * Method:    getNativePathToRunningJDKBundle
  38  * Signature: ()Ljava/lang/String;
  39  */
  40 // TODO: Un-comment this out
  41 /*JNIEXPORT jstring JNICALL Java_com_apple_laf_AquaFileView_getNativePathToRunningJDKBundle
  42 (JNIEnv *env, jclass clazz)
  43 {
  44     jstring returnValue = NULL;
  45 JNF_COCOA_ENTER(env);
  46 
  47     returnValue = JNFNSToJavaString(env, getRunningJavaBundle());
  48 
  49 JNF_COCOA_EXIT(env);
  50     return returnValue;
  51 }*/
  52 
  53 /*
  54  * Class:     com_apple_laf_AquaFileView
  55  * Method:    getNativePathToSharedJDKBundle
  56  * Signature: ()Ljava/lang/String;
  57  */
  58 JNIEXPORT jstring JNICALL Java_com_apple_laf_AquaFileView_getNativePathToSharedJDKBundle
  59 (JNIEnv *env, jclass clazz)
  60 {
  61     jstring returnValue = NULL;
  62 JNF_COCOA_ENTER(env);
  63 
  64     returnValue = JNFNSToJavaString(env, [[NSBundle bundleWithIdentifier:@"com.apple.JavaVM"] bundlePath]);
  65 
  66 JNF_COCOA_EXIT(env);
  67     return returnValue;
  68 }
  69 
  70 /*
  71  * Class:     com_apple_laf_AquaFileView
  72  * Method:    getNativeMachineName
  73  * Signature: ()Ljava/lang/String;
  74  */
  75 JNIEXPORT jstring JNICALL Java_com_apple_laf_AquaFileView_getNativeMachineName
  76 (JNIEnv *env, jclass clazz)
  77 {
  78     jstring returnValue = NULL;
  79 JNF_COCOA_ENTER(env);
  80 
  81     CFStringRef machineName = CSCopyMachineName();
  82     returnValue = JNFNSToJavaString(env, (NSString*)machineName);
  83 
  84     if (machineName != NULL) {
  85         CFRelease(machineName);
  86     }
  87 
  88 JNF_COCOA_EXIT(env);
  89     return returnValue;
  90 }
  91 
  92 /*
  93  * Class:     com_apple_laf_AquaFileView
  94  * Method:    getNativeLSInfo
  95  * Signature: ([BZ)I
  96  */
  97 JNIEXPORT jint JNICALL Java_com_apple_laf_AquaFileView_getNativeLSInfo
  98 (JNIEnv *env, jclass clazz, jbyteArray absolutePath, jboolean isDir)
  99 {
 100     jint returnValue = com_apple_laf_AquaFileView_UNINITALIZED_LS_INFO;
 101 JNF_COCOA_ENTER(env);
 102 
 103     jbyte *byteArray = (*env)->GetByteArrayElements(env, absolutePath, NULL);
 104     CHECK_NULL_RETURN(byteArray, returnValue);
 105     jsize length = (*env)->GetArrayLength(env, absolutePath);
 106 
 107     // Can't assume that byteArray is NULL terminated and FSPathMakeRef doesn't
 108     // let us specify a length.
 109     UInt8 arrayCopy[length + 1];
 110     jsize i;
 111     for (i = 0; i < length; i++) {
 112         arrayCopy[i] = (UInt8)byteArray[i];
 113     }
 114     arrayCopy[length] = '\0';
 115     (*env)->ReleaseByteArrayElements(env, absolutePath, byteArray, JNI_ABORT);
 116 
 117     Boolean isDirectory = (isDir == JNI_TRUE ? true : false);
 118     FSRef ref;
 119     OSErr err = FSPathMakeRef((const UInt8 *)&arrayCopy, &ref, &isDirectory);
 120     if (err == noErr) {
 121         LSItemInfoRecord itemInfo;
 122         err = LSCopyItemInfoForRef(&ref, kLSRequestBasicFlagsOnly, &itemInfo);
 123 
 124         if (err == noErr) {
 125             returnValue = itemInfo.flags;
 126         }
 127     }
 128 
 129 JNF_COCOA_EXIT(env);
 130     return returnValue;
 131 }
 132 
 133 /*
 134  * Class:     com_apple_laf_AquaFileView
 135  * Method:    getNativeDisplayName
 136  * Signature: ([BZ)Ljava/lang/String;
 137  */
 138 JNIEXPORT jstring JNICALL Java_com_apple_laf_AquaFileView_getNativeDisplayName
 139 (JNIEnv *env, jclass clazz, jbyteArray absolutePath, jboolean isDir)
 140 {
 141     jstring returnValue = NULL;
 142 JNF_COCOA_ENTER(env);
 143 
 144     jbyte *byteArray = (*env)->GetByteArrayElements(env, absolutePath, NULL);
 145     CHECK_NULL_RETURN(byteArray, returnValue);
 146     jsize length = (*env)->GetArrayLength(env, absolutePath);
 147 
 148     // Can't assume that byteArray is NULL terminated and FSPathMakeRef doesn't
 149     // let us specify a length.
 150     UInt8 arrayCopy[length + 1];
 151     jsize i;
 152     for (i = 0; i < length; i++) {
 153         arrayCopy[i] = (UInt8)byteArray[i];
 154     }
 155     arrayCopy[length] = '\0';
 156     (*env)->ReleaseByteArrayElements(env, absolutePath, byteArray, JNI_ABORT);
 157 
 158     Boolean isDirectory = (isDir == JNI_TRUE ? true : false);
 159     FSRef ref;
 160 
 161     OSErr theErr = FSPathMakeRefWithOptions((const UInt8 *)&arrayCopy,
 162                                             kFSPathMakeRefDoNotFollowLeafSymlink,
 163                                             &ref, &isDirectory);
 164     if (theErr == noErr) {
 165         CFStringRef displayName = NULL;
 166 
 167         theErr = LSCopyDisplayNameForRef(&ref, &displayName);
 168 
 169         if (theErr == noErr) {
 170             CFMutableStringRef mutableDisplayName = CFStringCreateMutableCopy(NULL, 0, displayName);
 171             CFStringNormalize(mutableDisplayName, kCFStringNormalizationFormC);
 172             returnValue = JNFNSToJavaString(env, (NSString *)mutableDisplayName);
 173             CFRelease(mutableDisplayName);
 174         }
 175 
 176         if (displayName != NULL) {
 177             CFRelease(displayName);
 178         }
 179     }
 180 
 181 JNF_COCOA_EXIT(env);
 182     return returnValue;
 183 }
 184 
 185 /*
 186  * Class:     com_apple_laf_AquaFileView
 187  * Method:    getNativePathForResolvedAlias
 188  * Signature: ([BZ)Ljava/lang/String;
 189  */
 190 JNIEXPORT jstring JNICALL Java_com_apple_laf_AquaFileView_getNativePathForResolvedAlias
 191 (JNIEnv *env, jclass clazz, jbyteArray pathToAlias, jboolean isDir)
 192 {
 193     jstring returnValue = NULL;
 194 JNF_COCOA_ENTER(env);
 195 
 196     UInt8 pathCString[MAXPATHLEN + 1];
 197     size_t maxPathLen = sizeof(pathCString) - 1;
 198 
 199     jbyte *byteArray = (*env)->GetByteArrayElements(env, pathToAlias, NULL);
 200     CHECK_NULL_RETURN(byteArray, returnValue);
 201     jsize length = (*env)->GetArrayLength(env, pathToAlias);
 202 
 203     if (length > maxPathLen) {
 204         length = maxPathLen;
 205     }
 206     strncpy((char *)pathCString, (char *)byteArray, length);
 207     // make sure it's null terminated
 208     pathCString[length] = '\0';
 209     (*env)->ReleaseByteArrayElements(env, pathToAlias, byteArray, JNI_ABORT);
 210 
 211     Boolean isDirectory = (isDir == JNI_TRUE ? true : false);
 212     FSRef fileRef;
 213     OSErr theErr = FSPathMakeRef(pathCString, &fileRef, &isDirectory);
 214 
 215     Boolean ignored;
 216     theErr = FSResolveAliasFileWithMountFlags(&fileRef, false, &ignored,
 217                                               &ignored, kResolveAliasFileNoUI);
 218     if (theErr == noErr) {
 219         UInt8 resolvedPath[MAXPATHLEN];
 220         theErr = FSRefMakePath(&fileRef, resolvedPath, MAXPATHLEN);
 221 
 222         if (theErr == noErr) {
 223             returnValue = (*env)->NewStringUTF(env, (char *)resolvedPath);
 224         }
 225     }
 226 
 227 JNF_COCOA_EXIT(env);
 228     return returnValue;
 229 }


   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 
  27 #include <JNIUtilities.h>
  28 
  29 #import "com_apple_laf_AquaFileView.h"
  30 
  31 #import <sys/param.h> // for MAXPATHLEN
  32 #import <CoreFoundation/CoreFoundation.h>

  33 
  34 /*
  35  * Class:     com_apple_laf_AquaFileView
  36  * Method:    getNativePathToRunningJDKBundle
  37  * Signature: ()Ljava/lang/String;
  38  */
  39 // TODO: Un-comment this out
  40 /*JNIEXPORT jstring JNICALL Java_com_apple_laf_AquaFileView_getNativePathToRunningJDKBundle
  41 (JNIEnv *env, jclass clazz)
  42 {
  43     jstring returnValue = NULL;
  44 JNI_COCOA_ENTER(env);
  45 
  46     returnValue = NSStringToJavaString(env, getRunningJavaBundle());
  47 
  48 JNI_COCOA_EXIT(env);
  49     return returnValue;
  50 }*/
  51 
  52 /*
  53  * Class:     com_apple_laf_AquaFileView
  54  * Method:    getNativePathToSharedJDKBundle
  55  * Signature: ()Ljava/lang/String;
  56  */
  57 JNIEXPORT jstring JNICALL Java_com_apple_laf_AquaFileView_getNativePathToSharedJDKBundle
  58 (JNIEnv *env, jclass clazz)
  59 {
  60     jstring returnValue = NULL;
  61 JNI_COCOA_ENTER(env);
  62 
  63     returnValue = NSStringToJavaString(env, [[NSBundle bundleWithIdentifier:@"com.apple.JavaVM"] bundlePath]);
  64 
  65 JNI_COCOA_EXIT(env);
  66     return returnValue;
  67 }
  68 
  69 /*
  70  * Class:     com_apple_laf_AquaFileView
  71  * Method:    getNativeMachineName
  72  * Signature: ()Ljava/lang/String;
  73  */
  74 JNIEXPORT jstring JNICALL Java_com_apple_laf_AquaFileView_getNativeMachineName
  75 (JNIEnv *env, jclass clazz)
  76 {
  77     jstring returnValue = NULL;
  78 JNI_COCOA_ENTER(env);
  79 
  80     CFStringRef machineName = CSCopyMachineName();
  81     returnValue = NSStringToJavaString(env, (NSString*)machineName);
  82 
  83     if (machineName != NULL) {
  84         CFRelease(machineName);
  85     }
  86 
  87 JNI_COCOA_EXIT(env);
  88     return returnValue;
  89 }
  90 
  91 /*
  92  * Class:     com_apple_laf_AquaFileView
  93  * Method:    getNativeLSInfo
  94  * Signature: ([BZ)I
  95  */
  96 JNIEXPORT jint JNICALL Java_com_apple_laf_AquaFileView_getNativeLSInfo
  97 (JNIEnv *env, jclass clazz, jbyteArray absolutePath, jboolean isDir)
  98 {
  99     jint returnValue = com_apple_laf_AquaFileView_UNINITALIZED_LS_INFO;
 100 JNI_COCOA_ENTER(env);
 101 
 102     jbyte *byteArray = (*env)->GetByteArrayElements(env, absolutePath, NULL);
 103     CHECK_NULL_RETURN(byteArray, returnValue);
 104     jsize length = (*env)->GetArrayLength(env, absolutePath);
 105 
 106     // Can't assume that byteArray is NULL terminated and FSPathMakeRef doesn't
 107     // let us specify a length.
 108     UInt8 arrayCopy[length + 1];
 109     jsize i;
 110     for (i = 0; i < length; i++) {
 111         arrayCopy[i] = (UInt8)byteArray[i];
 112     }
 113     arrayCopy[length] = '\0';
 114     (*env)->ReleaseByteArrayElements(env, absolutePath, byteArray, JNI_ABORT);
 115 
 116     Boolean isDirectory = (isDir == JNI_TRUE ? true : false);
 117     FSRef ref;
 118     OSErr err = FSPathMakeRef((const UInt8 *)&arrayCopy, &ref, &isDirectory);
 119     if (err == noErr) {
 120         LSItemInfoRecord itemInfo;
 121         err = LSCopyItemInfoForRef(&ref, kLSRequestBasicFlagsOnly, &itemInfo);
 122 
 123         if (err == noErr) {
 124             returnValue = itemInfo.flags;
 125         }
 126     }
 127 
 128 JNI_COCOA_EXIT(env);
 129     return returnValue;
 130 }
 131 
 132 /*
 133  * Class:     com_apple_laf_AquaFileView
 134  * Method:    getNativeDisplayName
 135  * Signature: ([BZ)Ljava/lang/String;
 136  */
 137 JNIEXPORT jstring JNICALL Java_com_apple_laf_AquaFileView_getNativeDisplayName
 138 (JNIEnv *env, jclass clazz, jbyteArray absolutePath, jboolean isDir)
 139 {
 140     jstring returnValue = NULL;
 141 JNI_COCOA_ENTER(env);
 142 
 143     jbyte *byteArray = (*env)->GetByteArrayElements(env, absolutePath, NULL);
 144     CHECK_NULL_RETURN(byteArray, returnValue);
 145     jsize length = (*env)->GetArrayLength(env, absolutePath);
 146 
 147     // Can't assume that byteArray is NULL terminated and FSPathMakeRef doesn't
 148     // let us specify a length.
 149     UInt8 arrayCopy[length + 1];
 150     jsize i;
 151     for (i = 0; i < length; i++) {
 152         arrayCopy[i] = (UInt8)byteArray[i];
 153     }
 154     arrayCopy[length] = '\0';
 155     (*env)->ReleaseByteArrayElements(env, absolutePath, byteArray, JNI_ABORT);
 156 
 157     Boolean isDirectory = (isDir == JNI_TRUE ? true : false);
 158     FSRef ref;
 159 
 160     OSErr theErr = FSPathMakeRefWithOptions((const UInt8 *)&arrayCopy,
 161                                             kFSPathMakeRefDoNotFollowLeafSymlink,
 162                                             &ref, &isDirectory);
 163     if (theErr == noErr) {
 164         CFStringRef displayName = NULL;
 165 
 166         theErr = LSCopyDisplayNameForRef(&ref, &displayName);
 167 
 168         if (theErr == noErr) {
 169             CFMutableStringRef mutableDisplayName = CFStringCreateMutableCopy(NULL, 0, displayName);
 170             CFStringNormalize(mutableDisplayName, kCFStringNormalizationFormC);
 171             returnValue = NSStringToJavaString(env, (NSString *)mutableDisplayName);
 172             CFRelease(mutableDisplayName);
 173         }
 174 
 175         if (displayName != NULL) {
 176             CFRelease(displayName);
 177         }
 178     }
 179 
 180 JNI_COCOA_EXIT(env);
 181     return returnValue;
 182 }
 183 
 184 /*
 185  * Class:     com_apple_laf_AquaFileView
 186  * Method:    getNativePathForResolvedAlias
 187  * Signature: ([BZ)Ljava/lang/String;
 188  */
 189 JNIEXPORT jstring JNICALL Java_com_apple_laf_AquaFileView_getNativePathForResolvedAlias
 190 (JNIEnv *env, jclass clazz, jbyteArray pathToAlias, jboolean isDir)
 191 {
 192     jstring returnValue = NULL;
 193 JNI_COCOA_ENTER(env);
 194 
 195     UInt8 pathCString[MAXPATHLEN + 1];
 196     size_t maxPathLen = sizeof(pathCString) - 1;
 197 
 198     jbyte *byteArray = (*env)->GetByteArrayElements(env, pathToAlias, NULL);
 199     CHECK_NULL_RETURN(byteArray, returnValue);
 200     jsize length = (*env)->GetArrayLength(env, pathToAlias);
 201 
 202     if (length > maxPathLen) {
 203         length = maxPathLen;
 204     }
 205     strncpy((char *)pathCString, (char *)byteArray, length);
 206     // make sure it's null terminated
 207     pathCString[length] = '\0';
 208     (*env)->ReleaseByteArrayElements(env, pathToAlias, byteArray, JNI_ABORT);
 209 
 210     Boolean isDirectory = (isDir == JNI_TRUE ? true : false);
 211     FSRef fileRef;
 212     OSErr theErr = FSPathMakeRef(pathCString, &fileRef, &isDirectory);
 213 
 214     Boolean ignored;
 215     theErr = FSResolveAliasFileWithMountFlags(&fileRef, false, &ignored,
 216                                               &ignored, kResolveAliasFileNoUI);
 217     if (theErr == noErr) {
 218         UInt8 resolvedPath[MAXPATHLEN];
 219         theErr = FSRefMakePath(&fileRef, resolvedPath, MAXPATHLEN);
 220 
 221         if (theErr == noErr) {
 222             returnValue = (*env)->NewStringUTF(env, (char *)resolvedPath);
 223         }
 224     }
 225 
 226 JNI_COCOA_EXIT(env);
 227     return returnValue;
 228 }
< prev index next >