Search in sources :

Example 1 with DescriptiveUrlBag

use of ch.cyberduck.core.DescriptiveUrlBag in project cyberduck by iterate-ch.

the class DefaultUrlProvider method toUrl.

@Override
public DescriptiveUrlBag toUrl(final Path file) {
    final DescriptiveUrlBag list = new DescriptiveUrlBag();
    if (file.attributes().getLink() != DescriptiveUrl.EMPTY) {
        list.add(file.attributes().getLink());
    }
    list.add(new DescriptiveUrl(URI.create(String.format("%s%s", new HostUrlProvider().withUsername(false).get(host), URIEncoder.encode(file.getAbsolute()))), DescriptiveUrl.Type.provider, MessageFormat.format(LocaleFactory.localizedString("{0} URL"), host.getProtocol().getScheme().toString().toUpperCase(Locale.ROOT))));
    list.addAll(new HostWebUrlProvider(host).toUrl(file));
    return list;
}
Also used : HostWebUrlProvider(ch.cyberduck.core.HostWebUrlProvider) DescriptiveUrl(ch.cyberduck.core.DescriptiveUrl) HostUrlProvider(ch.cyberduck.core.HostUrlProvider) DescriptiveUrlBag(ch.cyberduck.core.DescriptiveUrlBag)

Example 2 with DescriptiveUrlBag

use of ch.cyberduck.core.DescriptiveUrlBag in project cyberduck by iterate-ch.

the class GoogleStorageUrlProvider method toUrl.

/**
 * This creates an URL that uses Cookie-based Authentication. The ACLs for the given Google user account
 * has to be setup first.
 * <p>
 * Google Storage lets you provide browser-based authenticated downloads to users who do not have
 * Google Storage accounts. To do this, you apply Google account-based ACLs to the object and then
 * you provide users with a URL that is scoped to the object.
 */
@Override
public DescriptiveUrlBag toUrl(final Path file) {
    final DescriptiveUrlBag list = new DefaultUrlProvider(session.getHost()).toUrl(file);
    if (file.isFile()) {
        // Authenticated browser download using cookie-based Google account authentication in conjunction with ACL
        list.add(new DescriptiveUrl(URI.create(String.format("https://storage.cloud.google.com%s", URIEncoder.encode(file.getAbsolute()))), DescriptiveUrl.Type.authenticated, MessageFormat.format(LocaleFactory.localizedString("{0} URL"), LocaleFactory.localizedString("Authenticated"))));
        // Website configuration
        final Distribution distribution = new Distribution(Distribution.DOWNLOAD, URI.create(String.format("%s://%s.%s", Distribution.DOWNLOAD.getScheme(), containerService.getContainer(file).getName(), session.getHost().getProtocol().getDefaultHostname())), false);
        distribution.setUrl(URI.create(String.format("%s://%s.%s", Distribution.DOWNLOAD.getScheme(), containerService.getContainer(file).getName(), session.getHost().getProtocol().getDefaultHostname())));
        list.addAll(new DistributionUrlProvider(distribution).toUrl(file));
    }
    // gsutil URI
    list.add(new DescriptiveUrl(URI.create(String.format("gs://%s%s", containerService.getContainer(file).getName(), file.isRoot() ? Path.DELIMITER : containerService.isContainer(file) ? Path.DELIMITER : String.format("/%s", URIEncoder.encode(containerService.getKey(file))))), DescriptiveUrl.Type.provider, MessageFormat.format(LocaleFactory.localizedString("{0} URL"), session.getHost().getProtocol().getName())));
    return list;
}
Also used : DescriptiveUrl(ch.cyberduck.core.DescriptiveUrl) DefaultUrlProvider(ch.cyberduck.core.shared.DefaultUrlProvider) DescriptiveUrlBag(ch.cyberduck.core.DescriptiveUrlBag) Distribution(ch.cyberduck.core.cdn.Distribution) DistributionUrlProvider(ch.cyberduck.core.cdn.DistributionUrlProvider)

Example 3 with DescriptiveUrlBag

use of ch.cyberduck.core.DescriptiveUrlBag in project cyberduck by iterate-ch.

the class NextcloudUrlProvider method toUrl.

@Override
public DescriptiveUrlBag toUrl(final Path file) {
    final DescriptiveUrlBag list = new DescriptiveUrlBag();
    list.add(new DescriptiveUrl(URI.create(String.format("%s%s", new HostUrlProvider().withUsername(false).get(session.getHost()), URIEncoder.encode(file.getAbsolute()))), DescriptiveUrl.Type.provider, MessageFormat.format(LocaleFactory.localizedString("{0} URL"), session.getHost().getProtocol().getScheme().toString().toUpperCase(Locale.ROOT))));
    return list;
}
Also used : DescriptiveUrl(ch.cyberduck.core.DescriptiveUrl) HostUrlProvider(ch.cyberduck.core.HostUrlProvider) DescriptiveUrlBag(ch.cyberduck.core.DescriptiveUrlBag)

Example 4 with DescriptiveUrlBag

use of ch.cyberduck.core.DescriptiveUrlBag in project cyberduck by iterate-ch.

the class SwiftUrlProvider method toUrl.

@Override
public DescriptiveUrlBag toUrl(final Path file) {
    final DescriptiveUrlBag list = new DescriptiveUrlBag();
    if (file.isFile()) {
        Region region = null;
        try {
            region = regionService.lookup(file);
        } catch (BackgroundException e) {
            log.warn(String.format("Failure looking up region for %s %s", file, e.getMessage()));
        }
        if (null == region) {
            list.addAll(new DefaultUrlProvider(session.getHost()).toUrl(file));
        } else {
            list.addAll(new HostWebUrlProvider(session.getHost()).toUrl(file));
            list.add(new DescriptiveUrl(URI.create(region.getStorageUrl(containerService.getContainer(file).getName(), containerService.getKey(file)).toString()), DescriptiveUrl.Type.provider, MessageFormat.format(LocaleFactory.localizedString("{0} URL"), session.getHost().getProtocol().getScheme().name().toUpperCase(Locale.ROOT))));
            // In one hour
            list.addAll(this.sign(region, file, this.getExpiry((int) TimeUnit.HOURS.toSeconds(1))));
            // Default signed URL expiring in 24 hours.
            list.addAll(this.sign(region, file, this.getExpiry((int) TimeUnit.SECONDS.toSeconds(new HostPreferences(session.getHost()).getInteger("s3.url.expire.seconds")))));
            // 1 Week
            list.addAll(this.sign(region, file, this.getExpiry((int) TimeUnit.DAYS.toSeconds(7))));
            // 1 Month
            list.addAll(this.sign(region, file, this.getExpiry((int) TimeUnit.DAYS.toSeconds(30))));
            // 1 Year
            list.addAll(this.sign(region, file, this.getExpiry((int) TimeUnit.DAYS.toSeconds(365))));
        }
    }
    // Filter by matching container name
    final Optional<Set<Distribution>> filtered = distributions.entrySet().stream().filter(entry -> new SimplePathPredicate(containerService.getContainer(file)).test(entry.getKey())).map(Map.Entry::getValue).findFirst();
    if (filtered.isPresent()) {
        // Add CloudFront distributions
        for (Distribution distribution : filtered.get()) {
            list.addAll(new DistributionUrlProvider(distribution).toUrl(file));
        }
    }
    return list;
}
Also used : HostWebUrlProvider(ch.cyberduck.core.HostWebUrlProvider) Set(java.util.Set) DescriptiveUrlBag(ch.cyberduck.core.DescriptiveUrlBag) HostPreferences(ch.cyberduck.core.preferences.HostPreferences) DescriptiveUrl(ch.cyberduck.core.DescriptiveUrl) DefaultUrlProvider(ch.cyberduck.core.shared.DefaultUrlProvider) Distribution(ch.cyberduck.core.cdn.Distribution) Region(ch.iterate.openstack.swift.model.Region) SimplePathPredicate(ch.cyberduck.core.SimplePathPredicate) Map(java.util.Map) BackgroundException(ch.cyberduck.core.exception.BackgroundException) DistributionUrlProvider(ch.cyberduck.core.cdn.DistributionUrlProvider)

Example 5 with DescriptiveUrlBag

use of ch.cyberduck.core.DescriptiveUrlBag in project cyberduck by iterate-ch.

the class B2UrlProvider method toUrl.

@Override
public DescriptiveUrlBag toUrl(final Path file) {
    if (file.isVolume()) {
        return DescriptiveUrlBag.empty();
    }
    final DescriptiveUrlBag list = new DescriptiveUrlBag();
    if (file.isFile()) {
        final String download = String.format("%s/file/%s/%s", session.getClient().getDownloadUrl(), URIEncoder.encode(containerService.getContainer(file).getName()), URIEncoder.encode(containerService.getKey(file)));
        list.add(new DescriptiveUrl(URI.create(download), DescriptiveUrl.Type.http, MessageFormat.format(LocaleFactory.localizedString("{0} URL"), Scheme.https.name().toUpperCase(Locale.ROOT))));
    }
    return list;
}
Also used : DescriptiveUrl(ch.cyberduck.core.DescriptiveUrl) DescriptiveUrlBag(ch.cyberduck.core.DescriptiveUrlBag)

Aggregations

DescriptiveUrlBag (ch.cyberduck.core.DescriptiveUrlBag)17 DescriptiveUrl (ch.cyberduck.core.DescriptiveUrl)16 Path (ch.cyberduck.core.Path)7 Test (org.junit.Test)6 Host (ch.cyberduck.core.Host)5 HostUrlProvider (ch.cyberduck.core.HostUrlProvider)5 HostWebUrlProvider (ch.cyberduck.core.HostWebUrlProvider)3 Distribution (ch.cyberduck.core.cdn.Distribution)3 DistributionUrlProvider (ch.cyberduck.core.cdn.DistributionUrlProvider)3 DefaultUrlProvider (ch.cyberduck.core.shared.DefaultUrlProvider)3 SimplePathPredicate (ch.cyberduck.core.SimplePathPredicate)2 TestProtocol (ch.cyberduck.core.TestProtocol)2 BackgroundException (ch.cyberduck.core.exception.BackgroundException)2 HostPreferences (ch.cyberduck.core.preferences.HostPreferences)2 TransferStatus (ch.cyberduck.core.transfer.TransferStatus)2 AccountInfo (ch.iterate.openstack.swift.model.AccountInfo)2 Region (ch.iterate.openstack.swift.model.Region)2 Map (java.util.Map)2 Set (java.util.Set)2 DisabledLoginCallback (ch.cyberduck.core.DisabledLoginCallback)1