Search in sources :

Example 11 with FileInputList

use of org.pentaho.di.core.fileinput.FileInputList in project pentaho-kettle by pentaho.

the class GetXMLDataDialog method get.

private void get() {
    InputStream is = null;
    try {
        GetXMLDataMeta meta = new GetXMLDataMeta();
        getInfo(meta);
        // check if the path is given
        if (!checkLoopXPath(meta)) {
            return;
        }
        int clearFields = SWT.YES;
        if (wFields.nrNonEmpty() > 0) {
            MessageBox messageBox = new MessageBox(shell, SWT.YES | SWT.NO | SWT.CANCEL | SWT.ICON_QUESTION);
            messageBox.setMessage(BaseMessages.getString(PKG, "GetXMLDataDialog.ClearFieldList.DialogMessage"));
            messageBox.setText(BaseMessages.getString(PKG, "GetXMLDataDialog.ClearFieldList.DialogTitle"));
            clearFields = messageBox.open();
            if (clearFields == SWT.CANCEL) {
                return;
            }
        }
        if (meta.isInFields()) {
            if (meta.isReadUrl()) {
                // Read URL
                String url = XMLSource;
                if (url == null) {
                    EnterStringDialog enterStringDialog = new EnterStringDialog(shell, "", BaseMessages.getString(PKG, "GetXMLDataDialog.AskURL.Title"), BaseMessages.getString(PKG, "GetXMLDataDialog.AskURL.Title"));
                    url = enterStringDialog.open();
                }
                populateFields(meta, url, true, true, clearFields);
            } else if (meta.getIsAFile()) {
                // Read file
                String str = XMLSource;
                if (str == null) {
                    FileDialog dialog = new FileDialog(shell, SWT.OPEN);
                    dialog.setFilterExtensions(new String[] { "*.xml;*.XML", "*" });
                    dialog.setFilterNames(new String[] { BaseMessages.getString(PKG, "System.FileType.XMLFiles"), BaseMessages.getString(PKG, "System.FileType.AllFiles") });
                    if (dialog.open() != null) {
                        str = dialog.getFilterPath() + System.getProperty("file.separator") + dialog.getFileName();
                    }
                }
                populateFields(meta, str, false, false, clearFields);
            } else {
                // Read xml
                String xml = XMLSource;
                if (xml == null) {
                    EnterTextDialog d = new EnterTextDialog(shell, BaseMessages.getString(PKG, "GetXMLDataDialog.AskXML.Title"), BaseMessages.getString(PKG, "GetXMLDataDialog.AskXML.Message"), null);
                    xml = d.open();
                }
                populateFields(meta, xml, true, false, clearFields);
            }
        } else {
            FileInputList inputList = meta.getFiles(transMeta);
            if (inputList.getFiles().size() > 0) {
                populateFields(meta, KettleVFS.getFilename(inputList.getFile(0)), false, false, clearFields);
            }
        }
    } catch (Exception e) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "GetXMLDataDialog.ErrorParsingData.DialogTitle"), BaseMessages.getString(PKG, "GetXMLDataDialog.ErrorParsingData.DialogMessage"), e);
    } finally {
        try {
            if (is != null) {
                is.close();
            }
        } catch (Exception e) {
        /* Ignore */
        }
    }
}
Also used : GetXMLDataMeta(org.pentaho.di.trans.steps.getxmldata.GetXMLDataMeta) InputStream(java.io.InputStream) EnterTextDialog(org.pentaho.di.ui.core.dialog.EnterTextDialog) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) EnterStringDialog(org.pentaho.di.ui.core.dialog.EnterStringDialog) FileDialog(org.eclipse.swt.widgets.FileDialog) FileInputList(org.pentaho.di.core.fileinput.FileInputList) KettleException(org.pentaho.di.core.exception.KettleException) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 12 with FileInputList

use of org.pentaho.di.core.fileinput.FileInputList in project pentaho-kettle by pentaho.

the class GetXMLDataDialog method getLoopPathList.

private void getLoopPathList() {
    try {
        GetXMLDataMeta meta = new GetXMLDataMeta();
        getInfo(meta);
        if (meta.isInFields()) {
            if (meta.isReadUrl()) {
                // Read URL
                String url = XMLSource;
                if (url == null) {
                    EnterStringDialog d = new EnterStringDialog(shell, "", BaseMessages.getString(PKG, "GetXMLDataDialog.AskURL.Title"), BaseMessages.getString(PKG, "GetXMLDataDialog.AskURL.Message"));
                    url = d.open();
                }
                populateLoopPaths(meta, url, true, true);
            } else if (meta.getIsAFile()) {
                // Read file
                String str = XMLSource;
                if (str == null) {
                    FileDialog dialog = new FileDialog(shell, SWT.OPEN);
                    dialog.setFilterExtensions(new String[] { "*.xml;*.XML", "*" });
                    dialog.setFilterNames(new String[] { BaseMessages.getString(PKG, "System.FileType.XMLFiles"), BaseMessages.getString(PKG, "System.FileType.AllFiles") });
                    if (dialog.open() != null) {
                        str = dialog.getFilterPath() + System.getProperty("file.separator") + dialog.getFileName();
                    }
                    populateLoopPaths(meta, str, false, false);
                }
            } else {
                // Read xml
                String xml = XMLSource;
                if (xml == null) {
                    EnterTextDialog d = new EnterTextDialog(shell, BaseMessages.getString(PKG, "GetXMLDataDialog.AskXML.Title"), BaseMessages.getString(PKG, "GetXMLDataDialog.AskXML.Message"), null);
                    xml = d.open();
                }
                populateLoopPaths(meta, xml, true, false);
            }
        } else {
            FileInputList fileinputList = meta.getFiles(transMeta);
            if (fileinputList.nrOfFiles() > 0) {
                if (fileinputList.getFile(0).exists()) {
                    populateLoopPaths(meta, KettleVFS.getFilename(fileinputList.getFile(0)), false, false);
                } else {
                    // The file not exists !
                    throw new KettleException(BaseMessages.getString(PKG, "GetXMLDataDialog.Exception.FileDoesNotExist", KettleVFS.getFilename(fileinputList.getFile(0))));
                }
            } else {
                // No file specified
                MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
                mb.setMessage(BaseMessages.getString(PKG, "GetXMLDataDialog.FilesMissing.DialogMessage"));
                mb.setText(BaseMessages.getString(PKG, "System.Dialog.Error.Title"));
                mb.open();
            }
        }
    } catch (Exception e) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "GetXMLDataDialog.UnableToGetListOfPaths.Title"), BaseMessages.getString(PKG, "GetXMLDataDialog.UnableToGetListOfPaths.Message"), e);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) GetXMLDataMeta(org.pentaho.di.trans.steps.getxmldata.GetXMLDataMeta) EnterTextDialog(org.pentaho.di.ui.core.dialog.EnterTextDialog) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) EnterStringDialog(org.pentaho.di.ui.core.dialog.EnterStringDialog) FileDialog(org.eclipse.swt.widgets.FileDialog) FileInputList(org.pentaho.di.core.fileinput.FileInputList) KettleException(org.pentaho.di.core.exception.KettleException) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 13 with FileInputList

use of org.pentaho.di.core.fileinput.FileInputList in project pentaho-kettle by pentaho.

the class MessagesSourceCrawler method crawl.

public void crawl() throws Exception {
    for (final String sourceDirectory : sourceDirectories) {
        FileObject folder = KettleVFS.getFileObject(sourceDirectory);
        FileObject[] javaFiles = folder.findFiles(new FileSelector() {

            @Override
            public boolean traverseDescendents(FileSelectInfo info) throws Exception {
                return true;
            }

            @Override
            public boolean includeFile(FileSelectInfo info) throws Exception {
                return info.getFile().getName().getExtension().equals("java");
            }
        });
        for (FileObject javaFile : javaFiles) {
            /**
             * We don't want the Messages.java files, there is nothing in there for us.
             */
            boolean skip = false;
            for (String filename : filesToAvoid) {
                if (javaFile.getName().getBaseName().equals(filename)) {
                    skip = true;
                }
            }
            if (skip) {
                // don't process this file.
                continue;
            }
            // For each of these files we look for keys...
            // 
            lookForOccurrencesInFile(sourceDirectory, javaFile);
        }
    }
    // 
    for (SourceCrawlerXMLFolder xmlFolder : xmlFolders) {
        String[] xmlDirs = { xmlFolder.getFolder() };
        String[] xmlMasks = { xmlFolder.getWildcard() };
        String[] xmlReq = { "N" };
        // search sub-folders too
        boolean[] xmlSubdirs = { true };
        FileInputList xulFileInputList = FileInputList.createFileList(new Variables(), xmlDirs, xmlMasks, xmlReq, xmlSubdirs);
        for (FileObject fileObject : xulFileInputList.getFiles()) {
            try {
                Document doc = XMLHandler.loadXMLFile(fileObject);
                // 
                for (SourceCrawlerXMLElement xmlElement : xmlFolder.getElements()) {
                    addLabelOccurrences(xmlFolder.getDefaultSourceFolder(), fileObject, doc.getElementsByTagName(xmlElement.getSearchElement()), xmlFolder.getKeyPrefix(), xmlElement.getKeyTag(), xmlElement.getKeyAttribute(), xmlFolder.getDefaultPackage(), xmlFolder.getPackageExceptions());
                }
            } catch (KettleXMLException e) {
                log.logError("Unable to open XUL / XML document: " + fileObject);
            }
        }
    }
}
Also used : FileSelector(org.apache.commons.vfs2.FileSelector) Document(org.w3c.dom.Document) FileSelectInfo(org.apache.commons.vfs2.FileSelectInfo) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) IOException(java.io.IOException) Variables(org.pentaho.di.core.variables.Variables) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) FileObject(org.apache.commons.vfs2.FileObject) FileInputList(org.pentaho.di.core.fileinput.FileInputList)

Example 14 with FileInputList

use of org.pentaho.di.core.fileinput.FileInputList in project pentaho-kettle by pentaho.

the class XMLInputMeta method check.

public void check(List<CheckResultInterface> remarks, TransMeta transMeta, StepMeta stepMeta, RowMetaInterface prev, String[] input, String[] output, RowMetaInterface info, VariableSpace space, Repository repository, IMetaStore metaStore) {
    CheckResult cr;
    // See if we get input...
    if (input.length > 0) {
        cr = new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, "XMLInputMeta.CheckResult.NoInputExpected"), stepMeta);
        remarks.add(cr);
    } else {
        cr = new CheckResult(CheckResultInterface.TYPE_RESULT_OK, BaseMessages.getString(PKG, "XMLInputMeta.CheckResult.NoInput"), stepMeta);
        remarks.add(cr);
    }
    FileInputList fileInputList = getFiles(transMeta);
    // String files[] = getFiles();
    if (fileInputList == null || fileInputList.getFiles().size() == 0) {
        cr = new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, "XMLInputMeta.CheckResult.NoFiles"), stepMeta);
        remarks.add(cr);
    } else {
        cr = new CheckResult(CheckResultInterface.TYPE_RESULT_OK, BaseMessages.getString(PKG, "XMLInputMeta.CheckResult.FilesOk", "" + fileInputList.getFiles().size()), stepMeta);
        remarks.add(cr);
    }
}
Also used : CheckResult(org.pentaho.di.core.CheckResult) FileInputList(org.pentaho.di.core.fileinput.FileInputList)

Example 15 with FileInputList

use of org.pentaho.di.core.fileinput.FileInputList in project pentaho-kettle by pentaho.

the class GetXMLDataMeta method exportResources.

/**
 * Since the exported transformation that runs this will reside in a ZIP file, we can't reference files relatively. So
 * what this does is turn the name of files into absolute paths OR it simply includes the resource in the ZIP file.
 * For now, we'll simply turn it into an absolute path and pray that the file is on a shared drive or something like
 * that.
 *
 * @param space
 *          the variable space to use
 * @param definitions
 * @param resourceNamingInterface
 * @param repository
 *          The repository to optionally load other resources from (to be converted to XML)
 * @param metaStore
 *          the metaStore in which non-kettle metadata could reside.
 *
 * @return the filename of the exported resource
 */
public String exportResources(VariableSpace space, Map<String, ResourceDefinition> definitions, ResourceNamingInterface resourceNamingInterface, Repository repository, IMetaStore metaStore) throws KettleException {
    try {
        // The object that we're modifying here is a copy of the original!
        // So let's change the filename from relative to absolute by grabbing the file object...
        // In case the name of the file comes from previous steps, forget about this!
        // 
        List<String> newFilenames = new ArrayList<String>();
        if (!isInFields()) {
            FileInputList fileList = getFiles(space);
            if (fileList.getFiles().size() > 0) {
                for (FileObject fileObject : fileList.getFiles()) {
                    // 
                    if (fileObject.exists()) {
                        // Convert to an absolute path and add it to the list.
                        // 
                        newFilenames.add(fileObject.getName().getPath());
                    }
                }
                // Still here: set a new list of absolute filenames!
                // 
                fileName = newFilenames.toArray(new String[newFilenames.size()]);
                // all null since converted to absolute path.
                fileMask = new String[newFilenames.size()];
                // all null, turn to "Y" :
                fileRequired = new String[newFilenames.size()];
                for (int i = 0; i < newFilenames.size(); i++) {
                    fileRequired[i] = "Y";
                }
            }
        }
        return null;
    } catch (Exception e) {
        throw new KettleException(e);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) ArrayList(java.util.ArrayList) FileObject(org.apache.commons.vfs2.FileObject) FileInputList(org.pentaho.di.core.fileinput.FileInputList) KettleException(org.pentaho.di.core.exception.KettleException) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) KettleStepException(org.pentaho.di.core.exception.KettleStepException)

Aggregations

FileInputList (org.pentaho.di.core.fileinput.FileInputList)54 KettleException (org.pentaho.di.core.exception.KettleException)25 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)22 MessageBox (org.eclipse.swt.widgets.MessageBox)18 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)16 CheckResult (org.pentaho.di.core.CheckResult)14 FileObject (org.apache.commons.vfs2.FileObject)12 FileDialog (org.eclipse.swt.widgets.FileDialog)11 EnterSelectionDialog (org.pentaho.di.ui.core.dialog.EnterSelectionDialog)11 Shell (org.eclipse.swt.widgets.Shell)10 RowMeta (org.pentaho.di.core.row.RowMeta)10 CTabFolder (org.eclipse.swt.custom.CTabFolder)9 ModifyEvent (org.eclipse.swt.events.ModifyEvent)9 ModifyListener (org.eclipse.swt.events.ModifyListener)9 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)9 SelectionEvent (org.eclipse.swt.events.SelectionEvent)9 ShellAdapter (org.eclipse.swt.events.ShellAdapter)9 ShellEvent (org.eclipse.swt.events.ShellEvent)9 FormAttachment (org.eclipse.swt.layout.FormAttachment)9 FormData (org.eclipse.swt.layout.FormData)9