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

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

Introduction

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

Prototype

public boolean exists() throws FileSystemException;

Source Link

Document

Determines if this file exists.

Usage

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

public static void moveFile(ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,
        Object FunctionContext) {

    try {//from w w w  .j a v a 2 s . c  om
        if (ArgList.length == 3 && !isNull(ArgList[0]) && !isNull(ArgList[1]) && !isUndefined(ArgList[0])
                && !isUndefined(ArgList[1])) {
            FileObject fileSource = null, fileDestination = null;

            try {
                // Source file to move
                fileSource = KettleVFS.getFileObject((String) ArgList[0]);
                // Destination filename
                fileDestination = KettleVFS.getFileObject((String) ArgList[1]);
                if (fileSource.exists()) {
                    // Source file exists...
                    if (fileSource.getType() == FileType.FILE) {
                        // Great..source is a file ...
                        boolean overwrite = false;
                        if (!ArgList[1].equals(null))
                            overwrite = (Boolean) ArgList[2];
                        boolean destinationExists = fileDestination.exists();
                        // Let's move the file...
                        if ((destinationExists && overwrite) || !destinationExists)
                            fileSource.moveTo(fileDestination);

                    }
                } else {
                    new RuntimeException("file to move [" + (String) ArgList[0] + "] can not be found!");
                }
            } catch (IOException e) {
                throw new RuntimeException("The function call moveFile throw an error : " + e.toString());
            } finally {
                if (fileSource != null)
                    try {
                        fileSource.close();
                    } catch (Exception e) {
                    }
                if (fileDestination != null)
                    try {
                        fileDestination.close();
                    } catch (Exception e) {
                    }
            }

        } else {
            throw new RuntimeException("The function call copyFile 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 void copyFile(Context actualContext, Scriptable actualObject, Object[] ArgList,
        Function FunctionContext) {

    try {//from  w  w  w.ja v  a2  s  .  c o  m
        if (ArgList.length == 3 && !isNull(ArgList[0]) && !isNull(ArgList[1]) && !isUndefined(ArgList[0])
                && !isUndefined(ArgList[1])) {
            FileObject fileSource = null, fileDestination = null;

            try {
                // Source file to copy
                fileSource = KettleVFS.getFileObject(Context.toString(ArgList[0]));
                // Destination filename
                fileDestination = KettleVFS.getFileObject(Context.toString(ArgList[1]));
                if (fileSource.exists()) {
                    // Source file exists...
                    if (fileSource.getType() == FileType.FILE) {
                        // Great..source is a file ...
                        boolean overwrite = false;
                        if (!ArgList[1].equals(null))
                            overwrite = Context.toBoolean(ArgList[2]);
                        boolean destinationExists = fileDestination.exists();
                        // Let's copy the file...
                        if ((destinationExists && overwrite) || !destinationExists)
                            FileUtil.copyContent(fileSource, fileDestination);

                    }
                } else {
                    Context.reportRuntimeError(
                            "file to copy [" + Context.toString(ArgList[0]) + "] can not be found!");
                }
            } catch (IOException e) {
                throw Context.reportRuntimeError("The function call copyFile throw an error : " + e.toString());
            } finally {
                if (fileSource != null)
                    try {
                        fileSource.close();
                    } catch (Exception e) {
                    }
                if (fileDestination != null)
                    try {
                        fileDestination.close();
                    } catch (Exception e) {
                    }
            }

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

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

public static void moveFile(Context actualContext, Scriptable actualObject, Object[] ArgList,
        Function FunctionContext) {

    try {//from  w w w.  ja v  a2 s . c o  m
        if (ArgList.length == 3 && !isNull(ArgList[0]) && !isNull(ArgList[1]) && !isUndefined(ArgList[0])
                && !isUndefined(ArgList[1])) {
            FileObject fileSource = null, fileDestination = null;

            try {
                // Source file to move
                fileSource = KettleVFS.getFileObject(Context.toString(ArgList[0]));
                // Destination filename
                fileDestination = KettleVFS.getFileObject(Context.toString(ArgList[1]));
                if (fileSource.exists()) {
                    // Source file exists...
                    if (fileSource.getType() == FileType.FILE) {
                        // Great..source is a file ...
                        boolean overwrite = false;
                        if (!ArgList[1].equals(null))
                            overwrite = Context.toBoolean(ArgList[2]);
                        boolean destinationExists = fileDestination.exists();
                        // Let's move the file...
                        if ((destinationExists && overwrite) || !destinationExists)
                            fileSource.moveTo(fileDestination);

                    }
                } else {
                    Context.reportRuntimeError(
                            "file to move [" + Context.toString(ArgList[0]) + "] can not be found!");
                }
            } catch (IOException e) {
                throw Context.reportRuntimeError("The function call moveFile throw an error : " + e.toString());
            } finally {
                if (fileSource != null)
                    try {
                        fileSource.close();
                    } catch (Exception e) {
                    }
                if (fileDestination != null)
                    try {
                        fileDestination.close();
                    } catch (Exception e) {
                    }
            }

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

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

public static String getLastModifiedTime(ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,
        Object FunctionContext) {
    try {/*from w w  w.j a  va  2s  .  co m*/
        if (ArgList.length == 2 && !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 dateformat = (String) ArgList[1];
                if (isNull(dateformat))
                    dateformat = "yyyy-MM-dd";
                String lastmodifiedtime = null;
                if (file.exists()) {
                    java.util.Date lastmodifiedtimedate = new java.util.Date(
                            file.getContent().getLastModifiedTime());
                    java.text.DateFormat dateFormat = new SimpleDateFormat(dateformat);
                    lastmodifiedtime = dateFormat.format(lastmodifiedtimedate);

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

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

        } else {
            throw new RuntimeException("The function call getLastModifiedTime 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 getLastModifiedTime(Context actualContext, Scriptable actualObject, Object[] ArgList,
        Function FunctionContext) {
    try {// www .  j a  v a2 s . c o m
        if (ArgList.length == 2 && !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 dateformat = Context.toString(ArgList[1]);
                if (isNull(dateformat))
                    dateformat = "yyyy-MM-dd";
                String lastmodifiedtime = null;
                if (file.exists()) {
                    java.util.Date lastmodifiedtimedate = new java.util.Date(
                            file.getContent().getLastModifiedTime());
                    java.text.DateFormat dateFormat = new SimpleDateFormat(dateformat);
                    lastmodifiedtime = dateFormat.format(lastmodifiedtimedate);

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

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

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

From source file:be.ibridge.kettle.job.entry.waitforfile.JobEntryWaitForFile.java

public Result execute(Result prev_result, int nr, Repository rep, Job parentJob) {
    LogWriter log = LogWriter.getInstance();
    Result result = new Result(nr);
    result.setResult(false);//  ww  w . jav a  2  s  .c o  m

    // starttime (in seconds)
    long timeStart = System.currentTimeMillis() / 1000;

    if (filename != null) {
        String realFilename = getRealFilename();
        try {
            FileObject fileObject = null;

            fileObject = KettleVFS.getFileObject(realFilename);

            long iMaximumTimeout = Const.toInt(getMaximumTimeout(), Const.toInt(DEFAULT_MAXIMUM_TIMEOUT, 0));
            long iCycleTime = Const.toInt(getCheckCycleTime(), Const.toInt(DEFAULT_CHECK_CYCLE_TIME, 0));

            //
            // Sanity check on some values, and complain on insanity
            //
            if (iMaximumTimeout < 0) {
                iMaximumTimeout = Const.toInt(DEFAULT_MAXIMUM_TIMEOUT, 0);
                log.logBasic(toString(), "Maximum timeout invalid, reset to " + iMaximumTimeout);
            }

            if (iCycleTime < 1) {
                // If lower than 1 set to the default
                iCycleTime = Const.toInt(DEFAULT_CHECK_CYCLE_TIME, 1);
                log.logBasic(toString(), "Check cycle time invalid, reset to " + iCycleTime);
            }

            if (iMaximumTimeout == 0) {
                log.logBasic(toString(), "Waiting indefinitely for file [" + realFilename + "]");
            } else {
                log.logBasic(toString(),
                        "Waiting " + iMaximumTimeout + " seconds for file [" + realFilename + "]");
            }

            boolean continueLoop = true;
            while (continueLoop && !parentJob.isStopped()) {
                if (fileObject.exists()) {
                    // file exists, we're happy to exit
                    log.logBasic(toString(), "Detected file [" + realFilename + "] within timeout");
                    result.setResult(true);
                    continueLoop = false;
                } else {
                    long now = System.currentTimeMillis() / 1000;

                    if ((iMaximumTimeout > 0) && (now > (timeStart + iMaximumTimeout))) {
                        continueLoop = false;

                        // file doesn't exist after timeout, either true or false                  
                        if (isSuccessOnTimeout()) {
                            log.logBasic(toString(),
                                    "Didn't detect file [" + realFilename + "] before timeout, success");
                            result.setResult(true);
                        } else {
                            log.logBasic(toString(),
                                    "Didn't detect file [" + realFilename + "] before timeout, failure");
                            result.setResult(false);
                        }
                    }

                    // sleep algorithm               
                    long sleepTime = 0;

                    if (iMaximumTimeout == 0) {
                        sleepTime = iCycleTime;
                    } else {
                        if ((now + iCycleTime) < (timeStart + iMaximumTimeout)) {
                            sleepTime = iCycleTime;
                        } else {
                            sleepTime = iCycleTime - ((now + iCycleTime) - (timeStart + iMaximumTimeout));
                        }
                    }

                    try {
                        if (sleepTime > 0) {
                            if (log.isDetailed()) {
                                log.logDetailed(toString(), "Sleeping " + sleepTime
                                        + " seconds before next check for file [" + realFilename + "]");
                            }
                            Thread.sleep(sleepTime * 1000);
                        }
                    } catch (InterruptedException e) {
                        // something strange happened
                        result.setResult(false);
                        continueLoop = false;
                    }
                }
            }

            if (!parentJob.isStopped() && fileObject.exists() && isFileSizeCheck()) {
                long oldSize = -1;
                long newSize = fileObject.getContent().getSize();

                log.logDetailed(toString(), "File [" + realFilename + "] is " + newSize + " bytes long");
                log.logBasic(toString(), "Waiting until file [" + realFilename + "] stops growing for "
                        + iCycleTime + " seconds");
                while (oldSize != newSize && !parentJob.isStopped()) {
                    try {
                        if (log.isDetailed()) {
                            log.logDetailed(toString(), "Sleeping " + iCycleTime
                                    + " seconds, waiting for file [" + realFilename + "] to stop growing");
                        }
                        Thread.sleep(iCycleTime * 1000);
                    } catch (InterruptedException e) {
                        // something strange happened
                        result.setResult(false);
                        continueLoop = false;
                    }
                    oldSize = newSize;
                    newSize = fileObject.getContent().getSize();
                    if (log.isDetailed()) {
                        log.logDetailed(toString(),
                                "File [" + realFilename + "] is " + newSize + " bytes long");
                    }
                }
                log.logBasic(toString(), "Stopped waiting for file [" + realFilename + "] to stop growing");
            }

            if (parentJob.isStopped()) {
                result.setResult(false);
            }
        } catch (IOException e) {
            log.logBasic(toString(), "Exception while waiting for file [" + realFilename + "] to stop growing: "
                    + e.getMessage());
        }
    } else {
        log.logError(toString(), "No filename is defined.");
    }

    return result;
}

From source file:com.panet.imeta.job.entries.copymoveresultfilenames.JobEntryCopyMoveResultFilenames.java

public Result execute(Result previousResult, int nr, Repository rep, Job parentJob) {
    LogWriter log = LogWriter.getInstance();
    Result result = previousResult;
    result.setNrErrors(1);//from w  w  w  .j  av a  2s.  c  om
    result.setResult(false);
    String realdestinationFolder = environmentSubstitute(getDestinationFolder());

    if (!CreateDestinationFolder(realdestinationFolder, log)) {
        return result;
    }

    if (previousResult != null) {
        NrErrors = 0;
        limitFiles = Const.toInt(environmentSubstitute(getNrErrorsLessThan()), 10);
        NrErrors = 0;
        NrSuccess = 0;
        successConditionBroken = false;
        successConditionBrokenExit = false;

        FileObject file = null;

        try {
            int size = result.getResultFiles().size();
            if (log.isBasic())
                log.logBasic(toString(),
                        Messages.getString("JobEntryCopyMoveResultFilenames.log.FilesFound", "" + size));

            List<ResultFile> resultFiles = result.getResultFilesList();
            if (resultFiles != null && resultFiles.size() > 0) {
                for (Iterator<ResultFile> it = resultFiles.iterator(); it.hasNext()
                        && !parentJob.isStopped();) {
                    if (successConditionBroken) {
                        log.logError(toString(), Messages.getString(
                                "JobEntryCopyMoveResultFilenames.Error.SuccessConditionbroken", "" + NrErrors));
                        throw new Exception(Messages.getString(
                                "JobEntryCopyMoveResultFilenames.Error.SuccessConditionbroken", "" + NrErrors));
                    }

                    ResultFile resultFile = (ResultFile) it.next();
                    file = resultFile.getFile();
                    if (file != null && file.exists()) {
                        if (!specifywildcard || (CheckFileWildcard(file.getName().getBaseName(),
                                environmentSubstitute(wildcard), true)
                                && !CheckFileWildcard(file.getName().getBaseName(),
                                        environmentSubstitute(wildcardexclude), false)
                                && specifywildcard)) {
                            // Copy or Move file
                            if (!ProcessFile(file, realdestinationFolder, log, result, parentJob)) {
                                // Update Errors
                                updateErrors();
                            }
                        }

                    } else {
                        log.logError(toString(), Messages.getString(
                                "JobEntryCopyMoveResultFilenames.log.ErrorCanNotFindFile", file.toString()));
                        // Update Errors
                        updateErrors();
                    }
                } // end for
            }
        } catch (Exception e) {
            log.logError(toString(), Messages.getString("JobEntryCopyMoveResultFilenames.Error", e.toString()));
        } finally {
            if (file != null) {
                try {
                    file.close();
                } catch (Exception ex) {
                }
                ;
            }
        }
    }
    // Success Condition
    result.setNrErrors(NrErrors);
    result.setNrLinesWritten(NrSuccess);
    if (getSuccessStatus())
        result.setResult(true);

    return result;
}

From source file:com.panet.imeta.trans.steps.mail.Mail.java

private void setAttachedFilesList(Object[] r, LogWriter log) throws Exception {
    String realSourceFileFoldername = null;
    String realSourceWildcard = null;
    FileObject sourcefile = null;
    FileObject file = null;//from  w  w w . j  a va  2 s .  c  om

    ZipOutputStream zipOutputStream = null;
    File masterZipfile = null;

    if (meta.isZipFilenameDynamic())
        data.ZipFilename = data.previousRowMeta.getString(r, data.indexOfDynamicZipFilename);

    try {

        if (meta.isDynamicFilename()) {
            // dynamic attached filenames
            if (data.indexOfSourceFilename > -1)
                realSourceFileFoldername = data.previousRowMeta.getString(r, data.indexOfSourceFilename);

            if (data.indexOfSourceWildcard > -1)
                realSourceWildcard = data.previousRowMeta.getString(r, data.indexOfSourceWildcard);

        } else {
            // static attached filenames
            realSourceFileFoldername = data.realSourceFileFoldername;
            realSourceWildcard = data.realSourceWildcard;
        }

        if (!Const.isEmpty(realSourceFileFoldername)) {
            sourcefile = KettleVFS.getFileObject(realSourceFileFoldername);
            if (sourcefile.exists()) {
                long FileSize = 0;
                FileObject list[] = null;
                if (sourcefile.getType() == FileType.FILE) {
                    list = new FileObject[1];
                    list[0] = sourcefile;
                } else
                    list = sourcefile
                            .findFiles(new TextFileSelector(sourcefile.toString(), realSourceWildcard));
                if (list.length > 0) {

                    boolean zipFiles = meta.isZipFiles();
                    if (zipFiles && data.zipFileLimit == 0) {
                        masterZipfile = new File(
                                System.getProperty("java.io.tmpdir") + Const.FILE_SEPARATOR + data.ZipFilename);

                        zipOutputStream = new ZipOutputStream(new FileOutputStream(masterZipfile));
                    }

                    for (int i = 0; i < list.length; i++) {

                        file = KettleVFS.getFileObject(KettleVFS.getFilename(list[i]));

                        if (zipFiles) {

                            if (data.zipFileLimit == 0) {
                                ZipEntry zipEntry = new ZipEntry(file.getName().getBaseName());
                                zipOutputStream.putNextEntry(zipEntry);

                                // Now put the content of this file into this archive...
                                BufferedInputStream inputStream = new BufferedInputStream(
                                        file.getContent().getInputStream());
                                int c;
                                while ((c = inputStream.read()) >= 0) {
                                    zipOutputStream.write(c);
                                }
                                inputStream.close();
                                zipOutputStream.closeEntry();
                            } else
                                FileSize += file.getContent().getSize();
                        } else {
                            addAttachedFilePart(file);
                        }
                    } // end for
                    if (zipFiles) {
                        if (log.isDebug())
                            log.logDebug(toString(), Messages.getString("Mail.Log.FileSize", "" + FileSize));
                        if (log.isDebug())
                            log.logDebug(toString(),
                                    Messages.getString("Mail.Log.LimitSize", "" + data.zipFileLimit));

                        if (data.zipFileLimit > 0 && FileSize > data.zipFileLimit) {

                            masterZipfile = new File(System.getProperty("java.io.tmpdir") + Const.FILE_SEPARATOR
                                    + data.ZipFilename);

                            zipOutputStream = new ZipOutputStream(new FileOutputStream(masterZipfile));

                            for (int i = 0; i < list.length; i++) {

                                file = KettleVFS.getFileObject(KettleVFS.getFilename(list[i]));

                                ZipEntry zipEntry = new ZipEntry(file.getName().getBaseName());
                                zipOutputStream.putNextEntry(zipEntry);

                                // Now put the content of this file into this archive...
                                BufferedInputStream inputStream = new BufferedInputStream(
                                        file.getContent().getInputStream());
                                int c;
                                while ((c = inputStream.read()) >= 0) {
                                    zipOutputStream.write(c);
                                }
                                inputStream.close();
                                zipOutputStream.closeEntry();

                            }

                        }
                        if (data.zipFileLimit > 0 && FileSize > data.zipFileLimit || data.zipFileLimit == 0) {
                            file = KettleVFS.getFileObject(masterZipfile.getAbsolutePath());
                            addAttachedFilePart(file);
                        }
                    }
                }
            } else {
                log.logError(toString(),
                        Messages.getString("Mail.Error.SourceFileFolderNotExists", realSourceFileFoldername));
            }
        }
    } catch (Exception e) {
        log.logError(toString(), e.getMessage());
    } finally {
        if (sourcefile != null) {
            try {
                sourcefile.close();
            } catch (Exception e) {
            }
        }
        if (file != null) {
            try {
                file.close();
            } catch (Exception e) {
            }
        }

        if (zipOutputStream != null) {
            try {
                zipOutputStream.finish();
                zipOutputStream.close();
            } catch (IOException e) {
                log.logError(toString(), "Unable to close attachement zip file archive : " + e.toString());
            }
        }
    }

}

From source file:net.sf.vfsjfilechooser.accessories.connection.ConnectionDialog.java

private void initListeners() {
    this.portTextField.addKeyListener(new KeyAdapter() {
        @Override//from   w w  w . j  a  v  a  2  s  . c  om
        public void keyTyped(KeyEvent e) {
            char c = e.getKeyChar();

            if (!((Character.isDigit(c) || (c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)))) {
                getToolkit().beep();
                e.consume();
            } else {
                setPortTextFieldDirty(true);
            }
        }
    });

    this.portTextField.addFocusListener(new FocusAdapter() {
        @Override
        public void focusLost(FocusEvent e) {
            JFormattedTextField f = (JFormattedTextField) e.getSource();
            String text = f.getText();

            if (text.length() == 0) {
                f.setValue(null);
            }

            try {
                f.commitEdit();
            } catch (ParseException exc) {
            }
        }
    });

    this.cancelButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (currentWorker != null) {
                if (currentWorker.isAlive()) {
                    currentWorker.interrupt();
                    setCursor(Cursor.getDefaultCursor());
                }
            }

            setVisible(false);
        }
    });

    this.connectButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            currentWorker = new Thread() {
                @Override
                public void run() {
                    StringBuilder error = new StringBuilder();
                    FileObject fo = null;

                    setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

                    try {
                        String m_username = usernameTextField.getText();
                        String m_defaultRemotePath = defaultRemotePathTextField.getText();
                        char[] m_password = passwordTextField.getPassword();
                        String m_hostname = hostnameTextField.getText();
                        String m_protocol = protocolList.getSelectedItem().toString();

                        int m_port = -1;

                        if (portTextField.isEditValid() && (portTextField.getValue() != null)) {
                            String s = portTextField.getValue().toString();
                            m_port = Integer.valueOf(s);
                        }

                        Builder credentialsBuilder = Credentials.newBuilder(m_hostname)
                                .defaultRemotePath(m_defaultRemotePath).username(m_username)
                                .password(m_password).protocol(m_protocol).port(m_port);

                        Credentials credentials = credentialsBuilder.build();

                        String uri = credentials.toFileObjectURL();

                        if (isInterrupted()) {
                            setPortTextFieldDirty(false);

                            return;
                        }

                        fo = VFSUtils.resolveFileObject(uri);

                        if ((fo != null) && !fo.exists()) {
                            fo = null;
                        }
                    } catch (Exception err) {
                        error.append(err.getMessage());
                        setCursor(Cursor.getDefaultCursor());
                    }

                    if ((error.length() > 0) || (fo == null)) {
                        error.delete(0, error.length());
                        error.append("Failed to connect!");
                        error.append("\n");
                        error.append("Please check parameters and try again.");

                        JOptionPane.showMessageDialog(ConnectionDialog.this, error, "Error",
                                JOptionPane.ERROR_MESSAGE);
                        setCursor(Cursor.getDefaultCursor());

                        return;
                    }

                    if (isInterrupted()) {
                        return;
                    }

                    fileChooser.setCurrentDirectory(fo);

                    setCursor(Cursor.getDefaultCursor());

                    resetFields();

                    if (bookmarksDialog != null) {
                        String bTitle = fo.getName().getBaseName();

                        if (bTitle.trim().equals("")) {
                            bTitle = fo.getName().toString();
                        }

                        String bURL = fo.getName().getURI();
                        bookmarksDialog.getBookmarks().add(new TitledURLEntry(bTitle, bURL));
                        bookmarksDialog.getBookmarks().save();
                    }

                    setVisible(false);
                }
            };

            currentWorker.setPriority(Thread.MIN_PRIORITY);
            currentWorker.start();
        }
    });

    // add the usual right click popup menu(copy, paste, etc.)
    PopupHandler.installDefaultMouseListener(hostnameTextField);
    PopupHandler.installDefaultMouseListener(portTextField);
    PopupHandler.installDefaultMouseListener(usernameTextField);
    PopupHandler.installDefaultMouseListener(passwordTextField);
    PopupHandler.installDefaultMouseListener(defaultRemotePathTextField);

    this.protocolList.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                selectPortNumber();
            }
        }
    });

    this.protocolList.setSelectedItem(Protocol.FTP);
}

From source file:com.panet.imeta.core.plugins.PluginLoader.java

private void build(FileObject parent, boolean isJar) throws KettleConfigException {
    try {/*from  www. j  a v a  2s. co  m*/
        FileObject xml = null;

        if (isJar) {
            FileObject exploded = explodeJar(parent);

            // try reading annotations first ...
            ResolverUtil<Plugin> resPlugins = new ResolverUtil<Plugin>();

            // grab all jar files not part of the "lib"
            File fparent = new File(exploded.getURL().getFile());
            File[] files = fparent.listFiles(new JarNameFilter());

            URL[] classpath = new URL[files.length];
            for (int i = 0; i < files.length; i++)
                classpath[i] = files[i].toURI().toURL();

            ClassLoader cl = new PDIClassLoader(classpath, Thread.currentThread().getContextClassLoader());
            resPlugins.setClassLoader(cl);

            for (FileObject couldBeJar : exploded.getChildren()) {
                if (couldBeJar.getName().getExtension().equals(JAR))
                    resPlugins.loadImplementationsInJar(Const.EMPTY_STRING, couldBeJar.getURL(),
                            tests.values().toArray(new ResolverUtil.Test[2]));
            }

            for (Class<? extends Plugin> match : resPlugins.getClasses()) {
                for (Class<? extends Annotation> cannot : tests.keySet()) {
                    Annotation annot = match.getAnnotation(cannot);
                    if (annot != null)
                        fromAnnotation(annot, exploded, match);
                }

            }

            // and we also read from the xml if present
            xml = exploded.getChild(Plugin.PLUGIN_XML_FILE);

            if (xml == null || !xml.exists())
                return;

            parent = exploded;

        } else
            xml = parent.getChild(Plugin.PLUGIN_XML_FILE);

        // then read the xml if it is there
        if (xml != null && xml.isReadable())
            fromXML(xml, parent);

    } catch (Exception e) {
        throw new KettleConfigException(e);
    }

    // throw new KettleConfigException("Unable to read plugin.xml from " +
    // parent);
}