Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFelipe Heidrich2010-01-18 20:56:13 +0000
committerFelipe Heidrich2010-01-18 20:56:13 +0000
commitc75fa2aaa81cd96400f0b4207d26c662b67c5bce (patch)
treef6c950dd930b0771def0a5ae0d9728ec12aae73c /bundles/org.eclipse.swt/Eclipse SWT Program
parentb6666a5139ca22ba429077362792bdaf8b234877 (diff)
downloadeclipse.platform.swt-c75fa2aaa81cd96400f0b4207d26c662b67c5bce.tar.gz
eclipse.platform.swt-c75fa2aaa81cd96400f0b4207d26c662b67c5bce.tar.xz
eclipse.platform.swt-c75fa2aaa81cd96400f0b4207d26c662b67c5bce.zip
Bug 299094 - [Program] org.eclipse.swt.program.Program.launch() will add prefix "file://" before fileName
Diffstat (limited to 'bundles/org.eclipse.swt/Eclipse SWT Program')
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Program/carbon/org/eclipse/swt/program/Program.java98
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT Program/cocoa/org/eclipse/swt/program/Program.java56
2 files changed, 67 insertions, 87 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Program/carbon/org/eclipse/swt/program/Program.java b/bundles/org.eclipse.swt/Eclipse SWT Program/carbon/org/eclipse/swt/program/Program.java
index 413c070b0c..b40c6e4754 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT Program/carbon/org/eclipse/swt/program/Program.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Program/carbon/org/eclipse/swt/program/Program.java
@@ -35,7 +35,6 @@ public final class Program {
static final String PREFIX_HTTP = "http://"; //$NON-NLS-1$
static final String PREFIX_HTTPS = "https://"; //$NON-NLS-1$
- static final String PREFIX_FILE = "file://"; //$NON-NLS-1$
/**
* Prevents uninitialized instances from being created outside the package.
@@ -223,6 +222,37 @@ public static Program [] getPrograms () {
return programs;
}
+static int getURL(String fileName) {
+ char[] chars = new char[fileName.length()];
+ fileName.getChars(0, chars.length, chars, 0);
+ int str = OS.CFStringCreateWithCharacters(0, chars, chars.length);
+ if (str == 0) return 0;
+ int file = str;
+ int fileManager = Cocoa.objc_msgSend(Cocoa.C_NSFileManager, Cocoa.S_defaultManager);
+ if (fileManager != 0 && Cocoa.objc_msgSend(fileManager, Cocoa.S_fileExistsAtPath, str) != 0) {
+ int url = Cocoa.objc_msgSend(Cocoa.C_NSURL, Cocoa.S_fileURLWithPath, str);
+ if (url != 0) {
+ int urlstr = Cocoa.objc_msgSend(url, Cocoa.S_absoluteString);
+ if (urlstr != 0) file = urlstr;
+ }
+ }
+ char[] unescapedChars = new char[] {'%'};
+ String lowercaseName = fileName.toLowerCase ();
+ if (lowercaseName.startsWith (PREFIX_HTTP) || lowercaseName.startsWith (PREFIX_HTTPS)) {
+ unescapedChars = new char[] {'%', '#'};
+ }
+ int unescapedStr = OS.CFStringCreateWithCharacters(0, unescapedChars, unescapedChars.length);
+ int escapedStr = OS.CFURLCreateStringByAddingPercentEscapes(OS.kCFAllocatorDefault, file, unescapedStr, 0, OS.kCFStringEncodingUTF8);
+ int url = 0;
+ if (escapedStr != 0) {
+ url = OS.CFURLCreateWithString(OS.kCFAllocatorDefault, escapedStr, 0);
+ OS.CFRelease(escapedStr);
+ }
+ if (unescapedStr != 0) OS.CFRelease(unescapedStr);
+ OS.CFRelease(str);
+ return url;
+}
+
/**
* Launches the operating system executable associated with the file or
* URL (http:// or https://). If the file is an executable then the
@@ -239,31 +269,10 @@ public static Program [] getPrograms () {
public static boolean launch (String fileName) {
if (fileName == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
int rc = -1;
- char[] unescapedChars = new char[] {'%'};
- String lowercaseName = fileName.toLowerCase ();
- if (lowercaseName.startsWith (PREFIX_HTTP) || lowercaseName.startsWith (PREFIX_HTTPS)) {
- unescapedChars = new char[] {'%', '#'};
- } else {
- if (!lowercaseName.startsWith (PREFIX_FILE)) {
- fileName = PREFIX_FILE + fileName;
- }
- }
- char[] chars = new char[fileName.length()];
- fileName.getChars(0, chars.length, chars, 0);
- int str = OS.CFStringCreateWithCharacters(0, chars, chars.length);
- if (str != 0) {
- int unescapedStr = OS.CFStringCreateWithCharacters(0, unescapedChars, unescapedChars.length);
- int escapedStr = OS.CFURLCreateStringByAddingPercentEscapes(OS.kCFAllocatorDefault, str, unescapedStr, 0, OS.kCFStringEncodingUTF8);
- if (escapedStr != 0) {
- int url = OS.CFURLCreateWithString(OS.kCFAllocatorDefault, escapedStr, 0);
- if (url != 0) {
- rc = OS.LSOpenCFURLRef(url, null);
- OS.CFRelease(url);
- }
- OS.CFRelease(escapedStr);
- }
- if (unescapedStr != 0) OS.CFRelease(unescapedStr);
- OS.CFRelease(str);
+ int url = getURL(fileName);
+ if (url != 0) {
+ rc = OS.LSOpenCFURLRef(url, null);
+ OS.CFRelease(url);
}
return rc == OS.noErr;
}
@@ -295,36 +304,15 @@ public boolean execute (String fileName) {
if (fileName.length() == 0) {
rc = OS.LSOpenApplication(params, null);
} else {
- char[] unescapedChars = new char[] {'%'};
- String lowercaseName = fileName.toLowerCase ();
- if (lowercaseName.startsWith (PREFIX_HTTP) || lowercaseName.startsWith (PREFIX_HTTPS)) {
- unescapedChars = new char[] {'%', '#'};
- } else {
- if (!lowercaseName.startsWith (PREFIX_FILE)) {
- fileName = PREFIX_FILE + fileName;
- }
- }
- char[] chars = new char[fileName.length()];
- fileName.getChars(0, chars.length, chars, 0);
- int str = OS.CFStringCreateWithCharacters(0, chars, chars.length);
- if (str != 0) {
- int unescapedStr = OS.CFStringCreateWithCharacters(0, unescapedChars, unescapedChars.length);
- int escapedStr = OS.CFURLCreateStringByAddingPercentEscapes(OS.kCFAllocatorDefault, str, unescapedStr, 0, OS.kCFStringEncodingUTF8);
- if (escapedStr != 0) {
- int urls = OS.CFArrayCreateMutable(OS.kCFAllocatorDefault, 1, OS.kCFTypeArrayCallBacks ());
- if (urls != 0) {
- int url = OS.CFURLCreateWithString(OS.kCFAllocatorDefault, escapedStr, 0);
- if (url != 0) {
- OS.CFArrayAppendValue(urls, url);
- OS.CFRelease(url);
- rc = OS.LSOpenURLsWithRole(urls, OS.kLSRolesAll, 0, params, null, 0);
- }
- OS.CFRelease(urls);
- }
- OS.CFRelease(escapedStr);
+ int url = getURL(fileName);
+ if (url != 0) {
+ int urls = OS.CFArrayCreateMutable(OS.kCFAllocatorDefault, 1, OS.kCFTypeArrayCallBacks ());
+ if (urls != 0) {
+ OS.CFArrayAppendValue(urls, url);
+ rc = OS.LSOpenURLsWithRole(urls, OS.kLSRolesAll, 0, params, null, 0);
+ OS.CFRelease(urls);
}
- if (unescapedStr != 0) OS.CFRelease(unescapedStr);
- OS.CFRelease(str);
+ OS.CFRelease(url);
}
}
OS.DisposePtr(fsRefPtr);
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Program/cocoa/org/eclipse/swt/program/Program.java b/bundles/org.eclipse.swt/Eclipse SWT Program/cocoa/org/eclipse/swt/program/Program.java
index c0c4eae80f..c96dc58426 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT Program/cocoa/org/eclipse/swt/program/Program.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Program/cocoa/org/eclipse/swt/program/Program.java
@@ -29,7 +29,6 @@ import java.util.Vector;
public final class Program {
String name, fullPath, identifier;
- static final String PREFIX_FILE = "file:"; //$NON-NLS-1$
static final String PREFIX_HTTP = "http://"; //$NON-NLS-1$
static final String PREFIX_HTTPS = "https://"; //$NON-NLS-1$
@@ -201,6 +200,25 @@ public static Program [] getPrograms () {
}
}
+static NSURL getURL (String fileName) {
+ NSString unescapedStr;
+ String lowercaseName = fileName.toLowerCase ();
+ if (lowercaseName.startsWith (PREFIX_HTTP) || lowercaseName.startsWith (PREFIX_HTTPS)) {
+ unescapedStr = NSString.stringWith("%#"); //$NON-NLS-1$
+ } else {
+ unescapedStr = NSString.stringWith("%"); //$NON-NLS-1$
+ }
+ NSString fullPath = NSString.stringWith(fileName);
+ if (NSFileManager.defaultManager().fileExistsAtPath(fullPath)) {
+ fullPath = NSURL.fileURLWithPath(fullPath).absoluteString();
+ }
+ int /*long*/ ptr = OS.CFURLCreateStringByAddingPercentEscapes(0, fullPath.id, unescapedStr.id, 0, OS.kCFStringEncodingUTF8);
+ NSString escapedString = new NSString(ptr);
+ NSURL url = NSURL.URLWithString(escapedString);
+ OS.CFRelease(ptr);
+ return url;
+}
+
/**
* Launches the operating system executable associated with the file or
* URL (http:// or https://). If the file is an executable then the
@@ -218,22 +236,9 @@ public static boolean launch (String fileName) {
if (fileName == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
NSAutoreleasePool pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
try {
- NSString unescapedStr = NSString.stringWith("%"); //$NON-NLS-1$
- String lowercaseName = fileName.toLowerCase ();
- if (lowercaseName.startsWith (PREFIX_HTTP) || lowercaseName.startsWith (PREFIX_HTTPS)) {
- unescapedStr = NSString.stringWith("%#"); //$NON-NLS-1$
- } else {
- if (!lowercaseName.startsWith (PREFIX_FILE)) {
- fileName = PREFIX_FILE + fileName;
- }
- }
- NSString fullPath = NSString.stringWith(fileName);
- int /*long*/ ptr = OS.CFURLCreateStringByAddingPercentEscapes(0, fullPath.id, unescapedStr.id, 0, OS.kCFStringEncodingUTF8);
- NSString escapedString = new NSString(ptr);
+ NSURL url = getURL(fileName);
NSWorkspace workspace = NSWorkspace.sharedWorkspace();
- boolean result = workspace.openURL(NSURL.URLWithString(escapedString));
- OS.CFRelease(ptr);
- return result;
+ return workspace.openURL(url);
} finally {
pool.release();
}
@@ -257,22 +262,9 @@ public boolean execute (String fileName) {
NSAutoreleasePool pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
try {
NSWorkspace workspace = NSWorkspace.sharedWorkspace();
- String lowercaseName = fileName.toLowerCase ();
- if (lowercaseName.startsWith (PREFIX_HTTP) || lowercaseName.startsWith (PREFIX_HTTPS)) {
- NSString fullPath = NSString.stringWith(fileName);
- NSString unescapedStr = NSString.stringWith("%#"); //$NON-NLS-1$
- int /*long*/ ptr = OS.CFURLCreateStringByAddingPercentEscapes(0, fullPath.id, unescapedStr.id, 0, OS.kCFStringEncodingUTF8);
- NSString escapedString = new NSString(ptr);
- NSArray urls = NSArray.arrayWithObject(NSURL.URLWithString(escapedString));
- OS.CFRelease(ptr);
- return workspace.openURLs(urls, NSString.stringWith(identifier), 0, null, 0);
- } else {
- if (fileName.startsWith (PREFIX_FILE)) {
- fileName = fileName.substring (PREFIX_FILE.length ());
- }
- NSString fullPath = NSString.stringWith (fileName);
- return workspace.openFile (fullPath, NSString.stringWith (name));
- }
+ NSURL url = getURL(fileName);
+ NSArray urls = NSArray.arrayWithObject(url);
+ return workspace.openURLs(urls, NSString.stringWith(identifier), 0, null, 0);
} finally {
pool.release();
}

Back to the top