Updated URI Template to follow official RFC6570

This commit is contained in:
Jocelyn Fiat
2012-05-14 18:11:12 +02:00
parent 278a71eaaf
commit 64eebd32db
18 changed files with 4631 additions and 2212 deletions

View File

@@ -1,52 +0,0 @@
note
description: "[
Summary description for {URI_TEMPLATE_CONSTANTS}.
see http://tools.ietf.org/html/draft-gregorio-uritemplate-05
]"
author: ""
date: "$Date$"
revision: "$Revision$"
class
URI_TEMPLATE_CONSTANTS
feature -- Operator
Reserved_operator: CHARACTER = '+'
Form_style_query_operator: CHARACTER = '?'
Path_style_parameters_operator: CHARACTER = ';'
Path_segment_operator: CHARACTER = '/'
Label_operator: CHARACTER = '.'
feature -- Separator
Default_delimiter: CHARACTER = '|' --| Draft 05
feature -- Explode
Explode_plus: CHARACTER = '+'
Explode_star: CHARACTER = '*'
feature -- Modified
Modifier_substring: CHARACTER = ':'
Modifier_remainder: CHARACTER = '^'
note
copyright: "2011-2011, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software
5949 Hollister Ave., Goleta, CA 93117 USA
Telephone 805-685-1006, Fax 805-685-6869
Website http://www.eiffel.com
Customer support http://support.eiffel.com
]"
end

View File

@@ -1,12 +1,9 @@
note
description: "[
Summary description for {URI_TEMPLATE}.
See http://tools.ietf.org/html/draft-gregorio-uritemplate-04
note for draft 05, check {URI_TEMPLATE_CONSTANTS}.Default_delimiter
Implementation of URI Template RFC6570.
]"
See http://tools.ietf.org/html/rfc6570
]"
legal: "See notice at end of class."
status: "See notice at end of class."
date: "$Date$"
@@ -513,7 +510,7 @@ feature {NONE} -- Implementation
end
note
copyright: "2011-2012, Eiffel Software and others"
copyright: "2011-2012, Jocelyn Fiat, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software

View File

@@ -2,9 +2,9 @@ note
description: "[
Summary description for {URI_TEMPLATE_CONSTANTS}.
see http://tools.ietf.org/html/draft-gregorio-uritemplate-04
see http://tools.ietf.org/html/rfc6570
]"
author: ""
author: "Jocelyn Fiat"
date: "$Date$"
revision: "$Revision$"
@@ -17,15 +17,19 @@ feature -- Operator
Form_style_query_operator: CHARACTER = '?'
Form_style_query_continuation: CHARACTER = '&'
Path_style_parameters_operator: CHARACTER = ';'
Path_segment_operator: CHARACTER = '/'
Fragment_expansion: CHARACTER = '#'
Label_operator: CHARACTER = '.'
feature -- Separator
Default_delimiter: CHARACTER = '=' --| Draft 0.4 , change to '|' for Draft 0.5
Default_delimiter: CHARACTER = '=' --| Not included in the RFC, but was part of previous Draft
feature -- Explode

View File

@@ -12,7 +12,7 @@ inherit
DEBUG_OUTPUT
export {NONE} all end
URI_TEMPLATE_CONSTANTS
export {NONE} all end
@@ -72,6 +72,17 @@ feature -- Processing
operator := '?'
op_prefix := '?'
op_delimiter := '&'
when form_style_query_continuation then
--| '&'
operator := '&'
op_prefix := '&'
op_delimiter := '&'
when fragment_expansion then
--| '#'
reserved := True
operator := '#'
op_prefix := '#'
op_delimiter := ','
when '|', '!', '@' then
operator := exp[1]
else
@@ -238,7 +249,7 @@ feature {NONE} -- Implementation
else
a_buffer.append_character (delimiter_char)
end
if l_use_default and (operator = Form_style_query_operator) and not vi.has_explode_star then
if l_use_default and (operator = Form_style_query_operator or operator = form_style_query_continuation or operator = path_style_parameters_operator) and not vi.has_explode_star then
a_buffer.append (vi.name)
if vi.has_explode_plus then
a_buffer.append_character ('.')
@@ -262,7 +273,7 @@ feature -- Status report
end
;note
copyright: "2011-2011, Eiffel Software and others"
copyright: "2011-2012, Jocelyn Fiat, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software

View File

@@ -45,12 +45,19 @@ feature {NONE} -- Initialization
when Form_style_query_operator then --| '?'
op_prefix := '?'
op_separator := '&'
when form_style_query_continuation then --| '&'
op_prefix := '&'
op_separator := '&'
when Path_style_parameters_operator then --| ';'
op_prefix := ';'
op_separator := ';'
when Path_segment_operator then --| '/'
op_prefix := '/'
op_separator := '/'
when fragment_expansion then --| '#'
reserved := True
op_prefix := '#'
op_separator := ','
when Label_operator then --| '.'
op_prefix := '.'
op_separator := '.'
@@ -169,7 +176,7 @@ feature -- Report
create Result.make (20)
if attached {READABLE_STRING_GENERAL} d as l_string then
v_enc := url_encoded_string (modified_string (l_string), not reserved)
if op = Form_style_query_operator then
if op = Form_style_query_operator or op = form_style_query_continuation then
Result.append (name)
Result.append_character ('=')
elseif op = Path_style_parameters_operator then
@@ -183,7 +190,7 @@ feature -- Report
if l_array.is_empty then
if dft /= Void then
inspect op
when Form_style_query_operator, Path_style_parameters_operator then
when Path_style_parameters_operator,Form_style_query_operator, form_style_query_continuation then
if not l_has_explode then
Result.append (name)
Result.append_character ('=')
@@ -195,6 +202,16 @@ feature -- Report
end
Result.append (dft.out)
end
-- if not explode_is_plus then
-- Result.append (name)
-- Result.append_character ('=')
-- Result.append (dft.out)
-- else
-- Result.append (name)
-- Result.append_character ('.')
-- Result.append (dft.out)
-- end
when Path_segment_operator then
if explode_is_plus then
Result.append (name)
@@ -220,7 +237,7 @@ feature -- Report
else
l_delimiter := ','
inspect op
when Form_style_query_operator then
when Form_style_query_operator, form_style_query_continuation, path_style_parameters_operator then
Result.append (name)
Result.append_character ('=')
else
@@ -242,6 +259,7 @@ feature -- Report
if explode_is_plus then
if
(op = Form_style_query_operator and explode_is_plus) or
(op = form_style_query_continuation and explode_is_plus) or
(op = Path_style_parameters_operator and l_has_explode)
then
Result.append (name)
@@ -250,7 +268,7 @@ feature -- Report
Result.append (name)
Result.append_character ('.')
end
elseif explode_is_star and op = Form_style_query_operator then
elseif explode_is_star and (op = Form_style_query_operator or op = form_style_query_continuation or op = path_style_parameters_operator) then
Result.append (name)
Result.append_character ('=')
end
@@ -269,7 +287,7 @@ feature -- Report
if l_table.is_empty then
if dft /= Void then
inspect op
when Form_style_query_operator, Path_style_parameters_operator then
when Path_style_parameters_operator, Form_style_query_operator, form_style_query_continuation then
if not l_has_explode then
Result.append (name)
Result.append_character ('=')
@@ -281,6 +299,15 @@ feature -- Report
end
Result.append (dft.out)
end
-- if not explode_is_plus then
-- Result.append (name)
-- Result.append_character ('=')
-- Result.append (dft.out)
-- else
-- Result.append (name)
-- Result.append_character ('.')
-- Result.append (dft.out)
-- end
when Path_segment_operator then
if explode_is_plus then
Result.append (name)
@@ -306,7 +333,7 @@ feature -- Report
else
l_delimiter := ','
inspect op
when Form_style_query_operator then
when Form_style_query_operator, form_style_query_continuation, path_style_parameters_operator then
Result.append (name)
Result.append_character ('=')
else
@@ -358,7 +385,7 @@ feature -- Report
else
v_enc := default_value
end
if op = Form_style_query_operator then
if op = Form_style_query_operator or op = form_style_query_continuation then
Result.append (name)
if v_enc /= Void then
Result.append_character ('=')
@@ -400,7 +427,7 @@ feature {NONE} -- Implementation
end
;note
copyright: "2011-2011, Eiffel Software and others"
copyright: "2011-2012, Jocelyn Fiat, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software

View File

@@ -57,26 +57,37 @@ feature -- Query
feature -- Query: url-decoded
url_decoded_query_variable (n: READABLE_STRING_8): detachable READABLE_STRING_32
encoded_name (n: READABLE_STRING_GENERAL): READABLE_STRING_8
-- URL encoded name `n'
-- to be used with ..._variable functions
do
if attached {READABLE_STRING_32} n as n32 then
Result := url_encoded_string (n32)
else
Result := n.as_string_8
end
end
url_decoded_query_variable (n: READABLE_STRING_GENERAL): detachable READABLE_STRING_32
-- Unencoded value related to variable name `n'
do
if attached query_variable (n) as v then
if attached query_variable (encoded_name (n)) as v then
Result := url_decoded_string (v)
end
end
url_decoded_path_variable (n: READABLE_STRING_8): detachable READABLE_STRING_32
url_decoded_path_variable (n: READABLE_STRING_GENERAL): detachable READABLE_STRING_32
-- Unencoded value related to variable name `n'
do
if attached path_variable (n) as v then
if attached path_variable (encoded_name (n)) as v then
Result := url_decoded_string (v)
end
end
url_decoded_variable (n: READABLE_STRING_8): detachable READABLE_STRING_32
url_decoded_variable (n: READABLE_STRING_GENERAL): detachable READABLE_STRING_32
-- Unencoded value related to variable name `n'
do
if attached variable (n) as v then
if attached variable (encoded_name (n)) as v then
Result := url_decoded_string (v)
end
end
@@ -85,7 +96,12 @@ feature {NONE} -- Implementation
url_decoded_string (s: READABLE_STRING_8): READABLE_STRING_32
do
Result := url_encoder.decoded_string (s.as_string_8)
Result := url_encoder.decoded_string (s)
end
url_encoded_string (s: READABLE_STRING_32): READABLE_STRING_8
do
Result := url_encoder.encoded_string (s)
end
url_encoder: URL_ENCODER