use of ch.cyberduck.core.StringAppender in project cyberduck by iterate-ch.
the class BoxClientErrorResponseHandler method handleResponse.
@Override
public T handleResponse(final HttpResponse response) throws IOException {
final StatusLine statusLine = response.getStatusLine();
final HttpEntity entity = response.getEntity();
if (statusLine.getStatusCode() >= 300) {
final StringAppender message = new StringAppender();
message.append(statusLine.getReasonPhrase());
final ClientError error = new JSON().getContext(null).readValue(entity.getContent(), ClientError.class);
message.append(error.getMessage());
throw new HttpResponseException(statusLine.getStatusCode(), message.toString());
}
return super.handleResponse(response);
}
use of ch.cyberduck.core.StringAppender in project cyberduck by iterate-ch.
the class NSAlert method alert.
public static NSAlert alert(String title, String message, String defaultButton, String alternateButton, String otherButton) {
NSAlert alert = NSAlert.alert();
alert.setMessageText(title);
alert.setInformativeText(new StringAppender().append(message).toString());
if (StringUtils.isNotBlank(defaultButton)) {
// OK
alert.addButtonWithTitle(defaultButton);
}
if (StringUtils.isNotBlank(otherButton)) {
// Cancel
alert.addButtonWithTitle(otherButton);
}
if (StringUtils.isNotBlank(alternateButton)) {
alert.addButtonWithTitle(alternateButton);
}
return alert;
}
use of ch.cyberduck.core.StringAppender in project cyberduck by iterate-ch.
the class BackgroundException method getDetail.
public String getDetail(boolean help) {
final StringAppender appender = new StringAppender();
appender.append(detail);
if (help) {
appender.append(this.getHelp());
}
return appender.toString();
}
use of ch.cyberduck.core.StringAppender in project cyberduck by iterate-ch.
the class NextcloudShareProvider method toDownloadUrl.
/**
* int) 0 = user; 1 = group; 3 = public link; 6 = federated cloud share
*/
@Override
public DescriptiveUrl toDownloadUrl(final Path file, final Object options, final PasswordCallback callback) throws BackgroundException {
final Host bookmark = session.getHost();
final StringBuilder request = new StringBuilder(String.format("https://%s/ocs/v2.php/apps/files_sharing/api/v1/shares?path=%s&shareType=%d", bookmark.getHostname(), URIEncoder.encode(StringUtils.substringAfter(file.getAbsolute(), new DelegatingHomeFeature(new DefaultPathHomeFeature(session.getHost()), session.getFeature(Home.class)).find().getAbsolute())), // Public link
3));
try {
request.append(String.format("&password=%s", callback.prompt(bookmark, LocaleFactory.localizedString("Passphrase", "Cryptomator"), MessageFormat.format(LocaleFactory.localizedString("Create a passphrase required to access {0}", "Credentials"), file.getName()), new LoginOptions().keychain(false).icon(bookmark.getProtocol().disk())).getPassword()));
} catch (LoginCanceledException e) {
// Ignore no password set
}
final HttpPost resource = new HttpPost(request.toString());
resource.setHeader("OCS-APIRequest", "true");
resource.setHeader(HttpHeaders.ACCEPT, "application/xml");
try {
return new DescriptiveUrl(session.getClient().execute(resource, new AbstractResponseHandler<URI>() {
@Override
public URI handleResponse(final HttpResponse response) throws HttpResponseException, IOException {
final StatusLine statusLine = response.getStatusLine();
final HttpEntity entity = response.getEntity();
if (statusLine.getStatusCode() >= 300) {
final StringAppender message = new StringAppender();
message.append(statusLine.getReasonPhrase());
final ocs error = new XmlMapper().readValue(entity.getContent(), ocs.class);
message.append(error.meta.message);
throw new HttpResponseException(statusLine.getStatusCode(), message.toString());
}
return super.handleResponse(response);
}
@Override
public URI handleEntity(final HttpEntity entity) throws IOException {
final XmlMapper mapper = new XmlMapper();
ocs value = mapper.readValue(entity.getContent(), ocs.class);
return URI.create(value.data.url);
}
}), DescriptiveUrl.Type.http);
} catch (HttpResponseException e) {
throw new DefaultHttpResponseExceptionMappingService().map(e);
} catch (IOException e) {
throw new DefaultIOExceptionMappingService().map(e);
}
}
use of ch.cyberduck.core.StringAppender in project cyberduck by iterate-ch.
the class FolderController method loadBundle.
@Override
public void loadBundle() {
final NSAlert alert = NSAlert.alert();
alert.setAlertStyle(NSAlert.NSInformationalAlertStyle);
alert.setMessageText(LocaleFactory.localizedString("Create new folder", "Folder"));
final String message = LocaleFactory.localizedString("Enter the name for the new folder", "Folder");
alert.setInformativeText(new StringAppender().append(message).toString());
alert.addButtonWithTitle(LocaleFactory.localizedString("Create", "Folder"));
alert.addButtonWithTitle(LocaleFactory.localizedString("Cancel", "Folder"));
alert.setIcon(IconCacheFactory.<NSImage>get().iconNamed("folderplus.tiff", 64));
super.loadBundle(alert);
}
Aggregations