Search in sources :

Example 1 with NSArray

use of ch.cyberduck.binding.foundation.NSArray in project cyberduck by iterate-ch.

the class PlistDeserializer method listForKey.

@Override
@SuppressWarnings("unchecked")
public <T> List<T> listForKey(final String key) {
    final NSObject value = dict.objectForKey(key);
    if (null == value) {
        return null;
    }
    if (value.isKindOfClass(NSArray.CLASS)) {
        final NSArray array = Rococoa.cast(value, NSArray.class);
        final NSEnumerator enumerator = array.objectEnumerator();
        NSObject next;
        final List<T> list = new ArrayList<T>();
        while ((next = enumerator.nextObject()) != null) {
            if (next.isKindOfClass(NSDictionary.CLASS)) {
                list.add((T) Rococoa.cast(next, NSDictionary.class));
            }
            if (next.isKindOfClass(NSString.CLASS)) {
                list.add((T) Rococoa.cast(next, NSString.class).toString());
            }
        }
        return list;
    }
    log.warn(String.format("Unexpected value type for serialized key %s", key));
    return null;
}
Also used : NSEnumerator(ch.cyberduck.binding.foundation.NSEnumerator) NSObject(ch.cyberduck.binding.foundation.NSObject) NSArray(ch.cyberduck.binding.foundation.NSArray) ArrayList(java.util.ArrayList) NSString(ch.cyberduck.binding.foundation.NSString)

Example 2 with NSArray

use of ch.cyberduck.binding.foundation.NSArray in project cyberduck by iterate-ch.

the class ApplicationSupportDirectoryFinder method find.

@Override
public Local find() {
    final NSArray directories = FoundationKitFunctions.library.NSSearchPathForDirectoriesInDomains(FoundationKitFunctions.NSSearchPathDirectory.NSApplicationSupportDirectory, FoundationKitFunctions.NSSearchPathDomainMask.NSUserDomainMask, true);
    final String application = preferences.getProperty("application.name");
    if (directories.count().intValue() == 0) {
        log.error("Failed searching for application support directory");
        return new FinderLocal("~/Library/Application Support", application);
    } else {
        final String directory = directories.objectAtIndex(new NSUInteger(0)).toString();
        if (log.isInfoEnabled()) {
            log.info(String.format("Found application support directory in %s", directory));
        }
        final Local folder = new FinderLocal(directory, application);
        if (log.isDebugEnabled()) {
            log.debug(String.format("Use folder %s for application support directory", folder));
        }
        return folder;
    }
}
Also used : FinderLocal(ch.cyberduck.core.local.FinderLocal) NSArray(ch.cyberduck.binding.foundation.NSArray) FinderLocal(ch.cyberduck.core.local.FinderLocal) Local(ch.cyberduck.core.Local) NSUInteger(org.rococoa.cocoa.foundation.NSUInteger)

Example 3 with NSArray

use of ch.cyberduck.binding.foundation.NSArray in project cyberduck by iterate-ch.

the class LibraryLogDirectoryFinder method find.

@Override
public Local find() {
    final NSArray directories = FoundationKitFunctions.library.NSSearchPathForDirectoriesInDomains(FoundationKitFunctions.NSSearchPathDirectory.NSLibraryDirectory, FoundationKitFunctions.NSSearchPathDomainMask.NSUserDomainMask, true);
    final String application = preferences.getProperty("application.name");
    if (directories.count().intValue() == 0) {
        log.error("Failed searching for library directory");
        return new FinderLocal("~/Library/Logs", application);
    } else {
        final String directory = directories.objectAtIndex(new NSUInteger(0)).toString();
        if (log.isInfoEnabled()) {
            log.info(String.format("Found library directory in %s", directory));
        }
        final Local folder = new FinderLocal(new FinderLocal(directory, "Logs"), application);
        if (log.isDebugEnabled()) {
            log.debug(String.format("Use folder %s for log directory", folder));
        }
        return folder;
    }
}
Also used : FinderLocal(ch.cyberduck.core.local.FinderLocal) NSArray(ch.cyberduck.binding.foundation.NSArray) FinderLocal(ch.cyberduck.core.local.FinderLocal) Local(ch.cyberduck.core.Local) NSUInteger(org.rococoa.cocoa.foundation.NSUInteger)

Example 4 with NSArray

use of ch.cyberduck.binding.foundation.NSArray 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 5 with NSArray

use of ch.cyberduck.binding.foundation.NSArray in project cyberduck by iterate-ch.

the class MainController method serviceUploadFileUrl_.

/**
 * NSService implementation
 */
@Action
public void serviceUploadFileUrl_(final NSPasteboard pboard, final String userData) {
    if (log.isDebugEnabled()) {
        log.debug(String.format("serviceUploadFileUrl_: with user data %s", userData));
    }
    if (pboard.availableTypeFromArray(NSArray.arrayWithObject(NSPasteboard.FilenamesPboardType)) != null) {
        NSObject o = pboard.propertyListForType(NSPasteboard.FilenamesPboardType);
        if (o != null) {
            if (o.isKindOfClass(NSArray.CLASS)) {
                final NSArray elements = Rococoa.cast(o, NSArray.class);
                List<Local> files = new ArrayList<Local>();
                for (int i = 0; i < elements.count().intValue(); i++) {
                    files.add(LocalFactory.get(elements.objectAtIndex(new NSUInteger(i)).toString()));
                }
                this.upload(files);
            }
        }
    }
}
Also used : NSObject(ch.cyberduck.binding.foundation.NSObject) NSArray(ch.cyberduck.binding.foundation.NSArray) ArrayList(java.util.ArrayList) NSUInteger(org.rococoa.cocoa.foundation.NSUInteger) AbstractBackgroundAction(ch.cyberduck.core.threading.AbstractBackgroundAction) Action(ch.cyberduck.binding.Action)

Aggregations

NSArray (ch.cyberduck.binding.foundation.NSArray)18 NSObject (ch.cyberduck.binding.foundation.NSObject)15 NSUInteger (org.rococoa.cocoa.foundation.NSUInteger)9 NSEnumerator (ch.cyberduck.binding.foundation.NSEnumerator)8 ArrayList (java.util.ArrayList)8 NSPoint (org.rococoa.cocoa.foundation.NSPoint)5 Local (ch.cyberduck.core.Local)4 TransferItem (ch.cyberduck.core.transfer.TransferItem)4 UploadTransfer (ch.cyberduck.core.transfer.UploadTransfer)4 Action (ch.cyberduck.binding.Action)3 NSString (ch.cyberduck.binding.foundation.NSString)3 DefaultMainAction (ch.cyberduck.core.threading.DefaultMainAction)3 NSInteger (org.rococoa.cocoa.foundation.NSInteger)3 NSPasteboard (ch.cyberduck.binding.application.NSPasteboard)2 NSDictionary (ch.cyberduck.binding.foundation.NSDictionary)2 NSURL (ch.cyberduck.binding.foundation.NSURL)2 Path (ch.cyberduck.core.Path)2 HostParserException (ch.cyberduck.core.exception.HostParserException)2 LocalAccessDeniedException (ch.cyberduck.core.exception.LocalAccessDeniedException)2 FinderLocal (ch.cyberduck.core.local.FinderLocal)2