/** * Checks whether directory used in ftp/ftps/sftp endpoint URI is relative. * Absolute path will be converted to relative path and a WARN will be printed. * @see <a href="http://camel.apache.org/ftp2.html">FTP/SFTP/FTPS Component</a> * @param ftpComponent * @param configuration */ public static void ensureRelativeFtpDirectory(Component ftpComponent, RemoteFileConfiguration configuration) { if (FileUtil.hasLeadingSeparator(configuration.getDirectoryName())) { String relativePath = FileUtil.stripLeadingSeparator(configuration.getDirectoryName()); LOG.warn(String.format("%s doesn't support absolute paths, \"%s\" will be converted to \"%s\". " + "After Camel 2.16, absolute paths will be invalid.", ftpComponent.getClass().getSimpleName(), configuration.getDirectoryName(), relativePath)); configuration.setDirectory(relativePath); configuration.setDirectoryName(relativePath); } }
basePath = FileUtil.stripLeadingSeparator(basePath); uriTemplate = FileUtil.stripLeadingSeparator(uriTemplate);
to = FileUtil.stripLeadingSeparator(to);
basePath = FileUtil.stripLeadingSeparator(basePath); uriTemplate = FileUtil.stripLeadingSeparator(uriTemplate);
path = FileUtil.stripLeadingSeparator(path); if (ObjectHelper.isNotEmpty(contextPath)) { contextPath = FileUtil.stripTrailingSeparator(contextPath); contextPath = FileUtil.stripLeadingSeparator(contextPath); if (ObjectHelper.isNotEmpty(contextPath)) { path = contextPath + "/" + path;
path = FileUtil.stripLeadingSeparator(path);
path = FileUtil.stripLeadingSeparator(path); if (ObjectHelper.isNotEmpty(contextPath)) { contextPath = FileUtil.stripTrailingSeparator(contextPath); contextPath = FileUtil.stripLeadingSeparator(contextPath); if (ObjectHelper.isNotEmpty(contextPath)) { path = contextPath + "/" + path;
path = FileUtil.stripLeadingSeparator(path); String scheme = "http"; String host = ""; if (ObjectHelper.isNotEmpty(contextPath)) { contextPath = FileUtil.stripTrailingSeparator(contextPath); contextPath = FileUtil.stripLeadingSeparator(contextPath); if (ObjectHelper.isNotEmpty(contextPath)) { path = contextPath + "/" + path;
to = FileUtil.stripLeadingSeparator(to);
private RemoteFile<SftpRemoteFile> asRemoteFile(String absolutePath, SftpRemoteFile file, String charset) { RemoteFile<SftpRemoteFile> answer = new RemoteFile<>(); answer.setCharset(charset); answer.setEndpointPath(endpointPath); answer.setFile(file); answer.setFileNameOnly(file.getFilename()); answer.setFileLength(file.getFileLength()); answer.setLastModified(file.getLastModified()); answer.setHostname(((RemoteFileConfiguration) endpoint.getConfiguration()).getHost()); answer.setDirectory(file.isDirectory()); // absolute or relative path boolean absolute = FileUtil.hasLeadingSeparator(absolutePath); answer.setAbsolute(absolute); // create a pseudo absolute name String dir = FileUtil.stripTrailingSeparator(absolutePath); String absoluteFileName = FileUtil.stripLeadingSeparator(dir + "/" + file.getFilename()); // if absolute start with a leading separator otherwise let it be relative if (absolute) { absoluteFileName = "/" + absoluteFileName; } answer.setAbsoluteFilePath(absoluteFileName); // the relative filename, skip the leading endpoint configured path String relativePath = ObjectHelper.after(absoluteFileName, endpointPath); // skip trailing / relativePath = FileUtil.stripLeadingSeparator(relativePath); answer.setRelativeFilePath(relativePath); // the file name should be the relative path answer.setFileName(answer.getRelativeFilePath()); return answer; }
fileName = FtpUtils.extractDirNameFromAbsolutePath(file.getName()); String absoluteFileName = FileUtil.stripLeadingSeparator(dir + "/" + fileName); relativePath = FileUtil.stripLeadingSeparator(relativePath); answer.setRelativeFilePath(relativePath);