Example usage for org.apache.commons.vfs.provider UriParser extractScheme

List of usage examples for org.apache.commons.vfs.provider UriParser extractScheme

Introduction

In this page you can find the example usage for org.apache.commons.vfs.provider UriParser extractScheme.

Prototype

public static String extractScheme(final String uri, final StringBuffer buffer) 

Source Link

Document

Extracts the scheme from a URI.

Usage

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

public FileName parseUri(final VfsComponentContext context, final FileName base, final String filename)
        throws FileSystemException {
    StringBuffer name = new StringBuffer();

    String scheme = UriParser.extractScheme(filename, name);
    UriParser.canonicalizePath(name, 0, name.length(), this);

    UriParser.fixSeparators(name);/*from  ww  w .  j  ava2 s . com*/

    // Normalise the path
    FileType fileType = UriParser.normalisePath(name);

    // Extract the root prefix
    final String bucketName = UriParser.extractFirstElement(name);

    return new S3FileName(scheme, bucketName, name.toString(), fileType);
}

From source file:com.jaspersoft.jasperserver.api.metadata.common.util.RepositoryFileNameParser.java

public FileName parseUri(final VfsComponentContext context, final FileName base, final String filename)
        throws FileSystemException {
    final StringBuffer name = new StringBuffer();

    // Extract the scheme
    final String foundScheme = UriParser.extractScheme(filename, name);

    if (!scheme.equals(foundScheme)) {
        throw new FileSystemException("invalid scheme: " + foundScheme);
    }//from  w w w  .  ja  va2 s.c o m

    // Decode and normalise the path
    UriParser.canonicalizePath(name, 0, name.length(), this);
    UriParser.fixSeparators(name);
    FileType fileType = UriParser.normalisePath(name);
    final String path = name.toString();

    return new RepositoryFileName(scheme, path, fileType);
}

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

/**
 * Makes sure <code>filename</code> always specifies a path that is within a
 * sub-directory of the webapp root path.
 *//*from  w w  w.  j ava  2 s  .co  m*/
public FileName parseUri(VfsComponentContext context, FileName baseName, String uri)
        throws FileSystemException {
    StringBuffer name = new StringBuffer();

    // Extract the scheme
    String scheme = UriParser.extractScheme(uri, name);
    if (scheme == null) { // this should never happen
        scheme = "gae";
    }

    // Remove encoding, and adjust the separators
    UriParser.canonicalizePath(name, 0, name.length(), this);
    UriParser.fixSeparators(name);

    // Normalise the path
    FileType fileType = UriParser.normalisePath(name);

    // all GAE files *must* be relative to the root file, which must be the
    // webapp root (though we have no way of enforcing this)
    String rootPath = "";
    if (baseName == null) { // this is the root object
        rootPath = name.toString();
        name.setLength(0);
    } else {
        rootPath = getRootPath(baseName);
        if (name.indexOf(rootPath) == 0) { // if ( name.startsWith( basePath ) )
            name.delete(0, rootPath.length());
        }
    }
    return new GaeFileName(scheme, rootPath, name.toString(), fileType);
}

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

public static String getRootPath(FileName baseName) throws FileSystemException {
    FileName rootName = baseName.getRoot();
    if (rootName instanceof GaeFileName) {
        return ((GaeFileName) rootName).getRootPath();
    } else {//from  w  ww.j  a va2 s .  c  om
        StringBuffer rootPath = new StringBuffer();
        UriParser.extractScheme(baseName.getURI(), rootPath);
        UriParser.normalisePath(rootPath);
        return rootPath.toString().intern();
    }
}

From source file:com.bedatadriven.renjin.appengine.AppEngineLocalFilesSystemProvider.java

@Override
public FileObject findFile(FileObject baseFile, String uri, FileSystemOptions properties)
        throws FileSystemException {

    System.out.println(uri);//from   ww  w.jav a  2s  .c om

    // Parse the name
    final StringBuffer buffer = new StringBuffer(uri);
    String scheme = UriParser.extractScheme(uri, buffer);
    if (scheme == null) {
        scheme = "file";
    }

    UriParser.fixSeparators(buffer);

    FileType fileType = UriParser.normalisePath(buffer);
    final String path = buffer.toString();

    // Create the temp file system if it does not exist
    // FileSystem filesystem = findFileSystem( this, (Properties) null);
    FileSystem filesystem = findFileSystem(this, properties);
    if (filesystem == null) {
        final FileName rootName = getContext().parseURI(scheme + ":" + FileName.ROOT_PATH);

        filesystem = new LocalFileSystem(rootName, rootFile.getAbsolutePath(), properties);
        addFileSystem(this, filesystem);
    }

    // Find the file
    return filesystem.resolveFile(path);
}