Example usage for org.apache.commons.vfs.provider URLFileName getUserName

List of usage examples for org.apache.commons.vfs.provider URLFileName getUserName

Introduction

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

Prototype

public String getUserName() 

Source Link

Document

Returns the user name part of this name.

Usage

From source file:org.docx4all.util.AuthenticationUtil.java

public final static int getAuthorisationStatus(WebdavFileObject fo) throws FileSystemException {
    int status = 401; //unauthorised and retry.

    org.apache.webdav.lib.methods.OptionsMethod optionsMethod = null;
    try {/* ww  w.j av a2 s.  c  o m*/
        String urlCharset = WebdavFileSystemConfigBuilder.getInstance()
                .getUrlCharset(fo.getFileSystem().getFileSystemOptions());
        URLFileName urlFileName = (URLFileName) fo.getName();
        optionsMethod = new org.apache.webdav.lib.methods.OptionsMethod(
                urlFileName.getPathQueryEncoded(urlCharset));

        optionsMethod.setMethodRetryHandler(WebdavMethodRetryHandler.getInstance());
        optionsMethod.setFollowRedirects(true);

        char[] username = null;
        if (urlFileName.getUserName() != null) {
            username = urlFileName.getUserName().toCharArray();
        }
        char[] password = null;
        if (urlFileName.getPassword() != null) {
            password = urlFileName.getPassword().toCharArray();
        }

        WebdavClientFactory factory = new WebdavClientFactory();
        HttpClient client = factory.createConnection(urlFileName.getHostName(), urlFileName.getPort(), username,
                password, fo.getFileSystem().getFileSystemOptions());
        status = client.executeMethod(optionsMethod);
    } catch (Exception exc) {
        throw new FileSystemException("Cannot get authorisation status", exc);
    } finally {
        if (optionsMethod != null) {
            optionsMethod.releaseConnection();
        }
    }

    return status;
}

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

@Override
public FileName parseUri(VfsComponentContext vfsComponentContext, FileName fileName, String s)
        throws FileSystemException {
    if (fileName == null) {
        s = encodeAccessKeys(s);/*w w w .j  av  a 2 s .  c o  m*/
    }
    URLFileName name = (URLFileName) super.parseUri(vfsComponentContext, fileName, s);
    FileType type = name.getType();

    /* There is a problem with parsing bucket uri which has not char "/" at the end.
     * In this case UrlParser parse URI and return filename with type file.
     * As S3 does not allow to store files without buckets - so bucket is always a folder
      */
    if (FileType.FILE.equals(type) && name.getPath().split("/").length == 2) {
        type = FileType.FOLDER;
    }
    String user = name.getUserName();
    String password = name.getPassword();
    return new S3FileName(name.getScheme(), name.getHostName(), name.getPort(), getDefaultPort(), user,
            password, name.getPath(), type, name.getQueryString());
}