public final class

URL

extends Object
java.lang.Object
   ↳ com.google.gwt.http.client.URL

Class Overview

Utility class for the encoding and decoding URLs in their entirety or by their individual components.

Required Module

Modules that use this class should inherit com.google.gwt.http.HTTP. {@gwt.include com/google/gwt/examples/http/InheritsExample.gwt.xml}

Summary

Public Methods
static String decode(String encodedURL)
Returns a string where all URL escape sequences have been converted back to their original character representations.
static String decodeComponent(String encodedURLComponent, boolean fromQueryString)
This method is deprecated. Use decodeQueryString(String), decodePathSegment(String)
static String decodeComponent(String encodedURLComponent)
This method is deprecated. Use decodeQueryString(String)
static String decodePathSegment(String encodedURLComponent)
Returns a string where all URL component escape sequences have been converted back to their original character representations.
static String decodeQueryString(String encodedURLComponent)
Returns a string where all URL component escape sequences have been converted back to their original character representations.
static String encode(String decodedURL)
Returns a string where all characters that are not valid for a complete URL have been escaped.
static String encodeComponent(String decodedURLComponent)
This method is deprecated. Use encodeQueryString(String)
static String encodeComponent(String decodedURLComponent, boolean queryStringSpaces)
This method is deprecated. Use encodeQueryString(String), encodePathSegment(String)
static String encodePathSegment(String decodedURLComponent)
Returns a string where all characters that are not valid for a URL component have been escaped.
static String encodeQueryString(String decodedURLComponent)
Returns a string where all characters that are not valid for a URL component have been escaped.
[Expand]
Inherited Methods
From class java.lang.Object

Public Methods

public static String decode (String encodedURL)

Returns a string where all URL escape sequences have been converted back to their original character representations.

Parameters
encodedURL string containing encoded URL encoded sequences
Returns
  • string with no encoded URL encoded sequences
Throws
NullPointerException if encodedURL is null

public static String decodeComponent (String encodedURLComponent, boolean fromQueryString)

This method is deprecated.
Use decodeQueryString(String), decodePathSegment(String)

Returns a string where all URL component escape sequences have been converted back to their original character representations.

Parameters
encodedURLComponent string containing encoded URL component sequences
fromQueryString if true, +'s will be turned into spaces, otherwise they'll be kept as-is.
Returns
  • string with no encoded URL component encoded sequences
Throws
NullPointerException if encodedURLComponent is null

public static String decodeComponent (String encodedURLComponent)

This method is deprecated.
Use decodeQueryString(String)

Returns a string where all URL component escape sequences have been converted back to their original character representations.

Note: this method will convert the space character escape short form, '+', into a space. It should therefore only be used for query-string parts.

Parameters
encodedURLComponent string containing encoded URL component sequences
Returns
  • string with no encoded URL component encoded sequences
Throws
NullPointerException if encodedURLComponent is null

public static String decodePathSegment (String encodedURLComponent)

Returns a string where all URL component escape sequences have been converted back to their original character representations.

Parameters
encodedURLComponent string containing encoded URL component sequences
Returns
  • string with no encoded URL component encoded sequences
Throws
NullPointerException if encodedURLComponent is null

public static String decodeQueryString (String encodedURLComponent)

Returns a string where all URL component escape sequences have been converted back to their original character representations.

Note: this method will convert the space character escape short form, '+', into a space. It should therefore only be used for query-string parts.

Parameters
encodedURLComponent string containing encoded URL component sequences
Returns
  • string with no encoded URL component encoded sequences
Throws
NullPointerException if encodedURLComponent is null

public static String encode (String decodedURL)

Returns a string where all characters that are not valid for a complete URL have been escaped. The escaping of a character is done by converting it into its UTF-8 encoding and then encoding each of the resulting bytes as a %xx hexadecimal escape sequence.

The following character sets are not escaped by this method:

  • ASCII digits or letters
  • ASCII punctuation characters:
     - _ . ! ~ * ' ( )
     
  • URL component delimiter characters:
     ; / ? : & = + $ , #
     

Parameters
decodedURL a string containing URL characters that may require encoding
Returns
  • a string with all invalid URL characters escaped
Throws
NullPointerException if decodedURL is null

public static String encodeComponent (String decodedURLComponent)

This method is deprecated.
Use encodeQueryString(String)

Returns a string where all characters that are not valid for a URL component have been escaped. The escaping of a character is done by converting it into its UTF-8 encoding and then encoding each of the resulting bytes as a %xx hexadecimal escape sequence.

Note: this method will convert any the space character into its escape short form, '+' rather than %20. It should therefore only be used for query-string parts.

The following character sets are not escaped by this method:

  • ASCII digits or letters
  • ASCII punctuation characters:
    - _ . ! ~ * ' ( )

Notice that this method does encode the URL component delimiter characters:

 ; / ? : & = + $ , #
 

Parameters
decodedURLComponent a string containing invalid URL characters
Returns
  • a string with all invalid URL characters escaped
Throws
NullPointerException if decodedURLComponent is null

public static String encodeComponent (String decodedURLComponent, boolean queryStringSpaces)

This method is deprecated.
Use encodeQueryString(String), encodePathSegment(String)

Returns a string where all characters that are not valid for a URL component have been escaped. The escaping of a character is done by converting it into its UTF-8 encoding and then encoding each of the resulting bytes as a %xx hexadecimal escape sequence.

The following character sets are not escaped by this method:

  • ASCII digits or letters
  • + *
  • ASCII punctuation characters:
    - _ . ! ~ * ' ( )

Notice that this method does encode the URL component delimiter characters:

 ; / ? : & = + $ , #
 

Parameters
decodedURLComponent a string containing invalid URL characters
queryStringSpaces if true, spaces will be encoded as +'s.
Returns
  • a string with all invalid URL characters escaped
Throws
NullPointerException if decodedURLComponent is null

public static String encodePathSegment (String decodedURLComponent)

Returns a string where all characters that are not valid for a URL component have been escaped. The escaping of a character is done by converting it into its UTF-8 encoding and then encoding each of the resulting bytes as a %xx hexadecimal escape sequence.

The following character sets are not escaped by this method:

  • ASCII digits or letters
  • ASCII punctuation characters:
    - _ . ! ~ * ' ( )

Notice that this method does encode the URL component delimiter characters:

 ; / ? : & = + $ , #
 

Parameters
decodedURLComponent a string containing invalid URL characters
Returns
  • a string with all invalid URL characters escaped
Throws
NullPointerException if decodedURLComponent is null

public static String encodeQueryString (String decodedURLComponent)

Returns a string where all characters that are not valid for a URL component have been escaped. The escaping of a character is done by converting it into its UTF-8 encoding and then encoding each of the resulting bytes as a %xx hexadecimal escape sequence.

Note: this method will convert any the space character into its escape short form, '+' rather than %20. It should therefore only be used for query-string parts.

The following character sets are not escaped by this method:

  • ASCII digits or letters
  • ASCII punctuation characters:
    - _ . ! ~ * ' ( )

Notice that this method does encode the URL component delimiter characters:

 ; / ? : & = + $ , #
 

Parameters
decodedURLComponent a string containing invalid URL characters
Returns
  • a string with all invalid URL characters escaped
Throws
NullPointerException if decodedURLComponent is null