com.sas.servlet.util
Class URLEncoder

com.sas.servlet.util.URLEncoder
All Implemented Interfaces:
org.apache.commons.codec.BinaryDecoder, org.apache.commons.codec.BinaryEncoder, org.apache.commons.codec.Decoder, org.apache.commons.codec.Encoder, org.apache.commons.codec.StringDecoder, org.apache.commons.codec.StringEncoder

public class URLEncoder

Adds methods for the purpose of avoiding calls to the parent's encode methods when the incoming string is determined to already be in a URL safe form.

Since:
3.1

Field Summary
static java.util.BitSet WWW_FORM_URL_COPY
          BitSet of ASCII characters that need to be encoded in a URL.
 
Constructor Summary
URLEncoder()
           
 
Method Summary
static java.lang.String encodeURL(java.lang.String pString, java.lang.String charset)
          Encodes a String into its URL safe form using the specified string charset.
static java.lang.String encodeURLBasedOnSet(java.util.BitSet safeSet, java.lang.String pString, java.lang.String charset, java.lang.String outputCharset)
          Encodes a String into its URL safe form using the specified safe-character BitSet.
static boolean isURLSafe(java.lang.String s)
           Returns a boolean indicating whether the incoming String is URL safe.
 

Field Detail

WWW_FORM_URL_COPY

public static final java.util.BitSet WWW_FORM_URL_COPY
BitSet of ASCII characters that need to be encoded in a URL.

Constructor Detail

URLEncoder

public URLEncoder()
Method Detail

encodeURL

public static java.lang.String encodeURL(java.lang.String pString,
                                         java.lang.String charset)
                                  throws java.io.UnsupportedEncodingException
Encodes a String into its URL safe form using the specified string charset. Unsafe characters are escaped. If it is determined, via the isURLSafe method, that the incoming String does not require encoding then that String is returned. Otherwise, this method delegates the operation to its parent's encodeUrl method and a new String constructed with the resulting byte array is returned.

Parameters:
pString - string to convert to a URL safe form
charset - the charset for pString
Returns:
URL safe string
Throws:
java.io.UnsupportedEncodingException - Thrown if charset is not supported
See Also:
isURLSafe(byte[]), URLCodec.encodeUrl(java.util.BitSet, byte[])

isURLSafe

public static boolean isURLSafe(java.lang.String s)

Returns a boolean indicating whether the incoming String is URL safe.

If any character of the incoming String is not defined in the WWW_FORM_URL set or if any character is a space character, then this method return false. Otherwise, it returns true.

Returns:
a boolean indicating whether the incoming String is URL safe.
See Also:
URLCodec.WWW_FORM_URL, encodeURL(String, String)

encodeURLBasedOnSet

public static java.lang.String encodeURLBasedOnSet(java.util.BitSet safeSet,
                                                   java.lang.String pString,
                                                   java.lang.String charset,
                                                   java.lang.String outputCharset)
                                            throws java.io.UnsupportedEncodingException
Encodes a String into its URL safe form using the specified safe-character BitSet. Characters that are not present in the specified safe are encoded. If it is determined, via the isURLSafe method, that the incoming String does not require encoding then that String is returned. Otherwise, this method delegates the operation to its parent's encodeUrl method and a new String constructed with the resulting byte array is returned.

Parameters:
pString - string to convert to a URL safe form
charset - the charset for pString
charset - the outputCharset
Returns:
URL safe string
Throws:
java.io.UnsupportedEncodingException - Thrown if charset is not supported
See Also:
isURLSafe(byte[]), URLCodec.encodeUrl(java.util.BitSet, byte[])



Copyright © 2009 SAS Institute Inc. All Rights Reserved.