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

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

Introduction

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

Prototype

public static String encodeWithinPath(String unescaped, String charset) throws URIException 

Source Link

Document

Escape and encode a string regarded as within the path component of an URI with a given charset.

Usage

From source file:net.hillsdon.fij.text.Escape.java

/**
 * Generate a correctly encoded URI string from the given components.
 * /*  w w  w  .  j ava 2s. c om*/
 * @param path The unencoded path. Will be encoded according to RFC3986.
 * @param query The unencoded query. May be null. Will be x-www-form-urlencoded.
 * @param fragment The unencoded fragment. May be null. Will be encoded according to RFC3986.
 * @param extraPath The <strong>encoded</strong> extra part to append to the path.
 * @return
 */
public static String constructEncodedURI(final String path, final String query, final String fragment,
        final String extraPath) {
    try {
        StringBuilder sb = new StringBuilder();
        sb.append(URIUtil.encodeWithinPath(path, "UTF-8"));
        if (extraPath != null) {
            sb.append(extraPath);
        }
        if (query != null) {
            sb.append("?");
            sb.append(URIUtil.encodeQuery(query, "UTF-8"));
        }
        if (fragment != null) {
            sb.append("#");
            sb.append(URIUtil.encodeWithinPath(fragment, "UTF-8"));
        }
        return sb.toString();
    } catch (URIException ex) {
        throw new Error("Java supports UTF-8!", ex);
    }
}

From source file:de.innovationgate.wgpublisher.webtml.utils.TMLContext.java

/**
 * creates an urlencoded RFC2396 dataurl
 * @param data//from w  w  w  . j a v a 2  s. co  m
 * @return
 * @throws UnsupportedEncodingException 
 * @throws URIException 
 */
private String createDataURL(String data, String contentType) throws URIException {
    StringBuffer url = new StringBuffer();
    url.append("data:");
    if (contentType != null) {
        url.append(contentType);
    }
    // RFC2396 defines that data is encoded in US-ASCII  
    url.append("," + URIUtil.encodeWithinPath(data, "UTF-8"));
    return url.toString();
}