Package com.facilita.fc.web
Class Coder
- java.lang.Object
-
- com.facilita.fc.web.Coder
-
public class Coder extends java.lang.Object
Provides static methods for encoding and decodingString
data. For more information about percent-encoding, refer to RFC 3986.
-
-
Constructor Summary
Constructors Constructor Description Coder(long cPtr, boolean cMemoryOwn)
For internal use only.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static java.lang.String
decodeHTML(java.lang.String data)
Decodes special characters within the specified HTMLString
.void
delete()
static long
getCPtr(Coder obj)
For internal use only.static java.lang.String
getDefaultCharactersAllowedInPostedForm()
Gets aString
containing all the characters that, by default, are allowed to be posted in aForm
.static java.lang.String
getDefaultUnsafeCharacters()
Gets aString
containing the characters that, by default, are considered to be unsafe and must be percent-encoded.static java.lang.String
postDataEncode(java.lang.String data)
Encodes aString
so that it can be sent to a web server as POST data.static java.lang.String
postDataEncode(java.lang.String data, java.lang.String charactersAllowedInPostedForm)
Encodes aString
so that it can be sent to a web server as POST data, specifying the characters which shouldn't be encoded.static java.lang.String
urlDecode(java.lang.String urlFragment)
Decodes a percent-encodedString
.static java.lang.String
urlEncode(java.lang.String urlFragment)
Encodes aString
using percent-encoding.static java.lang.String
urlEncode(java.lang.String urlFragment, java.lang.String unsafeCharacters)
Encodes aString
using percent-encoding, specifying which characters should be encoded.static java.lang.String
urlEncode(java.lang.String urlFragment, java.lang.String unsafeCharacters, boolean encodeReservedCharacters)
Encodes aString
using percent-encoding, specifying which characters should be encoded (optionally including reserved characters).
-
-
-
Method Detail
-
getCPtr
public static long getCPtr(Coder obj)
For internal use only. Of no interest to the user.- Parameters:
obj
- a reference to an object of this class- Returns:
- a long containing the address of the CPP wrapped object
-
delete
public void delete()
-
urlDecode
public static java.lang.String urlDecode(java.lang.String urlFragment)
Decodes a percent-encodedString
. Converts percent-encoded characters such as%3F
into the character they represent, in this case the question mark character?
.For more information about percent-encoding, refer to RFC 3986.
e.g.
String decoded = Coder.urlDecode("search%3Fq%3Dcamera"); // decoded == search?q=camera
- Parameters:
urlFragment
- the text to decode; this is usually a portion of aUrl
- Returns:
- the decoded text
-
urlEncode
public static java.lang.String urlEncode(java.lang.String urlFragment, java.lang.String unsafeCharacters, boolean encodeReservedCharacters)
Encodes aString
using percent-encoding, specifying which characters should be encoded (optionally including reserved characters).A character in the
String
will be percent-encoded if:- It is outside the printable ASCII range (i.e. is not in the ASCII range 32 to 127) OR
- It is one of the defined
unsafeCharacters
OR - It is a reserved character, and
encodeReservedCharacters
has the valuetrue
For more information about percent-encoding, refer to RFC 3986.
e.g.
String encoded = Coder.urlEncode("search?q=camera", "<>\"%{}|\\^[]` \n\t\r&", true); // encoded == search%3Fq%3Dcamera
- Parameters:
urlFragment
- the text to percent-encodeunsafeCharacters
- aString
containing a list of characters that need to be percent-encodedencodeReservedCharacters
-true
if reserved characters should be encoded- Returns:
- the encoded text
- See Also:
getDefaultUnsafeCharacters()
-
urlEncode
public static java.lang.String urlEncode(java.lang.String urlFragment, java.lang.String unsafeCharacters)
Encodes aString
using percent-encoding, specifying which characters should be encoded.A character in the
String
will be percent-encoded if:- It is outside the printable ASCII range (i.e. is not in the ASCII range 32 to 127) OR
- It is one of the defined
unsafeCharacters
For more information about percent-encoding, refer to RFC 3986.
e.g.
String encoded = Coder.urlEncode("search?q=camera", "<>\"%{}|\\^[]` \n\t\r&"); // encoded == search%3Fq%3Dcamera
- Parameters:
urlFragment
- the text to percent-encodeunsafeCharacters
- aString
containing a list of characters that need to be percent-encoded- Returns:
- the encoded text
- See Also:
getDefaultUnsafeCharacters()
-
urlEncode
public static java.lang.String urlEncode(java.lang.String urlFragment)
Encodes aString
using percent-encoding.A character in the
String
will be percent-encoded if:- It is outside the printable ASCII range (i.e. is not in the ASCII range 32 to 127) OR
- It is one of the default
unsafeCharacters
(seegetDefaultUnsafeCharacters()
)
For more information about percent-encoding, refer to RFC 3986.
e.g.
String encoded = Coder.urlEncode("search?q=camera"); // encoded == search%3Fq%3Dcamera
- Parameters:
urlFragment
- the text to percent-encode- Returns:
- the encoded text
-
postDataEncode
public static java.lang.String postDataEncode(java.lang.String data)
Encodes aString
so that it can be sent to a web server as POST data. This is done using percent-encoding, in a similar way tourlEncode(String)
, with the exception that space characters will be converted to+
, not%20
- Parameters:
data
- the text to encode- Returns:
- the encoded text
-
postDataEncode
public static java.lang.String postDataEncode(java.lang.String data, java.lang.String charactersAllowedInPostedForm)
Encodes aString
so that it can be sent to a web server as POST data, specifying the characters which shouldn't be encoded. This is done using percent-encoding, in a similar way tourlEncode(String)
, with the exception that space characters will be converted to+
, not%20
- Parameters:
data
- the text to encodecharactersAllowedInPostedForm
- aString
containing characters that can be present in POST data without being percent-encoded (seegetDefaultCharactersAllowedInPostedForm()
)- Returns:
- the encoded text
-
decodeHTML
public static java.lang.String decodeHTML(java.lang.String data)
Decodes special characters within the specified HTMLString
. For example,&
will be converted to&
.- Parameters:
data
- the text to decode- Returns:
- the decoded text
-
getDefaultCharactersAllowedInPostedForm
public static java.lang.String getDefaultCharactersAllowedInPostedForm()
Gets aString
containing all the characters that, by default, are allowed to be posted in aForm
.By default, a character will be percent-encoded within a form if it is:
- Outside the ASCII range OR
- Not an alpha-numeric character AND not in this list of allowed characters
' '
- space'-'
- hyphen'_'
- underscore'.'
- full stop'*'
- asterisk
- Returns:
- a
String
containing the characters that, by default, are allowed to be posted in aForm
- See Also:
postDataEncode(String)
-
getDefaultUnsafeCharacters
public static java.lang.String getDefaultUnsafeCharacters()
Gets aString
containing the characters that, by default, are considered to be unsafe and must be percent-encoded.A character in a string will be percent-encoded if it is:
- Outside the printable ASCII range (i.e. is not in the ASCII range 32 to 127) OR
- One of these unsafe characters
'<'
- less-than sign'>'
- greater-than sign'"'
- quotation mark'%'
- percent sign'{'
- left curly bracket'}'
- right curly bracket'|'
- vertical line'\'
- reverse solidus'^'
- circumflex accent'['
- left square bracket']'
- right square bracket'`'
- grave accent' '
- space'\r'
- carriage return'\n'
- line feed'\t'
- tab'&'
- ampersand
- Returns:
- a
String
containing the characters that, by default, are considered unsafe and must be percent-encoded - See Also:
urlEncode(String, String, boolean)
-
-