Class EncodedURLStringConverter
- All Implemented Interfaces:
Serializable,StringConverter<URL>
An implementation of
StringConverter
for
URL
values.
Different from
URLStringConverter,
this implementation expects an "application/x-www-form-url"
encoded String as the argument for
fromString(CharSequence)
and returns such a String from
toString(URL).
The method
fromString(CharSequence)
will use
URLDecoder.decode(String, Charset)
to get the decode URL String, then it calls
URLStringConverter.fromString(CharSequence)
to create a URL instance from it.
toString(URL)
uses
URLStringConverter.toString(URL)
to get a String out of the URL and encodes it with a call to
URLEncoder.encode(String, Charset).
Based on the World Wide Web Consortium Recommendation
both methods (fromString() and toString()) are using
UTF-8 as the
charset argument.
- Author:
- Thomas Thrien (thomas.thrien@tquadrat.org)
- Version:
- $Id: EncodedURLStringConverter.java 1080 2024-01-03 11:05:21Z tquadrat $
- Since:
- 0.1.0
- See Also:
- UML Diagram
-
UML Diagram for "org.tquadrat.foundation.util.stringconverter.EncodedURLStringConverter"
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final EncodedURLStringConverterAn instance of this class.private final CharsetThe character encoding that is used at default.Fields inherited from class org.tquadrat.foundation.util.stringconverter.URLStringConverter
MSG_InvalidURLFields inherited from interface org.tquadrat.foundation.lang.StringConverter
METHOD_NAME_GetSubjectClass, METHOD_NAME_Provider -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new instance ofEncodedURLStringConverterthat uses UTF-8 as the default encoding.EncodedURLStringConverter(Charset encoding) Creates a new instance ofEncodedURLStringConverterthat uses the given encoding as the default encoding. -
Method Summary
Modifier and TypeMethodDescriptionfromString(CharSequence source) final URLfromString(CharSequence source, Charset charset) Converts the given String that contains a validapplication/x-www-form-urlencoded URL into an instance ofURL, using the provided character encoding.final Stringfinal StringConverts the givenURL, into anapplication/x-www-form-urlencoded String representation, using the provided character encoding.Methods inherited from class org.tquadrat.foundation.util.stringconverter.URLStringConverter
getSubjectClass, provider
-
Field Details
-
m_Encoding
The character encoding that is used at default. -
INSTANCE
An instance of this class.
This instance uses UTF-8 as the default encoding.
-
-
Constructor Details
-
EncodedURLStringConverter
public EncodedURLStringConverter()Creates a new instance ofEncodedURLStringConverterthat uses UTF-8 as the default encoding. -
EncodedURLStringConverter
Creates a new instance ofEncodedURLStringConverterthat uses the given encoding as the default encoding.- Parameters:
encoding- The default character encoding.- See Also:
-
-
Method Details
-
fromString
Converts the given String that contains a validapplication/x-www-form-urlencoded URL into an instance ofURL, using the provided character encoding.- Parameters:
source- The source; can benull.charset- The character encoding of the String.- Returns:
- The respective URL, or
nullif the source was alreadynull. - Throws:
IllegalArgumentException- The source was either not a valid URL, or the encoding was invalid.
-
fromString
This method uses the default character encoding as set by the constructor.
- Specified by:
fromStringin interfaceStringConverter<URL>- Overrides:
fromStringin classURLStringConverter- Throws:
IllegalArgumentException
-
toString
Converts the givenURL, into anapplication/x-www-form-urlencoded String representation, using the provided character encoding.- Parameters:
source- The source; can benull.charset- The character encoding for the String.- Returns:
- The respective String representation, or
nullif the source was alreadynull. - Throws:
IllegalArgumentException- The source was either not a valid URL, or the encoding was invalid.
-
toString
This method uses the default character encoding as set by the constructor.
- Specified by:
toStringin interfaceStringConverter<URL>- Overrides:
toStringin classURLStringConverter
-
