Example usage for org.apache.commons.vfs.provider FileNameParser parseUri

List of usage examples for org.apache.commons.vfs.provider FileNameParser parseUri

Introduction

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

Prototype

public FileName parseUri(final VfsComponentContext context, final FileName base, final String filename)
        throws FileSystemException;

Source Link

Document

parses a String into a filename

Usage

From source file:org.pentaho.di.core.vfs.configuration.KettleSftpFileSystemConfigBuilder.java

/**
 * Publicly expose a generic way to set parameters
 *//*w w  w  .j  ava 2  s  . co m*/
@Override
public void setParameter(FileSystemOptions opts, String name, String value, String fullParameterName,
        String vfsUrl) throws IOException {
    if (!fullParameterName.startsWith("vfs.sftp")) {
        // This is not an SFTP parameter. Delegate to the generic handler
        super.setParameter(opts, name, value, fullParameterName, vfsUrl);
    } else {
        // Check for the presence of a host in the full variable name
        try {
            // Parse server name from vfsFilename
            FileNameParser sftpFilenameParser = SftpFileNameParser.getInstance();
            URLFileName file = (URLFileName) sftpFilenameParser.parseUri(null, null, vfsUrl);

            if (!parameterContainsHost(fullParameterName) || fullParameterName.endsWith(file.getHostName())) {
                // Match special cases for parameter names
                if (name.equalsIgnoreCase("AuthKeyPassphrase")) {
                    setParam(opts, UserInfo.class.getName(), new PentahoUserInfo(value));
                } else if (name.equals("identity")) {
                    File[] identities = (File[]) this.getParam(opts, "identities");

                    if (identities == null) {
                        identities = new File[] { new File(value) };
                    } else {
                        // Copy, in a Java 5 friendly manner, identities into a larger array
                        File[] temp = new File[identities.length + 1];
                        System.arraycopy(identities, 0, temp, 0, identities.length);
                        identities = temp;

                        identities[identities.length - 1] = new File(value);
                    }
                    setParam(opts, "identities", identities);
                } else {
                    setParam(opts, name, value);
                }
            } else {
                // No host match found
                log.logDebug("No host match found for: " + fullParameterName);
            }
        } catch (IOException e) {
            log.logError("Failed to set VFS parameter: [" + fullParameterName + "] " + value, e);
        }
    }
}

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

@Test
public void rootPathNoClusterName() throws FileSystemException {
    final String URI = "maprfs:///";

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

    assertEquals(URI, name.getURI());
    assertEquals("maprfs", name.getScheme());
}

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());
}

From source file:org.pentaho.s3.vfs.S3FileNameParserTest.java

@Test
public void testParseUri_withKeys() throws Exception {
    FileNameParser parser = S3FileNameParser.getInstance();
    String expected = buildS3URL("/rcf-emr-staging", true);

    FileName filename = parser.parseUri(null, null,
            "s3://" + awsAccessKey + ":" + awsSecretKey + "@" + HOST + "/rcf-emr-staging");
    assertEquals(expected, filename.getURI());

}

From source file:org.pentaho.s3.vfs.S3FileNameParserTest.java

@Test
public void testParseUri_withoutKeys() throws Exception {
    FileNameParser parser = S3FileNameParser.getInstance();
    String expected = buildS3URL("/", false);

    FileName filename = parser.parseUri(null, null, "s3://" + HOST + "/");
    assertEquals(expected, filename.getURI());

}