1 19 20 package org.netbeans.modules.openfile; 21 22 import java.io.File ; 23 24 import org.openide.DialogDisplayer; 25 import org.openide.NotifyDescriptor; 26 import org.openide.filesystems.FileObject; 27 import org.openide.filesystems.FileUtil; 28 import org.openide.util.Lookup; 29 import org.openide.util.NbBundle; 30 31 36 public final class OpenFile { 37 38 39 private OpenFile() {} 40 41 46 public static boolean open(FileObject fileObject, int line) { 47 for (OpenFileImpl impl : Lookup.getDefault().lookupAll(OpenFileImpl.class)) { 48 if (impl.open(fileObject, line)) { 49 return true; 50 } 51 } 52 return false; 53 } 54 55 64 static boolean openFile(File file, int line) { 65 if (!checkFileExists(file)) { 66 return false; 67 } 68 69 FileObject fileObject; 70 fileObject = FileUtil.toFileObject(FileUtil.normalizeFile(file)); 71 if (fileObject != null) { 72 return open(fileObject, line); 73 } 74 return false; 75 } 76 77 88 private static boolean checkFileExists(File file) { 89 final String errMsgKey; 90 if (!file.exists()) { 91 errMsgKey = "MSG_fileNotFound"; } else if (isSpecifiedByUNCPath(file)) { 93 errMsgKey = "MSG_UncNotSupported"; } else if (!file.isFile() && !file.isDirectory()) { 95 errMsgKey = "MSG_fileNotFound"; } else { 97 return true; 98 } 99 100 final String fileName = file.toString(); 101 final String msg = NbBundle.getMessage(OpenFile.class, 102 errMsgKey, 103 fileName); 104 DialogDisplayer.getDefault().notifyLater(new NotifyDescriptor.Message(msg)); 105 return false; 106 } 107 108 115 static boolean isSpecifiedByUNCPath(File file) { 116 assert file != null && file.exists(); 117 118 file = FileUtil.normalizeFile(file); 119 return file.getPath().startsWith("\\\\"); } 121 122 } 123 | Popular Tags |