Example usage for org.apache.commons.vfs FileName getPath

List of usage examples for org.apache.commons.vfs FileName getPath

Introduction

In this page you can find the example usage for org.apache.commons.vfs FileName getPath.

Prototype

public String getPath();

Source Link

Document

Returns the absolute path of this file, within its file system.

Usage

From source file:com.panet.imeta.core.vfs.KettleVFS.java

public static String getFilename(FileObject fileObject) {
    FileName fileName = fileObject.getName();
    String root = fileName.getRootURI();
    if (!root.startsWith("file:"))
        return fileName.getURI(); // nothing we can do about non-normal files.
    if (root.endsWith(":/")) // Windows
    {/*from ww w .  ja  v  a 2  s.  c  o m*/
        root = root.substring(8, 10);
    } else // *nix & OSX
    {
        root = "";
    }
    String fileString = root + fileName.getPath();
    if (!"/".equals(Const.FILE_SEPARATOR)) {
        fileString = Const.replace(fileString, "/", Const.FILE_SEPARATOR);
    }
    return fileString;
}

From source file:com.thinkberg.moxo.vfs.s3.S3FileNameTest.java

public void testGetRootFolderFromUri() throws FileSystemException {
    String path = "/myfolder";
    String uri = ROOT + path;//from   w w  w.  ja  v a2 s . co  m
    FileName fileName = S3FileNameParser.getInstance().parseUri(null, null, uri);
    assertEquals(path, fileName.getPath());
}

From source file:com.panet.imeta.trans.steps.accessinput.AccessInputMeta.java

public static String getFilename(FileObject fileObject) {
    FileName fileName = fileObject.getName();
    String root = fileName.getRootURI();
    if (!root.startsWith("file:"))
        return fileName.getURI();
    if (root.endsWith(":/"))
        root = root.substring(8, 10);// ww w . j ava 2s . co  m
    else
        root = root.substring(7, root.length() - 1);
    String fileString = root + fileName.getPath();
    if (!"/".equals(Const.FILE_SEPARATOR))
        fileString = Const.replace(fileString, "/", Const.FILE_SEPARATOR);
    return fileString;
}

From source file:com.newatlanta.appengine.vfs.provider.GaeFileSystemManager.java

/**
 * Resolves a URI, relative to a base file with the specified FileSystem
 * configuration options.//from www .jav  a  2s.co  m
 */
@Override
public FileObject resolveFile(FileObject baseFile, String uri, FileSystemOptions opts)
        throws FileSystemException {
    // let the specified provider handle it
    if (!isCombinedLocal || isSchemeSpecified(uri)) {
        return super.resolveFile(baseFile, uri, opts);
    }

    FileObject localFile;
    FileObject gaeFile;

    if (baseFile != null) {
        // if uri starts with "/", determine if it includes the base path;
        // if it doesn't, then remove the leading "/" to create a relative
        // path; this is required to properly resolve "file://"
        uri = checkRelativity(baseFile, uri);

        FileObject fileObject = super.resolveFile(baseFile, uri, opts);
        if (fileObject.exists() && (fileObject.getType().hasContent())) {
            return fileObject; // return existing file
        }
        // fileObject doesn't exist or is a folder, check other file system
        if (fileObject.getName().getScheme().equals("gae")) {
            gaeFile = fileObject;
            FileName baseName = baseFile.getName();
            if (baseName instanceof GaeFileName) {
                String localUri = "file://" + ((GaeFileName) baseName).getRootPath() + baseName.getPath() + "/"
                        + uri;
                localFile = super.resolveFile(null, localUri, opts);
            } else {
                localFile = super.resolveFile(baseFile, "file://" + uri, opts);
            }
            if (localFile.exists() && (localFile.getType().hasContent())) {
                return localFile; // return existing local files
            }
        } else {
            localFile = fileObject;
            gaeFile = super.resolveFile(baseFile, "gae://" + uri, opts);
        }
    } else {
        // neither scheme nor baseFile specified, check local first
        localFile = super.resolveFile(null, uri, opts);
        if (localFile.exists() && (localFile.getType().hasContent())) {
            return localFile; // return existing local files
        }
        // localFile doesn't exist or is a folder, check GAE file system
        gaeFile = super.resolveFile(null, "gae://" + uri, opts);
    }

    ((GaeFileObject) gaeFile).setCombinedLocal(true);

    // when we get here we either have a non-existing file, or a folder;
    // return the GAE file/folder if it exists
    if (gaeFile.exists()) {
        return gaeFile;
    }

    // never return local folders
    if (localFile.exists()) {
        gaeFile.createFolder(); // create GAE "shadow" for existing local folder
        return gaeFile;
    }
    return gaeFile; // neither local nor GAE file/folder exists
}

From source file:com.newatlanta.appengine.vfs.provider.GaeFileObject.java

private Key createKey(FileName fileName) throws FileSystemException {
    // key name is relative path from the webapp root directory
    return KeyFactory.createKey(ENTITY_KIND, fileName.getPath());
}

From source file:org.josso.tooling.gshell.install.installer.VFSInstaller.java

/**
 * Get local file path./*from  w  w w. j  a  v  a  2 s  . c  o m*/
 * 
 * @param file file
 * @return local file path
 */
protected String getLocalFilePath(FileObject file) {
    FileName fileName = file.getName();
    String localPath = fileName.getPath();
    String rootFile = ((LocalFileName) fileName).getRootFile();
    if (rootFile != null) {
        localPath = rootFile + fileName.getPath();
    }
    return localPath;
}

From source file:org.pentaho.di.core.vfs.KettleVFS.java

public static String getFilename(FileObject fileObject) {
    FileName fileName = fileObject.getName();
    String root = fileName.getRootURI();
    if (!root.startsWith("file:")) {
        return fileName.getURI(); // nothing we can do about non-normal files.
    }//from  w  w w .j  a  va2 s  . com
    if (root.startsWith("file:////")) {
        return fileName.getURI(); // we'll see 4 forward slashes for a windows/smb network share
    }
    if (root.endsWith(":/")) { // Windows
        root = root.substring(8, 10);
    } else { // *nix & OSX
        root = "";
    }
    String fileString = root + fileName.getPath();
    if (!"/".equals(Const.FILE_SEPARATOR)) {
        fileString = Const.replace(fileString, "/", Const.FILE_SEPARATOR);
    }
    return fileString;
}

From source file:org.pentaho.di.trans.steps.accessinput.AccessInputMeta.java

public static String getFilename(FileObject fileObject) {
    FileName fileName = fileObject.getName();
    String root = fileName.getRootURI();
    if (!root.startsWith("file:")) {
        return fileName.getURI();
    }//from w ww .  j a  va2  s  .c  o  m
    if (root.endsWith(":/")) {
        root = root.substring(8, 10);
    } else {
        root = root.substring(7, root.length() - 1);
    }
    String fileString = root + fileName.getPath();
    if (!"/".equals(Const.FILE_SEPARATOR)) {
        fileString = Const.replace(fileString, "/", Const.FILE_SEPARATOR);
    }
    return fileString;
}

From source file:org.pentaho.hdfs.vfs.test.MapRFileNameParserTest.java

@Test
public void withPath() throws FileSystemException {
    final String URI = "maprfs:///my/file/path";

    FileNameParser parser = new MapRFileNameParser();
    FileName name = parser.parseUri(null, null, URI);

    assertEquals(URI, name.getURI());
    assertEquals("maprfs", name.getScheme());
    assertEquals("/my/file/path", name.getPath());
}

From source file:org.pentaho.hdfs.vfs.test.MapRFileNameParserTest.java

@Test
public void withPathAndClusterName() throws FileSystemException {
    final String URI = "maprfs://cluster2/my/file/path";

    FileNameParser parser = new MapRFileNameParser();
    FileName name = parser.parseUri(null, null, URI);

    assertEquals(URI, name.getURI());
    assertEquals("maprfs", name.getScheme());
    assertTrue(name.getURI().startsWith("maprfs://cluster2/"));
    assertEquals("/my/file/path", name.getPath());
}