org.apache.commons.httpclient.util

Class URIUtil


public class URIUtil
extends Object

The URI escape and character encoding and decoding utility. It's compatible with HttpURL rather than URI.

Nested Class Summary

protected static class
URIUtil.Coder
Deprecated. use org.apache.commons.codec.net.URLCodec

Field Summary

protected static BitSet
empty

Method Summary

static String
decode(String escaped)
Unescape and decode a given string regarded as an escaped string with the default protocol charset.
static String
decode(String escaped, String charset)
Unescape and decode a given string regarded as an escaped string.
static String
encode(String unescaped, BitSet allowed)
Escape and encode a given string with allowed characters not to be escaped and the default protocol charset.
static String
encode(String unescaped, BitSet allowed, String charset)
Escape and encode a given string with allowed characters not to be escaped and a given charset.
static String
encodeAll(String unescaped)
Get the all escaped and encoded string with the default protocl charset.
static String
encodeAll(String unescaped, String charset)
Get the all escaped and encoded string with a given charset.
static String
encodePath(String unescaped)
Escape and encode a string regarded as the path component of an URI with the default protocol charset.
static String
encodePath(String unescaped, String charset)
Escape and encode a string regarded as the path component of an URI with a given charset.
static String
encodePathQuery(String unescaped)
Escape and encode a string regarded as the path and query components of an URI with the default protocol charset.
static String
encodePathQuery(String unescaped, String charset)
Escape and encode a string regarded as the path and query components of an URI with a given charset.
static String
encodeQuery(String unescaped)
Escape and encode a string regarded as the query component of an URI with the default protocol charset.
static String
encodeQuery(String unescaped, String charset)
Escape and encode a string regarded as the query component of an URI with a given charset.
static String
encodeWithinAuthority(String unescaped)
Escape and encode a string regarded as within the authority component of an URI with the default protocol charset.
static String
encodeWithinAuthority(String unescaped, String charset)
Escape and encode a string regarded as within the authority component of an URI with a given charset.
static String
encodeWithinPath(String unescaped)
Escape and encode a string regarded as within the path component of an URI with the default protocol charset.
static String
encodeWithinPath(String unescaped, String charset)
Escape and encode a string regarded as within the path component of an URI with a given charset.
static String
encodeWithinQuery(String unescaped)
Escape and encode a string regarded as within the query component of an URI with the default protocol charset.
static String
encodeWithinQuery(String unescaped, String charset)
Escape and encode a string regarded as within the query component of an URI with a given charset.
static String
getFromPath(String uri)
Get the path of an URI and its rest part.
static String
getName(String uri)
Get the basename of an URI.
static String
getPath(String uri)
Get the path of an URI.
static String
getPathQuery(String uri)
Get the path and query of an URI.
static String
getQuery(String uri)
Get the query of an URI.

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Details

empty

protected static final BitSet empty

Method Details

decode

public static String decode(String escaped)
            throws URIException
Unescape and decode a given string regarded as an escaped string with the default protocol charset.
Parameters:
escaped - a string
Returns:
the unescaped string
Throws:
URIException - if the string cannot be decoded (invalid)
Usages and Demos :

View More Examples of decode(String escaped)
   1: 
   2: import org.apache.commons.httpclient.util.URIUtil;
   3: import junit.framework.*;
   4:         ...
   5:         try {
   6:             String stringRet = URIUtil.encodeWithinQuery(unescaped1);
   7:             assertEquals("abc123%2B%20%25_%3F%3D%26%23.%C3%A4", stringRet);
   8:         ...
   9:             stringRet = URIUtil.decode(stringRet);
  10:             assertEquals(unescaped1, stringRet);

View Full Code Here

decode

public static String decode(String escaped,
                            String charset)
            throws URIException
Unescape and decode a given string regarded as an escaped string.
Parameters:
escaped - a string
charset - the charset
Returns:
the unescaped string
Throws:
URIException - if the charset is not supported
Usages and Demos :

View More Examples of decode(String escaped,String charset)
   1: import org.apache.commons.httpclient.methods.StringRequestEntity;
   2: import org.apache.commons.httpclient.util.URIUtil;
   3: 
   4:         ...
   5:             String value = s.substring(i + 1, s.length()).trim(); 
   6:             value = URIUtil.decode(value, CHARSET_UTF8);
   7:             params.put(name, value);
   8:         ...
   9:             String value = s.substring(i + 1, s.length()).trim(); 
  10:             value = URIUtil.decode(value, CHARSET_UTF8);
  11:             params.put(name, value);

View Full Code Here

encode

public static String encode(String unescaped,
                            BitSet allowed)
            throws URIException
Escape and encode a given string with allowed characters not to be escaped and the default protocol charset.
Parameters:
unescaped - a string
allowed - allowed characters not to be escaped
Returns:
the escaped string
Throws:
URIException - if the default protocol charset is not supported
Usages and Demos :

View More Examples of encode(String unescaped,BitSet allowed)
   1: 
   2: import org.apache.commons.httpclient.util.URIUtil;
   3: 
   4:         ...
   5:             if (host != null) {
   6:                 buff.append(URIUtil.encode(host, URI.allowed_host));
   7:                 if (port != -1 || port != DEFAULT_PORT) {
   8:         ...
   9:             }
  10:             buff.append(URIUtil.encode(path, URI.allowed_abs_path));
  11:         }
  12:         ...
  13:             buff.append('?');
  14:             buff.append(URIUtil.encode(query, URI.allowed_query));

View Full Code Here
   1: import org.apache.commons.httpclient.auth.CredentialsProvider;
   2: import org.apache.commons.httpclient.util.URIUtil;
   3: import org.apache.commons.io.FileUtils;
   4:         ...
   5:         bits.or(allowed);
   6:         return URIUtil.encode(str, bits);
   7:     }
   8: 

View Full Code Here

encode

public static String encode(String unescaped,
                            BitSet allowed,
                            String charset)
            throws URIException
Escape and encode a given string with allowed characters not to be escaped and a given charset.
Parameters:
unescaped - a string
allowed - allowed characters not to be escaped
charset - the charset
Returns:
the escaped string

encodeAll

public static String encodeAll(String unescaped)
            throws URIException
Get the all escaped and encoded string with the default protocl charset. It's the same function to use encode(String unescaped, Bitset empty, URI.getDefaultProtocolCharset()).
Parameters:
unescaped - an unescaped string
Returns:
the escaped string
Throws:
URIException - if the default protocol charset is not supported

encodeAll

public static String encodeAll(String unescaped,
                               String charset)
            throws URIException
Get the all escaped and encoded string with a given charset. It's the same function to use encode(String unescaped, Bitset empty, String charset).
Parameters:
unescaped - an unescaped string
charset - the charset
Returns:
the escaped string
Throws:
URIException - if the charset is not supported
See Also:
encode

encodePath

public static String encodePath(String unescaped)
            throws URIException
Escape and encode a string regarded as the path component of an URI with the default protocol charset.
Parameters:
unescaped - an unescaped string
Returns:
the escaped string
Throws:
URIException - if the default protocol charset is not supported
Usages and Demos :

View More Examples of encodePath(String unescaped)
   1: import org.apache.commons.httpclient.URIException;
   2: import org.apache.commons.httpclient.util.URIUtil;
   3: import org.apache.commons.vfs.FileName;
   4:         ...
   5:             {
   6:                 return URIUtil.encodePath(getPathDecoded(), charset);
   7:             }
   8:         ...
   9:             {
  10:                 return URIUtil.encodePath(getPathDecoded());
  11:             }
  12:         ...
  13:         {
  14:             sb.append(URIUtil.encodePath(getPathDecoded(), charset));

View Full Code Here
   1: import org.apache.commons.httpclient.util.DateParser;
   2: import org.apache.commons.httpclient.util.URIUtil;
   3: import org.apache.commons.vfs.FileContentInfoFactory;
   4:         ...
   5:     {
   6:         String pathEncoded = URIUtil.encodePath(decodedPath);
   7:         return pathEncoded;
   8:     }

View Full Code Here

encodePath

public static String encodePath(String unescaped,
                                String charset)
            throws URIException
Escape and encode a string regarded as the path component of an URI with a given charset.
Parameters:
unescaped - an unescaped string
charset - the charset
Returns:
the escaped string
Throws:
URIException - if the charset is not supported
See Also:
encode
Usages and Demos :

View More Examples of encodePath(String unescaped,String charset)
   1: 
   2: import org.apache.commons.httpclient.util.URIUtil;
   3: import org.apache.commons.httpclient.URIException;
   4:         ...
   5:         try {
   6:             return URIUtil.encodePath(path, "UTF-8");
   7:         } catch (URIException e) {
   8:         ...
   9:         try {
  10:             return URIUtil.encodePathQuery(pathQuery, "UTF-8");
  11:         } catch (URIException e) {

View Full Code Here

encodePathQuery

public static String encodePathQuery(String unescaped)
            throws URIException
Escape and encode a string regarded as the path and query components of an URI with the default protocol charset.
Parameters:
unescaped - an unescaped string
Returns:
the escaped string
Throws:
URIException - if the default protocol charset is not supported

encodePathQuery

public static String encodePathQuery(String unescaped,
                                     String charset)
            throws URIException
Escape and encode a string regarded as the path and query components of an URI with a given charset.
Parameters:
unescaped - an unescaped string
charset - the charset
Returns:
the escaped string
Throws:
URIException - if the charset is not supported
See Also:
encode
Usages and Demos :

View More Examples of encodePathQuery(String unescaped,String charset)
   1: 
   2: import org.apache.commons.httpclient.util.URIUtil;
   3: import org.apache.commons.httpclient.URIException;
   4:         ...
   5:         try {
   6:             return URIUtil.encodePath(path, "UTF-8");
   7:         } catch (URIException e) {
   8:         ...
   9:         try {
  10:             return URIUtil.encodePathQuery(pathQuery, "UTF-8");
  11:         } catch (URIException e) {

View Full Code Here

encodeQuery

public static String encodeQuery(String unescaped)
            throws URIException
Escape and encode a string regarded as the query component of an URI with the default protocol charset. When a query string is not misunderstood the reserved special characters ("&", "=", "+", ",", and "$") within a query component, this method is recommended to use in encoding the whole query.
Parameters:
unescaped - an unescaped string
Returns:
the escaped string
Throws:
URIException - if the default protocol charset is not supported

encodeQuery

public static String encodeQuery(String unescaped,
                                 String charset)
            throws URIException
Escape and encode a string regarded as the query component of an URI with a given charset. When a query string is not misunderstood the reserved special characters ("&", "=", "+", ",", and "$") within a query component, this method is recommended to use in encoding the whole query.
Parameters:
unescaped - an unescaped string
charset - the charset
Returns:
the escaped string
Throws:
URIException - if the charset is not supported
See Also:
encode

encodeWithinAuthority

public static String encodeWithinAuthority(String unescaped)
            throws URIException
Escape and encode a string regarded as within the authority component of an URI with the default protocol charset. Within the authority component, the characters ";", ":", "@", "?", and "/" are reserved.
Parameters:
unescaped - an unescaped string
Returns:
the escaped string
Throws:
URIException - if the default protocol charset is not supported

encodeWithinAuthority

public static String encodeWithinAuthority(String unescaped,
                                           String charset)
            throws URIException
Escape and encode a string regarded as within the authority component of an URI with a given charset. Within the authority component, the characters ";", ":", "@", "?", and "/" are reserved.
Parameters:
unescaped - an unescaped string
charset - the charset
Returns:
the escaped string
Throws:
URIException - if the charset is not supported
See Also:
encode

encodeWithinPath

public static String encodeWithinPath(String unescaped)
            throws URIException
Escape and encode a string regarded as within the path component of an URI with the default protocol charset. The path may consist of a sequence of path segments separated by a single slash "/" character. Within a path segment, the characters "/", ";", "=", and "?" are reserved.
Parameters:
unescaped - an unescaped string
Returns:
the escaped string
Throws:
URIException - if the default protocol charset is not supported
Usages and Demos :

View More Examples of encodeWithinPath(String unescaped)
   1: import org.apache.commons.httpclient.HttpState;
   2: import org.apache.commons.httpclient.util.URIUtil;
   3: 
   4:         ...
   5:         try {
   6:             return URIUtil.encodeWithinPath(value);
   7:         } catch (URIException e) {
   8:             throw new RepositoryException("Error encoding " + name + " string", e);
   9:         }

View Full Code Here
   1: import org.apache.commons.httpclient.URIException;
   2: import org.apache.commons.httpclient.util.URIUtil;
   3: import org.apache.xmlbeans.XmlOptions;
   4:         ...
   5:         try {
   6:             return URIUtil.encodeWithinPath(value);
   7:         } catch (URIException e) {
   8:             throw new RepositoryException("Error encoding " + name + " string", e);
   9:         }

View Full Code Here

encodeWithinPath

public static String encodeWithinPath(String unescaped,
                                      String charset)
            throws URIException
Escape and encode a string regarded as within the path component of an URI with a given charset. The path may consist of a sequence of path segments separated by a single slash "/" character. Within a path segment, the characters "/", ";", "=", and "?" are reserved.
Parameters:
unescaped - an unescaped string
charset - the charset
Returns:
the escaped string
Throws:
URIException - if the charset is not supported
See Also:
encode

encodeWithinQuery

public static String encodeWithinQuery(String unescaped)
            throws URIException
Escape and encode a string regarded as within the query component of an URI with the default protocol charset. When a query comprise the name and value pairs, it is used in order to encode each name and value string. The reserved special characters within a query component are being included in encoding the query.
Parameters:
unescaped - an unescaped string
Returns:
the escaped string
Throws:
URIException - if the default protocol charset is not supported
Usages and Demos :

View More Examples of encodeWithinQuery(String unescaped)
   1: 
   2: import org.apache.commons.httpclient.util.URIUtil;
   3: import junit.framework.*;
   4:         ...
   5:         try {
   6:             String stringRet = URIUtil.encodeWithinQuery(unescaped1);
   7:             assertEquals("abc123%2B%20%25_%3F%3D%26%23.%C3%A4", stringRet);
   8:         ...
   9:             stringRet = URIUtil.decode(stringRet);
  10:             assertEquals(unescaped1, stringRet);

View Full Code Here

encodeWithinQuery

public static String encodeWithinQuery(String unescaped,
                                       String charset)
            throws URIException
Escape and encode a string regarded as within the query component of an URI with a given charset. When a query comprise the name and value pairs, it is used in order to encode each name and value string. The reserved special characters within a query component are being included in encoding the query.
Parameters:
unescaped - an unescaped string
charset - the charset
Returns:
the escaped string
Throws:
URIException - if the charset is not supported
See Also:
encode

getFromPath

public static String getFromPath(String uri)
Get the path of an URI and its rest part.
Parameters:
uri - a string regarded an URI
Returns:
the string from the path part

getName

public static String getName(String uri)
Get the basename of an URI. It's possibly an empty string.
Parameters:
uri - a string regarded an URI
Returns:
the basename string; an empty string if the path ends with slash

getPath

public static String getPath(String uri)
Get the path of an URI.
Parameters:
uri - a string regarded an URI
Returns:
the path string
Usages and Demos :

View More Examples of getPath(String uri)
   1: 
   2: import org.apache.commons.httpclient.util.URIUtil;
   3: 
   4:         ...
   5:             expectedResult = pathTests[i].getExpectedResult();
   6:             assertEquals("Path test", expectedResult, URIUtil.getPath(testValue));
   7:         }
   8:         ...
   9:             expectedResult = queryTests[i].getExpectedResult();
  10:             assertEquals("Path test", expectedResult, URIUtil.getQuery(testValue));
  11:         }

View Full Code Here
   1: 
   2: import org.apache.commons.httpclient.util.URIUtil;
   3: 
   4:         ...
   5:             if (CmsStringUtil.isNotEmpty(uri)) {
   6:                 uri = URIUtil.getPath(uri);
   7:             }
   8:             return uri;
   9:         } else {

View Full Code Here

getPathQuery

public static String getPathQuery(String uri)
Get the path and query of an URI.
Parameters:
uri - a string regarded an URI
Returns:
the path and query string

getQuery

public static String getQuery(String uri)
Get the query of an URI.
Parameters:
uri - a string regarded an URI
Returns:
the query string; null if empty or undefined
Usages and Demos :

View More Examples of getQuery(String uri)
   1: 
   2: import org.apache.commons.httpclient.util.URIUtil;
   3: 
   4:         ...
   5:             expectedResult = pathTests[i].getExpectedResult();
   6:             assertEquals("Path test", expectedResult, URIUtil.getPath(testValue));
   7:         }
   8:         ...
   9:             expectedResult = queryTests[i].getExpectedResult();
  10:             assertEquals("Path test", expectedResult, URIUtil.getQuery(testValue));
  11:         }

View Full Code Here