public Path parse(final String uri) { final Host host = new HostParser(factory).get(uri); if(StringUtils.isBlank(host.getDefaultPath())) { return new Path(String.valueOf(Path.DELIMITER), EnumSet.of(detector.detect(host.getDefaultPath()))); } return new Path(PathNormalizer.normalize(host.getDefaultPath()), EnumSet.of(detector.detect(host.getDefaultPath()))); } }
@Override public boolean validate() { Host host = HostParser.parse(urlField.stringValue()); return StringUtils.isNotBlank(host.getDefaultPath()); }
@Override protected URI getOrigin(final Path container, final Distribution.Method method) { final URI url = URI.create(String.format("%s%s", new WebUrlProvider(origin).toUrl().getUrl(), PathNormalizer.normalize(origin.getDefaultPath(), true))); if(log.isDebugEnabled()) { log.debug(String.format("Use origin %s for distribution %s", url, method)); } return url; }
@Override public void change(final Host bookmark) { updateField(pathField, bookmark.getDefaultPath()); pathField.setEnabled(bookmark.getProtocol().isPathConfigurable()); } });
@Override public void callback(int returncode) { if(DEFAULT_OPTION == returncode) { final String selected = bookmarksPopup.selectedItem().representedObject(); for(Host bookmark : bookmarks) { // Determine selected bookmark if(bookmark.getUuid().equals(selected)) { if(bookmark.equals(mount)) { // Use current working directory of browser for destination upload(bookmark, files, destination); } else { // No mounted browser if(StringUtils.isNotBlank(bookmark.getDefaultPath())) { upload(bookmark, files, new Path(PathNormalizer.normalize(bookmark.getDefaultPath()), EnumSet.of(Path.Type.directory))); } else { upload(bookmark, files, destination); } } break; } } } }
protected boolean userIsOwner() { final MantaAccountHomeInfo account = new MantaAccountHomeInfo(host.getCredentials().getUsername(), host.getDefaultPath()); return StringUtils.equals(host.getCredentials().getUsername(), account.getAccountOwner()); }
protected boolean isWorldReadable(final Path file) { final MantaAccountHomeInfo account = new MantaAccountHomeInfo(host.getCredentials().getUsername(), host.getDefaultPath()); return file.isChild(account.getAccountPublicRoot()); }
@Override public DescriptiveUrlBag toUrl(final Path file) { final DescriptiveUrlBag list = new DescriptiveUrlBag(); final DescriptiveUrl base = this.toUrl(); list.add(new DescriptiveUrl(URI.create(String.format("%s%s", base.getUrl(), URIEncoder.encode( PathNormalizer.normalize(PathRelativizer.relativize(PathNormalizer.normalize(host.getDefaultPath(), true), file.getAbsolute())) ))).normalize(), base.getType(), base.getHelp()) ); return list; }
@Override public Path find() throws BackgroundException { final Host host = session.getHost(); if(host.getWorkdir() != null) { return new PathDictionary().deserialize(host.getWorkdir().serialize(SerializerFactory.get())); } else { final String path = host.getDefaultPath(); if(StringUtils.isNotBlank(path)) { return this.find(DEFAULT_HOME, path); } else { // No default path configured return DEFAULT_HOME; } } }
@Override public void callback(final int returncode) { switch(returncode) { case DEFAULT_OPTION: final Host host = HostParser.parse(urlField.stringValue()); final Path file = new Path(PathNormalizer.normalize(host.getDefaultPath()), EnumSet.of(detector.detect(host.getDefaultPath()))); host.setDefaultPath(file.getParent().getAbsolute()); final Transfer transfer = new DownloadTransfer(host, file, LocalFactory.get(PreferencesFactory.get().getProperty("queue.download.folder"), file.getName())); TransferControllerFactory.get().start(transfer, new TransferOptions()); break; } }
protected boolean isWorldReadable(final MantaObject object) { final MantaAccountHomeInfo accountHomeInfo = new MantaAccountHomeInfo(host.getCredentials().getUsername(), host.getDefaultPath()); return StringUtils.startsWithAny( object.getPath(), accountHomeInfo.getAccountPublicRoot().getAbsolute()); }
@Override public Path find() throws BackgroundException { final Path home = super.find(); if(home == DEFAULT_HOME) { return new MantaAccountHomeInfo(session.getHost().getCredentials().getUsername(), session.getHost().getDefaultPath()).getNormalizedHomePath(); } return home; } }
/** * @return URL */ public String get(final Host bookmark) { final Scheme scheme = bookmark.getProtocol().getScheme(); final int port = bookmark.getPort(); final String username = bookmark.getCredentials().getUsername(); final String hostname = bookmark.getHostname(); final String path = bookmark.getDefaultPath(); return this.get(scheme, port, username, hostname, path); }
@Override public String get(final Host bookmark) { switch(bookmark.getProtocol().getScheme()) { case sftp: return super.get(Scheme.ftp, bookmark.getPort(), bookmark.getCredentials().getUsername(), bookmark.getHostname(), bookmark.getDefaultPath()); } return super.get(bookmark); } }
protected boolean isUserWritable(final MantaObject object) { final MantaAccountHomeInfo account = new MantaAccountHomeInfo(host.getCredentials().getUsername(), host.getDefaultPath()); return StringUtils.startsWithAny( object.getPath(), account.getAccountPublicRoot().getAbsolute(), account.getAccountPrivateRoot().getAbsolute()); }
protected boolean isUserWritable(final Path file) { final MantaAccountHomeInfo account = new MantaAccountHomeInfo(host.getCredentials().getUsername(), host.getDefaultPath()); return file.equals(account.getAccountPublicRoot()) || file.equals(account.getAccountPrivateRoot()) || file.isChild(account.getAccountPublicRoot()) || file.isChild(account.getAccountPrivateRoot()); }
if(directory.isRoot()) { return new AttributedList<Path>(Collections.singletonList( new MantaAccountHomeInfo(session.getHost().getCredentials().getUsername(), session.getHost().getDefaultPath()).getNormalizedHomePath()));
public Credentials get() throws BackgroundException { final Host address = new HostParser(factory).get(url); final Path access = new Path(PathNormalizer.normalize(address.getDefaultPath()), EnumSet.of(Path.Type.file)); address.setDefaultPath(String.valueOf(Path.DELIMITER)); final DAVSession connection = new DAVSession(address, trust, key); connection.withListener(transcript).open(ProxyFactory.get().find(address), new DisabledHostKeyCallback(), new DisabledLoginCallback()); final InputStream in = new DAVReadFeature(connection).read(access, new TransferStatus(), new DisabledConnectionCallback()); try { final Credentials credentials = this.parse(in); connection.close(); return credentials; } finally { connection.removeListener(transcript); } }
if(Objects.equals(bookmark.getDefaultPath(), bookmark.getProtocol().getDefaultPath()) || !selected.isPathConfigurable()) { bookmark.setDefaultPath(selected.getDefaultPath());
@Action public void hostFieldDidChange(final NSNotification sender) { final String input = hostField.stringValue(); if(Scheme.isURL(input)) { final Host parsed = HostParser.parse(input); bookmark.setHostname(parsed.getHostname()); bookmark.setProtocol(parsed.getProtocol()); bookmark.setPort(parsed.getPort()); bookmark.setDefaultPath(parsed.getDefaultPath()); } else { bookmark.setHostname(input); final Credentials auto = CredentialsConfiguratorFactory.get(bookmark.getProtocol()).configure(bookmark); final Credentials credentials = bookmark.getCredentials(); credentials.setUsername(auto.getUsername()); credentials.setPassword(auto.getPassword()); credentials.setIdentity(auto.getIdentity()); credentials.setToken(auto.getToken()); credentials.setCertificate(auto.getCertificate()); } this.update(); }