Search in sources :

Example 1 with NSBundle

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;
}
Also used : NSBundle(ch.cyberduck.binding.foundation.NSBundle) FinderLocal(ch.cyberduck.core.local.FinderLocal) FinderLocal(ch.cyberduck.core.local.FinderLocal) Local(ch.cyberduck.core.Local)

Example 2 with NSBundle

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;
}
Also used : NotfoundException(ch.cyberduck.core.exception.NotfoundException) NSBundle(ch.cyberduck.binding.foundation.NSBundle) FinderLocal(ch.cyberduck.core.local.FinderLocal) Local(ch.cyberduck.core.Local)

Example 3 with NSBundle

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;
}
Also used : NSEnumerator(ch.cyberduck.binding.foundation.NSEnumerator) NSObject(ch.cyberduck.binding.foundation.NSObject) NSBundle(ch.cyberduck.binding.foundation.NSBundle) NSArray(ch.cyberduck.binding.foundation.NSArray) ArrayList(java.util.ArrayList) NSURL(ch.cyberduck.binding.foundation.NSURL) Application(ch.cyberduck.core.local.Application)

Example 4 with NSBundle

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;
}
Also used : NSBundle(ch.cyberduck.binding.foundation.NSBundle) NSURL(ch.cyberduck.binding.foundation.NSURL) ObjCObjectByReference(org.rococoa.ObjCObjectByReference) Application(ch.cyberduck.core.local.Application)

Example 5 with NSBundle

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);
}
Also used : NSBundle(ch.cyberduck.binding.foundation.NSBundle)

Aggregations

NSBundle (ch.cyberduck.binding.foundation.NSBundle)9 Local (ch.cyberduck.core.Local)5 FinderLocal (ch.cyberduck.core.local.FinderLocal)3 NSObject (ch.cyberduck.binding.foundation.NSObject)2 NSURL (ch.cyberduck.binding.foundation.NSURL)2 NotfoundException (ch.cyberduck.core.exception.NotfoundException)2 Application (ch.cyberduck.core.local.Application)2 Test (org.junit.Test)2 NSWorkspace (ch.cyberduck.binding.application.NSWorkspace)1 NSArray (ch.cyberduck.binding.foundation.NSArray)1 NSDictionary (ch.cyberduck.binding.foundation.NSDictionary)1 NSEnumerator (ch.cyberduck.binding.foundation.NSEnumerator)1 ArrayList (java.util.ArrayList)1 Ignore (org.junit.Ignore)1 ObjCObjectByReference (org.rococoa.ObjCObjectByReference)1