use of ch.cyberduck.binding.foundation.NSBundle in project cyberduck by iterate-ch.
the class BundleApplicationResourcesFinder method bundle.
public NSBundle bundle() {
if (cached != null) {
return cached;
}
if (log.isInfoEnabled()) {
log.info("Loading application bundle resources");
}
final NSBundle main = NSBundle.mainBundle();
if (null == main) {
cached = null;
} else {
final Local executable = new FinderLocal(main.executablePath());
cached = this.bundle(main, executable);
}
return cached;
}
use of ch.cyberduck.binding.foundation.NSBundle in project cyberduck by iterate-ch.
the class BundleApplicationResourcesFinder method bundle.
protected NSBundle bundle(final NSBundle main, Local executable) {
if (!executable.isSymbolicLink()) {
return main;
}
while (executable.isSymbolicLink()) {
try {
executable = executable.getSymlinkTarget();
} catch (NotfoundException e) {
return main;
}
}
Local folder = executable.getParent();
NSBundle b;
do {
b = NSBundle.bundleWithPath(folder.getAbsolute());
if (null == b) {
log.error(String.format("Loading bundle %s failed", folder));
break;
}
if (StringUtils.equals(String.valueOf(Path.DELIMITER), b.bundlePath())) {
break;
}
folder = folder.getParent();
} while (b.executablePath() == null);
return b;
}
use of ch.cyberduck.binding.foundation.NSBundle in project cyberduck by iterate-ch.
the class LaunchServicesSchemeHandler method getAllHandlers.
@Override
public List<Application> getAllHandlers(final String scheme) {
final List<Application> handlers = new ArrayList<Application>();
final NSArray applications = LaunchServicesLibrary.library.LSCopyApplicationURLsForURL(NSURL.URLWithString(String.format("%s:/", scheme)), LaunchServicesLibrary.kLSRolesAll);
NSEnumerator ordered = applications.objectEnumerator();
NSObject next;
while (((next = ordered.nextObject()) != null)) {
final NSURL url = Rococoa.cast(next, NSURL.class);
final NSBundle bundle = NSBundle.bundleWithPath(url.path());
if (null == bundle) {
log.warn(String.format("Failure loading bundle for path %s", url.path()));
continue;
}
final Application application = applicationFinder.getDescription(bundle.bundleIdentifier());
if (applicationFinder.isInstalled(application)) {
handlers.add(application);
}
}
return handlers;
}
use of ch.cyberduck.binding.foundation.NSBundle in project cyberduck by iterate-ch.
the class LaunchServicesSchemeHandler method getDefaultHandler.
/**
* See ApplicationServices/ApplicationServices.h#LSCopyDefaultHandlerForURLScheme
*
* @param scheme The protocol identifier
* @return The bundle identifier for the application registered as the default handler for this scheme
*/
@Override
public Application getDefaultHandler(final String scheme) {
final ObjCObjectByReference error = new ObjCObjectByReference();
final NSURL url = LaunchServicesLibrary.library.LSCopyDefaultApplicationURLForURL(NSURL.URLWithString(String.format("%s:/", scheme)), LaunchServicesLibrary.kLSRolesAll, error);
if (url != null) {
final NSBundle bundle = NSBundle.bundleWithPath(url.path());
if (null == bundle) {
log.warn(String.format("Failure loading bundle for path %s", url.path()));
return Application.notfound;
}
final Application application = applicationFinder.getDescription(bundle.bundleIdentifier());
if (applicationFinder.isInstalled(application)) {
return application;
}
}
return Application.notfound;
}
use of ch.cyberduck.binding.foundation.NSBundle in project cyberduck by iterate-ch.
the class LaunchServicesApplicationFinder method find.
/**
* The default application for this file as set by the launch services
*
* @param filename Filename
* @return The bundle identifier of the default application to open the
* file of this type or null if unknown
*/
@Override
public Application find(final String filename) {
final String extension = Path.getExtension(filename);
if (!defaultApplicationCache.contains(extension)) {
if (StringUtils.isEmpty(extension)) {
return Application.notfound;
}
final String path = this.findForType(extension);
if (StringUtils.isEmpty(path)) {
defaultApplicationCache.put(extension, Application.notfound);
} else {
final NSBundle bundle = NSBundle.bundleWithPath(path);
if (null == bundle) {
log.error(String.format("Loading bundle %s failed", path));
defaultApplicationCache.put(extension, Application.notfound);
} else {
defaultApplicationCache.put(extension, this.getDescription(bundle.bundleIdentifier()));
}
}
}
return defaultApplicationCache.get(extension);
}
Aggregations