Example usage for java.net URI toString

List of usage examples for java.net URI toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns the content of this URI as a string.

Usage

From source file:com.vmware.identity.idm.server.ServerUtils.java

public static Collection<String> getConnectionStringFromUris(Collection<URI> uris) {
    List<String> connectionStrs = new ArrayList<String>();
    for (URI uri : uris) {
        connectionStrs.add(uri.toString());
    }/* w  w w . j a  v a  2  s  . c o  m*/
    return Collections.unmodifiableCollection(connectionStrs);
}

From source file:org.wrml.runtime.format.application.vnd.wrml.design.schema.SchemaDesignFormatter.java

private static ObjectNode buildSyntaxNode(final ObjectMapper objectMapper, final Type heapValueType,
        final SyntaxLoader syntaxLoader) {

    if (!String.class.equals(heapValueType) && heapValueType instanceof Class<?>) {

        // TODO: Make it easy/possible to get the Syntax Document's title and uri

        final Class<?> heapValueClass = (Class<?>) heapValueType;
        final URI syntaxUri = syntaxLoader.getSyntaxUri(heapValueClass);
        final String syntaxName = heapValueClass.getSimpleName();
        final ObjectNode syntaxNode = objectMapper.createObjectNode();

        syntaxNode.put(PropertyName.title.name(), syntaxName);
        syntaxNode.put(PropertyName.uri.name(), syntaxUri.toString());
        return syntaxNode;
    }/*  w w  w  .  j a  v  a2s.com*/
    return null;
}

From source file:com.sworddance.util.UriFactoryImpl.java

public static URI createUriWithQuery(URI uri, Map<String, String> parameters) {
    Map<String, String> queryMap = getQueryMap(uri);
    queryMap.putAll(parameters);//from  www .j av a 2 s  . co  m
    String noQueryUriString = uri.toString();
    int queryDelimiterIndex = noQueryUriString.indexOf('?');
    if (queryDelimiterIndex > -1) {
        noQueryUriString = noQueryUriString.substring(0, queryDelimiterIndex);
    }
    URI noQueryUri = createUriWithSchemaAndPath(noQueryUriString);
    String queryString = createQueryString(queryMap);
    return URI.create(noQueryUri + "?" + queryString);
}

From source file:net.community.chest.gitcloud.facade.frontend.git.GitController.java

static final HttpRequestBase resolveRequest(RequestMethod method, URI uri) {
    if (RequestMethod.GET.equals(method)) {
        return new HttpGet(uri);
    } else if (RequestMethod.POST.equals(method)) {
        return new HttpPost(uri);
    } else { // TODO add support for HEAD, OPTIONS, TRACE, PUT if necessary
        throw new UnsupportedOperationException(uri.toString() + " - unknown method: " + method);
    }/*  w w  w  .  j av a 2s  . c o  m*/
}

From source file:org.wrml.runtime.format.application.vnd.wrml.design.schema.SchemaDesignFormatter.java

private static ObjectNode buildChoicesNode(final ObjectMapper objectMapper, final Type heapValueType,
        final SchemaLoader schemaLoader) {

    if (heapValueType == null || !(heapValueType instanceof Class<?>)) {
        return null;
    }//from   www  .  j  a va 2  s  .  c  om

    final Class<?> choicesEnumClass = (Class<?>) heapValueType;

    if (!choicesEnumClass.isEnum()) {
        return null;
    }

    final URI choicesUri = schemaLoader.getTypeUri(choicesEnumClass);
    final String choicesName = choicesEnumClass.getSimpleName();
    final ObjectNode choicesNode = objectMapper.createObjectNode();

    choicesNode.put(PropertyName.title.name(), choicesName);
    choicesNode.put(PropertyName.uri.name(), choicesUri.toString());

    // TODO: Only embed the choices once per schema to lighten the download?
    final Object[] enumConstants = choicesEnumClass.getEnumConstants();
    if (enumConstants != null && enumConstants.length > 0) {
        final ArrayNode valuesNode = objectMapper.createArrayNode();

        choicesNode.put(PropertyName.values.name(), valuesNode);

        for (final Object enumConstant : enumConstants) {
            final String choice = String.valueOf(enumConstant);
            valuesNode.add(choice);
        }
    }

    return choicesNode;
}

From source file:com.adaptris.core.fs.FsHelper.java

/**
 * Creates a {@link URL} based on the passed destination.
 * <p>/*from w  ww  . j a  v a 2  s  .co m*/
 * If a {@code scheme} is present and is equal to {@code file} then the URL is deemed to be <strong>absolute</strong> and is used
 * as is. If the {@code scheme} is null then the URL is considered a {@code "file"} URL, and <strong>relative</strong>> to the
 * current working directory.
 * </p>
 * 
 * @param s the string to convert to a URL.
 * @param backslashConvert whether or not to convert backslashes into forward slashes.
 * 
 */
public static URL createUrlFromString(String s, boolean backslashConvert)
        throws IOException, URISyntaxException {
    String destToConvert = backslashConvert ? backslashToSlash(s) : s;
    URI configuredUri = null;
    try {
        configuredUri = new URI(destToConvert);
    } catch (URISyntaxException e) {
        // Specifically here to cope with file:///c:/ (which is
        // technically illegal according to RFC2396 but we need
        // to support it
        if (destToConvert.split(":").length >= 3) {
            configuredUri = new URI(URLEncoder.encode(destToConvert, "UTF-8"));
        } else {
            throw e;
        }
    }
    String scheme = configuredUri.getScheme();

    if ("file".equals(scheme)) {
        // nb for some reason, configuredUri.toUrl() doesn't work...
        // return configuredUri.toURL();
        return new URL(configuredUri.toString());
    } else {
        if (scheme == null) {
            return new URL("file:///" + configuredUri.toString());
        } else {
            throw new IllegalArgumentException("Illegal URL [" + s + "]");
        }
    }
}

From source file:com.microsoft.tfs.client.common.ui.helpers.CredentialsHelper.java

public static Credentials getOAuthCredentials(final URI serverURI, final JwtCredentials accessToken,
        final Action<DeviceFlowResponse> callback) {
    removeStaleOAuth2Token();//ww  w.ja v a 2 s  .  co m

    final Authenticator authenticator;
    final OAuth2Authenticator oauth2Authenticator = OAuth2Authenticator.getAuthenticator(CLIENT_ID,
            REDIRECT_URL, accessTokenStore, callback);
    final Token token;

    final AuthLibHttpClientFactory authLibHttpClientFactory = new AuthLibHttpClientFactory();
    Global.setHttpClientFactory(authLibHttpClientFactory);

    if (serverURI != null) {
        log.debug("Interactively retrieving credential based on oauth2 flow for " + serverURI.toString()); //$NON-NLS-1$
        log.debug("Trying to persist credential, generating a PAT"); //$NON-NLS-1$

        authenticator = new VstsPatAuthenticator(oauth2Authenticator, tokenStore);

        final String tokenKey = authenticator.getUriToKeyConversion().convert(serverURI,
                authenticator.getAuthType());
        removeStalePersonalAccessToken(tokenKey, serverURI);

        final TokenPair oauth2Token = (accessToken == null) ? null
                : new TokenPair(accessToken.getAccessToken(), "null"); //$NON-NLS-1$

        token = authenticator.getPersonalAccessToken(serverURI, VsoTokenScope.AllScopes,
                getAccessTokenDescription(serverURI.toString()), PromptBehavior.AUTO, oauth2Token);
    } else {
        log.debug("Interactively retrieving credential based on oauth2 flow for VSTS"); //$NON-NLS-1$
        log.debug("Do not try to persist, generating oauth2 token."); //$NON-NLS-1$

        authenticator = oauth2Authenticator;

        final TokenPair tokenPair = authenticator.getOAuth2TokenPair();
        token = tokenPair != null ? tokenPair.AccessToken : null;
    }

    if (token != null && token.Type != null && !StringUtil.isNullOrEmpty(token.Value)) {
        switch (token.Type) {
        case Personal:
            return new PatCredentials(token.Value);
        case Access:
            return new JwtCredentials(token.Value);
        }
    }

    log.warn(Messages.getString("CredentialsHelper.InteractiveAuthenticationFailedDetailedLog1")); //$NON-NLS-1$
    log.warn(Messages.getString("CredentialsHelper.InteractiveAuthenticationFailedDetailedLog2")); //$NON-NLS-1$
    log.warn(Messages.getString("CredentialsHelper.InteractiveAuthenticationFailedDetailedLog3")); //$NON-NLS-1$

    removeOAuth2Token(true);

    // Failed to get credential, return null
    return null;
}

From source file:com.sworddance.util.UriFactoryImpl.java

/**
 * @param root//from w  ww .  j a  va2 s  .c  om
 * @param filePath
 * @param defaultFileName
 * @return resolvedUri
 */
public static URI resolveWithDefaultFile(Object root, Object filePath, String defaultFileName) {
    URI rootUri = createUriWithSchemaAndPath(root);
    ApplicationNullPointerException.notNull(rootUri, root);

    String filePathStr = sanitizePath(filePath);
    URI uri;
    if (isNotBlank(filePathStr)) {
        uri = rootUri.resolve("./" + percentEncoding(filePathStr));
    } else {
        uri = rootUri;
    }
    if (uri.toString().endsWith(PATH_SEPARATOR) && isNotBlank(defaultFileName)) {
        uri = uri.resolve("." + PATH_SEPARATOR + percentEncoding(defaultFileName));
    }
    return uri;
}

From source file:eu.planets_project.tb.gui.backing.ServiceBrowser.java

/**
 * @param fmt/*from   w w w  .java  2  s . c o m*/
 * @return
 */
private static SelectItem createFormatURISelectItem(URI fmt) {
    return new SelectItem(fmt.toString(), fmt.toString());
}

From source file:org.mulgara.scon.Connection.java

/**
 * Encodes a URI if it looks like it needs it.
 * @param u The URI to encode, if needed.
 * @return a minimally encoded URI./*w w w . j a  v  a  2 s  .c  o m*/
 */
private static final String enc(URI u) {
    try {
        // if there is no query, then just return the unencoded URI
        String query = u.getRawQuery();
        if (query == null)
            return u.toString();
        // encode the query, and add it to the end of the URI
        String encQuery = encode(query);
        String encU = new URI(u.getScheme(), u.getUserInfo(), u.getHost(), u.getPort(), u.getPath(), encQuery,
                u.getFragment()).toString();
        // if the partial encoding works, then return it
        if (decode(encU).equals(u.toString()))
            return encU;
        // nothing else worked, so encode it fully
        return encode(u.toString());
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException("Unable to encode a URI", e);
    }
}