Search in sources :

Example 66 with FileObject

use of org.apache.commons.vfs2.FileObject in project pentaho-kettle by pentaho.

the class VFSFileProvider method writeFile.

/**
 * @param inputStream
 * @param destDir
 * @param path
 * @param overwrite
 * @return
 * @throws FileException
 */
@Override
public VFSFile writeFile(InputStream inputStream, VFSFile destDir, String path, boolean overwrite) throws FileException {
    FileObject fileObject = null;
    try {
        fileObject = KettleVFS.getFileObject(path, new Variables(), VFSHelper.getOpts(destDir.getPath(), destDir.getConnection()));
    } catch (KettleException ke) {
        throw new FileException();
    }
    if (fileObject != null) {
        try (OutputStream outputStream = fileObject.getContent().getOutputStream()) {
            IOUtils.copy(inputStream, outputStream);
            outputStream.flush();
            return VFSFile.create(destDir.getPath(), fileObject, destDir.getConnection(), destDir.getDomain());
        } catch (IOException e) {
            return null;
        }
    }
    return null;
}
Also used : Variables(org.pentaho.di.core.variables.Variables) KettleException(org.pentaho.di.core.exception.KettleException) FileException(org.pentaho.di.plugins.fileopensave.api.providers.exception.FileException) KettleFileException(org.pentaho.di.core.exception.KettleFileException) OutputStream(java.io.OutputStream) FileObject(org.apache.commons.vfs2.FileObject) IOException(java.io.IOException)

Example 67 with FileObject

use of org.apache.commons.vfs2.FileObject in project pentaho-kettle by pentaho.

the class VFSFileProvider method getFile.

@Override
public VFSFile getFile(VFSFile file) {
    try {
        FileObject fileObject = KettleVFS.getFileObject(file.getPath(), new Variables(), VFSHelper.getOpts(file.getPath(), file.getConnection()));
        if (!fileObject.exists()) {
            return null;
        }
        String parent = null;
        if (fileObject.getParent() != null && fileObject.getParent().getName() != null) {
            parent = fileObject.getParent().getName().getURI();
        } else {
            parent = fileObject.getURL().getProtocol() + "://";
        }
        if (fileObject.getType().equals(FileType.FOLDER)) {
            return VFSDirectory.create(parent, fileObject, null, file.getDomain());
        } else {
            return VFSFile.create(parent, fileObject, null, file.getDomain());
        }
    } catch (KettleFileException | FileSystemException e) {
    // File does not exist
    }
    return null;
}
Also used : Variables(org.pentaho.di.core.variables.Variables) KettleFileException(org.pentaho.di.core.exception.KettleFileException) FileSystemException(org.apache.commons.vfs2.FileSystemException) FileObject(org.apache.commons.vfs2.FileObject)

Example 68 with FileObject

use of org.apache.commons.vfs2.FileObject in project pentaho-kettle by pentaho.

the class VFSFileProvider method doMove.

/**
 * @param file
 * @param newPath
 * @param overwrite
 * @return
 */
private VFSFile doMove(VFSFile file, String newPath, boolean overwrite) {
    try {
        FileObject fileObject = KettleVFS.getFileObject(file.getPath(), new Variables(), VFSHelper.getOpts(file.getPath(), file.getConnection()));
        FileObject renameObject = KettleVFS.getFileObject(newPath, new Variables(), VFSHelper.getOpts(file.getPath(), file.getConnection()));
        if (overwrite && renameObject.exists()) {
            renameObject.delete();
        }
        fileObject.moveTo(renameObject);
        if (file instanceof VFSDirectory) {
            return VFSDirectory.create(renameObject.getParent().getPublicURIString(), renameObject, file.getConnection(), file.getDomain());
        } else {
            return VFSFile.create(renameObject.getParent().getPublicURIString(), renameObject, file.getConnection(), file.getDomain());
        }
    } catch (KettleFileException | FileSystemException e) {
        return null;
    }
}
Also used : Variables(org.pentaho.di.core.variables.Variables) VFSDirectory(org.pentaho.di.plugins.fileopensave.providers.vfs.model.VFSDirectory) KettleFileException(org.pentaho.di.core.exception.KettleFileException) FileSystemException(org.apache.commons.vfs2.FileSystemException) FileObject(org.apache.commons.vfs2.FileObject)

Example 69 with FileObject

use of org.apache.commons.vfs2.FileObject in project pentaho-kettle by pentaho.

the class PartitionerPluginType method registerXmlPlugins.

protected void registerXmlPlugins() throws KettlePluginException {
    for (PluginFolderInterface folder : pluginFolders) {
        if (folder.isPluginXmlFolder()) {
            List<FileObject> pluginXmlFiles = findPluginXmlFiles(folder.getFolder());
            for (FileObject file : pluginXmlFiles) {
                try {
                    Document document = XMLHandler.loadXMLFile(file);
                    Node pluginNode = XMLHandler.getSubNode(document, "partitioner-plugin");
                    if (pluginNode != null) {
                        registerPluginFromXmlResource(pluginNode, KettleVFS.getFilename(file.getParent()), this.getClass(), false, file.getParent().getURL());
                    }
                } catch (Exception e) {
                    // We want to report this plugin.xml error, perhaps an XML typo or something like that...
                    // 
                    log.logError("Error found while reading partitioning plugin.xml file: " + file.getName().toString(), e);
                }
            }
        }
    }
}
Also used : Node(org.w3c.dom.Node) FileObject(org.apache.commons.vfs2.FileObject) Document(org.w3c.dom.Document) KettlePluginException(org.pentaho.di.core.exception.KettlePluginException)

Example 70 with FileObject

use of org.apache.commons.vfs2.FileObject in project pentaho-kettle by pentaho.

the class JobEntryPluginType method registerXmlPlugins.

protected void registerXmlPlugins() throws KettlePluginException {
    for (PluginFolderInterface folder : pluginFolders) {
        if (folder.isPluginXmlFolder()) {
            List<FileObject> pluginXmlFiles = findPluginXmlFiles(folder.getFolder());
            for (FileObject file : pluginXmlFiles) {
                try {
                    Document document = XMLHandler.loadXMLFile(file);
                    Node pluginNode = XMLHandler.getSubNode(document, "plugin");
                    if (pluginNode != null) {
                        registerPluginFromXmlResource(pluginNode, KettleVFS.getFilename(file.getParent()), this.getClass(), false, file.getParent().getURL());
                    }
                } catch (Exception e) {
                    // We want to report this plugin.xml error, perhaps an XML typo or something like that...
                    // 
                    log.logError("Error found while reading job entry plugin.xml file: " + file.getName().toString(), e);
                }
            }
        }
    }
}
Also used : Node(org.w3c.dom.Node) FileObject(org.apache.commons.vfs2.FileObject) Document(org.w3c.dom.Document) KettlePluginException(org.pentaho.di.core.exception.KettlePluginException)

Aggregations

FileObject (org.apache.commons.vfs2.FileObject)646 KettleException (org.pentaho.di.core.exception.KettleException)206 IOException (java.io.IOException)203 FileSystemException (org.apache.commons.vfs2.FileSystemException)173 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)104 KettleFileException (org.pentaho.di.core.exception.KettleFileException)97 Test (org.junit.Test)82 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)68 File (java.io.File)60 InputStream (java.io.InputStream)48 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)37 KettleStepException (org.pentaho.di.core.exception.KettleStepException)36 ArrayList (java.util.ArrayList)35 ResultFile (org.pentaho.di.core.ResultFile)33 ILanguageImpl (org.metaborg.core.language.ILanguageImpl)32 Result (org.pentaho.di.core.Result)32 OutputStream (java.io.OutputStream)29 FileName (org.apache.commons.vfs2.FileName)29 KettleValueException (org.pentaho.di.core.exception.KettleValueException)29 IStrategoTerm (org.spoofax.interpreter.terms.IStrategoTerm)28