use of ch.cyberduck.core.DescriptiveUrl in project cyberduck by iterate-ch.
the class BoxShareFeature method createFileSharedLink.
private DescriptiveUrl createFileSharedLink(final Path file, final PasswordCallback callback) throws BackgroundException {
try {
final String password = this.prompt(file, callback);
final File link = new SharedLinksFilesApi(new BoxApiClient(session.getClient())).putFilesIdAddSharedLink("shared_link", fileid.getFileId(file, new DisabledListProgressListener()), new FilesFileIdaddSharedLinkBody().sharedLink(new FilesfileIdaddSharedLinkSharedLink().password(password)));
return new DescriptiveUrl(URI.create(link.getSharedLink().getDownloadUrl()), DescriptiveUrl.Type.signed);
} catch (ApiException e) {
throw new BoxExceptionMappingService(fileid).map(e);
}
}
use of ch.cyberduck.core.DescriptiveUrl in project cyberduck by iterate-ch.
the class PathAttributesDictionary method deserialize.
public <T> PathAttributes deserialize(T serialized) {
final Deserializer dict = factory.create(serialized);
final PathAttributes attributes = new PathAttributes();
final String sizeObj = dict.stringForKey("Size");
if (sizeObj != null) {
attributes.setSize(Long.parseLong(sizeObj));
}
final String quotaObj = dict.stringForKey("Quota");
if (quotaObj != null) {
attributes.setQuota(Long.parseLong(quotaObj));
}
final String modifiedObj = dict.stringForKey("Modified");
if (modifiedObj != null) {
attributes.setModificationDate(Long.parseLong(modifiedObj));
}
final String createdObj = dict.stringForKey("Created");
if (createdObj != null) {
attributes.setCreationDate(Long.parseLong(createdObj));
}
final String revisionObj = dict.stringForKey("Revision");
if (revisionObj != null) {
attributes.setRevision(Long.parseLong(revisionObj));
}
final List<T> versionsObj = dict.listForKey("Versions");
if (versionsObj != null) {
final AttributedList<Path> versions = new AttributedList<>();
for (T versionDict : versionsObj) {
versions.add(new PathDictionary(factory).deserialize(versionDict));
}
attributes.setVersions(versions);
}
final String etagObj = dict.stringForKey("ETag");
if (etagObj != null) {
attributes.setETag(etagObj);
}
final Object permissionObj = dict.objectForKey("Permission");
if (permissionObj != null) {
attributes.setPermission(new PermissionDictionary().deserialize(permissionObj));
}
final Object aclObj = dict.objectForKey("Acl");
if (aclObj != null) {
attributes.setAcl(new AclDictionary().deserialize(aclObj));
}
if (dict.mapForKey("Link") != null) {
final Map<String, String> link = dict.mapForKey("Link");
attributes.setLink(new DescriptiveUrl(URI.create(link.get("Url")), DescriptiveUrl.Type.valueOf(link.get("Type"))));
} else {
final String linkObj = dict.stringForKey("Link");
if (linkObj != null) {
attributes.setLink(new DescriptiveUrl(URI.create(linkObj), DescriptiveUrl.Type.http));
}
}
if (dict.mapForKey("Checksum") != null) {
final Map<String, String> checksum = dict.mapForKey("Checksum");
attributes.setChecksum(new Checksum(HashAlgorithm.valueOf(checksum.get("Algorithm")), checksum.get("Hash")));
} else {
attributes.setChecksum(Checksum.parse(dict.stringForKey("Checksum")));
}
attributes.setVersionId(dict.stringForKey("Version"));
attributes.setFileId(dict.stringForKey("File Id"));
attributes.setLockId(dict.stringForKey("Lock Id"));
final String duplicateObj = dict.stringForKey("Duplicate");
if (duplicateObj != null) {
attributes.setDuplicate(Boolean.parseBoolean(duplicateObj));
}
final String hiddenObj = dict.stringForKey("Hidden");
if (hiddenObj != null) {
attributes.setHidden(Boolean.parseBoolean(hiddenObj));
}
attributes.setMetadata(Collections.emptyMap());
attributes.setRegion(dict.stringForKey("Region"));
attributes.setStorageClass(dict.stringForKey("Storage Class"));
final Object vaultObj = dict.objectForKey("Vault");
if (vaultObj != null) {
attributes.setVault(new PathDictionary(factory).deserialize(vaultObj));
}
final Map<String, String> customObj = dict.mapForKey("Custom");
if (customObj != null) {
attributes.setCustom(customObj);
}
return attributes;
}
use of ch.cyberduck.core.DescriptiveUrl 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;
}
use of ch.cyberduck.core.DescriptiveUrl in project cyberduck by iterate-ch.
the class DistributionUrlProviderTest method testStreaming.
@Test
public void testStreaming() {
final Distribution distribution = new Distribution(Distribution.STREAMING, "n", URI.create("https://test.cyberduck.ch.s3.amazonaws.com"), true);
distribution.setUrl(URI.create("rtmp://d1f6cbdjcbzyiu.cloudfront.net/cfx/st"));
final DescriptiveUrl cdn = new DistributionUrlProvider(distribution).toUrl(new Path("/test.cyberduck.ch/p/f", EnumSet.of(Path.Type.file))).find(DescriptiveUrl.Type.cdn);
assertEquals("rtmp://d1f6cbdjcbzyiu.cloudfront.net/cfx/st/p/f", cdn.getUrl());
assertEquals("n Streaming (RTMP) CDN URL", cdn.getHelp());
final DescriptiveUrl origin = new DistributionUrlProvider(distribution).toUrl(new Path("/test.cyberduck.ch/p/f", EnumSet.of(Path.Type.file))).find(DescriptiveUrl.Type.origin);
assertEquals("https://test.cyberduck.ch.s3.amazonaws.com/p/f", origin.getUrl());
assertEquals("n Origin URL", origin.getHelp());
}
use of ch.cyberduck.core.DescriptiveUrl in project cyberduck by iterate-ch.
the class DistributionUrlProviderTest method testCustomOrigin.
@Test
public void testCustomOrigin() {
final Distribution distribution = new Distribution(Distribution.CUSTOM, "n", URI.create("http://test.cyberduck.ch/"), true);
final DescriptiveUrl url = new DistributionUrlProvider(distribution).toUrl(new Path("/p/f", EnumSet.of(Path.Type.directory))).find(DescriptiveUrl.Type.origin);
assertEquals("http://test.cyberduck.ch/p/f", url.getUrl());
assertEquals("n Origin URL", url.getHelp());
}
Aggregations