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

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

Introduction

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

Prototype

boolean exists() throws FileSystemException;

Source Link

Document

Determines if this file exists.

Usage

From source file:de.innovationgate.wgpublisher.design.sync.FileContainerDeployment.java

public boolean isUpdated()
        throws InstantiationException, IllegalAccessException, IOException, WGDesignSyncException {

    FileObject metadataFile = getMetadataFile();
    if (metadataFile.exists() && metadataFile.getContent().getLastModifiedTime() != _timestampOfMetadataFile) {
        return true;
    }/*  w  w w. ja v  a  2s.co  m*/

    List<FileObject> files = getFileContainerFiles();
    Collections.sort(files, new FileNameComparator());

    FileObject file;
    List<String> existingFiles = new ArrayList<String>();

    // Check for new and updated files
    for (int i = 0; i < files.size(); i++) {
        file = (FileObject) files.get(i);
        if (isExcludedFileContainerFile(file)) {
            continue;
        }

        ContainerFile containerFile = getContainerFile(file);
        if (containerFile == null) {
            return true;
        } else if (existingFiles.contains(containerFile.getName().toLowerCase())) {

            // Possible on case-sensitive file systems. A file with same name and
            // different case has already been processed. Ignore this duplicate.
            issueWarning(file.getName().getPathDecoded());
            continue;
        } else {
            existingFiles.add(containerFile.getName().toLowerCase());
            if (containerFile.getTimestamp() != file.getContent().getLastModifiedTime()) {
                return true;
            }
        }
    }

    // Check for deleted files
    List<String> containerFiles = new ArrayList<String>(_files.keySet());
    containerFiles.removeAll(existingFiles);
    if (containerFiles.size() > 0) {
        return true;
    } else {
        return false;
    }

}

From source file:de.innovationgate.wgpublisher.design.sync.DesignDeployment.java

public boolean isUpdated()
        throws InstantiationException, IllegalAccessException, IOException, WGDesignSyncException {

    FileObject metadataFile = getMetadataFile();
    FileObject codeFile = getCodeFile();

    if (_codeFileSize == -1) {
        _codeFileSize = codeFile.getContent().getSize();
    }// w  w w .j  a va2s  . com

    return ((metadataFile.exists()
            && metadataFile.getContent().getLastModifiedTime() != _timestampOfMetadataFile)
            || codeFile.getContent().getLastModifiedTime() != _timestampOfCodeFile
            || codeFile.getContent().getSize() != _codeFileSize);

}

From source file:de.innovationgate.wgpublisher.design.fs.AbstractDesignFile.java

private FileObject getOrCreateMetadataDir() throws FileSystemException, WGDesignSyncException {
    FileObject metadataDir = getMetadataDir();

    if (!metadataDir.exists() && metadataDir.getFileSystem().hasCapability(Capability.CREATE)) {
        metadataDir.createFolder();/*  ww w. j  a va2s  .com*/
    }

    return metadataDir;
}

From source file:de.innovationgate.wgpublisher.design.fs.AbstractDesignFile.java

protected FileObject getOrCreateMetadataFile()
        throws InstantiationException, IllegalAccessException, IOException, WGDesignSyncException {

    FileObject metadataFile = getMetadataFile();

    if (!metadataFile.exists() && metadataFile.getFileSystem().hasCapability(Capability.CREATE)) {
        getOrCreateMetadataDir();/*from   w w w.  ja v a 2  s. c  om*/
        createMetadataFile(metadataFile);
    }

    return metadataFile;
}

From source file:de.innovationgate.wgpublisher.design.fs.FileSystemDesignSource.java

public void createDesign(String designName) throws WGNotSupportedException, WGADesignCreationException {

    try {/*w  w  w  .j  ava2  s. c  om*/
        // Create the folder
        FileObject designDir = _dir.resolveFile(designName);
        if (designDir.exists()) {
            throw new WGADesignCreationException("A directory of name '" + designName + "' already exists");
        }
        designDir.createFolder();

        // Nuffin else to do .... initial deploy will do the rest
    } catch (Exception e) {
        throw new WGADesignCreationException("Exception creating file system design '" + designName + "'", e);
    }

}

From source file:de.innovationgate.wgpublisher.design.fs.FileSystemDesignSource.java

private CSConfig loadConfig(FileObject syncInfo) {

    try {/* w w  w.  j ava 2s  . c  o m*/
        if (syncInfo == null || !syncInfo.exists()) {
            return new CSConfig();
        }

        FileObject csConfig = syncInfo.getParent().resolveFile(SystemContainerManager.CSCONFIG_PATH);
        if (csConfig.exists()) {
            return CSConfig.load(csConfig);
        } else {
            return null;
        }
    } catch (Exception e) {
        _core.getLog().error("Exception loading design config", e);
        return null;
    }
}

From source file:de.innovationgate.wgpublisher.design.fs.FileSystemDesignSource.java

private OverlayData loadOverlayData(FileObject syncInfo) {

    try {//from w  w  w .jav a  2  s.  com
        if (syncInfo == null || !syncInfo.exists()) {
            return null;
        }

        FileObject overlayData = syncInfo.getParent().resolveFile(SystemContainerManager.OVERLAY_DATA_PATH);
        if (overlayData.exists()) {
            return OverlayData.load(overlayData);
        } else {
            return null;
        }
    } catch (Exception e) {
        _core.getLog().error("Exception loading overlay data", e);
        return null;
    }
}

From source file:com.sludev.commons.vfs.simpleshell.SimpleShell.java

/**
 * Does a 'cd' command./*w  w w .  j  ava2 s  .c  o  m*/
 * If the taget directory does not exist, a message is printed to <code>System.err</code>.
 */
public void cd(final String[] cmd) throws Exception {
    final String path;
    if (cmd.length > 1) {
        path = cmd[1];
    } else {
        path = System.getProperty("user.home");
    }

    // Locate and validate the folder
    FileObject tmp = mgr.resolveFile(cwd, path);
    if (tmp.exists()) {
        cwd = tmp;
    } else {
        System.out.println("Folder does not exist: " + tmp.getName());
    }
    System.out.println("Current folder is " + cwd.getName());
}

From source file:com.sludev.commons.vfs.simpleshell.SimpleShell.java

/**
 * Does a 'touch' command.//from ww  w  .  jav a 2s  . c o m
 * 
 * @param cmd
 * @throws java.lang.Exception
 */
public void touch(final String[] cmd) throws Exception {
    if (cmd.length < 2) {
        throw new Exception("USAGE: touch <path>");
    }
    final FileObject file = mgr.resolveFile(cwd, cmd[1]);
    if (!file.exists()) {
        file.createFile();
    }
    file.getContent().setLastModifiedTime(System.currentTimeMillis());
}

From source file:de.innovationgate.wgpublisher.design.fs.AbstractDesignFile.java

protected FileObject getFileContainerFile(String name) throws FileSystemException, WGDesignSyncException {

    // First step: Fast lookup for the given file in the given and lower case
    FileObject file = getCodeFile().resolveFile(name);
    if (file.exists()) {
        return (!isExcludedFileContainerFile(file) ? file : null);
    }/*  w  w w .j  ava  2 s  .co  m*/

    file = getCodeFile().resolveFile(name.toLowerCase());
    if (file.exists()) {
        return (!isExcludedFileContainerFile(file) ? file : null);
    }

    // Second step: Slow but case insensitive search for file 
    Iterator<FileObject> files = getFileContainerFiles().iterator();
    while (files.hasNext()) {
        file = files.next();
        if (file.getName().getBaseName().equalsIgnoreCase(name)) {
            return (!isExcludedFileContainerFile(file) ? file : null);
        }
    }

    return null;

}