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