Search in sources :

Example 1 with NSDictionary

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

the class InterarchyBookmarkCollection method parse.

private void parse(final ProtocolFactory protocols, NSDictionary item) {
    final PlistDeserializer bookmark = new PlistDeserializer(item);
    final List<NSDictionary> children = bookmark.listForKey("Children");
    if (null != children) {
        for (NSDictionary child : children) {
            this.parse(protocols, child);
        }
        return;
    }
    final String url = bookmark.stringForKey("URL");
    if (StringUtils.isBlank(url)) {
        // Possibly a folder
        return;
    }
    final Host host;
    try {
        host = new HostParser(protocols).get(url);
    } catch (HostParserException e) {
        log.warn(e);
        return;
    }
    final String title = bookmark.stringForKey("Title");
    if (StringUtils.isNotBlank(title)) {
        host.setNickname(title);
    }
    this.add(host);
}
Also used : PlistDeserializer(ch.cyberduck.core.serializer.impl.jna.PlistDeserializer) NSDictionary(ch.cyberduck.binding.foundation.NSDictionary) HostParser(ch.cyberduck.core.HostParser) Host(ch.cyberduck.core.Host) HostParserException(ch.cyberduck.core.exception.HostParserException)

Example 2 with NSDictionary

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

the class FetchBookmarkCollection method parse.

@Override
protected void parse(final ProtocolFactory protocols, final Local file) throws AccessDeniedException {
    NSDictionary serialized = NSDictionary.dictionaryWithContentsOfFile(file.getAbsolute());
    if (null == serialized) {
        throw new LocalAccessDeniedException(String.format("Invalid bookmark file %s", file));
    }
    NSDictionary dict = new PlistDeserializer(serialized).objectForKey("Shortcuts v2");
    if (null == dict) {
        throw new LocalAccessDeniedException(String.format("Invalid bookmark file %s", file));
    }
    dict = new PlistDeserializer(dict).objectForKey("Shortcuts");
    if (null == dict) {
        throw new LocalAccessDeniedException(String.format("Invalid bookmark file %s", file));
    }
    List<NSDictionary> shortcuts = new PlistDeserializer(dict).listForKey("Shortcuts");
    for (NSDictionary shortcut : shortcuts) {
        PlistDeserializer reader = new PlistDeserializer(shortcut);
        NSDictionary remote = reader.objectForKey("Remote Item");
        if (null == remote) {
            continue;
        }
        NSDictionary location = new PlistDeserializer(remote).objectForKey("Location");
        if (null == location) {
            continue;
        }
        String url = new PlistDeserializer(location).stringForKey("URL");
        if (null == url) {
            continue;
        }
        final Host host;
        try {
            host = new HostParser(protocols).get(url);
        } catch (HostParserException e) {
            log.warn(e);
            continue;
        }
        host.setNickname(reader.stringForKey("Name"));
        this.add(host);
    }
}
Also used : PlistDeserializer(ch.cyberduck.core.serializer.impl.jna.PlistDeserializer) NSDictionary(ch.cyberduck.binding.foundation.NSDictionary) HostParser(ch.cyberduck.core.HostParser) Host(ch.cyberduck.core.Host) LocalAccessDeniedException(ch.cyberduck.core.exception.LocalAccessDeniedException) HostParserException(ch.cyberduck.core.exception.HostParserException)

Example 3 with NSDictionary

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

the class FlowBookmarkCollection method parse.

private void parse(final ProtocolFactory protocols, NSDictionary serialized) {
    List<NSDictionary> items = new PlistDeserializer(serialized).listForKey("BookmarkItems");
    for (NSDictionary item : items) {
        final PlistDeserializer bookmark = new PlistDeserializer(item);
        String classname = bookmark.stringForKey("ClassName");
        if (null == classname) {
            continue;
        }
        if ("Bookmark".equals(classname)) {
            this.read(protocols, bookmark);
        }
        if ("BookmarkFolder".equals(classname)) {
            this.parse(protocols, item);
        }
    }
}
Also used : PlistDeserializer(ch.cyberduck.core.serializer.impl.jna.PlistDeserializer) NSDictionary(ch.cyberduck.binding.foundation.NSDictionary)

Example 4 with NSDictionary

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

the class MainController method aboutMenuClicked.

@Action
public void aboutMenuClicked(final ID sender) {
    final NSDictionary dict = NSDictionary.dictionaryWithObjectsForKeys(NSArray.arrayWithObjects(preferences.getProperty("application.name"), preferences.getProperty("application.version"), preferences.getProperty("application.revision"), preferences.getProperty("application.copyright")), NSArray.arrayWithObjects("ApplicationName", "ApplicationVersion", "Version", "Copyright"));
    NSApplication.sharedApplication().orderFrontStandardAboutPanelWithOptions(dict);
}
Also used : NSDictionary(ch.cyberduck.binding.foundation.NSDictionary) AbstractBackgroundAction(ch.cyberduck.core.threading.AbstractBackgroundAction) Action(ch.cyberduck.binding.Action)

Example 5 with NSDictionary

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

the class Transmit3BookmarkCollection method parse.

@Override
protected void parse(final ProtocolFactory protocols, final Local file) throws AccessDeniedException {
    final NSDictionary serialized = NSDictionary.dictionaryWithContentsOfFile(file.getAbsolute());
    if (null == serialized) {
        throw new LocalAccessDeniedException(String.format("Invalid bookmark file %s", file));
    }
    // Adds a class translation mapping to NSKeyedUnarchiver whereby objects encoded with a given class name
    // are decoded as instances of a given class instead.
    final TransmitFavoriteCollection c = Rococoa.createClass("TransmitFavoriteCollection", TransmitFavoriteCollection.class);
    final TransmitFavorite f = Rococoa.createClass("TransmitFavorite", TransmitFavorite.class);
    final NSData collectionsData = Rococoa.cast(serialized.objectForKey("FavoriteCollections"), NSData.class);
    if (null == collectionsData) {
        throw new LocalAccessDeniedException(String.format("Error unarchiving bookmark file %s", file));
    }
    final NSKeyedUnarchiver reader = NSKeyedUnarchiver.createForReadingWithData(collectionsData);
    reader.setClass_forClassName(c, "FavoriteCollection");
    reader.setClass_forClassName(c, "HistoryCollection");
    reader.setClass_forClassName(f, "Favorite");
    reader.setClass_forClassName(f, "DotMacFavorite");
    if (!reader.containsValueForKey("FavoriteCollection")) {
        log.warn("Missing key FavoriteCollection");
        return;
    }
    final TransmitFavoriteCollection rootCollection = Rococoa.cast(reader.decodeObjectForKey("FavoriteCollection"), TransmitFavoriteCollection.class);
    reader.finishDecoding();
    if (null == rootCollection) {
        throw new LocalAccessDeniedException(String.format("Error unarchiving bookmark file %s", file));
    }
    // The root has collections
    final NSArray collections = rootCollection.favorites();
    final NSEnumerator collectionsEnumerator = collections.objectEnumerator();
    NSObject next;
    while ((next = collectionsEnumerator.nextObject()) != null) {
        final TransmitFavoriteCollection collection = Rococoa.cast(next, TransmitFavoriteCollection.class);
        if ("History".equals(collection.name())) {
            continue;
        }
        NSArray favorites = collection.favorites();
        NSEnumerator favoritesEnumerator = favorites.objectEnumerator();
        NSObject favorite;
        while ((favorite = favoritesEnumerator.nextObject()) != null) {
            this.parse(protocols, Rococoa.cast(favorite, TransmitFavorite.class));
        }
    }
}
Also used : NSEnumerator(ch.cyberduck.binding.foundation.NSEnumerator) NSObject(ch.cyberduck.binding.foundation.NSObject) NSData(ch.cyberduck.binding.foundation.NSData) NSArray(ch.cyberduck.binding.foundation.NSArray) NSDictionary(ch.cyberduck.binding.foundation.NSDictionary) LocalAccessDeniedException(ch.cyberduck.core.exception.LocalAccessDeniedException) NSKeyedUnarchiver(ch.cyberduck.binding.foundation.NSKeyedUnarchiver)

Aggregations

NSDictionary (ch.cyberduck.binding.foundation.NSDictionary)14 LocalAccessDeniedException (ch.cyberduck.core.exception.LocalAccessDeniedException)8 PlistDeserializer (ch.cyberduck.core.serializer.impl.jna.PlistDeserializer)6 NSObject (ch.cyberduck.binding.foundation.NSObject)4 Host (ch.cyberduck.core.Host)4 NSEnumerator (ch.cyberduck.binding.foundation.NSEnumerator)3 NSArray (ch.cyberduck.binding.foundation.NSArray)2 Credentials (ch.cyberduck.core.Credentials)2 HostParser (ch.cyberduck.core.HostParser)2 Protocol (ch.cyberduck.core.Protocol)2 HostParserException (ch.cyberduck.core.exception.HostParserException)2 ObjCObjectByReference (org.rococoa.ObjCObjectByReference)2 Action (ch.cyberduck.binding.Action)1 NSWorkspace (ch.cyberduck.binding.application.NSWorkspace)1 NSAppleScript (ch.cyberduck.binding.foundation.NSAppleScript)1 NSBundle (ch.cyberduck.binding.foundation.NSBundle)1 NSData (ch.cyberduck.binding.foundation.NSData)1 NSKeyedUnarchiver (ch.cyberduck.binding.foundation.NSKeyedUnarchiver)1 NSString (ch.cyberduck.binding.foundation.NSString)1 Collection (ch.cyberduck.core.Collection)1