com.conveyal.gtfs.loader.URLField Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gtfs-lib Show documentation
Show all versions of gtfs-lib Show documentation
A library to load and index GTFS feeds of arbitrary size using disk-backed storage
package com.conveyal.gtfs.loader;
import com.conveyal.gtfs.error.NewGTFSError;
import com.conveyal.gtfs.error.NewGTFSErrorType;
import com.conveyal.gtfs.storage.StorageException;
import java.net.URL;
import java.sql.JDBCType;
import java.sql.PreparedStatement;
import java.sql.SQLType;
import java.util.Set;
/**
* Created by abyrd on 2017-03-31
*/
public class URLField extends Field {
public URLField(String name, Requirement requirement) {
super(name, requirement);
}
/** Check that a string can be properly parsed and is in range. */
public ValidateFieldResult validateAndConvert (String string) {
ValidateFieldResult result = cleanString(string);
try {
new URL(result.clean); // TODO call this to validate, but we can't default to zero
return result;
} catch (Exception ex) {
result.errors.add(NewGTFSError.forFeed(NewGTFSErrorType.URL_FORMAT, string));
return result;
}
}
public Set setParameter(PreparedStatement preparedStatement, int oneBasedIndex, String string) {
try {
ValidateFieldResult result = validateAndConvert(string);
preparedStatement.setString(oneBasedIndex, result.clean);
return result.errors;
} catch (Exception ex) {
throw new StorageException(ex);
}
}
@Override
public SQLType getSqlType() {
return JDBCType.VARCHAR;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy