use of ch.cyberduck.core.exception.HostParserException 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.core.exception.HostParserException 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.core.exception.HostParserException in project cyberduck by iterate-ch.
the class MainController method handleGetURLEvent_withReplyEvent.
/**
* Extract the URL from the Apple event and handle it here.
*/
@Action
public void handleGetURLEvent_withReplyEvent(NSAppleEventDescriptor event, NSAppleEventDescriptor reply) {
log.debug(String.format("Received URL from event %s", event));
final NSAppleEventDescriptor param = event.paramDescriptorForKeyword(keyAEResult);
if (null == param) {
log.error("No URL parameter");
return;
}
final String url = param.stringValue();
if (StringUtils.isEmpty(url)) {
log.error("URL parameter is empty");
return;
}
switch(url) {
case "x-cyberduck-action:update":
updater.check(false);
break;
default:
if (StringUtils.startsWith(url, OAuth2AuthorizationService.CYBERDUCK_REDIRECT_URI)) {
final String action = StringUtils.removeStart(url, OAuth2AuthorizationService.CYBERDUCK_REDIRECT_URI);
final List<NameValuePair> pairs = URLEncodedUtils.parse(URI.create(action), Charset.defaultCharset());
String state = StringUtils.EMPTY;
String code = StringUtils.EMPTY;
for (NameValuePair pair : pairs) {
if (StringUtils.equals(pair.getName(), "state")) {
state = StringUtils.equals(pair.getName(), "state") ? pair.getValue() : StringUtils.EMPTY;
}
if (StringUtils.equals(pair.getName(), "code")) {
code = StringUtils.equals(pair.getName(), "code") ? pair.getValue() : StringUtils.EMPTY;
}
}
final OAuth2TokenListenerRegistry oauth = OAuth2TokenListenerRegistry.get();
oauth.notify(state, code);
} else if (StringUtils.startsWith(url, CteraProtocol.CTERA_REDIRECT_URI)) {
final String action = StringUtils.removeStart(url, String.format("%s:", preferences.getProperty("oauth.handler.scheme")));
final List<NameValuePair> pairs = URLEncodedUtils.parse(URI.create(action), Charset.defaultCharset());
String code = StringUtils.EMPTY;
for (NameValuePair pair : pairs) {
if (StringUtils.equals(pair.getName(), "ActivationCode")) {
code = StringUtils.equals(pair.getName(), "ActivationCode") ? pair.getValue() : StringUtils.EMPTY;
}
}
final OAuth2TokenListenerRegistry oauth = OAuth2TokenListenerRegistry.get();
oauth.notify(StringUtils.EMPTY, code);
} else {
try {
final Host h = HostParser.parse(url);
h.setCredentials(CredentialsConfiguratorFactory.get(h.getProtocol()).configure(h));
if (Path.Type.file == detector.detect(h.getDefaultPath())) {
final Path file = new Path(PathNormalizer.normalize(h.getDefaultPath()), EnumSet.of(Path.Type.file));
TransferControllerFactory.get().start(new DownloadTransfer(h, file, LocalFactory.get(preferences.getProperty("queue.download.folder"), file.getName())), new TransferOptions());
} else {
for (BrowserController browser : MainController.getBrowsers()) {
if (browser.isMounted()) {
if (new HostUrlProvider().get(browser.getSession().getHost()).equals(new HostUrlProvider().get(h))) {
// Handle browser window already connected to the same host. #4215
browser.window().makeKeyAndOrderFront(null);
if (Path.Type.directory == detector.detect(h.getDefaultPath())) {
browser.setWorkdir(new Path(PathNormalizer.normalize(h.getDefaultPath()), EnumSet.of(Path.Type.directory)));
}
return;
}
}
}
final BrowserController browser = newDocument(false);
browser.mount(h);
}
} catch (HostParserException e) {
log.warn(e);
}
}
}
}
use of ch.cyberduck.core.exception.HostParserException in project cyberduck by iterate-ch.
the class DownloadController method callback.
@Override
public void callback(final int returncode) {
switch(returncode) {
case DEFAULT_OPTION:
try {
final Host host = HostParser.parse(urlField.stringValue());
final Path file = new Path(PathNormalizer.normalize(host.getDefaultPath()), EnumSet.of(detector.detect(host.getDefaultPath())));
host.setDefaultPath(file.getParent().getAbsolute());
final Transfer transfer = new DownloadTransfer(host, file, LocalFactory.get(PreferencesFactory.get().getProperty("queue.download.folder"), file.getName()));
TransferControllerFactory.get().start(transfer, new TransferOptions());
break;
} catch (HostParserException e) {
log.warn(e);
}
}
}
use of ch.cyberduck.core.exception.HostParserException in project cyberduck by iterate-ch.
the class HostParser method parsePort.
static void parsePort(final StringReader reader, final Host host, final Consumer<HostParserException> decorator) throws HostParserException {
Integer port = null;
int tracker = reader.position;
while (!reader.endOfString()) {
final char c = (char) reader.read();
if (Character.isDigit(c)) {
port = Optional.ofNullable(port).orElse(0) * 10 + Character.getNumericValue(c);
} else {
if (c != '/') {
port = null;
log.warn(String.format("Got %s in port. This is unsupported. Continuing with default port", c));
reader.skip(tracker - reader.position);
} else {
reader.skip(-1);
}
break;
}
}
if (port != null && host.getProtocol().isPortConfigurable()) {
if (port <= 0 || port >= 65536) {
throw decorate(new HostParserException(String.format("Port %d is outside allowed range 0-65536", port)), decorator);
}
host.setPort(port);
}
}
Aggregations