Example usage for org.apache.commons.vfs FileObject getName

List of usage examples for org.apache.commons.vfs FileObject getName

Introduction

In this page you can find the example usage for org.apache.commons.vfs FileObject getName.

Prototype

public FileName getName();

Source Link

Document

Returns the name of this file.

Usage

From source file:com.panet.imeta.job.entries.copyfiles.JobEntryCopyFiles.java

private boolean CreateDestinationFolder(FileObject filefolder) {
    LogWriter log = LogWriter.getInstance();
    FileObject folder = null;
    try {//from ww w . j  a v a 2 s.  c  o m
        if (destination_is_a_file)
            folder = filefolder.getParent();
        else
            folder = filefolder;

        if (!folder.exists()) {
            if (create_destination_folder) {
                if (log.isDetailed())
                    log.logDetailed("Folder", "Folder  " + folder.getName() + " does not exist !");
                folder.createFolder();
                if (log.isDetailed())
                    log.logDetailed("Folder", "Folder parent was created.");
            } else {
                log.logError("Folder", "Folder  " + folder.getName() + " does not exist !");
                return false;
            }
        }
        return true;
    } catch (Exception e) {
        log.logError(toString(), "Couldn't created parent folder " + folder.getName());

    } finally {
        if (folder != null) {
            try {
                folder.close();
            } catch (Exception ex) {
            }
            ;
        }
    }
    return false;
}

From source file:brainflow.app.toplevel.BrainFlow.java

public IImageSource createDataSource(String path) throws BrainFlowException {

    try {//from  w ww .ja v a2 s .  co m
        FileObject fobj = VFS.getManager().resolveFile(path);

        if (!BrainIO.isSupportedImageFile(fobj.getName().getBaseName())) {
            throw new BrainFlowException(
                    "argument " + fobj.getName().getBaseName() + " is not a valid image path");
        }

        java.util.List<IImageSource<IImageData>> sources = BrainIO.loadDataSources(new FileObject[] { fobj });
        if (sources.size() > 1) {
            log.warning("multiple matching files for path " + path + "... using first match.");
        }

        return sources.get(0);

    } catch (FileSystemException e) {
        throw new BrainFlowException(e.getMessage(), e);
    }

}

From source file:net.sf.vfsjfilechooser.plaf.basic.BasicVFSFileChooserUI.java

public void changeDirectory(FileObject dir) {
    VFSJFileChooser fc = getFileChooser();

    fc.setCurrentDirectory(dir);// ww w  . java2 s .com

    if ((fc.getFileSelectionMode() == SELECTION_MODE.FILES_AND_DIRECTORIES)
            && fc.getFileSystemView().isFileSystem(dir)) {
        setFileName(dir.getName().getBaseName());
    }
}

From source file:com.panet.imeta.job.entries.ssh2put.JobEntrySSH2PUT.java

public Result execute(Result previousResult, int nr, Repository rep, Job parentJob) {
    LogWriter log = LogWriter.getInstance();
    Result result = previousResult;
    result.setResult(false);//from   w  ww .ja v  a2 s  .  c o m

    try {

        // Get real variable value
        String realServerName = environmentSubstitute(serverName);
        int realServerPort = Const.toInt(environmentSubstitute(serverPort), 22);
        String realUserName = environmentSubstitute(userName);
        String realServerPassword = environmentSubstitute(password);
        // Proxy Host
        String realProxyHost = environmentSubstitute(httpproxyhost);
        int realProxyPort = Const.toInt(environmentSubstitute(httpproxyport), 22);
        String realproxyUserName = environmentSubstitute(httpproxyusername);
        String realProxyPassword = environmentSubstitute(httpProxyPassword);
        // Key file
        String realKeyFilename = environmentSubstitute(keyFilename);
        String relKeyFilepass = environmentSubstitute(keyFilePass);
        // Source files
        String realLocalDirectory = environmentSubstitute(localDirectory);
        String realwildcard = environmentSubstitute(wildcard);
        // Remote destination
        String realftpDirectory = environmentSubstitute(ftpDirectory);
        // Destination folder (Move to)
        String realDestinationFolder = environmentSubstitute(destinationfolder);

        try {
            // Remote source 
            realftpDirectory = FTPUtils.normalizePath(realftpDirectory);
            // Destination folder (Move to)
            realDestinationFolder = FTPUtils.normalizePath(realDestinationFolder);
        } catch (Exception e) {
            log.logError(toString(), Messages.getString("JobSSH2PUT.Log.CanNotNormalizePath", e.getMessage()));
            result.setNrErrors(1);
            return result;
        }

        // Check for mandatory fields
        boolean mandatoryok = true;
        if (Const.isEmpty(realServerName)) {
            mandatoryok = false;
            log.logError(toString(), Messages.getString("JobSSH2PUT.Log.ServernameMissing"));
        }
        if (usehttpproxy) {
            if (Const.isEmpty(realProxyHost)) {
                mandatoryok = false;
                log.logError(toString(), Messages.getString("JobSSH2PUT.Log.HttpProxyhostMissing"));
            }
        }
        if (publicpublickey) {
            if (Const.isEmpty(realKeyFilename)) {
                mandatoryok = false;
                log.logError(toString(), Messages.getString("JobSSH2PUT.Log.KeyFileMissing"));
            } else {
                // Let's check if folder exists...
                if (!KettleVFS.fileExists(realKeyFilename)) {
                    mandatoryok = false;
                    log.logError(toString(), Messages.getString("JobSSH2PUT.Log.KeyFileNotExist"));
                }
            }
        }

        if (Const.isEmpty(realLocalDirectory)) {
            mandatoryok = false;
            log.logError(toString(), Messages.getString("JobSSH2PUT.Log.LocalFolderMissing"));
        }
        if (afterFtpPut.equals("move_file")) {
            if (Const.isEmpty(realDestinationFolder)) {
                mandatoryok = false;
                log.logError(toString(), Messages.getString("JobSSH2PUT.Log.DestinatFolderMissing"));
            } else {
                // Let's check if folder exists...
                if (!KettleVFS.fileExists(realDestinationFolder)) {
                    mandatoryok = false;
                    log.logError(toString(),
                            Messages.getString("JobSSH2PUT.Log.DestinatFolderNotExist", realDestinationFolder));
                }
            }
        }

        if (mandatoryok) {

            Connection conn = null;
            SFTPv3Client client = null;
            boolean good = true;

            int nbfilestoput = 0;
            int nbput = 0;
            int nbrerror = 0;

            try {
                // Create a connection instance 
                conn = getConnection(realServerName, realServerPort, realProxyHost, realProxyPort,
                        realproxyUserName, realProxyPassword);

                if (timeout > 0) {
                    // Use timeout
                    // Cache Host Key
                    if (cachehostkey)
                        conn.connect(new SimpleVerifier(database), 0, timeout * 1000);
                    else
                        conn.connect(null, 0, timeout * 1000);

                } else {
                    // Cache Host Key
                    if (cachehostkey)
                        conn.connect(new SimpleVerifier(database));
                    else
                        conn.connect();
                }

                // Authenticate

                boolean isAuthenticated = false;
                if (publicpublickey) {
                    String keyContent = KettleVFS.getTextFileContent(realKeyFilename, Const.XML_ENCODING);
                    isAuthenticated = conn.authenticateWithPublicKey(realUserName, keyContent.toCharArray(),
                            relKeyFilepass);
                } else {
                    isAuthenticated = conn.authenticateWithPassword(realUserName, realServerPassword);
                }

                // LET'S CHECK AUTHENTICATION ...
                if (isAuthenticated == false)
                    log.logError(toString(), Messages.getString("JobSSH2PUT.Log.AuthenticationFailed"));
                else {
                    if (log.isBasic())
                        log.logBasic(toString(),
                                Messages.getString("JobSSH2PUT.Log.Connected", serverName, userName));

                    client = new SFTPv3Client(conn);

                    if (log.isDetailed())
                        log.logDetailed(toString(), Messages.getString("JobSSH2PUT.Log.ProtocolVersion",
                                "" + client.getProtocolVersion()));

                    // Check if remote directory exists
                    if (!Const.isEmpty(realftpDirectory)) {
                        if (!sshDirectoryExists(client, realftpDirectory)) {
                            good = false;
                            if (createRemoteFolder) {
                                good = CreateRemoteFolder(client, realftpDirectory);
                                if (good)
                                    log.logBasic(toString(),
                                            Messages.getString("JobSSH2PUT.Log.RemoteDirectoryCreated"));

                            } else
                                log.logError(toString(), Messages
                                        .getString("JobSSH2PUT.Log.RemoteDirectoryNotExist", realftpDirectory));
                        } else if (log.isDetailed())
                            log.logDetailed(toString(), Messages
                                    .getString("JobSSH2PUT.Log.RemoteDirectoryExist", realftpDirectory));
                    }

                    if (good) {
                        // Get files list from local folder (source)
                        List<FileObject> myFileList = getFiles(realLocalDirectory);

                        // Prepare Pattern for wildcard
                        Pattern pattern = null;
                        if (!Const.isEmpty(realwildcard))
                            pattern = Pattern.compile(realwildcard);

                        // Let's put files now ...
                        // Get the files in the list
                        for (int i = 0; i < myFileList.size() && !parentJob.isStopped(); i++) {
                            FileObject myFile = myFileList.get(i);
                            String localFilename = myFile.toString();
                            String remoteFilename = myFile.getName().getBaseName();

                            // do we have a target directory?
                            if (!Const.isEmpty(realftpDirectory))
                                remoteFilename = realftpDirectory + FTPUtils.FILE_SEPARATOR + remoteFilename;

                            boolean getIt = true;

                            // First see if the file matches the regular expression!
                            if (pattern != null) {
                                Matcher matcher = pattern.matcher(remoteFilename);
                                getIt = matcher.matches();
                            }

                            if (getIt) {
                                nbfilestoput++;

                                boolean putok = true;

                                if ((onlyGettingNewFiles == false) || (onlyGettingNewFiles == true)
                                        && !sshFileExists(client, remoteFilename)) {
                                    putok = putFile(myFile, remoteFilename, client);
                                    if (!putok) {
                                        nbrerror++;
                                        log.logError(toString(), Messages.getString(
                                                "JobSSH2PUT.Log.Error.CanNotPutFile", localFilename));
                                    } else {
                                        nbput++;
                                    }
                                }
                                if (putok && !afterFtpPut.equals("do_nothing")) {
                                    deleteOrMoveFiles(myFile, realDestinationFolder);
                                }
                            }
                        }
                        /********************************RESULT ********************/
                        if (log.isDetailed()) {
                            log.logDetailed(toString(),
                                    Messages.getString("JobSSH2PUT.Log.Result.JobEntryEnd1"));
                            log.logDetailed(toString(),
                                    Messages.getString("JobSSH2PUT.Log.Result.TotalFiles", "" + nbfilestoput));
                            log.logDetailed(toString(),
                                    Messages.getString("JobSSH2PUT.Log.Result.TotalFilesPut", "" + nbput));
                            log.logDetailed(toString(),
                                    Messages.getString("JobSSH2PUT.Log.Result.TotalFilesError", "" + nbrerror));
                            log.logDetailed(toString(),
                                    Messages.getString("JobSSH2PUT.Log.Result.JobEntryEnd2"));
                        }
                        if (nbrerror == 0)
                            result.setResult(true);
                        /********************************RESULT ********************/
                    }

                }

            } catch (Exception e) {
                result.setNrErrors(nbrerror);
                log.logError(toString(), Messages.getString("JobSSH2PUT.Log.Error.ErrorFTP", e.getMessage()));
            } finally {
                if (conn != null)
                    conn.close();
                if (client != null)
                    client.close();
            }
        }
    } catch (Exception e) {
        result.setResult(false);
        result.setNrErrors(1L);
        log.logError(toString(), Messages.getString("JobSSH2PUT.Log.Error.UnexpectedError"), e);
    }

    return result;
}

From source file:be.ibridge.kettle.jsoup.JsoupInputMeta.java

/**
 * 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.
        /*  w ww  .  j  a  v  a  2 s. c om*/
 * TODO: create options to configure this behavior 
 */
public String exportResources(VariableSpace space, Map<String, ResourceDefinition> definitions,
        ResourceNamingInterface resourceNamingInterface, Repository repository) 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()) {
                    // From : ${Internal.Transformation.Filename.Directory}/../foo/bar.xml
                    // To   : /home/matt/test/files/foo/bar.xml
                    //
                    // If the file doesn't exist, forget about this effort too!
                    //
                    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()]);
                fileMask = new String[newFilenames.size()]; // all null since converted to absolute path.
                fileRequired = new String[newFilenames.size()]; // all null, turn to "Y" :
                for (int i = 0; i < newFilenames.size(); i++)
                    fileRequired[i] = "Y";
            }
        }
        return null;
    } catch (Exception e) {
        throw new KettleException(e); //$NON-NLS-1$
    }
}

From source file:com.panet.imeta.trans.steps.rssoutput.RssOutput.java

public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException {
    meta = (RssOutputMeta) smi;//w  ww.  j  av a2  s  .co  m
    data = (RssOutputData) sdi;

    Object[] r = getRow(); // this also waits for a previous step to be finished.

    if (r == null) // no more input to be expected...
    {
        if (!first) {
            if (!meta.isCustomRss()) {
                // No more input..so write and close the file.
                WriteToFile(data.channeltitlevalue, data.channellinkvalue, data.channeldescriptionvalue,
                        data.channelpubdatevalue, data.channelcopyrightvalue, data.channelimagelinkvalue,
                        data.channelimagedescriptionvalue, data.channelimagelinkvalue,
                        data.channelimageurlvalue, data.channellanguagevalue, data.channelauthorvalue);
            } else {

                // Write to document
                OutputFormat format = org.dom4j.io.OutputFormat.createPrettyPrint();
                // Set encoding ...          
                if (Const.isEmpty(meta.getEncoding()))
                    format.setEncoding("iso-8859-1");
                else
                    format.setEncoding(meta.getEncoding());

                try {
                    XMLWriter writer = new XMLWriter(new FileWriter(new File(data.filename)), format);
                    writer.write(data.document);
                    writer.close();
                } catch (Exception e) {
                } finally {
                    data.document = null;
                }

            }
        }
        setOutputDone();
        return false;
    }

    if (first) {
        first = false;
        data.inputRowMeta = getInputRowMeta();
        data.outputRowMeta = data.inputRowMeta.clone();
        meta.getFields(data.outputRowMeta, getStepname(), null, null, this);
        // Let's check for filename...

        if (meta.isFilenameInField()) {
            if (Const.isEmpty(meta.getFileNameField())) {
                logError(Messages.getString("RssOutput.Log.FilenameFieldMissing"));
                setErrors(1);
                stopAll();
                return false;
            }

            // get filename field index
            data.indexOfFieldfilename = data.inputRowMeta.indexOfValue(meta.getFileNameField());
            if (data.indexOfFieldfilename < 0) {
                // The field is unreachable !
                logError(Messages.getString("RssOutput.Log.ErrorFindingField", meta.getFileNameField()));
                throw new KettleException(
                        Messages.getString("RssOutput.Log.ErrorFindingField", meta.getFileNameField()));
            }

        } else {
            data.filename = buildFilename();
        }

        // Check if filename is empty..
        if (Const.isEmpty(data.filename)) {
            logError(Messages.getString("RssOutput.Log.FilenameEmpty"));
            throw new KettleException(Messages.getString("RssOutput.Log.FilenameEmpty"));
        }

        // Do we need to create parent folder ?
        if (meta.isCreateParentFolder()) {
            // Check for parent folder
            FileObject parentfolder = null;
            try {
                // Get parent folder
                parentfolder = KettleVFS.getFileObject(data.filename).getParent();
                if (!parentfolder.exists()) {
                    if (log.isDetailed())
                        log.logDetailed(toString(), Messages.getString("RssOutput.Log.ParentFolderExists",
                                parentfolder.getName().toString()));
                    parentfolder.createFolder();
                    if (log.isDetailed())
                        log.logDetailed(toString(), Messages.getString("RssOutput.Log.CanNotCreateParentFolder",
                                parentfolder.getName().toString()));
                }
            } catch (Exception e) {
                // The field is unreachable !
                logError(Messages.getString("RssOutput.Log.CanNotCreateParentFolder",
                        parentfolder.getName().toString()));
                throw new KettleException(Messages.getString("RssOutput.Log.CanNotCreateParentFolder",
                        parentfolder.getName().toString()));

            } finally {
                if (parentfolder != null) {
                    try {
                        parentfolder.close();
                    } catch (Exception ex) {
                    }
                    ;
                }
            }
        }

        if (!meta.isCustomRss()) {
            // Let's check for mandatory fields ...
            if (Const.isEmpty(meta.getChannelTitle())) {
                logError(Messages.getString("RssOutput.Log.ChannelTitleMissing"));
                setErrors(1);
                stopAll();
                return false;
            }
            if (Const.isEmpty(meta.getChannelDescription())) {
                logError(Messages.getString("RssOutput.Log.ChannelDescription"));
                setErrors(1);
                stopAll();
                return false;
            }
            if (Const.isEmpty(meta.getChannelLink())) {
                logError(Messages.getString("RssOutput.Log.ChannelLink"));
                setErrors(1);
                stopAll();
                return false;
            }

            // Let's take the index of channel title field ...
            data.indexOfFieldchanneltitle = data.inputRowMeta.indexOfValue(meta.getChannelTitle());
            if (data.indexOfFieldchanneltitle < 0) {
                // The field is unreachable !
                logError(Messages.getString("RssOutput.Log.ErrorFindingField", meta.getChannelTitle()));
                throw new KettleException(
                        Messages.getString("RssOutput.Log.ErrorFindingField", meta.getChannelTitle()));
            }
            data.channeltitlevalue = data.inputRowMeta.getString(r, data.indexOfFieldchanneltitle);

            // Let's take the index of channel description field ...   
            data.indexOfFieldchanneldescription = data.inputRowMeta.indexOfValue(meta.getChannelDescription());
            if (data.indexOfFieldchanneldescription < 0) {
                // The field is unreachable !
                logError(Messages.getString("RssOutput.Log.ErrorFindingField", meta.getChannelDescription()));
                throw new KettleException(
                        Messages.getString("RssOutput.Log.ErrorFindingField", meta.getChannelDescription()));
            }

            data.channeldescriptionvalue = data.inputRowMeta.getString(r, data.indexOfFieldchanneldescription);

            // Let's take the index of channel link field ...   
            data.indexOfFieldchannellink = data.inputRowMeta.indexOfValue(meta.getChannelLink());
            if (data.indexOfFieldchannellink < 0) {
                // The field is unreachable !
                logError(Messages.getString("RssOutput.Log.ErrorFindingField", meta.getChannelLink()));
                throw new KettleException(
                        Messages.getString("RssOutput.Log.ErrorFindingField", meta.getChannelLink()));
            }

            data.channellinkvalue = data.inputRowMeta.getString(r, data.indexOfFieldchannellink);

            if (!Const.isEmpty(meta.getItemTitle())) {
                // Let's take the index of item title field ...   
                data.indexOfFielditemtitle = data.inputRowMeta.indexOfValue(meta.getItemTitle());
                if (data.indexOfFielditemtitle < 0) {
                    // The field is unreachable !
                    logError(Messages.getString("RssOutput.Log.ErrorFindingField", meta.getItemTitle()));
                    throw new KettleException(
                            Messages.getString("RssOutput.Log.ErrorFindingField", meta.getItemTitle()));
                }
            }

            if (!Const.isEmpty(meta.getItemDescription())) {
                // Let's take the index of item description field ...
                data.indexOfFielditemdescription = data.inputRowMeta.indexOfValue(meta.getItemDescription());
                if (data.indexOfFielditemdescription < 0) {
                    // The field is unreachable !
                    logError(Messages.getString("RssOutput.Log.ErrorFindingField", meta.getItemDescription()));
                    throw new KettleException(
                            Messages.getString("RssOutput.Log.ErrorFindingField", meta.getItemDescription()));
                }
            }
            if (meta.AddGeoRSS()) {
                if (Const.isEmpty(meta.getGeoPointLong()))
                    throw new KettleException(Messages.getString("RssOutput.Log.GeoPointLatEmpty"));
                if (Const.isEmpty(meta.getGeoPointLong()))
                    throw new KettleException(Messages.getString("RssOutput.Log.GeoPointLongEmpty"));

                // Let's take the index of item geopointX field ...
                data.indexOfFielditempointx = data.inputRowMeta.indexOfValue(meta.getGeoPointLat());
                if (data.indexOfFielditempointx < 0) {
                    // The field is unreachable !
                    logError(Messages.getString("RssOutput.Log.ErrorFindingField", meta.getGeoPointLat()));
                    throw new KettleException(
                            Messages.getString("RssOutput.Log.ErrorFindingField", meta.getGeoPointLat()));
                }
                // Let's take the index of item geopointY field ...
                data.indexOfFielditempointy = data.inputRowMeta.indexOfValue(meta.getGeoPointLong());
                if (data.indexOfFielditempointy < 0) {
                    // The field is unreachable !
                    logError(Messages.getString("RssOutput.Log.ErrorFindingField", meta.getGeoPointLong()));
                    throw new KettleException(
                            Messages.getString("RssOutput.Log.ErrorFindingField", meta.getGeoPointLong()));
                }
            }

            //It's time to check non empty fields !
            // Channel PubDate field ...
            if (!Const.isEmpty(meta.getChannelPubDate())) {
                data.indexOfFieldchannelpubdate = data.inputRowMeta.indexOfValue(meta.getChannelPubDate());
                if (data.indexOfFieldchannelpubdate < 0) {
                    // The field is unreachable !
                    logError(Messages.getString("RssOutput.Log.ErrorFindingField", meta.getChannelPubDate()));
                    throw new KettleException(
                            Messages.getString("RssOutput.Log.ErrorFindingField", meta.getChannelPubDate()));
                }

                data.channelpubdatevalue = data.inputRowMeta.getDate(r, data.indexOfFieldchannelpubdate);
            }
            // Channel Language field ...
            if (!Const.isEmpty(meta.getChannelLanguage())) {
                data.indexOfFieldchannellanguage = data.inputRowMeta.indexOfValue(meta.getChannelLanguage());
                if (data.indexOfFieldchannellanguage < 0) {
                    // The field is unreachable !
                    logError(Messages.getString("RssOutput.Log.ErrorFindingField", meta.getChannelLanguage()));
                    throw new KettleException(
                            Messages.getString("RssOutput.Log.ErrorFindingField", meta.getChannelLanguage()));
                }

                data.channellanguagevalue = data.inputRowMeta.getString(r, data.indexOfFieldchannellanguage);
            }

            // Channel Copyright field ...
            if (!Const.isEmpty(meta.getChannelCopyright())) {
                data.indexOfFieldchannelcopyright = data.inputRowMeta.indexOfValue(meta.getChannelCopyright());
                if (data.indexOfFieldchannelcopyright < 0) {
                    // The field is unreachable !
                    logError(Messages.getString("RssOutput.Log.ErrorFindingField", meta.getChannelCopyright()));
                    throw new KettleException(
                            Messages.getString("RssOutput.Log.ErrorFindingField", meta.getChannelCopyright()));
                }

                data.channelcopyrightvalue = data.inputRowMeta.getString(r, data.indexOfFieldchannelcopyright);
            }

            // Channel Author field ...
            if (!Const.isEmpty(meta.getChannelAuthor())) {
                data.indexOfFieldchannelauthor = data.inputRowMeta.indexOfValue(meta.getChannelAuthor());
                if (data.indexOfFieldchannelauthor < 0) {
                    // The field is unreachable !
                    logError(Messages.getString("RssOutput.Log.ErrorFindingField", meta.getChannelAuthor()));
                    throw new KettleException(
                            Messages.getString("RssOutput.Log.ErrorFindingField", meta.getChannelAuthor()));
                }

                data.channelauthorvalue = data.inputRowMeta.getString(r, data.indexOfFieldchannelauthor);
            }

            // Channel Image field ...
            if (meta.AddImage()) {
                // Channel image title
                if (!Const.isEmpty(meta.getChannelImageTitle())) {
                    data.indexOfFieldchannelimagetitle = data.inputRowMeta
                            .indexOfValue(meta.getChannelImageTitle());
                    if (data.indexOfFieldchannelimagetitle < 0) {
                        // The field is unreachable !
                        logError(Messages.getString("RssOutput.Log.ErrorFindingField",
                                meta.getChannelImageTitle()));
                        throw new KettleException(Messages.getString("RssOutput.Log.ErrorFindingField",
                                meta.getChannelImageTitle()));
                    }

                    data.channelimagetitlevalue = data.inputRowMeta.getString(r,
                            data.indexOfFieldchannelimagetitle);
                }

                // Channel link title
                if (!Const.isEmpty(meta.getChannelImageLink())) {
                    data.indexOfFieldchannelimagelink = data.inputRowMeta
                            .indexOfValue(meta.getChannelImageLink());
                    if (data.indexOfFieldchannelimagelink < 0) {
                        // The field is unreachable !
                        logError(Messages.getString("RssOutput.Log.ErrorFindingField",
                                meta.getChannelImageLink()));
                        throw new KettleException(Messages.getString("RssOutput.Log.ErrorFindingField",
                                meta.getChannelImageLink()));
                    }

                    data.channelimagelinkvalue = data.inputRowMeta.getString(r,
                            data.indexOfFieldchannelimagelink);
                }

                // Channel url title
                if (!Const.isEmpty(meta.getChannelImageUrl())) {
                    data.indexOfFieldchannelimageurl = data.inputRowMeta
                            .indexOfValue(meta.getChannelImageUrl());
                    if (data.indexOfFieldchannelimageurl < 0) {
                        // The field is unreachable !
                        logError(Messages.getString("RssOutput.Log.ErrorFindingField",
                                meta.getChannelImageUrl()));
                        throw new KettleException(Messages.getString("RssOutput.Log.ErrorFindingField",
                                meta.getChannelImageUrl()));
                    }

                    data.channelimageurlvalue = data.inputRowMeta.getString(r,
                            data.indexOfFieldchannelimageurl);
                }

                // Channel description title
                if (!Const.isEmpty(meta.getChannelImageDescription())) {
                    data.indexOfFieldchannelimagedescription = data.inputRowMeta
                            .indexOfValue(meta.getChannelImageDescription());
                    if (data.indexOfFieldchannelimagedescription < 0) {
                        // The field is unreachable !
                        logError(Messages.getString("RssOutput.Log.ErrorFindingField",
                                meta.getChannelImageDescription()));
                        throw new KettleException(Messages.getString("RssOutput.Log.ErrorFindingField",
                                meta.getChannelImageDescription()));
                    }

                    data.channelimagedescriptionvalue = data.inputRowMeta.getString(r,
                            data.indexOfFieldchannelimagedescription);
                }

            }

            // Item link field ...
            if (!Const.isEmpty(meta.getItemLink())) {
                data.indexOfFielditemlink = data.inputRowMeta.indexOfValue(meta.getItemLink());
                if (data.indexOfFielditemlink < 0) {
                    // The field is unreachable !
                    logError(Messages.getString("RssOutput.Log.ErrorFindingField", meta.getItemLink()));
                    throw new KettleException(
                            Messages.getString("RssOutput.Log.ErrorFindingField", meta.getItemLink()));
                }

            }

            // Item pubdate field ...
            if (!Const.isEmpty(meta.getItemPubDate())) {
                data.indexOfFielditempubdate = data.inputRowMeta.indexOfValue(meta.getItemPubDate());
                if (data.indexOfFielditempubdate < 0) {
                    // The field is unreachable !
                    logError(Messages.getString("RssOutput.Log.ErrorFindingField", meta.getItemPubDate()));
                    throw new KettleException(
                            Messages.getString("RssOutput.Log.ErrorFindingField", meta.getItemPubDate()));
                }
            }

            // Item author field ...
            if (!Const.isEmpty(meta.getItemAuthor())) {
                data.indexOfFielditemauthor = data.inputRowMeta.indexOfValue(meta.getItemAuthor());
                if (data.indexOfFielditemauthor < 0) {
                    // The field is unreachable !
                    logError(Messages.getString("RssOutput.Log.ErrorFindingField", meta.getItemAuthor()));
                    throw new KettleException(
                            Messages.getString("RssOutput.Log.ErrorFindingField", meta.getItemAuthor()));
                }
            }
        } else {
            // Custom RSS
            // Check Custom channel fields
            data.customchannels = new int[meta.getChannelCustomFields().length];
            for (int i = 0; i < meta.getChannelCustomFields().length; i++) {
                data.customchannels[i] = data.inputRowMeta.indexOfValue(meta.getChannelCustomFields()[i]);
                if (data.customchannels[i] < 0) // couldn't find field!
                {
                    throw new KettleStepException(Messages.getString("RssOutput.Exception.FieldRequired", //$NON-NLS-1$
                            meta.getChannelCustomFields()[i])); //$NON-NLS-2$
                }
            }
            // Check Custom channel fields
            data.customitems = new int[meta.getItemCustomFields().length];
            for (int i = 0; i < meta.getItemCustomFields().length; i++) {
                data.customitems[i] = data.inputRowMeta.indexOfValue(meta.getItemCustomFields()[i]);
                if (data.customitems[i] < 0) // couldn't find field!
                {
                    throw new KettleStepException(Messages.getString("RssOutput.Exception.FieldRequired", //$NON-NLS-1$
                            meta.getItemCustomFields()[i])); //$NON-NLS-2$
                }
            }
            // Prepare Output RSS Custom document
            data.document = DocumentHelper.createDocument();
            data.rssElement = data.document.addElement("rss");
            data.rssElement.addAttribute("version", "2.0");
            // add namespaces here ...
            for (int i = 0; i < meta.getNameSpaces().length; i++) {
                data.rssElement.addAttribute(environmentSubstitute(meta.getNameSpacesTitle()[i]),
                        environmentSubstitute(meta.getNameSpaces()[i]));
            }

            // Add channel
            data.channel = data.rssElement.addElement("channel");

            // Set channel Only the first time ...
            for (int i = 0; i < data.customchannels.length; i++) {
                String channelname = environmentSubstitute(meta.getChannelCustomTags()[i]);
                String channelvalue = data.inputRowMeta.getString(r, data.customchannels[i]);

                if (log.isDetailed())
                    log.logDetailed(toString(), "outputting channel value <" + channelname + ">" + channelvalue
                            + "<" + channelname + "/>");

                // add Channel
                Element channeltag = data.channel.addElement(channelname);
                channeltag.setText(channelvalue);

            }
        }
    } // end test first time

    // Let's get value for each item...
    if (!meta.isCustomRss()) {
        String itemtitlevalue = null;
        String itemauthorvalue = null;
        String itemlinkvalue = null;
        Date itemdatevalue = null;
        String itemdescvalue = null;
        String itemgeopointx = null;
        String itemgeopointy = null;

        if (data.indexOfFielditemtitle > -1)
            itemtitlevalue = data.inputRowMeta.getString(r, data.indexOfFielditemtitle);
        if (data.indexOfFielditemauthor > -1)
            itemauthorvalue = data.inputRowMeta.getString(r, data.indexOfFielditemauthor);
        if (data.indexOfFielditemlink > -1)
            itemlinkvalue = data.inputRowMeta.getString(r, data.indexOfFielditemlink);
        if (data.indexOfFielditempubdate > -1)
            itemdatevalue = data.inputRowMeta.getDate(r, data.indexOfFielditempubdate);
        if (data.indexOfFielditemdescription > -1)
            itemdescvalue = data.inputRowMeta.getString(r, data.indexOfFielditemdescription);
        if (data.indexOfFielditempointx > -1)
            itemgeopointx = data.inputRowMeta.getString(r, data.indexOfFielditempointx);
        if (data.indexOfFielditempointy > -1)
            itemgeopointy = data.inputRowMeta.getString(r, data.indexOfFielditempointy);

        // Now add entry ..
        if (!createEntry(itemauthorvalue, itemtitlevalue, itemlinkvalue, itemdatevalue, itemdescvalue,
                itemgeopointx, itemgeopointy))
            throw new KettleException("Error adding item to feed");
    } else {

        // Set item tag at each row received 
        if (meta.isDisplayItem()) {
            data.itemtag = data.channel.addElement("item");
        }
        for (int i = 0; i < data.customitems.length; i++) {
            // get item value and name
            String itemname = environmentSubstitute(meta.getItemCustomTags()[i]);
            String itemvalue = data.inputRowMeta.getString(r, data.customitems[i]);

            if (log.isDetailed())
                log.logDetailed(toString(),
                        "outputting item value <" + itemname + ">" + itemvalue + "<" + itemname + "/>");

            // add Item
            if (meta.isDisplayItem()) {
                Element itemtagsub = data.itemtag.addElement(itemname);
                itemtagsub.setText(itemvalue);
            } else {
                // display item at channel level
                data.channel.addElement(itemname);
                data.channel.setText(itemvalue);
            }
        }
    }

    try {
        putRow(data.outputRowMeta, r); // in case we want it to go further...
        incrementLinesOutput();

        if (checkFeedback(getLinesOutput())) {
            if (log.isDebug())
                logDebug(Messages.getString("RssOutput.Log.Linenr", "" + getLinesOutput()));
        }

    } catch (KettleStepException e) {
        logError(Messages.getString("RssOutputMeta.Log.ErrorInStep") + e.getMessage()); //$NON-NLS-1$
        setErrors(1);
        stopAll();
        setOutputDone(); // signal end to receiver(s)
        return false;
    }

    return true;
}

From source file:com.akretion.kettle.steps.terminatooor.ScriptValuesAddedFunctions.java

public static String getShortFilename(ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,
        Object FunctionContext) {
    try {/*from  w ww .  jav a  2  s .c  o m*/
        if (ArgList.length == 1 && !isNull(ArgList[0]) && !isUndefined(ArgList[0])) {
            if (ArgList[0].equals(null))
                return null;
            FileObject file = null;

            try {
                // Source file
                file = KettleVFS.getFileObject((String) ArgList[0]);
                String Filename = null;
                if (file.exists()) {
                    Filename = file.getName().getBaseName().toString();

                } else {
                    new RuntimeException("file [" + (String) ArgList[0] + "] can not be found!");
                }

                return Filename;
            } catch (IOException e) {
                throw new RuntimeException(
                        "The function call getShortFilename throw an error : " + e.toString());
            } finally {
                if (file != null)
                    try {
                        file.close();
                    } catch (Exception e) {
                    }
            }

        } else {
            throw new RuntimeException("The function call getShortFilename is not valid.");
        }
    } catch (Exception e) {
        throw new RuntimeException(e.toString());
    }
}

From source file:com.akretion.kettle.steps.terminatooor.ScriptValuesAddedFunctions.java

public static String getFileExtension(ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,
        Object FunctionContext) {
    try {//from   ww  w  . j a  v  a2  s  .  c  o m
        if (ArgList.length == 1 && !isNull(ArgList[0]) && !isUndefined(ArgList[0])) {
            if (ArgList[0].equals(null))
                return null;
            FileObject file = null;

            try {
                // Source file
                file = KettleVFS.getFileObject((String) ArgList[0]);
                String Extension = null;
                if (file.exists()) {
                    Extension = file.getName().getExtension().toString();

                } else {
                    new RuntimeException("file [" + (String) ArgList[0] + "] can not be found!");
                }

                return Extension;
            } catch (IOException e) {
                throw new RuntimeException(
                        "The function call getFileExtension throw an error : " + e.toString());
            } finally {
                if (file != null)
                    try {
                        file.close();
                    } catch (Exception e) {
                    }
            }

        } else {
            throw new RuntimeException("The function call getFileExtension is not valid.");
        }
    } catch (Exception e) {
        throw new RuntimeException(e.toString());
    }
}

From source file:com.panet.imeta.trans.steps.scriptvalues_mod.ScriptValuesAddedFunctions.java

public static String getShortFilename(Context actualContext, Scriptable actualObject, Object[] ArgList,
        Function FunctionContext) {
    try {//from  w  ww  . java 2s  . c o m
        if (ArgList.length == 1 && !isNull(ArgList[0]) && !isUndefined(ArgList[0])) {
            if (ArgList[0].equals(null))
                return null;
            FileObject file = null;

            try {
                // Source file
                file = KettleVFS.getFileObject(Context.toString(ArgList[0]));
                String Filename = null;
                if (file.exists()) {
                    Filename = file.getName().getBaseName().toString();

                } else {
                    Context.reportRuntimeError("file [" + Context.toString(ArgList[0]) + "] can not be found!");
                }

                return Filename;
            } catch (IOException e) {
                throw Context.reportRuntimeError(
                        "The function call getShortFilename throw an error : " + e.toString());
            } finally {
                if (file != null)
                    try {
                        file.close();
                    } catch (Exception e) {
                    }
            }

        } else {
            throw Context.reportRuntimeError("The function call getShortFilename is not valid.");
        }
    } catch (Exception e) {
        throw Context.reportRuntimeError(e.toString());
    }
}

From source file:com.panet.imeta.trans.steps.scriptvalues_mod.ScriptValuesAddedFunctions.java

public static String getFileExtension(Context actualContext, Scriptable actualObject, Object[] ArgList,
        Function FunctionContext) {
    try {/*w w w  . j av  a2 s  .c om*/
        if (ArgList.length == 1 && !isNull(ArgList[0]) && !isUndefined(ArgList[0])) {
            if (ArgList[0].equals(null))
                return null;
            FileObject file = null;

            try {
                // Source file
                file = KettleVFS.getFileObject(Context.toString(ArgList[0]));
                String Extension = null;
                if (file.exists()) {
                    Extension = file.getName().getExtension().toString();

                } else {
                    Context.reportRuntimeError("file [" + Context.toString(ArgList[0]) + "] can not be found!");
                }

                return Extension;
            } catch (IOException e) {
                throw Context.reportRuntimeError(
                        "The function call getFileExtension throw an error : " + e.toString());
            } finally {
                if (file != null)
                    try {
                        file.close();
                    } catch (Exception e) {
                    }
            }

        } else {
            throw Context.reportRuntimeError("The function call getFileExtension is not valid.");
        }
    } catch (Exception e) {
        throw Context.reportRuntimeError(e.toString());
    }
}