Added visitor patterns to WSF_VALUE

Handling UTF-8 unencoding for WSF_VALUE ...
Added WSF_TABLE_VALUE to handle list[]=a&list[]=b ...

Library encoder: added UTF8 facilities
This commit is contained in:
Jocelyn Fiat
2011-10-24 17:23:36 +02:00
parent 663a39d2ec
commit fb7854fbcc
27 changed files with 781 additions and 52 deletions

View File

@@ -0,0 +1,68 @@
note
description: "[
Iterator visitor on WSF_VALUE using agent for callback
]"
date: "$Date$"
revision: "$Revision$"
class
WSF_VALUE_AGENT_ITERATOR
inherit
WSF_VALUE_ITERATOR
redefine
process_table,
process_multiple_string,
process_string
end
create
make
feature {NONE} -- Initialization
make
do
create on_table_actions
create on_string_actions
create on_multiple_string_actions
end
feature -- Actions
on_table_actions: ACTION_SEQUENCE [TUPLE [WSF_TABLE_VALUE]]
on_string_actions: ACTION_SEQUENCE [TUPLE [WSF_STRING_VALUE]]
on_multiple_string_actions: ACTION_SEQUENCE [TUPLE [WSF_MULTIPLE_STRING_VALUE]]
feature -- Visitor
process_table (v: WSF_TABLE_VALUE)
do
on_table_actions.call ([v])
process_iterable_of_value (v)
end
process_string (v: WSF_STRING_VALUE)
do
on_string_actions.call ([v])
end
process_multiple_string (v: WSF_MULTIPLE_STRING_VALUE)
do
on_multiple_string_actions.call ([v])
process_iterable_of_value (v)
end
;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

@@ -0,0 +1,51 @@
note
description: "[
Iterator visitor on WSF_VALUE
]"
date: "$Date$"
revision: "$Revision$"
class
WSF_VALUE_ITERATOR
inherit
WSF_VALUE_VISITOR
feature -- Helper
process_iterable_of_value (it: ITERABLE [WSF_VALUE])
do
across
it as c
loop
c.item.process (Current)
end
end
feature -- Visitor
process_table (v: WSF_TABLE_VALUE)
do
process_iterable_of_value (v)
end
process_string (v: WSF_STRING_VALUE)
do
end
process_multiple_string (v: WSF_MULTIPLE_STRING_VALUE)
do
process_iterable_of_value (v)
end
;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

@@ -0,0 +1,38 @@
note
description: "[
NULL Visitor implementation
]"
date: "$Date$"
revision: "$Revision$"
class
WSF_VALUE_NULL_VISITOR
inherit
WSF_VALUE_VISITOR
feature -- Visitor
process_table (v: WSF_TABLE_VALUE)
do
end
process_string (v: WSF_STRING_VALUE)
do
end
process_multiple_string (v: WSF_MULTIPLE_STRING_VALUE)
do
end
;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

@@ -0,0 +1,48 @@
note
description: "[
Component to visit WSF_VALUE
]"
date: "$Date$"
revision: "$Revision$"
deferred class
WSF_VALUE_VISITOR
feature -- Visitor
safe_process_value (v: detachable WSF_TABLE_VALUE)
do
if v /= Void then
v.process (Current)
end
end
process_table (v: WSF_TABLE_VALUE)
require
v_attached: v /= Void
deferred
end
process_string (v: WSF_STRING_VALUE)
require
v_attached: v /= Void
deferred
end
process_multiple_string (v: WSF_MULTIPLE_STRING_VALUE)
require
v_attached: v /= Void
deferred
end
;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

@@ -127,10 +127,17 @@ feature -- Element change
string_values.extend (s)
end
feature -- Visitor
process (vis: WSF_VALUE_VISITOR)
do
vis.process_multiple_string (Current)
end
invariant
string_values_not_empty: string_values.count >= 1
;note
note
copyright: "2011-2011, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[

View File

@@ -65,20 +65,14 @@ feature -- Conversion
create Result.make_from_string (string)
end
feature {NONE} -- Implementation
feature -- Visitor
url_decoded_string (s: READABLE_STRING_8): READABLE_STRING_32
-- Decoded url-encoded string `s'
process (vis: WSF_VALUE_VISITOR)
do
Result := url_encoder.decoded_string (s)
vis.process_string (Current)
end
url_encoder: URL_ENCODER
once
create Result
end
;note
note
copyright: "2011-2011, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[

View File

@@ -0,0 +1,131 @@
note
description: "[
Table value which can contain value indexed by a key
]"
date: "$Date$"
revision: "$Revision$"
class
WSF_TABLE_VALUE
inherit
WSF_VALUE
ITERABLE [WSF_VALUE]
create
make
feature {NONE} -- Initialization
make (a_name: READABLE_STRING_8)
do
name := url_decoded_string (a_name)
create values.make (5)
end
feature -- Access
name: READABLE_STRING_32
first_value: detachable WSF_VALUE
-- First value if any.
do
across
values as c
until
Result /= Void
loop
Result := c.item
end
end
first_key: detachable READABLE_STRING_32
do
across
values as c
until
Result /= Void
loop
Result := c.key
end
end
values: HASH_TABLE [WSF_VALUE, READABLE_STRING_32]
value (k: READABLE_STRING_32): detachable WSF_VALUE
do
Result := values.item (k)
end
count: INTEGER
do
Result := values.count
end
feature -- Element change
add_value (a_value: WSF_VALUE; k: READABLE_STRING_32)
require
same_name: a_value.name.same_string (name)
do
values.force (a_value, k)
end
feature -- Traversing
new_cursor: ITERATION_CURSOR [WSF_VALUE]
do
Result := values.new_cursor
end
feature -- Helper
same_string (a_other: READABLE_STRING_GENERAL): BOOLEAN
-- Does `a_other' represent the same string as `Current'?
do
if values.count = 1 and then attached first_value as f then
Result := f.same_string (a_other)
end
end
is_case_insensitive_equal (a_other: READABLE_STRING_8): BOOLEAN
-- Does `a_other' represent the same case insensitive string as `Current'?
do
if values.count = 1 and then attached first_value as f then
Result := f.is_case_insensitive_equal (a_other)
end
end
as_string: STRING_32
do
create Result.make_from_string ("{")
if values.count = 1 and then attached first_key as fk then
Result.append (fk + ": ")
if attached value (fk) as fv then
Result.append (fv.as_string)
else
Result.append ("???")
end
else
across
values as c
loop
if Result.count > 1 then
Result.append_character (',')
end
Result.append (c.key + ": ")
Result.append (c.item.as_string)
end
end
Result.append_character ('}')
end
feature -- Visitor
process (vis: WSF_VALUE_VISITOR)
do
vis.process_table (Current)
end
end