Example usage for org.apache.commons.httpclient.util URIUtil encodeWithinAuthority

List of usage examples for org.apache.commons.httpclient.util URIUtil encodeWithinAuthority

Introduction

In this page you can find the example usage for org.apache.commons.httpclient.util URIUtil encodeWithinAuthority.

Prototype

public static String encodeWithinAuthority(String unescaped) throws URIException 

Source Link

Document

Escape and encode a string regarded as within the authority component of an URI with the default protocol charset.

Usage

From source file:pl.nask.hsn2.normalizers.URLNormalizerUtils.java

public static String normalizeUserInfo(StringBuilder in, int start, int end) throws URIException {
    int endSq = URLNormalizerUtils.findFirstMatch(in, "@", start, end);
    if (endSq < 0) {
        endSq = end;//from w  w  w  .  ja v  a  2 s  .c o m
    }
    StringBuilder sb = new StringBuilder(in.substring(start, endSq));

    int sep = findFirstMatch(sb, ":", 0);
    String enc = null;
    if (sep > 0) {
        removeObfuscatedEncoding(sb, 0, sep, new EncodingType[] { EncodingType.USERINFO });
        sep = findFirstMatch(sb, ":", 0);
        enc = URIUtil.encodeWithinAuthority(sb.substring(0, sep));
        sb.replace(0, sep, enc);
    } else {
        removeObfuscatedEncoding(sb, new EncodingType[] { EncodingType.USERINFO });
        enc = URIUtil.encodeWithinAuthority(sb.toString());
        sb.replace(0, sb.length(), enc);
    }
    in.replace(start, end, sb.toString());
    return sb.toString();
}