Search in sources :

Example 61 with KettleFileException

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).
        }
    }
}
Also used : KettleFileException(org.pentaho.di.core.exception.KettleFileException) SimpleMessageDialog(org.pentaho.di.ui.core.dialog.SimpleMessageDialog) KettleMissingPluginsException(org.pentaho.di.core.exception.KettleMissingPluginsException) Node(org.w3c.dom.Node) Document(org.w3c.dom.Document) Point(org.pentaho.di.core.gui.Point) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint) MessageBox(org.eclipse.swt.widgets.MessageBox) FileSystemException(org.apache.commons.vfs2.FileSystemException) LogSettingsDialog(org.pentaho.di.ui.spoon.dialog.LogSettingsDialog) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) SubjectDataBrowserDialog(org.pentaho.di.ui.core.dialog.SubjectDataBrowserDialog) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) ImportRulesDialog(org.pentaho.di.ui.imp.ImportRulesDialog) RepositoriesDialog(org.pentaho.di.ui.repository.RepositoriesDialog) KettlePropertiesFileDialog(org.pentaho.di.ui.core.dialog.KettlePropertiesFileDialog) EnterMappingDialog(org.pentaho.di.ui.core.dialog.EnterMappingDialog) Dialog(org.eclipse.jface.dialogs.Dialog) CheckTransProgressDialog(org.pentaho.di.ui.spoon.dialog.CheckTransProgressDialog) PreviewRowsDialog(org.pentaho.di.ui.core.dialog.PreviewRowsDialog) ShowMessageDialog(org.pentaho.di.ui.core.dialog.ShowMessageDialog) CapabilityManagerDialog(org.pentaho.di.ui.spoon.dialog.CapabilityManagerDialog) TransHopDialog(org.pentaho.di.ui.trans.dialog.TransHopDialog) TransLoadProgressDialog(org.pentaho.di.ui.trans.dialog.TransLoadProgressDialog) EnterOptionsDialog(org.pentaho.di.ui.core.dialog.EnterOptionsDialog) BrowserEnvironmentWarningDialog(org.pentaho.di.ui.core.dialog.BrowserEnvironmentWarningDialog) AuthProviderDialog(org.pentaho.di.ui.core.auth.AuthProviderDialog) EnterSearchDialog(org.pentaho.di.ui.core.dialog.EnterSearchDialog) EnterStringsDialog(org.pentaho.di.ui.core.dialog.EnterStringsDialog) VfsFileChooserDialog(org.pentaho.vfs.ui.VfsFileChooserDialog) EnterTextDialog(org.pentaho.di.ui.core.dialog.EnterTextDialog) EnterSelectionDialog(org.pentaho.di.ui.core.dialog.EnterSelectionDialog) SelectDirectoryDialog(org.pentaho.di.ui.repository.dialog.SelectDirectoryDialog) MetaStoreExplorerDialog(org.pentaho.di.ui.spoon.dialog.MetaStoreExplorerDialog) RepositoryImportProgressDialog(org.pentaho.di.ui.repository.dialog.RepositoryImportProgressDialog) SaveProgressDialog(org.pentaho.di.ui.spoon.dialog.SaveProgressDialog) AnalyseImpactProgressDialog(org.pentaho.di.ui.spoon.dialog.AnalyseImpactProgressDialog) RepositoryExportProgressDialog(org.pentaho.di.ui.repository.dialog.RepositoryExportProgressDialog) AboutDialog(org.pentaho.di.ui.core.dialog.AboutDialog) JobLoadProgressDialog(org.pentaho.di.ui.job.dialog.JobLoadProgressDialog) WizardDialog(org.eclipse.jface.wizard.WizardDialog) SimpleMessageDialog(org.pentaho.di.ui.core.dialog.SimpleMessageDialog) CheckResultDialog(org.pentaho.di.ui.core.dialog.CheckResultDialog) ShowBrowserDialog(org.pentaho.di.ui.core.dialog.ShowBrowserDialog) FileDialog(org.eclipse.swt.widgets.FileDialog) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) FileObject(org.apache.commons.vfs2.FileObject)

Aggregations

KettleFileException (org.pentaho.di.core.exception.KettleFileException)61 IOException (java.io.IOException)32 FileObject (org.apache.commons.vfs2.FileObject)30 KettleException (org.pentaho.di.core.exception.KettleException)25 FileSystemException (org.apache.commons.vfs2.FileSystemException)10 DataInputStream (java.io.DataInputStream)8 File (java.io.File)7 ResultFile (org.pentaho.di.core.ResultFile)7 SocketTimeoutException (java.net.SocketTimeoutException)6 FileInputStream (java.io.FileInputStream)5 InputStream (java.io.InputStream)5 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)5 BufferedInputStream (java.io.BufferedInputStream)4 InputStreamReader (java.io.InputStreamReader)4 GZIPInputStream (java.util.zip.GZIPInputStream)4 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)4 KettleEOFException (org.pentaho.di.core.exception.KettleEOFException)4 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)4 DataOutputStream (java.io.DataOutputStream)3 FileNotFoundException (java.io.FileNotFoundException)3