use of org.knime.core.node.defaultnodesettings.SettingsModelOptionalString in project GenericKnimeNodes by genericworkflownodes.
the class MimeFileImporterNodeModel method validateSettings.
/**
* {@inheritDoc}
*/
@Override
protected void validateSettings(final NodeSettingsRO settings) throws InvalidSettingsException {
SettingsModelString tmp_filename = m_filename.createCloneWithValidatedValue(settings);
if (tmp_filename.getStringValue().isEmpty()) {
throw new InvalidSettingsException("No File selected.");
}
convertToURL(tmp_filename);
SettingsModelOptionalString tmp_file_extension = m_file_extension.createCloneWithValidatedValue(settings);
if (tmp_file_extension.isActive()) {
if (tmp_file_extension.getStringValue().equals("")) {
throw new InvalidSettingsException("No File extension (override) provided.");
} else if (MIMETypeHelper.getMIMEtypeByExtension(tmp_file_extension.getStringValue()) == null) {
throw new InvalidSettingsException("No MIME type registered for file extension: " + tmp_file_extension.getStringValue());
}
} else if (MIMETypeHelper.getMIMEtype(tmp_filename.getStringValue()) == null) {
throw new InvalidSettingsException("File of unknown MIME type selected: " + tmp_filename.getStringValue());
}
}
use of org.knime.core.node.defaultnodesettings.SettingsModelOptionalString in project GenericKnimeNodes by genericworkflownodes.
the class ListMimeFileImporterNodeModel method validateSettings.
/**
* {@inheritDoc}
*/
@Override
protected void validateSettings(final NodeSettingsRO settings) throws InvalidSettingsException {
SettingsModelStringArray tmp_filenames = m_filenames.createCloneWithValidatedValue(settings);
if (tmp_filenames == null || tmp_filenames.getStringArrayValue().length == 0) {
throw new InvalidSettingsException("No Files selected.");
}
SettingsModelOptionalString tmp_file_extension = m_file_extension.createCloneWithValidatedValue(settings);
if (tmp_file_extension.isActive()) {
if (tmp_file_extension.getStringValue().equals("")) {
throw new InvalidSettingsException("No File extension (override) provided.");
} else if (MIMETypeHelper.getMIMEtypeByExtension(tmp_file_extension.getStringValue()) == null) {
throw new InvalidSettingsException("No MIMEtype registered for file extension: " + tmp_file_extension.getStringValue());
}
} else {
List<String> mts = new ArrayList<String>();
String mt = null;
for (String filename : tmp_filenames.getStringArrayValue()) {
mt = MIMETypeHelper.getMIMEtype(filename);
if (mt == null) {
throw new InvalidSettingsException("Files of unknown MIMEtype selected: " + filename);
}
mts.add(mt);
}
for (String mimeType : mts) {
if (!mimeType.equals(mt)) {
throw new InvalidSettingsException("Files with mixed MIMEType loaded");
}
}
}
}
Aggregations