Class UrlEncoder


  • public class UrlEncoder
    extends Object
    Adapted from Spring Framework's UriUtils class, but defines instances for query string encoding versus URL path component encoding.

    The difference is important because a space is encoded as a + in a query string, but this is a valid value in a path component (and is therefore not decode back to a space).

    Author:
    Thomas Heigl
    See Also:
    RFC-2396
    • Field Detail

      • QUERY_INSTANCE

        public static final UrlEncoder QUERY_INSTANCE
        Encoder used to encode name or value components of a query string.

        For example: http://org.acme/notthis/northis/oreventhis?buthis=isokay&asis=thispart
      • PATH_INSTANCE

        public static final UrlEncoder PATH_INSTANCE
        Encoder used to encode segments of a path.

        For example: http://org.acme/foo/thispart/orthispart?butnot=thispart
    • Constructor Detail

      • UrlEncoder

        protected UrlEncoder​(org.apache.wicket.util.encoding.UrlEncoder.Type type)
        Allow subclass to call constructor.
        Parameters:
        type - encoder type
    • Method Detail

      • encode

        public String encode​(String s,
                             String charsetName)
        Parameters:
        s - string to encode
        charsetName - charset to use for encoding
        Returns:
        encoded string
      • encode

        public String encode​(String unsafeInput,
                             Charset charset)
        Parameters:
        unsafeInput - string to encode
        charset - encoding to use
        Returns:
        encoded string