Namespace: OpenEdge.Net
Type: Class UriEncoder
Parent Classes:
Progress.Lang.Object

Inherits: Progress.Lang.Object


Copyright (c) 2022,2024 by Progress Software Corporation. All rights reserved.
File:UriEncoder
Purpose:Performs percent-encoding for a URI, in whole or in part
Author(s):pjudge
Created:2022-01-10
Notes:* the grammer for determining valid, non-encoded values is
reserved = gen-delims / sub-delims
gen-delims = ":" / "/" / "?" / "#" / "[" / "]" / "@"
sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
ALPHA / DIGIT / "-" / "." / "_" / "~" /
"!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "=" /
":" / "@"
unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
Default:unreserved
Query:query = *( pchar / "/" / "?" )
ALPHA / DIGIT / "-" / "." / "_" / "~" /
"!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "=" /
":" / "@" /
"/" / "?"
Scheme:scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
Fragment:fragment = *( pchar / "/" / "?" )
Path:path-abempty = *( "/" segment )
segment = *pchar
UserInfo:userinfo = *( unreserved / pct-encoded / sub-delims / ":" )
Host:host = IP-literal / IPv4address / reg-name
reg-name = *( unreserved / pct-encoded / sub-delims )
IP-literal = "[" ( IPv6address / IPvFuture ) "]"
IPv6address = 6( h16 ":" ) ls32
/ "::" 5( h16 ":" ) ls32
/ [ h16 ] "::" 4( h16 ":" ) ls32
/ [ *1( h16 ":" ) h16 ] "::" 3( h16 ":" ) ls32
/ [ *2( h16 ":" ) h16 ] "::" 2( h16 ":" ) ls32
/ [ *3( h16 ":" ) h16 ] "::" h16 ":" ls32
/ [ *4( h16 ":" ) h16 ] "::" ls32
/ [ *5( h16 ":" ) h16 ] "::" h16
/ [ *6( h16 ":" ) h16 ] "::"
ls32 = ( h16 ":" h16 ) / IPv4address
; least-significant 32 bits of address
h16 = 1*4HEXDIG
; 16 bits of address represented in hexadecimal
IPv4address = dec-octet "." dec-octet "." dec-octet "." dec-octet
dec-octet = DIGIT ; 0-9
/ %x31-39 DIGIT ; 10-99
/ "1" 2DIGIT ; 100-199
/ "2" %x30-34 DIGIT ; 200-249
/ "25" %x30-35 ; 250-255



Method Summary
  Options Name Purpose
  CHARACTER Decode (character) /* Decodes an encoded string Uses OpenEdge.Net.HTTP.PercentEncoder:Decode() to perform the decoding @param character An encoded string @return character A decoded string */
  CHARACTER Decode (character, character) /** Attempts to decode a previously-encoded string. @param character The string to decode @param character The target codepage to encode into. Defaults to CPINTERNAL @return character A decoded URL @throws AppError If the encoding is malformed */
  CHARACTER Encode (character, UriEncodingTypeEnum) /** Encodes a string for a particular purpose. Usage of Encode<encoding-type> is recommended. The method does NOT re-encode % characters. @param character The string to encode @param EncondingTypeEnum The type of encoding to apply @return character the encoded string */
  CHARACTER Encode (character, UriEncodingTypeEnum, logical) /** Encodes a string for a particular purpose. Usage of Encode<encoding-type> is recommended, unless the re-encoding of % characters is desired. @param character The string to encode @param EncondingTypeEnum The type of encoding to apply @param logical TRUE if any percent characters should be encoded as %25 @return character the encoded string */
  CHARACTER EncodeCookie (character) /* Encodes a string per Cookie encoding rules. This method is here for historical reasons. Cookie US-ASCII characters excluding CTLs, whitespace (32) DQUOTE (34), comma (44), semicolon (59), and backslash (92) @param character A string to encode @return character An encoded string */
  CHARACTER EncodeCookie (String) /* Encodes a string per Cookie encoding rules. This method is here for historical reasons. Cookie US-ASCII characters excluding CTLs, whitespace (32) DQUOTE (34), comma (44), semicolon (59), and backslash (92) @param String A string to encode @return character An encoded string */
  CHARACTER EncodeDefault (character) /* Encodes a string per URI Default encoding rules https://tools.ietf.org/html/rfc3986#page-11 Default = unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" @param character A string to encode @return character An encoded string */
  CHARACTER EncodeDefault (String) /* Encodes a string per URI Default encoding rules https://tools.ietf.org/html/rfc3986#page-11 Default = unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" @param String A string to encode @return character An encoded string */
  CHARACTER EncodeFragment (character) /* Encodes a string per URI Fragment encoding rules https://tools.ietf.org/html/rfc3986#page-11 unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "=" pchar = unreserved / pct-encoded / sub-delims / ":" / "@" Fragment : fragment = *( pchar / "/" / "?" ) @param character A string to encode @return character An encoded string */
  CHARACTER EncodeFragment (String) /* Encodes a string per URI Fragment encoding rules https://tools.ietf.org/html/rfc3986#page-11 unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "=" pchar = unreserved / pct-encoded / sub-delims / ":" / "@" Fragment : fragment = *( pchar / "/" / "?" ) @param String A string to encode @return character An encoded string */
  CHARACTER EncodeHost (character) /* Encodes a string per URI Host encoding rules https://tools.ietf.org/html/rfc3986#page-11 sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "=" unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" Host = *( unreserved / pct-encoded / sub-delims ) @param character A string to encode @return character An encoded string */
  CHARACTER EncodeHost (longchar, logical) /* Encodes a host value. This method knows how to deal with IPv6 hosts. @parameter longchar The host name @param logical TRUE if any % values should be encoded @return character An encoded value. */
  CHARACTER EncodeHost (String) /* Encodes a string per URI Host encoding rules https://tools.ietf.org/html/rfc3986#page-11 sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "=" unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" Host = *( unreserved / pct-encoded / sub-delims ) @param String A string to encode @return character An encoded string */
  CHARACTER EncodePath (character) /* Encodes a string per URI Path encoding rules https://tools.ietf.org/html/rfc3986#page-11 sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "=" unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" Path = 1*( unreserved / pct-encoded / sub-delims / "@" ) @param character A string to encode @return character An encoded string */
  CHARACTER EncodePath (String) /* Encodes a string per URI Path encoding rules https://tools.ietf.org/html/rfc3986#page-11 sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "=" unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" Path = 1*( unreserved / pct-encoded / sub-delims / "@" ) @param String A string to encode @return character An encoded string */
  CHARACTER EncodeQuery (character) /* Encodes a string per URI Query encoding rules https://tools.ietf.org/html/rfc3986#page-11 sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "=" pchar = unreserved / pct-encoded / sub-delims / ":" / "@" Query = *( pchar / "/" / "?" ) @param character A string to encode @return character An encoded string */
  CHARACTER EncodeQuery (IStringKeyedMap) /* Encodes a URI's Query string per URI query encoding rules. @param IStringKeyedMap @return character An encoded query string */
  CHARACTER EncodeQuery (IStringStringMap) /* Encodes a URI's Query string per URI query encoding rules. @param IStringStringMap @return character An encoded query string */
  CHARACTER EncodeQuery (String) /* Encodes a string per URI Query encoding rules https://tools.ietf.org/html/rfc3986#page-11 sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "=" pchar = unreserved / pct-encoded / sub-delims / ":" / "@" Query = *( pchar / "/" / "?" ) @param String A string to encode @return character An encoded string */
  CHARACTER EncodeScheme (character) /* Encodes a string per URI Scheme encoding rules https://tools.ietf.org/html/rfc3986#page-11 Scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." ) @param character A string to encode @return character An encoded string */
  CHARACTER EncodeScheme (String) /* Encodes a string per URI Scheme encoding rules https://tools.ietf.org/html/rfc3986#page-11 Scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." ) @param String A string to encode @return character An encoded string */
  CHARACTER EncodeUserinfo (character) /* Encodes a string per URI userinfo encoding rules https://tools.ietf.org/html/rfc3986#page-11 sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "=" unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" Host = *( unreserved / pct-encoded / sub-delims / ":" ) @param character A string to encode @return character An encoded string */
  CHARACTER EncodeUserinfo (String) /* Encodes a string per URI userinfo encoding rules https://tools.ietf.org/html/rfc3986#page-11 sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "=" unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" Host = *( unreserved / pct-encoded / sub-delims / ":" ) @param String A string to encode @return character An encoded string */
  CHARACTER EncodeUserinfo (URI) /* Encodes this uri's Host per URI Host encoding rules @param URI The URI whose info to encode @return character An encoded string */

Constructor Summary
  Options Name Purpose
  UriEncoder () /* Default constructor */

Method Detail
Top

CHARACTER Decode (character)

/* Decodes an encoded string
Uses OpenEdge.Net.HTTP.PercentEncoder:Decode() to perform the decoding
Parameters:
pData CHARACTER
 
Returns CHARACTER
  character A decoded string
Top

CHARACTER Decode (character, character)

Purpose: Attempts to decode a previously-encoded string.
@throws AppError If the encoding is malformed
Parameters:
pEncodedString CHARACTER
 
pTargetCodepage CHARACTER
 
Returns CHARACTER
  character A decoded URL
Top

CHARACTER Encode (character, UriEncodingTypeEnum)

Purpose: Encodes a string for a particular purpose. Usage of Encode<encoding-type> is recommended.
The method does NOT re-encode % characters.
Parameters:
pString CHARACTER
 
pEncodingType OpenEdge.Net.UriEncodingTypeEnum
 
Returns CHARACTER
  character the encoded string
Top

CHARACTER Encode (character, UriEncodingTypeEnum, logical)

Purpose: Encodes a string for a particular purpose. Usage of Encode<encoding-type> is recommended,
unless the re-encoding of % characters is desired.
Parameters:
pString CHARACTER
 
pEncodingType OpenEdge.Net.UriEncodingTypeEnum
 
pReEncode LOGICAL
 
Returns CHARACTER
  character the encoded string
Top

CHARACTER EncodeCookie (character)

/* Encodes a string per Cookie encoding rules. This method is here for historical reasons.
Cookie US-ASCII characters excluding CTLs, whitespace (32) DQUOTE (34), comma (44), semicolon (59), and backslash (92)
Parameters:
pString CHARACTER
 
Returns CHARACTER
  character An encoded string
Top

CHARACTER EncodeCookie (String)

/* Encodes a string per Cookie encoding rules. This method is here for historical reasons.
Cookie US-ASCII characters excluding CTLs, whitespace (32) DQUOTE (34), comma (44), semicolon (59), and backslash (92)
Parameters:
pString OpenEdge.Core.String
 
Returns CHARACTER
  character An encoded string
Top

CHARACTER EncodeDefault (character)

/* Encodes a string per URI Default encoding rules
https://tools.ietf.org/html/rfc3986#page-11 //tools.ietf.org/html/rfc3986#page-11
Default = unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
Parameters:
pcString CHARACTER
 
Returns CHARACTER
  character An encoded string
Top

CHARACTER EncodeDefault (String)

/* Encodes a string per URI Default encoding rules
https://tools.ietf.org/html/rfc3986#page-11 //tools.ietf.org/html/rfc3986#page-11
Default = unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
Parameters:
pString OpenEdge.Core.String
 
Returns CHARACTER
  character An encoded string
Top

CHARACTER EncodeFragment (character)

/* Encodes a string per URI Fragment encoding rules
https://tools.ietf.org/html/rfc3986#page-11 //tools.ietf.org/html/rfc3986#page-11
unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
Fragment : fragment = *( pchar / "/" / "?" )
Parameters:
pcString CHARACTER
 
Returns CHARACTER
  character An encoded string
Top

CHARACTER EncodeFragment (String)

/* Encodes a string per URI Fragment encoding rules
https://tools.ietf.org/html/rfc3986#page-11 //tools.ietf.org/html/rfc3986#page-11
unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
Fragment : fragment = *( pchar / "/" / "?" )
Parameters:
pString OpenEdge.Core.String
 
Returns CHARACTER
  character An encoded string
Top

CHARACTER EncodeHost (character)

/* Encodes a string per URI Host encoding rules
https://tools.ietf.org/html/rfc3986#page-11 //tools.ietf.org/html/rfc3986#page-11
sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
Host = *( unreserved / pct-encoded / sub-delims )
Parameters:
pcString CHARACTER
 
Returns CHARACTER
  character An encoded string
Top

CHARACTER EncodeHost (longchar, logical)

/* Encodes a host value. This method knows how to deal with IPv6 hosts.
Parameters:
pHost LONGCHAR
 
pReencode LOGICAL
 
Returns CHARACTER
  character An encoded value.
Top

CHARACTER EncodeHost (String)

/* Encodes a string per URI Host encoding rules
https://tools.ietf.org/html/rfc3986#page-11 //tools.ietf.org/html/rfc3986#page-11
sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
Host = *( unreserved / pct-encoded / sub-delims )
Parameters:
pString OpenEdge.Core.String
 
Returns CHARACTER
  character An encoded string
Top

CHARACTER EncodePath (character)

/* Encodes a string per URI Path encoding rules
https://tools.ietf.org/html/rfc3986#page-11 //tools.ietf.org/html/rfc3986#page-11
sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
Path = 1*( unreserved / pct-encoded / sub-delims / "@" )
Parameters:
pcString CHARACTER
 
Returns CHARACTER
  character An encoded string
Top

CHARACTER EncodePath (String)

/* Encodes a string per URI Path encoding rules
https://tools.ietf.org/html/rfc3986#page-11 //tools.ietf.org/html/rfc3986#page-11
sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
Path = 1*( unreserved / pct-encoded / sub-delims / "@" )
Parameters:
pString OpenEdge.Core.String
 
Returns CHARACTER
  character An encoded string
Top

CHARACTER EncodeQuery (character)

/* Encodes a string per URI Query encoding rules
https://tools.ietf.org/html/rfc3986#page-11 //tools.ietf.org/html/rfc3986#page-11
sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
Query = *( pchar / "/" / "?" )
Parameters:
pcString CHARACTER
 
Returns CHARACTER
  character An encoded string
Top

CHARACTER EncodeQuery (IStringKeyedMap)

/* Encodes a URI's Query string per URI query encoding rules.
Parameters:
pQueryMap OpenEdge.Core.Collections.IStringKeyedMap
 
Returns CHARACTER
  character An encoded query string
Top

CHARACTER EncodeQuery (IStringStringMap)

/* Encodes a URI's Query string per URI query encoding rules.
Parameters:
pQueryMap OpenEdge.Core.Collections.IStringStringMap
 
Returns CHARACTER
  character An encoded query string
Top

CHARACTER EncodeQuery (String)

/* Encodes a string per URI Query encoding rules
https://tools.ietf.org/html/rfc3986#page-11 //tools.ietf.org/html/rfc3986#page-11
sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
Query = *( pchar / "/" / "?" )
Parameters:
pString OpenEdge.Core.String
 
Returns CHARACTER
  character An encoded string
Top

CHARACTER EncodeScheme (character)

/* Encodes a string per URI Scheme encoding rules
https://tools.ietf.org/html/rfc3986#page-11 //tools.ietf.org/html/rfc3986#page-11
Scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
Parameters:
pcString CHARACTER
 
Returns CHARACTER
  character An encoded string
Top

CHARACTER EncodeScheme (String)

/* Encodes a string per URI Scheme encoding rules
https://tools.ietf.org/html/rfc3986#page-11 //tools.ietf.org/html/rfc3986#page-11
Scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
Parameters:
pString OpenEdge.Core.String
 
Returns CHARACTER
  character An encoded string
Top

CHARACTER EncodeUserinfo (character)

/* Encodes a string per URI userinfo encoding rules
https://tools.ietf.org/html/rfc3986#page-11 //tools.ietf.org/html/rfc3986#page-11
sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
Host = *( unreserved / pct-encoded / sub-delims / ":" )
Parameters:
pcString CHARACTER
 
Returns CHARACTER
  character An encoded string
Top

CHARACTER EncodeUserinfo (String)

/* Encodes a string per URI userinfo encoding rules
https://tools.ietf.org/html/rfc3986#page-11 //tools.ietf.org/html/rfc3986#page-11
sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
Host = *( unreserved / pct-encoded / sub-delims / ":" )
Parameters:
pString OpenEdge.Core.String
 
Returns CHARACTER
  character An encoded string
Top

CHARACTER EncodeUserinfo (URI)

/* Encodes this uri's Host per URI Host encoding rules
Parameters:
pURI OpenEdge.Net.URI
 
Returns CHARACTER
  character An encoded string


Constructor Detail
Top

UriEncoder ()

/* Default constructor