Example usage for org.apache.commons.vfs2 FileObject equals

List of usage examples for org.apache.commons.vfs2 FileObject equals

Introduction

In this page you can find the example usage for org.apache.commons.vfs2 FileObject equals.

Prototype

public boolean equals(Object obj) 

Source Link

Document

Indicates whether some other object is "equal to" this one.

Usage

From source file:com.googlecode.vfsjfilechooser2.utils.VFSUtils.java

/**
 * Returns whether a folder contains a given file
 * @param folder A folder/*from   www  .  j av a2 s .c om*/
 * @param file A file
 * @return whether a folder contains a given file
 */
public static boolean isParent(FileObject folder, FileObject file) {
    try {
        FileObject parent = file.getParent();

        if (parent == null) {
            return false;
        }

        return parent.equals(folder);
    } catch (FileSystemException ex) {
        return false;
    }
}

From source file:com.googlecode.vfsjfilechooser2.filepane.VFSFilePane.java

public Action getNewFolderAction() {
    if (!readOnly && (newFolderAction == null)) {
        newFolderAction = new AbstractAction(newFolderActionLabelText) {
            private Action basicNewFolderAction;

            {//from   ww  w .ja  v a  2s.c  o m
                putValue(Action.ACTION_COMMAND_KEY, VFSFilePane.ACTION_NEW_FOLDER);

                FileObject currentDirectory = getFileChooser().getCurrentDirectoryObject();

                if (currentDirectory != null) {
                    setEnabled(canWrite(currentDirectory));
                }
            }

            public void actionPerformed(ActionEvent ev) {
                if (basicNewFolderAction == null) {
                    basicNewFolderAction = fileChooserUIAccessor.getNewFolderAction();
                }

                VFSJFileChooser fc = getFileChooser();
                FileObject oldFile = fc.getSelectedFileObject();
                basicNewFolderAction.actionPerformed(ev);

                FileObject newFile = fc.getSelectedFileObject();

                if ((newFile != null) && !newFile.equals(oldFile) && VFSUtils.isDirectory(newFile)) {
                    newFolderFile = newFile;
                }
            }
        };
    }

    return newFolderAction;
}

From source file:org.aludratest.service.file.impl.AbstractFileAction.java

protected void getOrCreateDirectory(FileObject directory) {
    FileObject root = configuration.getRootFolder();
    if (!root.equals(directory)) {
        try {//from   www . ja v  a 2 s  .c o  m
            getOrCreateDirectory(directory.getParent());
            directory.createFolder();
        } catch (IOException e) {
            throw new TechnicalException("Error creating directory", e);
        }
    }
}

From source file:org.aludratest.service.file.impl.FileActionImpl.java

private void getOrCreateDirectory(FileObject directory) {
    FileObject root = configuration.getRootFolder();
    if (!root.equals(directory)) {
        try {/*from   w ww  . j  a v  a 2  s. c  o m*/
            getOrCreateDirectory(directory.getParent());
            directory.createFolder();
        } catch (FileSystemException e) {
            throw new TechnicalException("Error creating directory", e);
        }
    }
}

From source file:org.apache.hadoop.gateway.topology.file.FileTopologyProvider.java

private void handleFileEvent(FileChangeEvent fileChangeEvent) throws FileSystemException {
    FileObject file = fileChangeEvent.getFile();
    if (file != null && (!file.getType().hasChildren() || file.equals(directory))) {
        reloadTopologies();/*from w ww  .  j ava  2 s .  co m*/
    }
}

From source file:org.kalypso.commons.io.VFSUtilities.java

/**
 * This function copies a source file to a given destination. If no filename is given in the destination file handle,
 * the filename of the source is used.<br>
 * <br>/* w ww .j  a v a  2 s .c  o  m*/
 * It is tried to copy the file three times. If all three tries has failed, only then an IOException is thrown. <br>
 * All other exceptions are thrown normally.
 *
 * @param source
 *          The source file.
 * @param destination
 *          The destination file or path.
 * @param overwrite
 *          If set, always overwrite existing and newer files
 */
public static void copyFileTo(final FileObject source, final FileObject destination, final boolean overwrite)
        throws IOException {
    if (source.equals(destination)) {
        KalypsoCommonsDebug.DEBUG.printf(Messages.getString("org.kalypso.commons.io.VFSUtilities.1"), //$NON-NLS-1$
                source.getName(), destination.getName());
        return;
    }

    /* Some variables for handling the errors. */
    boolean success = false;
    int cnt = 0;

    while (success == false) {
        try {
            if (FileType.FOLDER.equals(source.getType()))
                throw new IllegalArgumentException(Messages.getString("org.kalypso.commons.io.VFSUtilities.2")); //$NON-NLS-1$

            /* If the destination is only a directory, use the sources filename for the destination file. */
            FileObject destinationFile = destination;
            if (FileType.FOLDER.equals(destination.getType()))
                destinationFile = destination.resolveFile(source.getName().getBaseName());

            if (overwrite || !destinationFile.exists()
                    || destinationFile.getContent().getSize() != source.getContent().getSize()) {
                /* Copy file. */
                KalypsoCommonsDebug.DEBUG.printf("Copy file '%s' to '%s'...%n", source.getName(), //$NON-NLS-1$
                        destinationFile.getName());
                FileUtil.copyContent(source, destinationFile);
                source.close();
            }

            /* End copying of this file, because it was a success. */
            success = true;
        } catch (final IOException e) {
            /* An error has occurred while copying the file. */
            KalypsoCommonsDebug.DEBUG.printf("An error has occured with the message: %s%n", //$NON-NLS-1$
                    e.getLocalizedMessage());

            /* If a certain amount (here 2) of retries was reached before, re-throw the error. */
            if (cnt >= 2) {
                KalypsoCommonsDebug.DEBUG.printf("The second retry has failed, rethrowing the error...%n"); //$NON-NLS-1$
                throw e;
            }

            /* Retry the copying of the file. */
            cnt++;
            KalypsoCommonsDebug.DEBUG.printf("Retry: %s%n", String.valueOf(cnt)); //$NON-NLS-1$
            success = false;

            /* Wait for some milliseconds. */
            try {
                Thread.sleep(1000);
            } catch (final InterruptedException e1) {
                /*
                 * Runs in the next loop then and if no error occurs then, it is ok. If an error occurs again, it is an
                 * exception thrown on the last failed retry or it is slept again.
                 */
            }
        }
    }
}

From source file:org.kalypso.service.wps.utils.simulation.WPSSimulationResultEater.java

/**
 * This function will create ComplexValueReference with the given file and copies it directly to the result directory.
 *
 * @param sourceFile//from   www .  j  av a  2  s.  c  o  m
 *          The file to reference in the ComplexValueReference.
 * @return A ComplexValueReference with the given file.
 */
private synchronized ComplexValueReference addComplexValueReference(final File sourceFile)
        throws SimulationException {
    checkResultDir();

    try {
        /* Getting the relative path to the source file. */
        final String relativePathToSource = FileUtilities.getRelativePathTo(m_tmpDir, sourceFile);
        if (relativePathToSource == null)
            throw new SimulationException(Messages.getString(
                    "org.kalypso.service.wps.utils.simulation.WPSSimulationResultEater.12", sourceFile)); //$NON-NLS-1$
        final String uri = m_resultDir.getURL().toExternalForm() + "/" + relativePathToSource; //$NON-NLS-1$

        final FileObject destination = m_vfsManager.resolveFile(uri);

        /* assure old behavior - for none existing source files! */
        if (sourceFile.exists()) {
            final FileObject source = m_vfsManager.toFileObject(sourceFile);
            if (!source.equals(destination))
                VFSUtilities.copy(source, destination);
        }

        // keep track of file references
        m_references.put(sourceFile, destination);

        /* Build complex value reference. */
        return WPS040ObjectFactoryUtilities.buildComplexValueReference(
                WPSUtilities.convertInternalToClient(destination.getURL().toExternalForm()), null, null, null);
    } catch (final IOException e) {
        throw new SimulationException(Messages.getString(
                "org.kalypso.service.wps.utils.simulation.WPSSimulationResultEater.13", sourceFile), e); //$NON-NLS-1$
    }
}

From source file:org.mycore.datamodel.ifs2.MCRStore.java

/**
 * Deletes the data stored in the given file object from the store
 * /*ww w  .  j a  v  a2  s  .  c  o m*/
 * @param fo
 *            the file object to be deleted
 */
void delete(FileObject fo) throws IOException {
    FileObject parent = fo.getParent();
    fo.delete(Selectors.SELECT_ALL);

    while (!parent.equals(baseDirectory)) {
        final FileObject[] children = parent.getChildren();
        if (children.length > 0) {
            break;
        }
        fo = parent;
        parent = fo.getParent();
        fo.delete();
    }
}

From source file:org.ow2.proactive_grid_cloud_portal.dataspace.FileSystem.java

public static ListFile list(FileObject fo, List<String> includes, List<String> excludes)
        throws FileSystemException {
    fo.refresh();// ww  w .j a v a  2s. c  o m
    ListFile answer = new ListFile();
    List<String> dirList = Lists.newArrayList();
    List<String> fileList = Lists.newArrayList();
    List<String> fullList = Lists.newArrayList();
    List<FileObject> foundFileObjects = new LinkedList<>();
    if (isNullOrEmpty(includes) && isNullOrEmpty(excludes)) {
        fo.findFiles(Selectors.SELECT_CHILDREN, false, foundFileObjects);
    } else {
        FileSelector selector = new org.objectweb.proactive.extensions.dataspaces.vfs.selector.FileSelector(
                includes, excludes);
        fo.findFiles(selector, false, foundFileObjects);
    }

    for (FileObject child : foundFileObjects) {
        FileType type = child.getType();
        FileName childName = child.getName();
        switch (type) {
        case FOLDER:
            if (!child.equals(fo)) {
                // exclude root directory from the list
                String relativePath = fo.getName().getRelativeName(childName);
                dirList.add(relativePath);
                fullList.add(relativePath);
            }
            break;
        case FILE:
            String relativePath = fo.getName().getRelativeName(childName);
            fileList.add(relativePath);
            fullList.add(relativePath);
            break;
        default:
            throw new RuntimeException("Unknown : " + type);
        }
    }
    Collections.sort(dirList);
    Collections.sort(fileList);
    Collections.sort(fullList);
    answer.setDirectoryListing(dirList);
    answer.setFileListing(fileList);
    answer.setFullListing(fullList);
    return answer;
}

From source file:org.pentaho.reporting.designer.extensions.pentaho.repository.dialogs.RepositoryOpenDialog.java

private ComboBoxModel createLocationModel(final FileObject selectedFolder) {
    if (fileSystemRoot == null) {
        return new DefaultComboBoxModel();
    }/*from   ww  w  .j a  v a2  s  .c o  m*/

    try {
        final ArrayList<FileObject> list = new ArrayList<FileObject>();
        FileObject folder = selectedFolder;
        while (folder != null) {
            if (fileSystemRoot.equals(folder)) {
                break;
            }

            if (folder.getType() != FileType.FILE) {
                list.add(folder);
            }

            final FileObject parent = folder.getParent();
            if (folder.equals(parent)) {
                // protect yourself against infinite loops ..
                break;
            }
            folder = parent;
        }
        list.add(fileSystemRoot);
        final DefaultComboBoxModel model = new DefaultComboBoxModel(list.toArray());
        model.setSelectedItem(list.get(0));
        return model;
    } catch (FileSystemException e) {
        return new DefaultComboBoxModel();
    }
}