APISonar


ch.cyberduck.core.DescriptiveUrl.Type.http

> ch > cyberduck > core > DescriptiveUrl > Type > http
ch APIs cyberduck APIs core APIs DescriptiveUrl APIs Type APIs http APIs

Example 1
public void testRelativeDocumentRoot() {
        Host host = new Host("localhost");
        host.setDefaultPath("public_html");
        Path path = new Path(
                "/usr/home/dkocher/public_html/file", EnumSet.of(Path.Type.directory));
        assertEquals("http://localhost/file", new DefaultUrlProvider(host).toUrl(path).find(DescriptiveUrl.Type.http).getUrl());
        host.setWebURL("http://127.0.0.1/~dkocher");
        assertEquals("http://127.0.0.1/~dkocher/file", new DefaultUrlProvider(host).toUrl(path).find(DescriptiveUrl.Type.http).getUrl());
    }
Example 2
public void testToHttpURL() throws Exception {
        final S3Session session = new S3Session(new Host(new S3Protocol(), new S3Protocol().getDefaultHostname()));
        Path p = new Path("/bucket/f/key f", EnumSet.of(Path.Type.file));
        assertEquals("https://bucket.s3.amazonaws.com/f/key%20f",
                new S3UrlProvider(session).toUrl(p).find(DescriptiveUrl.Type.http).getUrl());
        assertTrue(new S3UrlProvider(session).toUrl(p).filter(DescriptiveUrl.Type.http).contains(
                new DescriptiveUrl(URI.create("http://bucket.s3.amazonaws.com/f/key%20f"))
        ));
        assertEquals(5, new S3UrlProvider(session, new DisabledPasswordStore() {
            @Override
            public String find(final Host host) {
                return "k";
            }
        }).toUrl(p).filter(DescriptiveUrl.Type.signed).size());
    }
Example 3
protected List<DescriptiveUrl> getURLs(Path selected) {
        final ArrayList<DescriptiveUrl> list = new ArrayList<DescriptiveUrl>();
        final UrlProvider provider = this.getSession().getFeature(UrlProvider.class);
        if(provider != null) {
            list.addAll(provider.toUrl(selected).filter(
                    DescriptiveUrl.Type.http, DescriptiveUrl.Type.cname, DescriptiveUrl.Type.cdn,
                    DescriptiveUrl.Type.signed, DescriptiveUrl.Type.authenticated, DescriptiveUrl.Type.torrent));
        }
        final DistributionConfiguration feature = this.getSession().getFeature(DistributionConfiguration.class);
        if(feature != null) {
            list.addAll(feature.toUrl(selected));
        }
        return list;
    }
Example 4
public DescriptiveUrl toDownloadUrl(final Path file, final Object options, final PasswordCallback callback) throws BackgroundException {
        final Permission permission = new Permission();
        // To make a file public you will need to assign the role reader to the type anyone
        permission.setRole("reader");
        permission.setType("anyone");
        try {
            session.getClient().permissions().create(fileid.getFileid(file, new DisabledListProgressListener()),
                permission);
        }
        catch(IOException e) {
            throw new DriveExceptionMappingService().map("Failure to write attributes of {0}", e, file);
        }
        return new DriveUrlProvider().toUrl(file).find(DescriptiveUrl.Type.http);
    }
Example 5
public DescriptiveUrlBag toUrl(final Path file) {
        final DescriptiveUrlBag list = new DescriptiveUrlBag();
        list.add(new DescriptiveUrl(URI.create(String.format("%s/home%s",
            new HostUrlProvider().withUsername(false).get(session.getHost()), URIEncoder.encode(file.getAbsolute()))),
            DescriptiveUrl.Type.http,
            MessageFormat.format(LocaleFactory.localizedString("{0} URL"), session.getHost().getProtocol().getScheme().toString().toUpperCase(Locale.ROOT))));
        return list;
    }
Example 6
protected PathAttributes convert(final OneDriveItem.Metadata metadata) {
        final PathAttributes attributes = new PathAttributes();
        attributes.setETag(metadata.getETag());
        attributes.setSize(metadata.getSize());
        try {
            attributes.setLink(new DescriptiveUrl(new URI(metadata.getWebUrl()), DescriptiveUrl.Type.http));
        }
        catch(URISyntaxException e) {
            log.warn(String.format("Cannot set link. Web URL returned %s", metadata.getWebUrl()), e);
        }
        attributes.setModificationDate(metadata.getLastModifiedDateTime().toInstant().toEpochMilli());
        attributes.setCreationDate(metadata.getCreatedDateTime().toInstant().toEpochMilli());
        return attributes;
    }
Example 7
public void testSftp() throws Exception {
        final Host host = new Host(new SFTPProtocol(), "test.cyberduck.ch", new Credentials(
                "u", "p"
        ));
        host.setDefaultPath("/my/documentroot");
        final SFTPSession session = new SFTPSession(host);
        assertEquals("sftp://test.cyberduck.ch/my/documentroot/f",
                new DefaultUrlProvider(host).toUrl(new Path("/my/documentroot/f", Path.DIRECTORY_TYPE)).find(DescriptiveUrl.Type.provider).getUrl());
        assertEquals("http://test.cyberduck.ch/f",
                new DefaultUrlProvider(host).toUrl(new Path("/my/documentroot/f", Path.DIRECTORY_TYPE)).find(DescriptiveUrl.Type.http).getUrl());
    }
Example 8
public void testToUrl() throws Exception {
        final Path bucket = new Path("/test-cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume));
        final Path test = new Path(bucket, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
        final B2FileidProvider fileid = new B2FileidProvider(session).withCache(cache);
        new B2TouchFeature(session, fileid).touch(test, new TransferStatus());
        final B2UrlProvider provider = new B2UrlProvider(session);
        assertEquals(0, provider.toUrl(bucket).size());
        assertEquals(1, provider.toUrl(test).size());
        assertNotNull(provider.toUrl(test).find(DescriptiveUrl.Type.http).getUrl());
        new B2DeleteFeature(session, fileid).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback());
    }