New directory layout created
This commit is contained in:
38
library/extras/file/json_file_reader.e
Normal file
38
library/extras/file/json_file_reader.e
Normal file
@@ -0,0 +1,38 @@
|
||||
indexing
|
||||
description: "Objects that ..."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
JSON_FILE_READER
|
||||
|
||||
feature -- Access
|
||||
|
||||
read_json_from (a_path: STRING): ?STRING is
|
||||
local
|
||||
l_file: PLAIN_TEXT_FILE
|
||||
template_content: STRING
|
||||
l_last_string: ?STRING
|
||||
do
|
||||
create l_file.make (a_path)
|
||||
-- We perform several checks until we make a real attempt to open the file.
|
||||
if not l_file.exists then
|
||||
print ("error: '" + a_path + "' does not exist%N")
|
||||
else
|
||||
if not l_file.is_readable then
|
||||
print ("error: '" + a_path + "' is not readable.%N")
|
||||
else
|
||||
l_file.open_read
|
||||
create template_content.make_empty
|
||||
l_file.read_stream (l_file.count)
|
||||
l_last_string := l_file.last_string
|
||||
check l_last_string /= Void end -- implied by postcondition of `l_file.read_stream'
|
||||
template_content.append (l_last_string.string)
|
||||
Result := template_content
|
||||
l_file.close
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
59
library/extras/visitor/json_visitor.e
Normal file
59
library/extras/visitor/json_visitor.e
Normal file
@@ -0,0 +1,59 @@
|
||||
indexing
|
||||
description:
|
||||
|
||||
"JSON Visitor"
|
||||
|
||||
pattern: "Visitor"
|
||||
author: "Javier Velilla"
|
||||
license:"MIT (see http://www.opensource.org/licenses/mit-license.php)"
|
||||
date: "2008/08/24"
|
||||
revision: "Revision 0.1"
|
||||
|
||||
deferred class
|
||||
JSON_VISITOR
|
||||
|
||||
feature -- Visitor Pattern
|
||||
|
||||
visit_json_array (a_json_array: JSON_ARRAY) is
|
||||
-- Visit `a_json_array'.
|
||||
require
|
||||
a_json_array_not_void: a_json_array /= Void
|
||||
deferred
|
||||
end
|
||||
|
||||
visit_json_boolean (a_json_boolean: JSON_BOOLEAN) is
|
||||
-- Visit `a_json_boolean'.
|
||||
require
|
||||
a_json_boolean_not_void: a_json_boolean /= Void
|
||||
deferred
|
||||
end
|
||||
|
||||
visit_json_null (a_json_null: JSON_NULL) is
|
||||
-- Visit `a_json_null'.
|
||||
require
|
||||
a_json_null_not_void: a_json_null /= Void
|
||||
deferred
|
||||
end
|
||||
|
||||
visit_json_number (a_json_number: JSON_NUMBER) is
|
||||
-- Visit `a_json_number'.
|
||||
require
|
||||
a_json_number_not_void: a_json_number /= Void
|
||||
deferred
|
||||
end
|
||||
|
||||
visit_json_object (a_json_object: JSON_OBJECT) is
|
||||
-- Visit `a_json_object'.
|
||||
require
|
||||
a_json_object_not_void: a_json_object /= Void
|
||||
deferred
|
||||
end
|
||||
|
||||
visit_json_string (a_json_string: JSON_STRING) is
|
||||
-- Visit `a_json_string'.
|
||||
require
|
||||
a_json_string_not_void: a_json_string /= Void
|
||||
deferred
|
||||
end
|
||||
|
||||
end
|
||||
102
library/extras/visitor/print_json_visitor.e
Normal file
102
library/extras/visitor/print_json_visitor.e
Normal file
@@ -0,0 +1,102 @@
|
||||
indexing
|
||||
description: "PRINT_JSON_VISITOR Generates the JSON-String for a JSON_VALUE"
|
||||
author: "jvelilla"
|
||||
date: "2008/08/24"
|
||||
revision: "0.1"
|
||||
|
||||
class
|
||||
PRINT_JSON_VISITOR
|
||||
|
||||
inherit
|
||||
JSON_VISITOR
|
||||
|
||||
create make
|
||||
|
||||
feature -- Initialization
|
||||
|
||||
make is
|
||||
-- Create a new instance
|
||||
do
|
||||
create to_json.make_empty
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
to_json: STRING
|
||||
-- JSON representation
|
||||
|
||||
feature -- Visitor Pattern
|
||||
|
||||
visit_json_array (a_json_array: JSON_ARRAY) is
|
||||
-- Visit `a_json_array'.
|
||||
local
|
||||
value: JSON_VALUE
|
||||
l_json_array: ARRAYED_LIST [JSON_VALUE]
|
||||
do
|
||||
l_json_array:=a_json_array.array_representation
|
||||
to_json.append ("[")
|
||||
from
|
||||
l_json_array.start
|
||||
until
|
||||
l_json_array.off
|
||||
loop
|
||||
value := l_json_array.item
|
||||
value.accept (Current)
|
||||
l_json_array.forth
|
||||
if not l_json_array.after then
|
||||
to_json.append(",")
|
||||
end
|
||||
end
|
||||
to_json.append ("]")
|
||||
end
|
||||
|
||||
visit_json_boolean (a_json_boolean: JSON_BOOLEAN) is
|
||||
-- Visit `a_json_boolean'.
|
||||
do
|
||||
to_json.append (a_json_boolean.item.out)
|
||||
end
|
||||
|
||||
visit_json_null (a_json_null: JSON_NULL) is
|
||||
-- Visit `a_json_null'.
|
||||
do
|
||||
to_json.append ("null")
|
||||
end
|
||||
|
||||
visit_json_number (a_json_number: JSON_NUMBER) is
|
||||
-- Visit `a_json_number'.
|
||||
do
|
||||
to_json.append (a_json_number.item)
|
||||
end
|
||||
|
||||
visit_json_object (a_json_object: JSON_OBJECT) is
|
||||
-- Visit `a_json_object'.
|
||||
local
|
||||
l_pairs: HASH_TABLE[JSON_VALUE,JSON_STRING]
|
||||
do
|
||||
l_pairs := a_json_object.map_representation
|
||||
to_json.append ("{")
|
||||
from
|
||||
l_pairs.start
|
||||
until
|
||||
l_pairs.off
|
||||
loop
|
||||
l_pairs.key_for_iteration.accept (Current)
|
||||
to_json.append (":")
|
||||
l_pairs.item_for_iteration.accept (Current)
|
||||
l_pairs.forth
|
||||
if not l_pairs.after then
|
||||
to_json.append (",")
|
||||
end
|
||||
end
|
||||
to_json.append ("}")
|
||||
end
|
||||
|
||||
visit_json_string (a_json_string: JSON_STRING) is
|
||||
-- Visit `a_json_string'.
|
||||
do
|
||||
to_json.append ("%"")
|
||||
to_json.append (a_json_string.item)
|
||||
to_json.append ("%"")
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user