com.qwazr.crawler.ftp.FtpCrawlItem Maven / Gradle / Ivy
Show all versions of qwazr-crawlers Show documentation
/*
* Copyright 2017-2020 Emmanuel Keller / QWAZR
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.qwazr.crawler.ftp;
import com.qwazr.crawler.common.CrawlItemBase;
import com.qwazr.utils.StringUtils;
import java.nio.file.Path;
import org.apache.commons.net.ftp.FTPFile;
public class FtpCrawlItem extends CrawlItemBase {
private final FTPFile ftpFile;
private final String parentPath;
private final Path localFilePath;
private FtpCrawlItem(Builder builder) {
super(builder);
this.ftpFile = builder.ftpFile;
this.parentPath = StringUtils.join(builder.parentPath, '/');
this.localFilePath = builder.localFilePath;
}
public String getUser() {
return ftpFile == null ? null : ftpFile.getUser();
}
public String getGroup() {
return ftpFile == null ? null : ftpFile.getGroup();
}
public String getName() {
return ftpFile == null ? null : ftpFile.getName();
}
public Path getLocalFilePath() {
return localFilePath;
}
static class Builder extends BaseBuilder {
private final String parentPath;
private FTPFile ftpFile;
private Path localFilePath;
protected Builder(final String currenPath, final String parentPath, final int depth) {
super(currenPath, depth);
this.parentPath = parentPath;
}
Builder ftpFile(final FTPFile ftpFile) {
this.ftpFile = ftpFile;
return me();
}
Builder localFilePath(final Path localFilePath) {
this.localFilePath = localFilePath;
return me();
}
@Override
protected Builder me() {
return this;
}
FtpCrawlItem build() {
return new FtpCrawlItem(this);
}
}
}