Example usage for org.apache.commons.vfs2 FileName getRelativeName

List of usage examples for org.apache.commons.vfs2 FileName getRelativeName

Introduction

In this page you can find the example usage for org.apache.commons.vfs2 FileName getRelativeName.

Prototype

String getRelativeName(FileName name) throws FileSystemException;

Source Link

Document

Converts a file name to a relative name, relative to this file name.

Usage

From source file:fr.cls.atoll.motu.library.misc.vfs.provider.gsiftp.GsiFtpFileObject.java

/**
 * Instantiates a new gsi ftp file object.
 * //from w w  w .  j av  a2 s . co  m
 * @param name the name
 * @param fileSystem the file system
 * @param rootName the root name
 * 
 * @throws FileSystemException the file system exception
 */
protected GsiFtpFileObject(final AbstractFileName name, final GsiFtpFileSystem fileSystem,
        final FileName rootName) throws FileSystemException {
    super(name, fileSystem);
    ftpFs = fileSystem;
    String relPathTmp = UriParser.decode(rootName.getRelativeName(name));

    // log.debug("FileName=" + name + " Root=" + rootName
    // + " Relative path=" + relPath );

    if (".".equals(relPathTmp)) {
        // do not use the "." as path against the ftp-server
        // e.g. the uu.net ftp-server do a recursive listing then
        // this.relPath = UriParser.decode(rootName.getPath());
        // this.relPath = ".";
        // boolean ok = true;
        // try {
        // cwd = ftpFs.getClient().getCurrentDir();
        // }
        // catch (ServerException se) { ok = false;}
        // catch (IOException se) { ok = false;}

        // if ( ! ok ) {
        // throw new FileSystemException("vfs.provider.gsiftp/get-type.error", getName());
        // }
        this.relPath = "/"; // cwd;
    } else {
        this.relPath = relPathTmp;
    }
}

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

/**
 * @param file the file/*ww  w.  j ava 2s .  c o  m*/
 * @return the full path
 */
public final String pathFromRoot(FileObject file) {
    FileName rootFolderName = rootFolder.getName();
    FileName fileName = file.getName();
    try {
        return rootFolderName.getRelativeName(fileName);
    } catch (FileSystemException e) {
        throw new AutomationException(
                "Error resolving relative path " + rootFolderName.getPath() + " -> " + fileName.getPath(), e);
    }
}

From source file:org.celeria.minecraft.backup.ArchiveWorldTaskTest.java

@Before
public void setUpTemporaryWorldFolder(@TemporaryWorldFolder final FileName temporaryWorldFolderName)
        throws Exception {
    when(temporaryWorldFolder.getChildren()).thenReturn(new FileObject[] { folder, file });
    when(temporaryWorldFolder.getName()).thenReturn(temporaryWorldFolderName);
    when(temporaryWorldFolderName.getRelativeName(fileName)).thenReturn("foobar");
}