Example usage for com.google.common.net UrlEscapers urlFragmentEscaper

List of usage examples for com.google.common.net UrlEscapers urlFragmentEscaper

Introduction

In this page you can find the example usage for com.google.common.net UrlEscapers urlFragmentEscaper.

Prototype

public static Escaper urlFragmentEscaper() 

Source Link

Document

Returns an Escaper instance that escapes strings so they can be safely included in a <a href="http://goo.gl/xXEq4p">URL fragment</a>.

Usage

From source file:diskCacheV111.namespace.MonitoringNameSpaceProvider.java

private String serialiseLink(PnfsId id, String name) {
    return id + " " + UrlEscapers.urlFragmentEscaper().escape(name);
}

From source file:com.pidoco.juri.JURI.java

protected CharSequence buildNoSideEffects() throws URISyntaxException {
    String scheme = this.scheme == null ? prototype.getScheme() : this.scheme;
    String rawUserInfo = this.rawUserInfo == null ? prototype.getRawUserInfo() : this.rawUserInfo;
    CharSequence rawHost = this.host == null ? prototype.getHost() : this.buildHostString();
    int port = this.port == null ? this.prototype.getPort() : this.port;
    CharSequence rawPath = this.rawPath == null ? this.prototype.getRawPath() : this.rawPath;
    CharSequence rawQuery = this.buildQueryParametersString();
    String rawFragment = this.fragment == null ? this.prototype.getRawFragment()
            : UrlEscapers.urlFragmentEscaper().escape(this.fragment);

    StringBuilder builder = new StringBuilder(32);
    if (!removeAuthorityAndScheme) {
        if (StringUtils.isNotBlank(scheme)) {
            builder.append(scheme);//from  ww  w . j av a  2 s  .com
            builder.append(':');
        }

        boolean hasAuthority = StringUtils.isNotBlank(rawHost) || port > -1
                || StringUtils.isNotBlank(rawUserInfo);
        if (hasAuthority) {
            builder.append("//");
        }
        if (StringUtils.isNotBlank(rawUserInfo)) {
            builder.append(rawUserInfo).append('@');
        }
        if (StringUtils.isNotBlank(rawHost)) {
            builder.append(rawHost);
        }
        if (port > 0) {
            builder.append(':').append(port);
        }
    }

    if (StringUtils.isNotBlank(rawPath)) {
        builder.append(rawPath);
    }
    if (StringUtils.isNotBlank(rawQuery)) {
        builder.append('?').append(rawQuery);
    }
    if (StringUtils.isNotBlank(rawFragment)) {
        builder.append('#').append(rawFragment);
    }

    return builder;
}

From source file:com.google.cloud.storage.contrib.nio.CloudStorageFileSystemProvider.java

/** Convenience method: replaces spaces with "%20", builds a URI, and calls getPath(uri). */
public CloudStoragePath getPath(String uriInStringForm) {
    String escaped = UrlEscapers.urlFragmentEscaper().escape(uriInStringForm);
    return getPath(URI.create(escaped));
}

From source file:com.pidoco.juri.JURI.java

/**
 * BEWARE, this cannot be used to escape many http scheme specific parts, as possibly other scheme's specific parts.
 * Problem is the different escaping of some characters depending on the (semantic) location.
 *
 * <p>If no scheme is currently set the scheme will become 'unspecified'.</p>
 *
 * @param schemeSpecificPart null or "" not allowed.
 *///from   w  ww  .  ja  v a  2  s . co m
public JURI setSchemeSpecificPart(String schemeSpecificPart) {
    schemeSpecificPart = StringUtils.defaultString(schemeSpecificPart);

    setRawSchemeSpecificPart(UrlEscapers.urlFragmentEscaper().escape(schemeSpecificPart));
    return this;
}

From source file:org.eclipse.mylyn.internal.wikitext.commonmark.inlines.PotentialBracketEndDelimiter.java

private String normalizeUri(String uriWithEscapes) {
    String uriWithoutBackslashEscapes = unescapeBackslashEscapes(uriWithEscapes);
    try {/* ww w  . j av a  2s. c  o m*/
        String uriWithoutHtmlEntities = replaceHtmlEntities(uriWithoutBackslashEscapes,
                UrlEscapers.urlFormParameterEscaper());
        String decoded = URLDecoder.decode(uriWithoutHtmlEntities, StandardCharsets.UTF_8.name());
        Escaper escaper = UrlEscapers.urlFragmentEscaper();
        return escaper.escape(decoded);
    } catch (Exception e) {
        return uriWithoutBackslashEscapes;
    }
}

From source file:com.google.cloud.storage.StorageImpl.java

@Override
public URL signUrl(BlobInfo blobInfo, long duration, TimeUnit unit, SignUrlOption... options) {
    EnumMap<SignUrlOption.Option, Object> optionMap = Maps.newEnumMap(SignUrlOption.Option.class);
    for (SignUrlOption option : options) {
        optionMap.put(option.getOption(), option.getValue());
    }/*from w  w w  .ja v  a  2 s. c  om*/
    ServiceAccountSigner credentials = (ServiceAccountSigner) optionMap
            .get(SignUrlOption.Option.SERVICE_ACCOUNT_CRED);
    if (credentials == null) {
        checkState(this.getOptions().getCredentials() instanceof ServiceAccountSigner,
                "Signing key was not provided and could not be derived");
        credentials = (ServiceAccountSigner) this.getOptions().getCredentials();
    }

    long expiration = TimeUnit.SECONDS.convert(getOptions().getClock().millisTime() + unit.toMillis(duration),
            TimeUnit.MILLISECONDS);

    StringBuilder stPath = new StringBuilder();
    if (!blobInfo.getBucket().startsWith(PATH_DELIMITER)) {
        stPath.append(PATH_DELIMITER);
    }
    stPath.append(blobInfo.getBucket());
    if (!blobInfo.getBucket().endsWith(PATH_DELIMITER)) {
        stPath.append(PATH_DELIMITER);
    }
    if (blobInfo.getName().startsWith(PATH_DELIMITER)) {
        stPath.setLength(stPath.length() - 1);
    }

    String escapedName = UrlEscapers.urlFragmentEscaper().escape(blobInfo.getName());
    stPath.append(escapedName.replace("?", "%3F"));

    URI path = URI.create(stPath.toString());

    try {
        SignatureInfo signatureInfo = buildSignatureInfo(optionMap, blobInfo, expiration, path);
        byte[] signatureBytes = credentials.sign(signatureInfo.constructUnsignedPayload().getBytes(UTF_8));
        StringBuilder stBuilder = new StringBuilder("https://storage.googleapis.com").append(path);
        String signature = URLEncoder.encode(BaseEncoding.base64().encode(signatureBytes), UTF_8.name());
        stBuilder.append("?GoogleAccessId=").append(credentials.getAccount());
        stBuilder.append("&Expires=").append(expiration);
        stBuilder.append("&Signature=").append(signature);

        return new URL(stBuilder.toString());

    } catch (MalformedURLException | UnsupportedEncodingException ex) {
        throw new IllegalStateException(ex);
    }
}