Search in sources :

Example 1 with StringAppender

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);
}
Also used : StatusLine(org.apache.http.StatusLine) HttpEntity(org.apache.http.HttpEntity) StringAppender(ch.cyberduck.core.StringAppender) JSON(ch.cyberduck.core.box.io.swagger.client.JSON) HttpResponseException(org.apache.http.client.HttpResponseException) ClientError(ch.cyberduck.core.box.io.swagger.client.model.ClientError)

Example 2 with StringAppender

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;
}
Also used : StringAppender(ch.cyberduck.core.StringAppender)

Example 3 with StringAppender

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();
}
Also used : StringAppender(ch.cyberduck.core.StringAppender)

Example 4 with StringAppender

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);
    }
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) DefaultHttpResponseExceptionMappingService(ch.cyberduck.core.http.DefaultHttpResponseExceptionMappingService) DelegatingHomeFeature(ch.cyberduck.core.shared.DelegatingHomeFeature) HttpEntity(org.apache.http.HttpEntity) LoginCanceledException(ch.cyberduck.core.exception.LoginCanceledException) HttpResponse(org.apache.http.HttpResponse) Host(ch.cyberduck.core.Host) DefaultPathHomeFeature(ch.cyberduck.core.shared.DefaultPathHomeFeature) HttpResponseException(org.apache.http.client.HttpResponseException) IOException(java.io.IOException) XmlMapper(com.fasterxml.jackson.dataformat.xml.XmlMapper) LoginOptions(ch.cyberduck.core.LoginOptions) StatusLine(org.apache.http.StatusLine) DescriptiveUrl(ch.cyberduck.core.DescriptiveUrl) AbstractResponseHandler(org.apache.http.impl.client.AbstractResponseHandler) StringAppender(ch.cyberduck.core.StringAppender) DefaultIOExceptionMappingService(ch.cyberduck.core.DefaultIOExceptionMappingService) Home(ch.cyberduck.core.features.Home)

Example 5 with StringAppender

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);
}
Also used : NSImage(ch.cyberduck.binding.application.NSImage) StringAppender(ch.cyberduck.core.StringAppender) NSAlert(ch.cyberduck.binding.application.NSAlert)

Aggregations

StringAppender (ch.cyberduck.core.StringAppender)24 NSAlert (ch.cyberduck.binding.application.NSAlert)10 NSImage (ch.cyberduck.binding.application.NSImage)6 LoginCanceledException (ch.cyberduck.core.exception.LoginCanceledException)6 Credentials (ch.cyberduck.core.Credentials)5 IOException (java.io.IOException)5 LoginOptions (ch.cyberduck.core.LoginOptions)4 DefaultIOExceptionMappingService (ch.cyberduck.core.DefaultIOExceptionMappingService)3 DefaultHttpResponseExceptionMappingService (ch.cyberduck.core.http.DefaultHttpResponseExceptionMappingService)3 HttpResponseException (org.apache.http.client.HttpResponseException)3 ConnectionCanceledException (ch.cyberduck.core.exception.ConnectionCanceledException)2 SFTPExceptionMappingService (ch.cyberduck.core.sftp.SFTPExceptionMappingService)2 Resource (net.schmizz.sshj.userauth.password.Resource)2 HttpEntity (org.apache.http.HttpEntity)2 StatusLine (org.apache.http.StatusLine)2 AlphanumericRandomStringService (ch.cyberduck.core.AlphanumericRandomStringService)1 DescriptiveUrl (ch.cyberduck.core.DescriptiveUrl)1 Host (ch.cyberduck.core.Host)1 PreferencesUseragentProvider (ch.cyberduck.core.PreferencesUseragentProvider)1 JSON (ch.cyberduck.core.box.io.swagger.client.JSON)1