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;
}
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;
}
}
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;
}
}
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;
}
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);
}
}
}
}
Aggregations