Example usage for java.net URI getAuthority

List of usage examples for java.net URI getAuthority

Introduction

In this page you can find the example usage for java.net URI getAuthority.

Prototype

public String getAuthority() 

Source Link

Document

Returns the decoded authority component of this URI.

Usage

From source file:at.bitfire.davdroid.URIUtils.java

/**
 * Parse a received absolute/relative URL and generate a normalized URI that can be compared.
 * @param original       URI to be parsed, may be absolute or relative
  * @param mustBePath    true if it's known that original is a path (may contain ":") and not an URI, i.e. ":" is not the scheme separator
 * @return             normalized URI/*from w  w w  .  ja v  a2 s.  c om*/
 * @throws URISyntaxException
 */
public static URI parseURI(String original, boolean mustBePath) throws URISyntaxException {
    if (mustBePath) {
        // may contain ":"
        // case 1: "my:file"        won't be parsed by URI correctly because it would consider "my" as URI scheme
        // case 2: "path/my:file"   will be parsed by URI correctly
        // case 3: "my:path/file"   won't be parsed by URI correctly because it would consider "my" as URI scheme
        int idxSlash = original.indexOf('/'), idxColon = original.indexOf(':');
        if (idxColon != -1) {
            // colon present
            if ((idxSlash != -1) && idxSlash < idxColon) // There's a slash, and it's before the colon  everything OK
                ;
            else // No slash before the colon; we have to put it there
                original = "./" + original;
        }
    }

    // escape some common invalid characters  servers keep sending unescaped crap like "my calendar.ics" or "{guid}.vcf"
    // this is only a hack, because for instance, "[" may be valid in URLs (IPv6 literal in host name)
    String repaired = original.replaceAll(" ", "%20").replaceAll("\\{", "%7B").replaceAll("\\}", "%7D");
    if (!repaired.equals(original))
        Log.w(TAG, "Repaired invalid URL: " + original + " -> " + repaired);

    URI uri = new URI(repaired);
    URI normalized = new URI(uri.getScheme(), uri.getAuthority(), uri.getPath(), uri.getQuery(),
            uri.getFragment());
    Log.v(TAG, "Normalized URL " + original + " -> " + normalized.toASCIIString());
    return normalized;
}

From source file:org.eclipse.buckminster.p2.remote.client.RemoteRepositoryFactory.java

protected static URI getServerURI(URI repoURI) {
    try {/* ww  w. j a  v a 2  s  .  co  m*/
        return new URI(repoURI.getScheme(), repoURI.getAuthority(), repoURI.getPath(), repoURI.getQuery(),
                null);
    } catch (URISyntaxException e) {
        return repoURI;
    }
}

From source file:com.blackducksoftware.integration.hub.util.HubUrlParser.java

public static String getBaseUrl(final String url) throws URISyntaxException {
    final URI uri = new URI(url);
    final String derivedUrlPrefix = StringUtils.join(uri.getScheme(), "://", uri.getAuthority(), "/");
    return derivedUrlPrefix;
}

From source file:at.bitfire.davdroid.URIUtils.java

public static URI ensureTrailingSlash(URI href) {
    if (!href.getPath().endsWith("/")) {
        try {/*from  w w w. j  ava2  s  .  c  om*/
            URI newURI = new URI(href.getScheme(), href.getAuthority(), href.getPath() + "/", null, null);
            Log.d(TAG, "Appended trailing slash to collection " + href + " -> " + newURI);
            href = newURI;
        } catch (URISyntaxException e) {
        }
    }
    return href;
}

From source file:gobblin.util.JobConfigurationUtils.java

/**
 * Load the properties from the specified file into a {@link Properties} object.
 *
 * @param fileName the name of the file to load properties from
 * @param conf configuration object to determine the file system to be used
 * @return a new {@link Properties} instance
 *//*from ww  w  . j  a v a2s. c o m*/
public static Properties fileToProperties(String fileName, Configuration conf)
        throws IOException, ConfigurationException {

    PropertiesConfiguration propsConfig = new PropertiesConfiguration();
    Path filePath = new Path(fileName);
    URI fileURI = filePath.toUri();

    if (fileURI.getScheme() == null && fileURI.getAuthority() == null) {
        propsConfig.load(FileSystem.getLocal(conf).open(filePath));
    } else {
        propsConfig.load(filePath.getFileSystem(conf).open(filePath));
    }
    return ConfigurationConverter.getProperties(propsConfig);
}

From source file:org.attribyte.util.URIEncoder.java

/**
 * Recodes a URI./*  w w w  .j av  a  2  s.com*/
 * @param uri The uri.
 * @return The recoded URI as a string.
 */
public static String recode(URI uri) {
    return encode(uri.getScheme(), uri.getAuthority(), uri.getPath(), uri.getQuery(), uri.getFragment());
}

From source file:org.eclipse.orion.internal.server.servlets.task.TaskJobHandler.java

private static URI createTaskLocation(URI baseLocation, String taskId, boolean keep) throws URISyntaxException {
    return new URI(baseLocation.getScheme(), baseLocation.getAuthority(),
            (keep ? "/task/id/" : "/task/temp/") + taskId, null, null); //$NON-NLS-1$
}

From source file:org.ovirt.engine.sdk4.internal.SsoUtils.java

/**
 * Construct SSO URL to obtain token from username and password.
 *
 * @param url oVirt engine URL// w ww. j a v  a  2s .c  om
 * @return URI to be used to obtain token
 */
public static URI buildSsoUrlBasic(String url) {
    try {
        URI uri = new URI(url);
        URIBuilder uriBuilder = new URIBuilder(String.format("%1$s://%2$s/ovirt-engine/sso/oauth/%3$s",
                uri.getScheme(), uri.getAuthority(), ENTRY_POINT_TOKEN));
        return uriBuilder.build();
    } catch (URISyntaxException ex) {
        throw new Error("Failed to build SSO authentication URL", ex);
    }
}

From source file:org.ovirt.engine.sdk4.internal.SsoUtils.java

/**
 * Construct SSO URL to obtain token from kerberos authentication.
 *
 * @param url oVirt engine URL//from  w w  w .  ja  v  a  2s. c o m
 * @return URI to be used to obtain token
 */
public static URI buildSsoUrlKerberos(String url) {
    try {
        URI uri = new URI(url);
        URIBuilder uriBuilder = new URIBuilder(String.format("%1$s://%2$s/ovirt-engine/sso/oauth/%3$s",
                uri.getScheme(), uri.getAuthority(), ENTRY_POINT_HTTP));
        return uriBuilder.build();
    } catch (URISyntaxException ex) {
        throw new Error("Failed to build SSO authentication URL", ex);
    }
}

From source file:com.ibm.jaggr.core.util.PathUtil.java

public static URI appendToPath(URI uri, String append) throws URISyntaxException {
    return new URI(uri.getScheme(), uri.getAuthority(), uri.getPath() + append, uri.getQuery(),
            uri.getFragment());/*w w  w . j av  a2  s. c o m*/
}