Package org.apache.catalina.util
Class URLEncoder
- java.lang.Object
-
- org.apache.catalina.util.URLEncoder
-
- All Implemented Interfaces:
java.lang.Cloneable
public final class URLEncoder extends java.lang.Object implements java.lang.CloneableThis class is very similar to the java.net.URLEncoder class. Unfortunately, with java.net.URLEncoder there is no way to specify to the java.net.URLEncoder which characters should NOT be encoded. This code was moved from DefaultServlet.java
-
-
Field Summary
Fields Modifier and Type Field Description static URLEncoderDEFAULTPre-configured encoder for URI paths.static URLEncoderQUERYPre-configured encoder for query strings.
-
Constructor Summary
Constructors Constructor Description URLEncoder()Constructs a new URLEncoder with alphanumeric characters as safe.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddSafeCharacter(char c)Marks the given character as safe (not requiring encoding).java.lang.Objectclone()java.lang.Stringencode(java.lang.String path, java.nio.charset.Charset charset)URL encodes the provided path using the given character set.voidremoveSafeCharacter(char c)Removes the given character from the set of safe characters.voidsetEncodeSpaceAsPlus(boolean encodeSpaceAsPlus)Sets whether space characters should be encoded as '+' instead of '%20'.
-
-
-
Field Detail
-
DEFAULT
public static final URLEncoder DEFAULT
Pre-configured encoder for URI paths.
-
QUERY
public static final URLEncoder QUERY
Pre-configured encoder for query strings.
-
-
Method Detail
-
addSafeCharacter
public void addSafeCharacter(char c)
Marks the given character as safe (not requiring encoding).- Parameters:
c- the character
-
removeSafeCharacter
public void removeSafeCharacter(char c)
Removes the given character from the set of safe characters.- Parameters:
c- the character
-
setEncodeSpaceAsPlus
public void setEncodeSpaceAsPlus(boolean encodeSpaceAsPlus)
Sets whether space characters should be encoded as '+' instead of '%20'.- Parameters:
encodeSpaceAsPlus- true to use '+' for spaces
-
encode
public java.lang.String encode(java.lang.String path, java.nio.charset.Charset charset)URL encodes the provided path using the given character set.- Parameters:
path- The path to encodecharset- The character set to use to convert the path to bytes- Returns:
- The encoded path
-
clone
public java.lang.Object clone()
- Overrides:
clonein classjava.lang.Object
-
-