use of org.pentaho.di.core.exception.KettleFileException in project pentaho-kettle by pentaho.
the class Spoon method openFile.
public void openFile(String filename, boolean importfile) {
// Open the XML and see what's in there.
// We expect a single <transformation> or <job> root at this time...
// does the file exist? If not, show an error dialog
boolean fileExists = false;
try {
final FileObject file = KettleVFS.getFileObject(filename);
fileExists = file.exists();
} catch (final KettleFileException | FileSystemException e) {
// nothing to do, null fileObject will be handled below
}
if (StringUtils.isBlank(filename) || !fileExists) {
final Dialog dlg = new SimpleMessageDialog(shell, BaseMessages.getString(PKG, "Spoon.Dialog.MissingRecentFile.Title"), BaseMessages.getString(PKG, "Spoon.Dialog.MissingRecentFile.Message", getFileType(filename).toLowerCase()), MessageDialog.ERROR, BaseMessages.getString(PKG, "System.Button.Close"), MISSING_RECENT_DLG_WIDTH, SimpleMessageDialog.BUTTON_WIDTH);
dlg.open();
return;
}
boolean loaded = false;
FileListener listener = null;
Node root = null;
// match by extension first
int idx = filename.lastIndexOf('.');
if (idx != -1) {
for (FileListener li : fileListeners) {
if (li.accepts(filename)) {
listener = li;
break;
}
}
}
// types.
try {
Document document = XMLHandler.loadXMLFile(filename);
root = document.getDocumentElement();
} catch (KettleXMLException e) {
if (log.isDetailed()) {
log.logDetailed(BaseMessages.getString(PKG, "Spoon.File.Xml.Parse.Error"));
}
}
// as XML
if (listener == null && root != null) {
for (FileListener li : fileListeners) {
if (li.acceptsXml(root.getNodeName())) {
listener = li;
break;
}
}
}
//
if (!Utils.isEmpty(filename)) {
if (listener != null) {
try {
loaded = listener.open(root, filename, importfile);
} catch (KettleMissingPluginsException e) {
log.logError(e.getMessage(), e);
}
}
if (!loaded) {
// Give error back
hideSplash();
MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
mb.setMessage(BaseMessages.getString(PKG, "Spoon.UnknownFileType.Message", filename));
mb.setText(BaseMessages.getString(PKG, "Spoon.UnknownFileType.Title"));
mb.open();
} else {
// set variables in the newly loaded
applyVariables();
// transformation(s) and job(s).
}
}
}
Aggregations