Compare commits

...

311 Commits

Author SHA1 Message Date
jvelilla
61f90bba38 Merge branch 'jvelilla-ewf_wsf_html5' 2015-05-29 15:38:30 -03:00
jvelilla
fac3dd3946 Merge branch 'ewf_wsf_html5' of https://github.com/jvelilla/EWF into jvelilla-ewf_wsf_html5 2015-05-29 15:38:08 -03:00
jvelilla
e1b583a2b3 Updated code based on comments 2015-05-28 10:07:40 -03:00
jvelilla
8c8dfdd4a3 Updated code based on review 2015-05-28 10:04:13 -03:00
jvelilla
857397e226 Updated code inherit from SHARED_HTML_ENCODER instead of creating new objects. 2015-05-28 09:39:14 -03:00
jvelilla
94340c1c01 Updated html5 classes based on review 2015-05-28 09:19:21 -03:00
8b60ab08e3 Added WSF_FILE_UTILITIES.new_file (p: PATH): detachable G
in order to provide non existing file, but not only for temporary files purpose.
2015-05-22 22:27:28 +02:00
jvelilla
28e51cc314 Initial import HTML5 support for attributes and input types.
Attributes
- Added support for new HTML5 attributes.
missing support for : form, list, and multiple attributes.

Input types: added the all the new input types.

Added test cases, still in progress.
2015-05-21 12:32:08 -03:00
jvelilla
a7c8d40b3e Moved EWF workbook from ewf_example to EWF main repository. 2015-05-18 11:06:04 -03:00
d4c0ff03b4 Added package.iron for nino library. 2015-05-12 19:04:36 +02:00
7fbfda3a66 Refactored wsf router dispatching implementation.
Now the path to take into account during dispatching is computed once
  in WSF_ROUTER.path_to_dispatch (req: WSF_REQUEST): READABLE_STRING_8
  And this function could be redefined in descendant of WSF_ROUTER.
2015-05-12 18:37:25 +02:00
9e467689df improved nino port number validation 2015-05-12 18:25:22 +02:00
c778e454cd Renamed a few index.md as README.md 2015-05-05 11:13:12 +02:00
44757b73eb Renamed Home.md as README.md 2015-05-05 11:10:36 +02:00
525978db1d Update doc structure, and fixed a few links. 2015-05-05 10:57:58 +02:00
71c90a2f39 Updated mediawiki and markdown link to local pages,
in order to use those files as browseable documentation, and close the github wiki.
2015-05-05 10:22:21 +02:00
8057dca032 Merge remote-tracking branch 'ewf_wiki/master' 2015-05-05 10:06:12 +02:00
91d7b956b9 update README to add google groups info. 2015-05-05 09:58:36 +02:00
881625a0f6 Updated code to remove obsolete call on recent version of json library.
Updated upload_image example to use PATH instead of DIRECTORY_NAME or similar.
Removed unused local variables.
2015-04-07 19:27:30 +02:00
b7a12eddaf Merge branch 'master' of https://github.com/eiffelhub/json 2015-04-07 18:36:38 +02:00
jvelilla
44b1ccbc3c Merge branch 'jvelilla-ewf_cookie' 2015-03-20 09:35:51 -03:00
jvelilla
30261632f6 Updated HTTP_COOKIE, enable to add a cookie with empty value.
Added feature to check if a date is valid rcf1123 is_valid_rfc1123_date.
Added test cases related to valid cookie dates.
Updated wsf_response add_cookie basedo on review comments.
2015-03-19 15:23:06 -03:00
jvelilla
08db0748f4 Updated is_valid_character, using NATURAL_32 as an argument to avoid multiple conversions.
Updated add_cookie, added features has_cookie_name and is_cookie line to avoid the use of
STRING.split and STRING.start_with.
2015-03-19 09:39:41 -03:00
jvelilla
9dc22bee24 Updated HTTP_COOKIE class based on comments.
Added missing descriptions in test classes
2015-03-17 17:00:07 -03:00
jvelilla
c4d362ff31 Added the add_cookie feature
Added test cases to check cookies in WSF_RESPONSE-
Added mock classes use for test cases.
2015-03-17 14:27:53 -03:00
jvelilla
4a35ff7b77 Updated code based on Jocelyn's comments. 2015-03-13 17:41:48 -03:00
jvelilla
871e9792a5 Added HTTP_COOKIE and test cases.
Added WSF_COOKIE class, inherit from HTTP_COOKIE.
2015-03-13 15:28:38 -03:00
5f4ab50bf9 Completed configuration setting to be compilable with recent changes in EiffelNet / NETWORK_STREAM_SOCKET interface. 2015-03-12 22:16:28 +01:00
f0a49aaf0a fixed location of before_15_01 folder. 2015-03-11 14:52:14 +01:00
1aae58e00b Removed the -safe since now new project should be void-safe 2015-03-05 20:37:28 +01:00
f81e5251e8 moved wizard under tools/estudio_wizard 2015-03-05 16:01:45 +01:00
b26504b4a1 moved wizard from tools to helpers 2015-03-05 16:00:43 +01:00
4eddad0bcb Updated script to install wizard in current EiffelStudio installation. 2015-03-05 15:27:29 +01:00
1b9aa0c598 Updated the ewf estudio wizard to have a console and a graphical wizard.
Usage:  wizard -callback file.cb path-to-rootdir folder.
2015-03-05 15:23:13 +01:00
6e52774507 Prepare nino ecf to be compilable with upcoming changes in EiffelNet / NETWORK_STREAM_SOCKET interface.
As EiffelNet release is related to EiffelStudio release,
   the condition "compiler version <= 15.02) is used,
   which means that before for release 15.01 and previous EiffelStudio
   releases, the project uses a specific TCP_STREAM_SOCKET, and for
   upcoming releases, it will use another version of that class).
  (see rev#96640 from eiffelstudio subversion repository)
2015-02-18 10:14:08 +01:00
e5403462bc Prepare nino ecf to be compilable with upcoming changes in EiffelNet / NETWORK_STREAM_SOCKET interface.
(see rev#96640 from eiffelstudio subversion repository)
2015-02-18 10:08:36 +01:00
33b555ff27 Fixed implementation of JSON_PARSER.is_valid_number (STRING): BOOLEAN 2015-01-08 18:57:31 +01:00
4c552671c1 Updated install_ewf.bat to use the new "ecf_tool" from https://svn.eiffel.com/eiffelstudio/trunk/Src/tools/ecf_tool . 2014-12-02 10:51:08 +01:00
25a362d043 Added more test cases for cookies. 2014-12-02 10:50:29 +01:00
023e03bb8f Completed change on debug handler and filter, to use WSF_DEBUG_INFORMATION. 2014-12-02 10:45:33 +01:00
0caad2105f Merge branch 'fix_cgi_value' of github.com:jocelyn/EWF 2014-12-01 15:53:45 +01:00
f14fdc2a69 Added assertions on router helpers, and also agent handler.
Closes issue #159
2014-12-01 15:44:49 +01:00
440d3f9c91 Fixing issues related to status code. 2014-11-28 16:10:50 +01:00
975ef90bab Better code for restbucks ORDER_HANDLER related to allowed_cross_origins and last_modified. 2014-11-28 16:06:30 +01:00
8c63e74b81 Fixed compilation of restbucks example using the policy driven framework. 2014-11-25 22:19:46 +01:00
6b9d248542 WSF_TRACE_RESPONSE should include "Content-Type: message/http" header
Close issue #145
2014-11-25 15:55:48 +01:00
6d2318ac9b Fixed issue#157 (WSF_REQUEST.cookies_table does not terminate on cookies without a value, or ending with semi-colon)
Added related autotest.
2014-11-24 22:22:12 +01:00
Colin Adams
0f76518b63 Added {WSF_REQUEST}.http_content_encoding 2014-11-19 14:41:50 +00:00
Colin Adams
bb5faec3c6 Issue #154 (documentation error in {WSF_SKELETON_HANDLER}.check_request) 2014-11-19 10:35:06 +00:00
Colin Adams
22301fc15d issue #149 (Simple CORS support for GET requests in policy-driven framework) 2014-11-18 16:02:10 +00:00
Colin Adams
f482ef06d5 Issue #150 (VARY header set to header contents rather than heqader name) 2014-11-18 13:48:38 +00:00
Colin Adams
4f62da8f90 Issue #144 (Add last_modified to WSF_SKELETON_HANDLER) 2014-11-18 10:37:36 +00:00
Jocelyn Fiat
eaa3dd435a Merge pull request #148 from colin-adams/response-code-411
Policy-driven framework should reject PUT requests that contain a Content-Range header

Close Issue #143
2014-11-17 17:37:06 +01:00
Colin Adams
e1d1d52260 Issue #143 2014-11-17 16:20:28 +00:00
0cc0ba047f Reintroduced parse_object as obsolete, to avoid breaking existing code. 2014-11-17 16:05:33 +01:00
641e114fed Converted ecf file to complete void-safe.
Improved JSON_PRETTY_STRING_VISITOR to support STRING_8 or STRING_32 output.
Added examples.
Added doc in the folder "doc".
Updated Readme and other files.
Added package.iron file.
2014-11-17 11:22:33 +01:00
73d45c9817 Updated WSF_FILE_UTILITIES with class comment,
and avoid having expanded generic class.
2014-10-28 12:52:23 +01:00
519b959073 Fixed compilation issue for wsf_js_widget package. 2014-10-10 16:06:03 +02:00
2cc751f326 Fixed compilation for wsf tests. 2014-10-10 14:26:50 +02:00
99588faf40 fixed compilation of filter example. 2014-10-10 13:51:20 +02:00
Jocelyn Fiat
9c6b6b978a Merge pull request #11 from jocelyn/improved_sept_2014
Fixed various issue with parsing string (such as \t and related),
    Implemented escaping of slash '/' only in case of '</' to avoid potential issue with javascript and </script>
    Many feature renaming to match Eiffel style and naming convention, kept previous feature as obsolete.
    Restructured the library to make easy extraction of "converter" classes if needed in the future.
    Marked converters classes as obsolete.
    Updated part of the code to use new feature names.
    Updated license and copyright.
    Updated classes with bottom indexing notes related to copyright and license.
2014-10-03 18:46:00 +02:00
0647a74875 Ensure backward compatibility for parse' / is_parsed'. 2014-10-03 18:44:09 +02:00
Jocelyn Fiat
de9d99e6bc Merge pull request #140 from jvelilla/ewf_router
Updated WSF_ROUTER, to import an existing router definition.
2014-10-01 19:41:38 +02:00
ae9f67391c Marked converters classes as obsolete. 2014-09-30 10:46:28 +02:00
82f832a556 Updated license and copyright.
Updated classes with bottom indexing notes related to copyright and license.
2014-09-30 10:46:12 +02:00
19dbbf89e7 Fixed various issue with parsing string (such as \t and related),
Implemented escaping of slash '/' only in case of '</' to avoid potential issue with javascript and </script>
Many feature renaming to match Eiffel style and naming convention, kept previous feature as obsolete.
Restructured the library to make easy extraction of "converter" classes if needed in the future.
Updated part of the code to use new feature names.
2014-09-24 20:08:12 +02:00
Olivier Ligot
5d6e3c69ee Fix filter example: logging filter must be the last one 2014-09-18 13:29:24 +02:00
Olivier Ligot
984d04e972 Filter example: add fcgi target 2014-09-17 17:11:37 +02:00
Olivier Ligot
83486ae0cc Fix authentication filter: use {HTTP_AUTHORIZATION}.is_basic 2014-09-17 15:40:43 +02:00
jvelilla
4fe5c5da7e Updated WSF_ROUTER.import feature. 2014-09-12 10:54:22 -03:00
jvelilla
ec1d8ca52f Updated WSF_ROUTER, to import an existing router definition. 2014-09-10 12:57:34 -03:00
Olivier Ligot
0404627153 Merge remote-tracking branch 'upstream/master' 2014-07-11 15:00:20 +02:00
jvelilla
de282948e6 Merge pull request #9 from Conaclos/working
Apply pretty tool.
2014-07-08 17:25:35 +02:00
Jocelyn Fiat
93f1fed997 Merge pull request #139 from jocelyn/widget_integration
Added custom-template in examples, as a base template to integrate easily other JS widgets.
2014-07-07 12:30:10 +02:00
f6ebd414d6 Added custom-template in examples, as a base template to integrate easily other JS widgets.
Added custom example (based on custom-template project) that demonstrates how to integrate a thirdparty JS component such as d3 within the application using wsf_js_widget.

Removed various unecessary ecf dependencies.
2014-07-07 12:15:18 +02:00
ff19adc6c8 Improved comment related to PATH_INFO and stripping multiple slashes sequence to single slash. 2014-07-07 11:27:31 +02:00
Jocelyn Fiat
41d24c91b4 Merge pull request #138 from jocelyn/widget_integration
Integrated WSF_JS_Widget library provided by Yassin Nasir Hassan and Severin Munger as an ETH student project.
It was updated to better support Unicode, and other minor changes, this is still under "draft" folder, as it may need various modifications on the interface and implementation.
2014-07-07 11:19:43 +02:00
0427f7a8d3 Fixed compilation issue related to old usage of modified JSON library. 2014-07-07 11:14:36 +02:00
985a5e5ce7 Merge branch 'master' of github.com:EiffelWebFramework/EWF into widget_integration 2014-07-07 10:30:42 +02:00
fe4c283336 Move wsf_js_widget library under draft/library/server/wsf_js_widget 2014-07-07 10:26:10 +02:00
Conaclos
20e704604a Apply pretty print tool.
Apply on each class in test suite and library.
2014-07-04 17:59:05 +02:00
jvelilla
0db02a8c52 Merge pull request #8 from Conaclos/working
Tests - Update syntax and improve implementation
2014-07-04 14:07:41 +02:00
1b4b50ee80 Replace any multiple slash sequence by a single slash character for PATH_INFO. 2014-07-02 11:36:43 +02:00
446c692f97 Various changes related to new WSF_DEBUG_INFORMATION and WSF_DEBUG_HANDLER. 2014-07-01 19:59:08 +02:00
7dfc6ea67a Fixed various issues related to unicode and CGI variables (assuming that CGI variables are utf-8 encoded, and sometime percent encoded).
Delayed computation of `value' and `name' from WSF_STRING.
Fixed computation of REQUEST_URI when the server does not provide it (this is rare, but possible).
   compute it as SERVER_NAME + encoded-PATH_INFO + {? + QUERY_STRING}
2014-07-01 19:57:14 +02:00
jvelilla
a5a257f452 Update format 2014-07-01 04:47:23 -07:00
jvelilla
bde0e2900b Created Deployment (markdown) 2014-07-01 04:42:56 -07:00
Conaclos
361773101e Add documentation and contracts for domain types. 2014-06-30 18:32:14 +02:00
Conaclos
052860b62c Improve converters.
Replace old syntax with new one and improve
implementation.
2014-06-30 18:31:42 +02:00
Conaclos
c5e1b1ee69 Syntax update.
Replace assigment attempt with object test.
2014-06-30 18:28:13 +02:00
0b1697f20d Verbose mode for the WSF_DEBUG_HANDLER. 2014-06-30 15:45:54 +02:00
add71543a4 Fixed error introduced during refactorying on WSF_DEBUG_FILTER 2014-06-30 15:21:03 +02:00
66a1e0629c Improved the debug example, so that it outputs more information. 2014-06-30 15:16:31 +02:00
425c976032 Ensure that PATH_INFO and REQUEST_URI are following the CGI specifications:
- PATH_INFO is percent decoded but still utf-8 encoded,
  this is available via WGI.path_info and WSF_REQUEST.utf_8_path_info.
- Added WSF_REQUEST.percent_encoded_path_info
- and WSF_REQUEST.path_info remains the unicode value for PATH_INFO

Added cgi_variables: WGI_REQUEST_CGI_VARIABLES to have a simple and quick view on CGI variables
Added execution_variables to be able to iterate on execution variables.
Added PERCENT_ENCODER.percent_decoded_utf_8_string
Improved the WSF_DEBUG_HANDLER to provide more information thanks to WSF_DEBUG_INFORMATION object.
2014-06-30 15:13:47 +02:00
Jocelyn Fiat
397dcc6128 Merge pull request #133 from jocelyn/better_uploading_file
Improved the uploading of file in regard to temporary filename.
2014-06-23 16:06:29 +02:00
a3c403323d Raised the void-safety level to "complete"
Added comments.
2014-06-23 16:05:20 +02:00
942896aa0c Fixed library location for http 2014-06-12 20:02:57 +02:00
93c92c0e38 Avoid decoding PATH_INFO and PATH_TRANSLATED to follow CGI spec. 2014-06-12 19:54:30 +02:00
394ca46f03 Added example to help debugging EWF
This is mainly a kind of echo server .. that return the request information.
2014-06-12 19:52:41 +02:00
67641da44d Improved the uploading of file in regard to temporary filename.
Avoid to overwrite the same file for concurrent requests uploading the same filename.
2014-06-11 16:52:22 +02:00
Olivier Ligot
a826051979 Merge remote-tracking branch 'upstream/master' 2014-05-22 22:09:00 +02:00
3c8dc0a9e1 Fixed various Unicode text handling.
Moved example folder inside the library, and renamed it "demo"
Improved example code.
2014-04-22 16:36:29 +02:00
cc7d268610 Code improvement
Cosmetic (comments, names, formatting)
2014-03-26 10:18:02 +01:00
hassany
acc8cda04f Fix STRING_32 issues 2014-03-19 23:13:16 +01:00
hassany
7c5637c063 Add javascript function 2014-03-19 21:37:07 +01:00
severin
b87392906b Updated readme 2014-03-19 16:58:08 +01:00
severin
4e7e1e9c45 Added more comments and assertions to all classes; clean up 2014-03-19 16:49:24 +01:00
hassany
c5363c948c Extend documentation 2014-03-12 21:51:15 +01:00
severin
4f7086a6de Updated comments and added contracts for core controls in webcontrol 2014-03-12 17:21:39 +01:00
severin
3c4e15b386 Merge branch 'widget' of github.com:ynh/EWF into widget 2014-03-12 13:54:45 +01:00
hassany
6685b3679b Add file definition 2014-03-12 13:54:20 +01:00
severin
d6a27c26aa Added assets to library 2014-03-05 15:58:10 +01:00
severin
e7c4b949f5 Merge branch 'widget' of github.com:ynh/EWF into widget 2014-03-05 15:57:24 +01:00
severin
f89e0abe69 Simplified WSF_EMAIL_VALIDATOR regexp 2014-03-05 15:57:16 +01:00
YNH Webdev
cbcf9550f8 Rename WSF_FILE to WSF_FILE_DEFINITION 2014-03-05 15:07:21 +01:00
YNH Webdev
d4b877f18e Add Basepath 2014-03-05 15:05:26 +01:00
YNH Webdev
605a094910 Change STRING TO STRING_32 2014-03-05 14:54:45 +01:00
Olivier Ligot
655c95158f json: comment '* text=auto' in .gitattributes 2014-03-03 14:18:07 +01:00
YNH Webdev
7ca62463b7 Rename progress_source 2014-02-26 10:55:33 +01:00
YNH Webdev
2cc26f98c6 Add class description to validators
Rename Wsf_progresssource
2014-02-23 19:10:23 +01:00
YNH Webdev
47b4357a72 Extend upload demo 2014-02-23 13:36:55 +01:00
YNH Webdev
a60bd19e58 Fix state transition 2014-02-23 13:14:09 +01:00
severin
439e43fad9 Began with class documentation 2014-02-21 00:23:35 +01:00
YNH Webdev
45ddc47b0e Finalize WSF_DYNAMIC_MULTI_CONTROL 2014-01-26 22:07:15 +01:00
YNH Webdev
8f148f2a5e Add dynamic multicontrol 2014-01-26 15:02:06 +01:00
YNH Webdev
5c9edeeae8 Image preview 2014-01-25 23:43:18 +01:00
YNH Webdev
13349d07a8 Fix upload state 2014-01-25 18:00:31 +01:00
severin
d82cacc18f Merge branch 'widget' of github.com:ynh/EWF into widget 2014-01-11 12:53:59 +01:00
YNH Webdev
564248284a Add set value to value controls 2014-01-11 01:10:24 +01:00
severin
ee473d8844 Included time library to set current date in date picker 2014-01-11 00:19:04 +01:00
severin
2fb0d73439 Added ability to form element to get value (for convenience/completion) 2014-01-10 15:32:05 +01:00
severin
5dd8a83081 Added ability to show/hide border of form elements 2014-01-08 22:12:02 +01:00
severin
f83a8db25c Small change on date picker control, removed date input 2014-01-08 20:29:09 +01:00
severin
320584a693 Modified datepicker control 2014-01-06 01:36:32 +01:00
severin
514a44e022 Removed country chooser widget 2014-01-05 15:01:14 +01:00
severin
191a00649f fixed js 2014-01-05 02:00:46 +01:00
severin
ecfd5738ce modified country and date/time chooser 2014-01-05 01:26:11 +01:00
severin
25fe7c8725 Included bootstrap datetimepicker 2014-01-04 16:33:08 +01:00
severin
dbcb1def29 Added date chooser widget 2014-01-04 16:14:30 +01:00
severin
c4acbf563f Added precondition in layout control 2014-01-04 14:15:05 +01:00
severin
c9599f449f Removed add_dropdown methods from navbar, some cleanup in different controls 2014-01-04 13:43:51 +01:00
severin
e675e8aad9 ATTENTION: ugly append_attributes added to stateless control, replaces set_attributes -> maybe improve 2014-01-04 10:51:07 +01:00
severin
37aac7053a Moved set_attributes from BASIC_CONTROL to STATELESS_CONTROL 2014-01-04 10:30:34 +01:00
severin
9c9a132329 Merge branch 'widget' of github.com:ynh/EWF into widget 2014-01-03 12:06:53 +01:00
YNH Webdev
ce305d4e54 Add disable option 2014-01-02 18:19:59 +01:00
YNH Webdev
d3c66cd7fe Allow remove 2014-01-02 03:20:57 +01:00
YNH Webdev
7bf95cd927 Add serverside file id to file structure 2014-01-01 23:50:12 +01:00
YNH Webdev
05d4f24f6f Allow detached values 2014-01-01 23:48:56 +01:00
YNH Webdev
d9c837918b Demo upload 2014-01-01 20:41:28 +01:00
severin
5adee83350 Merge branch 'widget' of github.com:ynh/EWF into widget 2014-01-01 14:44:30 +01:00
severin
720e26d19d Small page control change 2014-01-01 14:44:22 +01:00
YNH Webdev
29356c0b61 Workin file upload 2014-01-01 01:35:43 +01:00
YNH Webdev
b39dd5c40d Change parameter type 2013-12-31 21:25:01 +01:00
YNH Webdev
1ae44e74e7 File upload implementation part1 2013-12-31 16:03:24 +01:00
YNH Webdev
7a5d1e378d Fix dropdown list, clean up actions 2013-12-31 12:10:05 +01:00
YNH Webdev
51c4e8ab9e Rename files 2013-11-11 08:28:08 +01:00
YNH Webdev
f369b26d88 Rename validators, Make forms resizable 2013-11-10 17:22:28 +01:00
YNH Webdev
40bb88a55f Validate all fields and make regexp stricter 2013-11-10 16:53:21 +01:00
YNH Webdev
72e7493842 Fix event handler 2013-11-10 16:39:04 +01:00
YNH Webdev
6213021f45 Fix form element control 2013-11-10 15:10:00 +01:00
YNH Webdev
eb3fb7e5f7 Update sample app 2013-11-10 13:58:44 +01:00
YNH Webdev
1ec14ec397 Fix email validation and min and max validator 2013-11-10 13:53:20 +01:00
YNH Webdev
38f422896d Fix slider 2013-11-09 17:14:58 +01:00
YNH Webdev
3895cf4399 Fix assert path 2013-11-09 14:42:17 +01:00
YNH Webdev
7e69fddac9 Fix rendering issue. Add active class 2013-11-08 23:03:30 +01:00
YNH Webdev
0721384b60 Adjust layout control and fix navlist 2013-11-08 09:27:56 +01:00
YNH Webdev
0d79799a5d Fix autocomplete 2013-11-08 00:09:09 +01:00
YNH Webdev
86339d8163 Redesign states and implement generated control_name 2013-11-08 00:03:02 +01:00
YNH Webdev
c9102af0aa Add stateless widgets 2013-11-06 15:44:31 +01:00
severin
6838089570 Fix Layout Control 2013-11-05 16:14:15 +01:00
severin
aba60a473a Added navlist widget 2013-11-05 16:05:24 +01:00
YNH Webdev
9a392ba292 Fix project 2013-11-05 15:50:28 +01:00
severin
85369d5247 Added WSF_LAYOUT_CONTROL 2013-11-05 15:39:42 +01:00
YNH Webdev
7c11de3073 Fix navbar state problem 2013-11-04 00:22:42 +01:00
YNH Webdev
4d07a6330d Add item alias 2013-11-03 12:51:35 +01:00
severin
dad4191c40 Fixed js 2013-11-02 23:02:07 +01:00
severin
b70450cfe9 Added dropdown control 2013-11-02 22:36:21 +01:00
severin
10b950a7e7 Fixed creation procedures (make) 2013-11-02 18:34:48 +01:00
YNH Webdev
1b831375ef Fix image sizes 2013-10-30 13:35:53 +01:00
YNH Webdev
a979bf24d4 Fix slider code 2013-10-30 13:14:48 +01:00
severin
4b11bbb73d Slider fix 2013-10-30 13:02:49 +01:00
YNH Webdev
f1cefd6173 Fix path 2013-10-29 23:14:45 +01:00
severin
ac31e1c29e Merge branch 'widget_slider' into widget
Conflicts:
	draft/library/wsf_js_widget/kernel/webcontrol/wsf_control.e
	examples/widgetapp/base_page.e
2013-10-29 15:39:32 +01:00
severin
61f032a819 Fixed WSF_MULTI_CONTROL (wrong order of subcontrols), completed navbar, improved slider 2013-10-29 15:32:57 +01:00
Severin
26e6a62e6b Test 2013-09-29 02:24:33 +02:00
YNH Webdev
01327a4b06 Add codeview 2013-09-28 16:24:51 +02:00
YNH Webdev
d3299f8e06 Fix news datasource 2013-09-28 09:49:53 +02:00
YNH Webdev
1100328fee Fix load state error 2013-09-28 09:44:39 +02:00
YNH Webdev
cb1a4825d2 Implement lazy js load wraper 2013-09-28 00:45:27 +02:00
YNH Webdev
aa9f4c4ed8 Load needed libraries dynamically 2013-09-28 00:30:29 +02:00
Severin Münger
c6d59d3366 Fixed slider 2013-09-27 18:13:55 +02:00
YNH Webdev
8353f34c45 Adjust widgetapp 2013-09-27 11:02:10 +02:00
YNH Webdev
b6c082e1fe Create new JSON_OBJECT 2013-09-27 10:57:40 +02:00
YNH Webdev
113df6efe1 Merge branch 'widget' of github.com:souvarin/EWF into widget 2013-09-24 15:20:43 +02:00
Severin Münger
83329ca4b7 Moved to draft 2013-09-24 15:18:14 +02:00
Severin Münger
f51201eae1 Removed WSF_STATELESS_MULTI_CONTROL 2013-09-24 15:02:33 +02:00
Severin Münger
c52a513378 Changed slider 2013-09-24 14:38:01 +02:00
Severin Münger
6908bfe7bf Added slider demo 2013-09-24 02:38:36 +02:00
Severin Münger
a5fa428e98 Added simple image slider widget 2013-09-24 01:28:29 +02:00
YNH Webdev
24f760c043 Add table title 2013-09-24 00:22:56 +02:00
YNH Webdev
3f089d6811 Implement remove 2013-09-24 00:18:38 +02:00
YNH Webdev
7e673b4628 Stop interval if deleted 2013-09-23 00:40:40 +02:00
YNH Webdev
ca633d3524 Introduce actions
First working modal
2013-09-23 00:15:43 +02:00
YNH Webdev
7dd726ca42 Set url within page class 2013-09-22 22:47:29 +02:00
YNH Webdev
3f6caa76dc Fix confict 2013-09-22 19:14:19 +02:00
YNH Webdev
5a18cb4246 Merge branch 'widget' of github.com:souvarin/EWF into widget_state_redesign
Conflicts:
	examples/widgetapp/base_page.e
2013-09-22 19:11:46 +02:00
YNH Webdev
b33de9985f Implement control isolation 2013-09-22 19:11:07 +02:00
YNH Webdev
3a9ede6e8c Restructure callbacks 2013-09-22 18:30:48 +02:00
Severin Münger
87569ccee9 Merge branch 'widget' of github.com:ynh/EWF into widget 2013-09-22 18:20:53 +02:00
Severin Münger
16b79ef193 Improved Navbar, changed attribute handling 2013-09-22 18:20:17 +02:00
YNH Webdev
f360e8a867 Add comments to grid controls 2013-09-22 14:35:26 +02:00
Severin Münger
57dd4ce259 Added comments to autocompletion, input, navbar, progressbar, validator, webcontrol. Some more little changes. 2013-09-21 23:01:36 +02:00
YNH Webdev
252b5ff758 Use append 2013-09-20 20:53:51 +02:00
YNH Webdev
b19598d902 Fix tuple 2013-09-20 20:51:19 +02:00
YNH Webdev
b5ef1fbbb5 Make recommended changes
- Implicit casting
- Use same_string
2013-09-20 20:49:03 +02:00
YNH Webdev
0a2883e040 Rename clusters to singular names 2013-09-20 19:22:46 +02:00
YNH Webdev
24474e6b31 Move project to wsf_js_widget 2013-09-20 19:19:34 +02:00
ynh
6c0eeebf27 Merge pull request #2 from jocelyn/widget_first_review
Minor changes
2013-09-20 03:34:36 -07:00
48f5cb78d5 Minor changes
- using http_client library instead of libcurl directly
 - using implicit conversion to JSON_STRING to improve code readability
 - use ARRAYED_LIST instead of LINKED_LIST .. for performance.
 - cosmetic .. but still a lot of feature clauses are missing, comments, assertions ...
2013-09-20 10:27:00 +02:00
YNH Webdev
1da678f726 Slow down fetching 2013-09-16 00:01:31 +02:00
Severin Münger
fccb6776b0 Fixed progressbar 2013-09-15 23:47:04 +02:00
Severin Münger
f2e85aca42 Merge branch 'widget' of github.com:ynh/EWF into widget 2013-09-15 22:14:07 +02:00
Severin Münger
2fbffb8c9e Added progress callback 2013-09-15 22:13:51 +02:00
YNH Webdev
dd8bddd45c Make js files local 2013-09-15 18:33:39 +02:00
YNH Webdev
358fe04699 Add all countries to flag list
Set encoding (Must be changed to UTF-8 in future)
2013-09-15 17:32:23 +02:00
YNH Webdev
647beea245 Rearrange demo
Add contact autocompletion
2013-09-15 15:25:13 +02:00
YNH Webdev
251974fd2f Create basepage 2013-09-15 14:16:18 +02:00
YNH Webdev
81952e7898 Merge branch 'widget_grid' into widget
Conflicts:
	examples/widgetapp/widget.coffee
	examples/widgetapp/widget.js
2013-09-15 14:04:45 +02:00
YNH Webdev
1ba9792547 Fix suggestions 2013-09-15 13:33:43 +02:00
Severin Münger
45e3a6d7cc Small changes 2013-09-15 13:25:01 +02:00
Severin Münger
be05edac7d Added Progress Control 2013-09-15 01:57:03 +02:00
Severin Münger
6761d22fa8 Added Progress Control 2013-09-15 01:55:17 +02:00
Severin Münger
9db93cf4c9 Included navbar example 2013-09-15 00:44:20 +02:00
YNH Webdev
15dd993b95 Fix change event 2013-09-14 22:45:58 +02:00
YNH Webdev
0f8444a585 Remove column from grid 2013-09-14 20:39:07 +02:00
YNH Webdev
6230d643c8 Style demo pages 2013-09-14 19:39:08 +02:00
YNH Webdev
cfe452543a Implement repeater 2013-09-14 18:41:49 +02:00
YNH Webdev
26ec7d94c6 Google news example 2013-09-14 17:46:57 +02:00
YNH Webdev
95f823e7a1 - Add event paramenter
- Implement Paging control
2013-09-14 14:27:11 +02:00
Severin Münger
09544ba6d2 Fixed rendering, added navbar 2013-09-13 23:24:49 +02:00
YNH Webdev
15676a7c9e Fix path in project 2013-09-13 19:42:24 +02:00
Severin Münger
efc1550ab9 Merge branch 'widget' of github.com:ynh/EWF into widget
Conflicts:
	library/server/wsf_html/webcontrol/wsf_control.e
2013-09-13 01:12:26 +02:00
Severin Münger
f53974b138 Small changes/fixes 2013-09-13 01:08:18 +02:00
YNH Webdev
6860860161 Fix render function 2013-09-13 01:05:35 +02:00
Severin Münger
9c65194d91 Small fix removed DOCTYPE 2013-09-13 00:41:31 +02:00
Severin Münger
b1cf630443 New Control structure 2013-09-13 00:28:37 +02:00
YNH Webdev
b3e383ea82 Merge branch 'widget' of github.com:souvarin/EWF into widget
Conflicts:
	library/server/wsf_html/wsf_html-safe.ecf
2013-09-13 00:21:58 +02:00
YNH Webdev
36368aff0b Add Grid Widget 2013-09-13 00:20:27 +02:00
Severin Münger
162735b328 Extended autocompletion with customized templates 2013-09-12 17:15:05 +02:00
Severin Münger
27023283e7 Autocompletion 2013-09-12 14:58:35 +02:00
Severin Münger
8fc405fef1 Changed structure 2013-09-12 11:38:31 +02:00
Severin Münger
55e91bff7f Merge branch 'widget' of github.com:ynh/EWF into widget 2013-09-06 23:34:50 +02:00
YNH Webdev
8b179fd98d Min/Max validator 2013-09-06 21:47:02 +02:00
Severin Münger
e5841f2dad Merge branch 'widget' of github.com:ynh/EWF into widget
Conflicts:
	examples/widgetapp/sample_page.e
2013-09-06 20:40:43 +02:00
Severin Münger
d45405f261 Some small changes 2013-09-06 20:36:04 +02:00
YNH Webdev
133ed9a0be Show server side error in validation box 2013-09-06 18:52:59 +02:00
YNH Webdev
33220b2b8e Add HTML control 2013-09-06 18:45:14 +02:00
YNH Webdev
f542975872 Small render fix 2013-09-06 18:13:23 +02:00
YNH Webdev
4dd4678b65 Comment js code 2013-09-06 18:09:39 +02:00
YNH Webdev
bbd48d24e4 Implement serverside and client side validatation 2013-09-06 18:06:43 +02:00
YNH Webdev
9f40c6355c First working checkbox list 2013-09-06 14:22:23 +02:00
YNH Webdev
0fcb80aa29 Merge branch 'widget' of github.com:souvarin/EWF into widget 2013-09-06 12:29:14 +02:00
Severin Münger
59a12dcac1 Added checkbox list, modified form validation 2013-09-06 01:20:41 +02:00
YNH Webdev
eb47c101ca Merge branch 'widget' of github.com:souvarin/EWF into widget 2013-09-05 23:37:19 +02:00
Severin Münger
c67a7f4982 Added validators for decimals and mails 2013-09-05 22:57:56 +02:00
Severin Münger
aba394502c Added Regexp validation (later used for mail, numbers...) 2013-09-05 22:09:08 +02:00
YNH Webdev
0c265f4f78 Fix form and textarea bug 2013-09-05 17:43:46 +02:00
YNH Webdev
32518cfb41 Merge branch 'widget' of github.com:souvarin/EWF into widget
Conflicts:
	library/server/wsf_html/webcontrol/wsf_control.e
2013-09-05 17:20:40 +02:00
YNH Webdev
225f821206 Test the new controls 2013-09-05 17:18:46 +02:00
Severin Münger
f506d9e925 Implemented WSF_CHECKBOX_CONTROL, added id attribute to rendering of WSF_CONTROL 2013-09-05 17:16:56 +02:00
YNH Webdev
edce18fb1f Merge branch 'widget' of github.com:ynh/EWF into widget 2013-09-05 16:53:29 +02:00
YNH Webdev
ad15ab13c5 Fix render function 2013-09-05 16:53:05 +02:00
Severin Münger
f52f6512a0 Restructured validators, fixed form element rendering 2013-09-05 16:51:51 +02:00
YNH Webdev
7bdafbd21e Fix render function 2013-09-05 16:51:37 +02:00
YNH Webdev
6486c8c472 Merge branch 'widget' of github.com:souvarin/EWF into widget 2013-09-05 16:28:21 +02:00
YNH Webdev
fb345c5f0c Add bootstrap 2013-09-05 16:27:55 +02:00
Severin Münger
deaeaa434d Implemented WSF_FORM_ELEMENT_CONTROL 2013-09-05 16:25:44 +02:00
Severin Münger
f9cc0afb9e Merge branch 'widget' of github.com:ynh/EWF into widget
Conflicts:
	library/server/wsf_html/webcontrol/wsf_control.e
	library/server/wsf_html/webcontrol/wsf_text_control.e
2013-09-05 15:40:11 +02:00
Severin Münger
ee0400463f Began with implementation of form handling 2013-09-05 15:37:59 +02:00
YNH Webdev
fa35c22d2d Use render tag 2013-09-05 15:33:56 +02:00
Severin Münger
422b73058c Adapted rendering of multi control 2013-09-05 15:12:22 +02:00
Severin Münger
c50a46206d Merge branch 'widget' of github.com:ynh/EWF into widget 2013-09-05 15:08:24 +02:00
Severin Münger
f866c067cb Changed creation procedures 2013-09-05 15:08:02 +02:00
YNH Webdev
811d087d74 Generate tag 2013-09-05 14:55:52 +02:00
YNH Webdev
633243311d Change wsf control 2013-09-05 14:48:19 +02:00
Severin Münger
ae9952a941 Added class for TextArea 2013-09-03 03:54:33 +02:00
Severin Münger
3b2ad80dc3 Added TextArea 2013-09-03 03:53:01 +02:00
Severin Münger
1c08439c1a forgot to add new files 2013-09-02 20:25:59 +02:00
Severin Münger
16c89180d2 Added generalized input control similiar to text 2013-09-02 03:44:30 +02:00
YNH Webdev
bc6b4f90c3 Only send changes back to client 2013-08-29 18:31:57 +02:00
YNH Webdev
275cc7aa21 Add comments
Use Precursor
2013-08-28 22:59:24 +02:00
YNH Webdev
e186475a81 Clean up code
Simplify event
2013-08-28 19:43:44 +02:00
YNH Webdev
595d0c501a Only callback if there is an event attached 2013-08-28 15:57:16 +02:00
YNH Webdev
4e09a15454 Remove ugly do nothing hack 2013-08-28 15:30:13 +02:00
YNH Webdev
b7ab840d71 Communication in both directions (Text control)
Code regrouping
2013-08-28 12:52:09 +02:00
YNH Webdev
b72e6871e8 Fix multi control
Use multi control in example
2013-08-28 11:04:54 +02:00
YNH Webdev
f14ea29636 Comment and reformat coffee script file 2013-08-28 00:34:25 +02:00
YNH Webdev
cb7f1f0ee3 First working callback 2013-08-28 00:04:42 +02:00
Severin Münger
ef34217a6d Added WSF_MULTI_CONTROL to support controls that consist of multiple separate controls. 2013-08-27 22:06:08 +02:00
Severin Münger
ab7ee8e4c3 Created first working sample page application. 2013-08-27 16:48:20 +02:00
YNH Webdev
1a1df35ff1 Remove content length 2013-08-27 16:45:50 +02:00
YNH Webdev
0c0fb5c9c8 Add html body 2013-08-27 16:44:58 +02:00
YNH Webdev
c29a6ad195 Add assigner 2013-08-27 16:33:54 +02:00
YNH Webdev
6fdffb7418 Add post condition 2013-08-27 16:18:51 +02:00
YNH Webdev
8db642cf3b Move initalize controls 2013-08-27 16:07:06 +02:00
YNH Webdev
850a05d6bb Pretty Print 2013-08-27 16:00:24 +02:00
YNH Webdev
74995101d1 Add a json state to each control 2013-08-27 15:58:56 +02:00
YNH Webdev
fa5d13e19d Fix path 2013-08-27 15:01:57 +02:00
YNH Webdev
9f7e72f0a4 Page structure 2013-08-27 14:47:43 +02:00
YNH Webdev
c224bf1bb1 Test 2013-08-27 13:53:34 +02:00
Severin Münger
b5b71a3db0 Created widget-project testapp project. 2013-08-27 13:48:44 +02:00
460 changed files with 69065 additions and 4110 deletions

1
.gitignore vendored
View File

@@ -3,4 +3,5 @@ tests/temp/
.svn/
*.swp
*~
*.scm
*#

View File

@@ -38,11 +38,12 @@ For download, check
Tasks and issues are managed with github issue system
* See https://github.com/EiffelWebFramework/EWF/issues
* And visual dashboard: https://waffle.io/eiffelwebframework/ewf
* Forum/group post: https://groups.google.com/forum/#!forum/eiffel-web-framework
## Requirements
* Compiling from EiffelStudio 7.2 to 13.11 and more recent version of the compiler.
* Developped using EiffelStudio 13.11 (on Windows, Linux)
* Tested using EiffelStudio 13.11 with "jenkins" CI server (not anymore compatible with 6.8 due to use of `TABLE_ITERABLE')
* Compiling from EiffelStudio 13.11 to 15.05 and more recent version of the compiler.
* Currently being developped using EiffelStudio 15.01 (on Windows, Linux)
* Tested using EiffelStudio 15.01 with "jenkins" CI server (not anymore compatible with 6.8 due to use of `TABLE_ITERABLE')
* The code have to allow __void-safe__ compilation and non void-safe system (see [more about void-safety](http://docs.eiffel.com/book/method/void-safe-programming-eiffel) )
## How to get the source code?
@@ -100,6 +101,7 @@ review the [guidelines for contributing](CONTRIBUTING.md).
Keep track of development and community news.
* Follow [@EiffelWeb](https://twitter.com/EiffelWeb) on Twitter
* [Forum](https://groups.google.com/forum/#!forum/eiffel-web-framework) on Google groups.
* Follow our [page](https://plus.google.com/u/0/110650349519032194479) and [community](https://plus.google.com/communities/110457383244374256721) on Google+
* Have a question that's not a feature request or bug report? [Ask on the mailing list](http://groups.google.com/group/eiffel-web-framework)

View File

@@ -0,0 +1,82 @@
note
description: "Summary description for {TCP_STREAM_SOCKET}."
date: "$Date: 2015-02-16 19:53:13 +0100 (lun., 16 févr. 2015) $"
revision: "$Revision: 96642 $"
class
TCP_STREAM_SOCKET
inherit
NETWORK_STREAM_SOCKET
redefine
make
end
create
make_server_by_address_and_port,
make_server_by_port
create {NETWORK_STREAM_SOCKET}
make_from_descriptor_and_address
feature {NONE} -- Initialization
make
-- Create a network stream socket.
do
Precursor
set_reuse_address
end
make_server_by_address_and_port (an_address: INET_ADDRESS; a_port: INTEGER)
-- Create server socket on `an_address' and `a_port'.
require
valid_port: a_port >= 0
do
make
create address.make_from_address_and_port (an_address, a_port)
bind
end
feature -- Basic operation
send_message (a_msg: STRING)
local
a_package : PACKET
a_data : MANAGED_POINTER
c_string : C_STRING
do
create c_string.make (a_msg)
create a_data.make_from_pointer (c_string.item, a_msg.count + 1)
create a_package.make_from_managed_pointer (a_data)
send (a_package, 1)
end
feature -- Output
put_readable_string_8 (s: READABLE_STRING_8)
-- Write readable string `s' to socket.
local
ext: C_STRING
do
create ext.make (s)
put_managed_pointer (ext.managed_data, 0, s.count)
end
feature -- Status report
try_ready_for_reading: BOOLEAN
-- Is data available for reading from the socket right now?
require
socket_exists: exists
local
retval: INTEGER
do
retval := c_select_poll_with_timeout (descriptor, True, 0)
Result := (retval > 0)
end
note
copyright: "2011-2015, Javier Velilla and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
end

View File

@@ -17,7 +17,8 @@ create
make_server_by_port
create {NETWORK_STREAM_SOCKET}
make_from_descriptor_and_address
make_from_descriptor_and_address,
make_empty
feature {NONE} -- Initialization
@@ -75,8 +76,8 @@ feature -- Status report
retval := c_select_poll_with_timeout (descriptor, True, 0)
Result := (retval > 0)
end
note
copyright: "2011-2011, Javier Velilla and others"
copyright: "2011-2015, Javier Velilla and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
end

View File

@@ -15,6 +15,21 @@
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
<library name="net" location="$ISE_LIBRARY\library\net\net-safe.ecf"/>
<library name="thread" location="$ISE_LIBRARY\library\thread\thread-safe.ecf"/>
<cluster name="nino" location=".\library\" recursive="true"/>
<cluster name="nino" location=".\library\" recursive="true">
<file_rule>
<exclude>spec</exclude>
</file_rule>
<file_rule>
<exclude>tcp_stream_socket.e</exclude>
<condition>
<version type="compiler" max="15.01.9.6506"/>
</condition>
</file_rule>
</cluster>
<cluster name="spec_before_15_01" location=".\library\spec\before_15_01\" recursive="true">
<condition>
<version type="compiler" max="15.01.9.6506"/>
</condition>
</cluster>
</target>
</system>

View File

@@ -15,6 +15,21 @@
<library name="base" location="$ISE_LIBRARY\library\base\base.ecf"/>
<library name="net" location="$ISE_LIBRARY\library\net\net.ecf"/>
<library name="thread" location="$ISE_LIBRARY\library\thread\thread.ecf"/>
<cluster name="nino" location=".\library\" recursive="true"/>
<cluster name="nino" location=".\library\" recursive="true">
<file_rule>
<exclude>spec</exclude>
</file_rule>
<file_rule>
<exclude>tcp_stream_socket.e</exclude>
<condition>
<version type="compiler" max="15.01.9.6506"/>
</condition>
</file_rule>
</cluster>
<cluster name="spec_before_15_01" location=".\library\spec\before_15_01\" recursive="true">
<condition>
<version type="compiler" max="15.01.9.6506"/>
</condition>
</cluster>
</target>
</system>

View File

@@ -0,0 +1,14 @@
package nino
project
nino = "nino-safe.ecf"
nino = "nino.ecf"
note
title: Eiffel Nino Web Server
description: Simple HTTPd server written in Eiffel
tags: web, httpd, server
license: Eiffel Forum v2
copyright: Javier Velilla, Jocelyn Fiat.
end

View File

@@ -1,5 +1,5 @@
# Set default behaviour, in case users don't have core.autocrlf set.
* text=auto
# * text=auto
# Explicitly declare text files we want to always be normalized and converted
# to native line endings on checkout.
@@ -7,3 +7,4 @@
*.ecf text
*.bat text
*.json text
*.txt text

View File

@@ -1,2 +1,2 @@
*.swp
EIFGENs
EIFGENs/

View File

@@ -1,10 +1,12 @@
History file for EJSON
History file for EJSON
======================
team: ""
date: "2011-07-06"
revision: "0.3.0"
WARNING: THIS FILE IS NOT UP TO DATE
+++++++++++++++++++++Important Changes since 0.2.0 version++++++++++++++++++++++++++++++++++++++++++++++
@@ -23,4 +25,4 @@ implementation.
*Added converters and factory classes
*Added new top level directories; library, test, build and example
*Added new top level directories; library, test, build and example

View File

@@ -1,4 +1,5 @@
Copyright (c) 2010 Javier Velilla and others, http://ejson.origo.ethz.ch
Copyright (c) 2010-2014 Javier Velilla, Jocelyn Fiat and others,
https://github.com/eiffelhub/json .
Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -6,10 +7,10 @@ of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
@@ -17,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
THE SOFTWARE.

View File

@@ -1,21 +1,26 @@
Readme file for eJSON
=====================
team: "Javier Velilla,Jocelyn Fiat, Paul Cohen"
date: "$Date$"
revision: "$Revision$"
team: "Javier Velilla, Jocelyn Fiat"
previous contributors: "Paul Cohen"
date: "2014-nov-17"
1. Introduction
---------------
eJSON stands for Eiffel JSON library and is a small Eiffel library for dealing
with the JSON format. The objective of the library is to provide two basic
features Eiffel2JSON and JSON2Eiffel.
with the JSON format. This library provides a JSON parser and visitors,
including a pretty printer.
The converters part is now obsolete and not recommended (remember: the
objective of converters were to provide two basic features Eiffel2JSON and
JSON2Eiffel). There will be a new design for converters as a standalone
library on top of Current json library.
2. Legal stuff
--------------
eJSON is copyrighted by the author Javier Velilla and others. It is licensed
eJSON is copyrighted by the author Javier Velilla, Jocelyn Fiat and others. It is licensed
under the MIT License. See the file license.txt in the same directory as this
readme file.
@@ -46,18 +51,18 @@ Currently the only documentation on eJSON is available at:
EJSON requires that you have:
1. Gobo 3.9 installed or later
2. One of the following compiler combinations installed:
* ISE Eiffel 6.5 or later.
1. One of the following compiler combinations installed:
* ISE Eiffel 13.11 or later.
* gec [try to test]
* tecomp [try to test]
eJSON probably works fine with other versions of the above compilers.
There are no known platform dependencies (Windows, Linux).
To install eJSON simply extract the ejson-X.Y.Z.zip file to some appropriate
place on your hard disk. There are no requirements on environment variables or
registry variables.
registry variables.
Note eJSON is also delivered within EiffelStudio release, under
$ISE_LIBRARY/contrib/library/text/parser/json
To verify that everything works you should compile the example programs and/or
the test program.
@@ -70,18 +75,18 @@ installation.
Directory Description
--------- -----------
doc Contains the eJSON.pdf documentation file.
examples Contains the two example programs.
ejson Contains the actual eJSON library classes.
test Contains a test program for eJSON.
doc Contains documentation file.
examples Contains example codes.
library Contains the actual eJSON library classes.
test Contains test suite for eJSON.
7. Contacting the Team
----------------------
Contact the team:
https://github.com/eiffelhub/json/issues
Javier Velilla «javier.hector@gmail.com»
Paul Cohen «paco@seibostudios.se»
Jocelyn Fiat «jfiat@eiffel.com»
8. Releases
@@ -92,8 +97,16 @@ history.txt.
Version Date Description
------- ---- -----------
0.6.0 2014-11-17 Fixed various issue with parsing string (such as \t and related),
Implemented escaping of slash '/' only in case of '</' to avoid
potential issue with javascript and </script>
Many feature renaming to match Eiffel style and naming convention,
kept previous feature as obsolete.
Restructured the library to make easy extraction of "converter"
classes if needed in the future.
Marked converters classes as obsolete.
0.5.0 2013-11-dd Added JSON_ITERATOR, simplified JSON_OBJECT
0.4.0 2012-12-12 Updated documentation URI
0.3.0 2011-07-06 JSON Factory Converters
0.2.0 2010-02-07 Adapted to EiffelStudio 6.4 or later, supports void-safety
0.1.0 2010-02-07 First release, Adapted to SmartEiffel 1.2r7 and EiffelStudio 6.2 or previous
0.1.0 2010-02-07 First release, Adapted to SmartEiffel 1.2r7 and EiffelStudio 6.2 or previous

View File

@@ -0,0 +1,295 @@
== Preface ==
This document is a living document! As always read and try out the code to understand what's really going on.
=== About the project ===
The eJSON project was started by Javier Velilla in 2008. The aim was simply to
provide JSON support to Eiffel programmers. A couple of other people have been
involved to various extent since the start; Berend de Boer, Jocelyn Fiat and
Manu Stapf. In 2009 Paul Cohen joined the project as an active developer and
later Jocelyn Fiat.
The current active maintainers:
- Javier Velilla
- Jocelyn Fiat
The formal name of the project is “eJSON”.
For questions regarding eJSON please contact
- <javier.hector at gmail.com>
- <jfiat at eiffel.com>
- or directly on [https://github.com/eiffelhub/json/issues]
=== Current version and status ===
The latest release is 0.6.0. eJSON has been improved and cleaned.
The converters are not obsolete.
== Introduction ==
=== What is JSON? ===
JSON (JavaScript Object Notation) is a lightweight computer data interchange format. It is a text-based, human-readable format for representing simple data structures and associative arrays (called objects). See the [http://en.wikipedia.org/wiki/JSON Wikipedia article on JSON], [http://www.json.org www.json.org] and [http://www.json.com www.json.com] for more information.
The JSON format is specified in [http://www.ietf.org/rfc/rfc4627.txt IETF RFC 4627] by Douglas Crockford. The official [http://www.iana.org/assignments/media-types Internet MIME media type] for JSON is "application/json". The recommended file name extension for JSON files is ".json".
=== Advantages ===
1. Lightweight data-interchange format.
2. Easy for humans to read and write.
3. Enables easy integration with AJAX/JavaScript web applications. See the article [http://www.developer.com/lang/jscript/article.php/3596836 Speeding Up AJAX with JSON] for a good short discussion on this subject.
4. JSON data structures translate with ease into the native data structures universal to almost all programming languages used today.
=== Use in Eiffel applications ===
JSON can be used as a general serialization format for Eiffel objects. As such it could be used as a:
* Data representation format in REST-based web service applications written in Eiffel.
* Serialization format for Eiffel objects in persistence solutions.
* File format for configuration files in Eiffel systems.
=== Prerequisites ===
eJSON works today with EiffelStudio 13.11
There is an optional extension that requires the latest snapshot of the Gobo Eiffel libraries (a working snapshot is distributed with EiffelStudio). The depencencies on Gobo are on Gobo's unicode
and regex libraries and for some of the extra features in eJSON, on Gobos structure classes DS_HASH_TABLE and DS_LINKED_LIST.
eJSON is intended to work with all ECMA compliant Eiffel compilers.
=== Installation ===
You can either download a given release and install on your machine or you can get the latest snapshot of the code.
To download go to the [http://ejson.origo.ethz.ch/download download page].
To get the latest snapshot of the code do:
: $ git clone https://github.com/eiffelhub/json.git json
*[https://github.com/eiffelhub/json/releases download page]
*[https://github.com/eiffelhub/json github project]
Note that the latest json release is also delivered with EiffelStudio installation under <code>$ISE_LIBRARY/contrib/library/text/parser/json</code>.
=== Cluster and directory layout ===
json/
library/ (Root directory for eJSON library classes)
kernel/ (All classes in this cluster should eventually only depend on ECMA Eiffel and FreeELKS).
json_array.e
json_boolean.e
json_null.e
json_number.e
json_object.e
json_string.e
json_value.e
parser/
json_parser.e
json_parser_access.e
json_reader.e
json_tokens.e
utility/
file/
json_file_reader.e
visitor/
json_visitor.e
json_iterator.e
json_pretty_string_visitor.e
print_json_visitor.e
converters/ (JSON core converter classes !OBSOLETE!)
json_converter.e
json_hash_table_converter.e
json_list_converter.e
json_linked_list_converter.e
json_arrayed_list_converter.e
support/
ejson.e
shared_ejson.e
gobo_converters/ (JSON core converter classes support for GOBO !OBSOLETE!)
converters/
json_ds_hash_table_converter.e
json_ds_linked_list_converter.e
shared_gobo_ejson.e
test/ (Contains autotest suite)
autotest/ (AutoTest based unit test).
examples/ (Example code)
=== Future development ===
Here is a list of suggestions for future development of eJSON.
* Ongoing: Provide a JSON_FACTORY class for easy conversion between arbitrary JSON and Eiffel values.
* Ongoing: Provide a mechanism for users to add custom converters between JSON values and user space Eiffel classes.
* Ongoing: Implement a full test framework for eJSON.
* Suggestion: Investigate performance and improve it if neccessary.
* Suggestion: Support JSON references. See [http://www.json.com/2007/10/19/json-referencing-proposal-and-library JSON Referencing Proposal and Library] and [http://www.sitepen.com/blog/2008/06/17/json-referencing-in-dojo JSON referencing in Dojo] for more information.
* Suggestion: Support JSON path. See [http://goessner.net/articles/JsonPath JSONPath - XPath for JSON] for more information.
* Suggestion: Support JSON schema validation. See [http://json-schema.org JSON Schema Proposal] for more information.
* Suggestion: Support RDF JSON serialization. See [http://n2.talis.com/wiki/RDF_JSON_Specification RDF JSON Specification] for more information.
* Suggestion: Add support to JSON classes for conversion from Eiffel manifest values. So one can write things like:
== A simple example ==
There are two basic approaches to using eJSON; either you use the basic JSON_VALUE classes, converting to and from JSON values to corresponding Eiffel instances or you use the high level eJSON interface class SHARED_EJSON. Of course you can use a mix of both approaches if you find it appropriate!
Here is an example of how to create a JSON number value from an INTEGER and then obtain the JSON representation for that value.
simple_example is
local
i: INTEGER
jn: JSON_NUMBER
s: STRING
do
i := 42
create jn.make_integer (i)
s := jn.representation -- s.is_equal ("42")
end
== Mapping of JSON values to Eiffel values ==
=== JSON number ===
JSON numbers are represented by the class JSON_NUMBER. JSON number values can be converted to/from NATURAL_*, INTEGER_* and REAL_64 values. For floating point values REAL_* is used. The complete mapping is as follows:
JSON number -> Eiffel:
* -128 <= n <= +127 -> INTEGER_8
* n can't be represented by INTEGER_8 and -32768 <= n <= +32767 -> INTEGER_16
* n can't be represented by INTEGER_16 and -2147483648 <= n <= +2147483647 -> INTEGER_32
* n can't be represented by INTEGER_32 and -9223372036854775808 <= n <= +9223372036854775807 -> INTEGER_64
* n can't be represented by INTEGER_64 and 9223372036854775808 <= n <= 18446744073709551615 -> NATURAL_64
* n has fractional dot '.' -> REAL_64.
* n -> eJSON exception if number can't be represented by a INTEGER_64, NATURAL_64 or REAL_64.
Eiffel -> JSON number:
* NATURAL_8, NATURAL_16, NATURAL_32, NATURAL_64, NATURAL -> JSON number
* INTEGER_8, INTEGER_16, INTEGER_32, INTEGER_64, INTEGER -> JSON number
* REAL_32, REAL_64, REAL -> JSON number
You can use the following creation routines to create JSON_NUMBER instances:
* JSON_NUMBER.make_integer
* JSON_NUMBER.make_real
* JSON_NUMBER.make_natural
eiffel_to_json_number_representation is
local
i: INTEGER
r: REAL
jn: JSON_NUMBER
do
print ("JSON representation of Eiffel INTEGER: '")
i := 123
create jn.make_integer (i)
print (jn.representation)
print ("'%N")
print ("JSON representation of Eiffel REAL: '")
r := 12.3
create jn.make_real (r)
print (jn.representation)
print ("'%N")
end
The output of the above code will be:
JSON representation of Eiffel INTEGER: '123'
JSON representation of Eiffel REAL: '12.300000190734863'
=== JSON boolean ===
JSON boolean values are represented by the class JSON_BOOLEAN. The JSON boolean value "true" is converted to/from the BOOLEAN value "True" and the JSON boolean value "false is converted to/from the BOOLEAN value "False".
eiffel_to_json_boolean_representation is
local
b: BOOLEAN
jb: JSON_BOOLEAN
do
print ("JSON representation of Eiffel BOOLEAN: '")
b := True
create jb.make (b)
print (jb.representation)
print ("'%N")
print("JSON representation of Eiffel BOOLEAN: '")
b := False
create jb.make (b)
print (jb.representation)
print ("'%N")
end
The output of the above code will be:
JSON representation of Eiffel BOOLEAN: 'true'
JSON representation of Eiffel BOOLEAN: 'false'
=== JSON string ===
JSON strings are represented by the class JSON_STRING. JSON string values can be converted to/from STRING_32, STRING and CHARACTER values. The complete mapping is as follows:
JSON string -> Eiffel:
* All JSON strings -> STRING or STRING_32
Eiffel -> JSON string:
* STRING_32 -> JSON string
* STRING -> JSON string
* CHARACTER -> JSON string
eiffel_to_json_string_representation is
local
s: STRING
js: JSON_STRING
do
print ("JSON representation of Eiffel STRING: '")
s := "JSON rocks!"
create js.make_from_string (s)
print (js.representation)
print ("'%N")
end
The output of the above code will be:
JSON representation of Eiffel STRING: '"JSON rocks!"'
Note: JSON escape unicode characters, as well a other specific characters, to get the unescaped string value, use either 'unescaped_string_8' or 'unescaped_string_32'.
=== JSON null ===
The JSON null value is represented by the class JSON_NULL. The JSON null value can be converted to/from Void.
eiffel_to_json_null_representation is
local
a: ANY
jn: JSON_NULL
do
create jn
print ("JSON representation for JSON null value: '")
print (jn.representation)
print ("'%N")
a := Void
if attached {JSON_NULL} json.value (a) as l_jn then -- json from SHARED_EJSON!
print ("JSON representation of Eiffel Void reference: '")
print (l_jn.representation)
print ("'%N")
end
end
The output of the above code will be:
JSON representation for JSON null value: 'null'
JSON representation of Eiffel Void reference: 'null'
=== JSON array ===
JSON array is represented by the class JSON_ARRAY.
=== JSON object ===
JSON object is represented by the class JSON_OBJECT.
== The eJSON visitor pattern ==
TBD. See examples.
== The eJSON file reader class ==
TBD.

View File

@@ -0,0 +1,83 @@
class
BASIC
create
make
feature {NONE} -- Initialization
make
-- Initialize `Current'.
local
parser: JSON_PARSER
printer: JSON_PRETTY_STRING_VISITOR
s: STRING_32
do
-- Create parser for content `json_content'
create parser.make_with_string (json_content)
-- Parse the content
parser.parse_content
if
parser.is_valid and then
attached parser.parsed_json_value as jv
then
-- Json content is valid, and well parser.
-- and the parsed json value is `jv'
-- Let's access the glossary/title value
if
attached {JSON_OBJECT} jv as j_object and then
attached {JSON_OBJECT} j_object.item ("glossary") as j_glossary and then
attached {JSON_STRING} j_glossary.item ("title") as j_title
then
print ("The glossary title is %"" + j_title.unescaped_string_8 + "%".%N")
else
print ("The glossary title was not found!%N")
end
-- Pretty print the parsed JSON
create s.make_empty
create printer.make (s)
jv.accept (printer)
print ("The JSON formatted using a pretty printer:%N")
print (s)
end
end
feature -- Status
feature -- Access
json_content: STRING = "[
{
"glossary": {
"title": "example glossary",
"GlossDiv": {
"title": "S",
"GlossList": {
"GlossEntry": {
"ID": "SGML",
"SortAs": "SGML",
"GlossTerm": "Standard Generalized Markup Language",
"Acronym": "SGML",
"Abbrev": "ISO 8879:1986",
"GlossDef": {
"para": "A meta-markup language, used to create markup languages such as DocBook.",
"GlossSeeAlso": ["GML", "XML"]
},
"GlossSee": "markup"
}
}
}
}
}
]"
feature -- Change
feature {NONE} -- Implementation
invariant
-- invariant_clause: True
end

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-13-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-13-0 http://www.eiffel.com/developers/xml/configuration-1-13-0.xsd" name="basic" uuid="5156B9EE-0436-42A3-BDA1-74710DF05A35">
<target name="basic">
<root class="BASIC" feature="make"/>
<setting name="console_application" value="true"/>
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
<library name="json" location="..\..\library\json-safe.ecf" readonly="false"/>
<cluster name="basic" location=".\"/>
</target>
</system>

View File

@@ -5,20 +5,25 @@ note
revision: "$Revision$"
file: "$HeadURL: $"
class JSON_ARRAYED_LIST_CONVERTER
class
JSON_ARRAYED_LIST_CONVERTER
obsolete
"This JSON converter design has issues [Sept/2014]."
inherit
JSON_LIST_CONVERTER
JSON_LIST_CONVERTER
redefine
object
end
create
make
make
feature -- Access
object: ARRAYED_LIST [detachable ANY]
object: ARRAYED_LIST [detachable ANY]
feature {NONE} -- Factory
@@ -27,4 +32,7 @@ feature {NONE} -- Factory
create Result.make (nb)
end
note
copyright: "2010-2014, Javier Velilla and others https://github.com/eiffelhub/json."
license: "https://github.com/eiffelhub/json/blob/master/License.txt"
end -- class JSON_ARRAYED_LIST_CONVERTER

View File

@@ -0,0 +1,44 @@
note
description: "A JSON converter"
author: "Paul Cohen"
date: "$Date$"
revision: "$Revision$"
file: "$HeadURL: $"
deferred class
JSON_CONVERTER
obsolete
"This JSON converter design has issues [Sept/2014]."
inherit
SHARED_EJSON
feature -- Access
object: ANY
-- Eiffel object
deferred
end
feature -- Conversion
from_json (j: attached like to_json): detachable like object
-- Convert from JSON value.
-- Returns Void if unable to convert
deferred
end
to_json (o: like object): detachable JSON_VALUE
-- Convert to JSON value
deferred
end
invariant
has_eiffel_object: object /= Void -- An empty object must be created at creation time!
note
copyright: "2010-2014, Javier Velilla and others https://github.com/eiffelhub/json."
license: "https://github.com/eiffelhub/json/blob/master/License.txt"
end

View File

@@ -0,0 +1,88 @@
note
description: "A JSON converter for HASH_TABLE [ANY, HASHABLE]"
author: "Paul Cohen"
date: "$Date: 2014-01-30 15:27:41 +0100 (jeu., 30 janv. 2014) $"
revision: "$Revision: 94128 $"
file: "$HeadURL: $"
class
JSON_HASH_TABLE_CONVERTER
obsolete
"This JSON converter design has issues [Sept/2014]."
inherit
JSON_CONVERTER
create
make
feature {NONE} -- Initialization
make
do
create object.make (0)
end
feature -- Access
object: HASH_TABLE [ANY, HASHABLE]
feature -- Conversion
from_json (j: attached like to_json): like object
do
create Result.make (j.count)
across
j as ic
loop
if attached json.object (ic.item, Void) as l_object then
if attached {HASHABLE} json.object (ic.key, Void) as h then
Result.put (l_object, h)
else
check
key_is_hashable: False
end
end
else
check
object_attached: False
end
end
end
end
to_json (o: like object): detachable JSON_OBJECT
local
js: JSON_STRING
failed: BOOLEAN
do
create Result.make
across
o as c
loop
if attached {JSON_STRING} json.value (c.key) as l_key then
js := l_key
else
if attached {READABLE_STRING_GENERAL} c.key as s_key then
create js.make_from_string_general (s_key)
else
create js.make_from_string (c.key.out)
end
end
if attached json.value (c.item) as jv then
Result.put (jv, js)
else
failed := True
end
end
if failed then
Result := Void
end
end
note
copyright: "2010-2014, Javier Velilla and others https://github.com/eiffelhub/json."
license: "https://github.com/eiffelhub/json/blob/master/License.txt"
end -- class JSON_HASH_TABLE_CONVERTER

View File

@@ -5,20 +5,25 @@ note
revision: "$Revision$"
file: "$HeadURL: $"
class JSON_LINKED_LIST_CONVERTER
class
JSON_LINKED_LIST_CONVERTER
obsolete
"This JSON converter design has issues [Sept/2014]."
inherit
JSON_LIST_CONVERTER
JSON_LIST_CONVERTER
redefine
object
end
create
make
make
feature -- Access
object: LINKED_LIST [detachable ANY]
object: LINKED_LIST [detachable ANY]
feature {NONE} -- Factory
@@ -27,4 +32,7 @@ feature {NONE} -- Factory
create Result.make
end
note
copyright: "2010-2014, Javier Velilla and others https://github.com/eiffelhub/json."
license: "https://github.com/eiffelhub/json/blob/master/License.txt"
end -- class JSON_LINKED_LIST_CONVERTER

View File

@@ -0,0 +1,80 @@
note
description: "A JSON converter for LIST [ANY]"
author: "Paul Cohen"
date: "$Date$"
revision: "$Revision$"
file: "$HeadURL: $"
deferred class
JSON_LIST_CONVERTER
obsolete
"This JSON converter design has issues [Sept/2014]."
inherit
JSON_CONVERTER
feature {NONE} -- Initialization
make
do
object := new_object (0)
end
feature -- Access
object: LIST [detachable ANY]
feature {NONE} -- Factory
new_object (nb: INTEGER): like object
deferred
ensure
Result /= Void
end
feature -- Conversion
from_json (j: attached like to_json): detachable like object
local
i: INTEGER
do
Result := new_object (j.count)
from
i := 1
until
i > j.count
loop
Result.extend (json.object (j [i], Void))
i := i + 1
end
end
to_json (o: like object): detachable JSON_ARRAY
local
c: ITERATION_CURSOR [detachable ANY]
failed: BOOLEAN
do
create Result.make (o.count)
from
c := o.new_cursor
until
c.after
loop
if attached json.value (c.item) as jv then
Result.add (jv)
else
failed := True
end
c.forth
end
if failed then
Result := Void
end
end
note
copyright: "2010-2014, Javier Velilla and others https://github.com/eiffelhub/json."
license: "https://github.com/eiffelhub/json/blob/master/License.txt"
end -- class JSON_ARRAYED_LIST_CONVERTER

View File

@@ -5,9 +5,14 @@ note
revision: "$Revision$"
file: "$HeadURL: $"
class EJSON
class
EJSON
obsolete
"This JSON converter design has issues [Sept/2014]."
inherit
EXCEPTIONS
feature -- Access
@@ -19,13 +24,13 @@ feature -- Access
i: INTEGER
ja: JSON_ARRAY
do
-- Try to convert from basic Eiffel types. Note that we check with
-- `conforms_to' since the client may have subclassed the base class
-- that these basic types are derived from.
-- Try to convert from basic Eiffel types. Note that we check with
-- `conforms_to' since the client may have subclassed the base class
-- that these basic types are derived from.
if an_object = Void then
create {JSON_NULL} Result
elseif attached {BOOLEAN} an_object as b then
create {JSON_BOOLEAN} Result.make_boolean (b)
create {JSON_BOOLEAN} Result.make (b)
elseif attached {INTEGER_8} an_object as i8 then
create {JSON_NUMBER} Result.make_integer (i8)
elseif attached {INTEGER_16} an_object as i16 then
@@ -47,7 +52,7 @@ feature -- Access
elseif attached {REAL_64} an_object as r64 then
create {JSON_NUMBER} Result.make_real (r64)
elseif attached {ARRAY [detachable ANY]} an_object as a then
create ja.make_array
create ja.make (a.count)
from
i := a.lower
until
@@ -56,24 +61,24 @@ feature -- Access
if attached value (a @ i) as v then
ja.add (v)
else
check value_attached: False end
check
value_attached: False
end
end
i := i + 1
end
Result := ja
elseif attached {CHARACTER_8} an_object as c8 then
create {JSON_STRING} Result.make_json (c8.out)
create {JSON_STRING} Result.make_from_string (c8.out)
elseif attached {CHARACTER_32} an_object as c32 then
create {JSON_STRING} Result.make_json (c32.out)
create {JSON_STRING} Result.make_from_string_32 (create {STRING_32}.make_filled (c32, 1))
elseif attached {STRING_8} an_object as s8 then
create {JSON_STRING} Result.make_json (s8)
create {JSON_STRING} Result.make_from_string (s8)
elseif attached {STRING_32} an_object as s32 then
create {JSON_STRING} Result.make_json_from_string_32 (s32)
create {JSON_STRING} Result.make_from_string_32 (s32)
end
if Result = Void then
-- Now check the converters
-- Now check the converters
if an_object /= Void and then attached converter_for (an_object) as jc then
Result := jc.to_json (an_object)
else
@@ -84,7 +89,7 @@ feature -- Access
object (a_value: detachable JSON_VALUE; base_class: detachable STRING): detachable ANY
-- Eiffel object from JSON value. If `base_class' /= Void an eiffel
-- object based on `base_class' will be returned. Raises an "eJSON
-- object based on `base_class' will be returned. Raises an "eJSON
-- exception" if unable to convert value.
local
i: INTEGER
@@ -160,12 +165,10 @@ feature -- Access
-- "eJSON exception" if unable to convert value.
require
json_not_void: json /= Void
local
jv: detachable JSON_VALUE
do
json_parser.set_representation (json)
jv := json_parser.parse
if jv /= Void then
json_parser.parse_content
if json_parser.is_valid and then attached json_parser.parsed_json_value as jv then
Result := object (jv, base_class)
end
end
@@ -190,8 +193,8 @@ feature -- Access
js_key, js_value: JSON_STRING
do
create Result.make
create js_key.make_json ("$ref")
create js_value.make_json (s)
create js_key.make_from_string ("$ref")
create js_value.make_from_string (s)
Result.put (js_value, js_key)
end
@@ -205,7 +208,7 @@ feature -- Access
local
c: ITERATION_CURSOR [STRING]
do
create Result.make_array
create Result.make (l.count)
from
c := l.new_cursor
until
@@ -262,7 +265,10 @@ feature {NONE} -- Implementation (JSON parser)
json_parser: JSON_PARSER
once
create Result.make_parser ("")
create Result.make_with_string ("{}")
end
note
copyright: "2010-2014, Javier Velilla and others https://github.com/eiffelhub/json."
license: "https://github.com/eiffelhub/json/blob/master/License.txt"
end -- class EJSON

View File

@@ -0,0 +1,43 @@
note
description: "[
Shared factory class for creating JSON objects. Maps JSON
objects to ELKS HASH_TABLEs and JSON arrays to ELKS
LINKED_LISTs. Use non-conforming inheritance from this
class to ensure that your classes share the same
JSON_FACTORY instance.
]"
author: "Paul Cohen"
date: "$Date$"
revision: "$Revision: 89185 $"
file: "$HeadURL: $"
class
SHARED_EJSON
obsolete
"This JSON converter design has issues [Sept/2014]."
feature -- Access
json: EJSON
-- A shared EJSON instance with default converters for
--LINKED_LIST [ANY] and HASH_TABLE [ANY, HASHABLE]
local
jalc: JSON_ARRAYED_LIST_CONVERTER
jllc: JSON_LINKED_LIST_CONVERTER
jhtc: JSON_HASH_TABLE_CONVERTER
once
create Result
create jalc.make
Result.add_converter (jalc)
create jllc.make
Result.add_converter (jllc)
create jhtc.make
Result.add_converter (jhtc)
end
note
copyright: "2010-2014, Javier Velilla and others https://github.com/eiffelhub/json."
license: "https://github.com/eiffelhub/json/blob/master/License.txt"
end -- class SHARED_EJSON

View File

@@ -1,37 +0,0 @@
note
description: "Objects that ..."
date: "$Date$"
revision: "$Revision$"
class
JSON_FILE_READER
feature -- Access
read_json_from (a_path: STRING): detachable STRING
local
l_file: PLAIN_TEXT_FILE
template_content: STRING
l_last_string: detachable STRING
do
create l_file.make_with_name (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

View File

@@ -9,20 +9,13 @@
</file_rule>
<option trace="false" profile="false" debug="false" warning="true" full_class_checking="true" is_attached_by_default="true" void_safety="all" syntax="standard" namespace="EJSON.Library">
<assertions/>
<warning name="export_class_missing" enabled="false"/>
<warning name="old_verbatim_strings" enabled="false"/>
<warning name="syntax" enabled="false"/>
<warning name="vjrv" enabled="false"/>
</option>
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf" readonly="true"/>
<cluster name="json" location=".\" recursive="true">
<file_rule>
<exclude>^/gobo$</exclude>
<exclude>^/kernel$</exclude>
<exclude>^/extras$</exclude>
</file_rule>
<cluster name="kernel" location=".\kernel\" recursive="true"/>
<cluster name="extras" location=".\extras\" recursive="true"/>
<cluster name="json" location=".\">
<cluster name="json_kernel" location=".\kernel\" recursive="true"/>
<cluster name="json_parser" location=".\parser\" recursive="true"/>
<cluster name="json_utility" location=".\utility\" recursive="true"/>
</cluster>
<cluster name="json_converter" location=".\converter\" recursive="true"/>
</target>
</system>

View File

@@ -9,20 +9,13 @@
</file_rule>
<option trace="false" profile="false" debug="false" warning="true" full_class_checking="true" void_safety="none" syntax="standard" namespace="EJSON.Library">
<assertions/>
<warning name="export_class_missing" enabled="false"/>
<warning name="old_verbatim_strings" enabled="false"/>
<warning name="syntax" enabled="false"/>
<warning name="vjrv" enabled="false"/>
</option>
<library name="base" location="$ISE_LIBRARY\library\base\base.ecf" readonly="true"/>
<cluster name="json" location=".\" recursive="true">
<file_rule>
<exclude>^/gobo$</exclude>
<exclude>^/kernel$</exclude>
<exclude>^/extras$</exclude>
</file_rule>
<cluster name="kernel" location=".\kernel\" recursive="true"/>
<cluster name="extras" location=".\extras\" recursive="true"/>
<cluster name="json" location=".\" >
<cluster name="json_kernel" location=".\kernel" recursive="true"/>
<cluster name="json_parser" location=".\parser" recursive="true"/>
<cluster name="json_utility" location=".\utility" recursive="true"/>
</cluster>
<cluster name="json_converter" location=".\converter" recursive="true"/>
</target>
</system>

View File

@@ -12,6 +12,6 @@
<library name="base" location="$ISE_LIBRARY\library\base\base.ecf" readonly="true"/>
<library name="json" location="json.ecf" readonly="true"/>
<library name="gobo_structure" location="$ISE_LIBRARY\library\gobo\gobo_structure.ecf"/>
<cluster name="json_gobo" location=".\gobo" recursive="true" />
<cluster name="json_gobo_converter" location=".\gobo_converter" recursive="true" />
</target>
</system>

View File

@@ -1,36 +0,0 @@
note
description: "A JSON converter"
author: "Paul Cohen"
date: "$Date$"
revision: "$Revision$"
file: "$HeadURL: $"
deferred class JSON_CONVERTER
inherit
SHARED_EJSON
feature -- Access
object: ANY
-- Eiffel object
deferred
end
feature -- Conversion
from_json (j: attached like to_json): detachable like object
-- Convert from JSON value.
-- Returns Void if unable to convert
deferred
end
to_json (o: like object): detachable JSON_VALUE
-- Convert to JSON value
deferred
end
invariant
has_eiffel_object: object /= Void -- An empty object must be created at creation time!
end

View File

@@ -1,76 +0,0 @@
note
description: "A JSON converter for HASH_TABLE [ANY, HASHABLE]"
author: "Paul Cohen"
date: "$Date: 2014-01-30 15:27:41 +0100 (jeu., 30 janv. 2014) $"
revision: "$Revision: 94128 $"
file: "$HeadURL: $"
class JSON_HASH_TABLE_CONVERTER
inherit
JSON_CONVERTER
create
make
feature {NONE} -- Initialization
make
do
create object.make (0)
end
feature -- Access
object: HASH_TABLE [ANY, HASHABLE]
feature -- Conversion
from_json (j: attached like to_json): like object
do
create Result.make (j.count)
across
j as ic
loop
if attached json.object (ic.item, Void) as l_object then
if attached {HASHABLE} json.object (ic.key, Void) as h then
Result.put (l_object, h)
else
check key_is_hashable: False end
end
else
check object_attached: False end
end
end
end
to_json (o: like object): detachable JSON_OBJECT
local
c: HASH_TABLE_ITERATION_CURSOR [ANY, HASHABLE]
js: JSON_STRING
failed: BOOLEAN
do
create Result.make
from
c := o.new_cursor
until
c.after
loop
if attached {JSON_STRING} json.value (c.key) as l_key then
js := l_key
else
create js.make_json (c.key.out)
end
if attached json.value (c.item) as jv then
Result.put (jv, js)
else
failed := True
end
c.forth
end
if failed then
Result := Void
end
end
end -- class JSON_HASH_TABLE_CONVERTER

View File

@@ -1,74 +0,0 @@
note
description: "A JSON converter for LIST [ANY]"
author: "Paul Cohen"
date: "$Date$"
revision: "$Revision$"
file: "$HeadURL: $"
deferred class JSON_LIST_CONVERTER
inherit
JSON_CONVERTER
feature {NONE} -- Initialization
make
do
object := new_object (0)
end
feature -- Access
object: LIST [detachable ANY]
feature {NONE} -- Factory
new_object (nb: INTEGER): like object
deferred
ensure
Result /= Void
end
feature -- Conversion
from_json (j: attached like to_json): detachable like object
local
i: INTEGER
do
Result := new_object (j.count)
from
i := 1
until
i > j.count
loop
Result.extend (json.object (j [i], Void))
i := i + 1
end
end
to_json (o: like object): detachable JSON_ARRAY
local
c: ITERATION_CURSOR [detachable ANY]
jv: detachable JSON_VALUE
failed: BOOLEAN
do
create Result.make_array
from
c := o.new_cursor
until
c.after
loop
jv := json.value (c.item)
if jv /= Void then
Result.add (jv)
else
failed := True
end
c.forth
end
if failed then
Result := Void
end
end
end -- class JSON_ARRAYED_LIST_CONVERTER

View File

@@ -1,178 +1,192 @@
note
description: "[
JSON_ARRAY represent an array in JSON.
An array in JSON is an ordered set of names.
Examples
array
[]
[elements]
]"
author: "Javier Velilla"
date: "2008/08/24"
revision: "Revision 0.1"
description: "[
JSON_ARRAY represent an array in JSON.
An array in JSON is an ordered set of names.
Examples
array
[]
[elements]
]"
author: "$Author$"
date: "$date$"
revision: "$Revision$"
class
JSON_ARRAY
JSON_ARRAY
inherit
JSON_VALUE
JSON_VALUE
ITERABLE [JSON_VALUE]
DEBUG_OUTPUT
create
make_array
make, make_empty,
make_array
feature {NONE} -- Initialization
make_array
-- Initialize JSON Array
do
create values.make (10)
end
make (nb: INTEGER)
-- Initialize JSON array with capacity of `nb' items.
do
create items.make (nb)
end
make_empty
-- Initialize empty JSON array.
do
make (0)
end
make_array
-- Initialize JSON Array
obsolete
"Use `make' Sept/2014"
do
make (10)
end
feature -- Access
i_th alias "[]" (i: INTEGER): JSON_VALUE
-- Item at `i'-th position
require
is_valid_index: valid_index (i)
do
Result := values.i_th (i)
end
i_th alias "[]" (i: INTEGER): JSON_VALUE
-- Item at `i'-th position
require
is_valid_index: valid_index (i)
do
Result := items.i_th (i)
end
representation: STRING
local
i: INTEGER
do
Result := "["
from
i := 1
until
i > count
loop
Result.append (i_th (i).representation)
i := i + 1
if i <= count then
Result.append_character (',')
end
end
Result.append_character (']')
end
representation: STRING
do
Result := "["
across
items as ic
loop
if Result.count > 1 then
Result.append_character (',')
end
Result.append (ic.item.representation)
end
Result.append_character (']')
end
feature -- Visitor pattern
accept (a_visitor: JSON_VISITOR)
-- Accept `a_visitor'.
-- (Call `visit_json_array' procedure on `a_visitor'.)
do
a_visitor.visit_json_array (Current)
end
accept (a_visitor: JSON_VISITOR)
-- Accept `a_visitor'.
-- (Call `visit_json_array' procedure on `a_visitor'.)
do
a_visitor.visit_json_array (Current)
end
feature -- Access
new_cursor: ITERATION_CURSOR [JSON_VALUE]
-- Fresh cursor associated with current structure
do
Result := values.new_cursor
Result := items.new_cursor
end
feature -- Mesurement
count: INTEGER
-- Number of items.
do
Result := values.count
end
count: INTEGER
-- Number of items.
do
Result := items.count
end
feature -- Status report
valid_index (i: INTEGER): BOOLEAN
-- Is `i' a valid index?
do
Result := (1 <= i) and (i <= count)
end
valid_index (i: INTEGER): BOOLEAN
-- Is `i' a valid index?
do
Result := (1 <= i) and (i <= count)
end
feature -- Change Element
put_front (v: JSON_VALUE)
require
v_not_void: v /= Void
do
values.put_front (v)
ensure
has_new_value: old values.count + 1 = values.count and
values.first = v
end
require
v_not_void: v /= Void
do
items.put_front (v)
ensure
has_new_value: old items.count + 1 = items.count and items.first = v
end
add, extend (v: JSON_VALUE)
require
v_not_void: v /= Void
do
values.extend (v)
ensure
has_new_value: old values.count + 1 = values.count and
values.has (v)
end
add, extend (v: JSON_VALUE)
require
v_not_void: v /= Void
do
items.extend (v)
ensure
has_new_value: old items.count + 1 = items.count and items.has (v)
end
prune_all (v: JSON_VALUE)
-- Remove all occurrences of `v'.
require
v_not_void: v /= Void
do
values.prune_all (v)
ensure
not_has_new_value: not values.has (v)
end
require
v_not_void: v /= Void
do
items.prune_all (v)
ensure
not_has_new_value: not items.has (v)
end
wipe_out
-- Remove all items.
do
values.wipe_out
end
do
items.wipe_out
end
feature -- Report
hash_code: INTEGER
-- Hash code value
do
from
values.start
Result := values.item.hash_code
until
values.off
loop
Result:= ((Result \\ 8388593) |<< 8) + values.item.hash_code
values.forth
end
Result := Result \\ values.count
end
hash_code: INTEGER
-- Hash code value
local
l_started: BOOLEAN
do
across
items as ic
loop
if l_started then
Result := ((Result \\ 8388593) |<< 8) + ic.item.hash_code
else
Result := ic.item.hash_code
l_started := True
end
end
Result := Result \\ items.count
end
feature -- Conversion
array_representation: ARRAYED_LIST [JSON_VALUE]
-- Representation as a sequences of values
-- be careful, modifying the return object may have impact on the original JSON_ARRAY object
do
Result := values
end
array_representation: ARRAYED_LIST [JSON_VALUE]
-- Representation as a sequences of values.
-- be careful, modifying the return object may have impact on the original JSON_ARRAY object.
do
Result := items
end
feature -- Status report
debug_output: STRING
-- String that should be displayed in debugger to represent `Current'.
do
Result := count.out + " item(s)"
end
debug_output: STRING
-- String that should be displayed in debugger to represent `Current'.
do
Result := count.out + " item(s)"
end
feature {NONE} -- Implementation
values: ARRAYED_LIST [JSON_VALUE]
-- Value container
items: ARRAYED_LIST [JSON_VALUE]
-- Value container
invariant
value_not_void: values /= Void
items_not_void: items /= Void
note
copyright: "2010-2014, Javier Velilla and others https://github.com/eiffelhub/json."
license: "https://github.com/eiffelhub/json/blob/master/License.txt"
end

View File

@@ -1,61 +1,87 @@
note
description: "JSON Truth values"
author: "Javier Velilla"
date: "2008/08/24"
revision: "Revision 0.1"
description: "JSON Boolean values"
author: "$Author$"
date: "$Date$"
revision: "$Revision$"
class
JSON_BOOLEAN
JSON_BOOLEAN
inherit
JSON_VALUE
JSON_VALUE
create
make_boolean
make,
make_true, make_false,
make_boolean
feature {NONE} -- Initialization
make_boolean (an_item: BOOLEAN)
--Initialize.
do
item := an_item
end
make (a_value: BOOLEAN)
-- Initialize Current JSON boolean with `a_boolean'.
do
item := a_value
end
make_true
-- Initialize Current JSON boolean with True.
do
make (True)
end
make_false
-- Initialize Current JSON boolean with False.
do
make (False)
end
make_boolean (a_item: BOOLEAN)
-- Initialize.
obsolete
"Use `make' Sept/2014"
do
make (a_item)
end
feature -- Access
item: BOOLEAN
-- Content
item: BOOLEAN
-- Content
hash_code: INTEGER
-- Hash code value
do
Result := item.hash_code
end
hash_code: INTEGER
-- Hash code value
do
Result := item.hash_code
end
representation: STRING
do
if item then
Result := "true"
else
Result := "false"
end
end
representation: STRING
do
if item then
Result := "true"
else
Result := "false"
end
end
feature -- Visitor pattern
accept (a_visitor: JSON_VISITOR)
-- Accept `a_visitor'.
-- (Call `visit_json_boolean' procedure on `a_visitor'.)
do
a_visitor.visit_json_boolean (Current)
end
accept (a_visitor: JSON_VISITOR)
-- Accept `a_visitor'.
-- (Call `visit_json_boolean' procedure on `a_visitor'.)
do
a_visitor.visit_json_boolean (Current)
end
feature -- Status report
debug_output: STRING
-- String that should be displayed in debugger to represent `Current'.
do
Result := item.out
end
debug_output: STRING
-- String that should be displayed in debugger to represent `Current'.
do
Result := item.out
end
note
copyright: "2010-2014, Javier Velilla and others https://github.com/eiffelhub/json."
license: "https://github.com/eiffelhub/json/blob/master/License.txt"
end

View File

@@ -1,47 +1,51 @@
note
description: "JSON Null Values"
author: "Javier Velilla"
date: "2008/08/24"
revision: "Revision 0.1"
description: "JSON Null Values"
author: "Javier Velilla"
date: "2008/08/24"
revision: "Revision 0.1"
class
JSON_NULL
JSON_NULL
inherit
JSON_VALUE
JSON_VALUE
feature --Access
hash_code: INTEGER
-- Hash code value
do
Result := null_value.hash_code
end
hash_code: INTEGER
-- Hash code value
do
Result := null_value.hash_code
end
representation: STRING
do
Result := "null"
end
representation: STRING
do
Result := "null"
end
feature -- Visitor pattern
accept (a_visitor: JSON_VISITOR)
-- Accept `a_visitor'.
-- (Call `visit_element_a' procedure on `a_visitor'.)
do
a_visitor.visit_json_null (Current)
end
accept (a_visitor: JSON_VISITOR)
-- Accept `a_visitor'.
-- (Call `visit_element_a' procedure on `a_visitor'.)
do
a_visitor.visit_json_null (Current)
end
feature -- Status report
debug_output: STRING
-- String that should be displayed in debugger to represent `Current'.
do
Result := null_value
end
debug_output: STRING
-- String that should be displayed in debugger to represent `Current'.
do
Result := null_value
end
feature {NONE}-- Implementation
feature {NONE} -- Implementation
null_value: STRING = "null"
null_value: STRING = "null"
note
copyright: "2010-2014, Javier Velilla and others https://github.com/eiffelhub/json."
license: "https://github.com/eiffelhub/json/blob/master/License.txt"
end

View File

@@ -1,99 +1,149 @@
note
description: "JSON Numbers, octal and hexadecimal formats are not used."
author: "Javier Velilla"
date: "2008/08/24"
revision: "Revision 0.1"
license:"MIT (see http://www.opensource.org/licenses/mit-license.php)"
description: "JSON Numbers, octal and hexadecimal formats are not used."
author: "$Author$"
date: "$Date$"
revision: "$Revision$"
license: "MIT (see http://www.opensource.org/licenses/mit-license.php)"
class
JSON_NUMBER
JSON_NUMBER
inherit
JSON_VALUE
redefine
is_equal
end
JSON_VALUE
redefine
is_equal
end
create
make_integer,
make_natural,
make_real
make_integer, make_natural, make_real
feature {NONE} -- initialization
make_integer (an_argument: INTEGER_64)
-- Initialize an instance of JSON_NUMBER from the integer value of `an_argument'.
do
item := an_argument.out
numeric_type := INTEGER_TYPE
end
make_integer (an_argument: INTEGER_64)
-- Initialize an instance of JSON_NUMBER from the integer value of `an_argument'.
do
item := an_argument.out
numeric_type := integer_type
end
make_natural (an_argument: NATURAL_64)
-- Initialize an instance of JSON_NUMBER from the unsigned integer value of `an_argument'.
do
item := an_argument.out
numeric_type := NATURAL_TYPE
end
make_natural (an_argument: NATURAL_64)
-- Initialize an instance of JSON_NUMBER from the unsigned integer value of `an_argument'.
do
item := an_argument.out
numeric_type := natural_type
end
make_real (an_argument: DOUBLE)
-- Initialize an instance of JSON_NUMBER from the floating point value of `an_argument'.
do
item := an_argument.out
numeric_type := DOUBLE_TYPE
end
make_real (an_argument: REAL_64)
-- Initialize an instance of JSON_NUMBER from the floating point value of `an_argument'.
do
item := an_argument.out
numeric_type := double_type
end
feature -- Access
item: STRING
-- Content
item: STRING
-- Content
hash_code: INTEGER
--Hash code value
do
Result := item.hash_code
end
numeric_type: INTEGER
-- Type of number (integer, natural or real).
representation: STRING
do
Result := item
end
feature -- Visitor pattern
hash_code: INTEGER
--Hash code value
do
Result := item.hash_code
end
accept (a_visitor: JSON_VISITOR)
-- Accept `a_visitor'.
-- (Call `visit_json_number' procedure on `a_visitor'.)
do
a_visitor.visit_json_number (Current)
end
representation: STRING
do
Result := item
end
feature -- Status
feature -- Conversion
is_equal (other: like Current): BOOLEAN
-- Is `other' attached to an object of the same type
-- as current object and identical to it?
do
Result := item.is_equal (other.item)
end
integer_64_item: INTEGER_64
-- Associated integer value.
require
is_integer: is_integer
do
Result := item.to_integer_64
end
natural_64_item: NATURAL_64
-- Associated natural value.
require
is_natural: is_natural
do
Result := item.to_natural_64
end
double_item, real_64_item: REAL_64
-- Associated real value.
require
is_real: is_real
do
Result := item.to_real_64
end
feature -- Status report
debug_output: STRING
-- String that should be displayed in debugger to represent `Current'.
do
Result := item
end
is_integer: BOOLEAN
-- Is Current an integer number?
do
Result := numeric_type = integer_type
end
is_natural: BOOLEAN
-- Is Current a natural number?
do
Result := numeric_type = natural_type
end
is_double, is_real: BOOLEAN
-- Is Current a real number?
do
Result := numeric_type = real_type
end
feature -- Visitor pattern
accept (a_visitor: JSON_VISITOR)
-- Accept `a_visitor'.
-- (Call `visit_json_number' procedure on `a_visitor'.)
do
a_visitor.visit_json_number (Current)
end
feature -- Status
is_equal (other: like Current): BOOLEAN
-- Is `other' attached to an object of the same type
-- as current object and identical to it?
do
Result := item.is_equal (other.item)
end
feature -- Status report
debug_output: STRING
-- String that should be displayed in debugger to represent `Current'.
do
Result := item
end
feature -- Implementation
INTEGER_TYPE: INTEGER = 1
DOUBLE_TYPE: INTEGER = 2
NATURAL_TYPE: INTEGER = 3
integer_type: INTEGER = 1
numeric_type: INTEGER
double_type, real_type: INTEGER = 2
natural_type: INTEGER = 3
invariant
item_not_void: item /= Void
item_not_void: item /= Void
note
copyright: "2010-2014, Javier Velilla and others https://github.com/eiffelhub/json."
license: "https://github.com/eiffelhub/json/blob/master/License.txt"
end

View File

@@ -1,250 +1,261 @@
note
description: "[
An JSON_OBJECT represent an object in JSON.
An object is an unordered set of name/value pairs
Examples:
object
{}
{"key": "value"}
]"
author: "Javier Velilla"
date: "2008/08/24"
revision: "Revision 0.1"
license:"MIT (see http://www.opensource.org/licenses/mit-license.php)"
description: "[
An JSON_OBJECT represent an object in JSON.
An object is an unordered set of name/value pairs
Examples:
object
{}
{"key": value}
{"key": "value"}
]"
author: "$Author$"
date: "$Date$"
revision: "$Revision$"
license: "MIT (see http://www.opensource.org/licenses/mit-license.php)"
class
JSON_OBJECT
JSON_OBJECT
inherit
JSON_VALUE
TABLE_ITERABLE [JSON_VALUE, JSON_STRING]
JSON_VALUE
DEBUG_OUTPUT
TABLE_ITERABLE [JSON_VALUE, JSON_STRING]
DEBUG_OUTPUT
create
make
make_empty, make_with_capacity, make
feature {NONE} -- Initialization
make
-- Initialize
do
create object.make (10)
end
make_with_capacity (nb: INTEGER)
-- Initialize with a capacity of `nb' items.
do
create items.make (nb)
end
make_empty
-- Initialize as empty object.
do
make_with_capacity (0)
end
make
-- Initialize with default capacity.
do
make_with_capacity (3)
end
feature -- Change Element
put (value: detachable JSON_VALUE; key: JSON_STRING)
-- Assuming there is no item of key `key',
-- insert `value' with `key'.
require
key_not_present: not has_key (key)
local
l_value: like value
do
l_value := value
if l_value = Void then
create {JSON_NULL} l_value
end
object.extend (l_value, key)
end
put_string (value: READABLE_STRING_GENERAL; key: JSON_STRING)
-- Assuming there is no item of key `key',
-- insert `value' with `key'.
require
key_not_present: not has_key (key)
local
l_value: JSON_STRING
do
create l_value.make_json_from_string_32 (value.as_string_32)
put (l_value, key)
end
put_integer (value: INTEGER_64; key: JSON_STRING)
-- Assuming there is no item of key `key',
-- insert `value' with `key'.
require
key_not_present: not has_key (key)
local
l_value: JSON_NUMBER
do
create l_value.make_integer (value)
put (l_value, key)
end
put_natural (value: NATURAL_64; key: JSON_STRING)
-- Assuming there is no item of key `key',
-- insert `value' with `key'.
require
key_not_present: not has_key (key)
local
l_value: JSON_NUMBER
do
create l_value.make_natural (value)
put (l_value, key)
end
put_real (value: DOUBLE; key: JSON_STRING)
-- Assuming there is no item of key `key',
-- insert `value' with `key'.
require
key_not_present: not has_key (key)
local
l_value: JSON_NUMBER
do
create l_value.make_real (value)
put (l_value, key)
end
put_boolean (value: BOOLEAN; key: JSON_STRING)
-- Assuming there is no item of key `key',
-- insert `value' with `key'.
require
key_not_present: not has_key (key)
local
l_value: JSON_BOOLEAN
do
create l_value.make_boolean (value)
put (l_value, key)
end
replace (value: detachable JSON_VALUE; key: JSON_STRING)
-- Assuming there is no item of key `key',
-- insert `value' with `key'.
local
l_value: like value
do
l_value := value
if l_value = Void then
create {JSON_NULL} l_value
end
object.force (l_value, key)
end
replace_with_string (value: READABLE_STRING_GENERAL; key: JSON_STRING)
-- Assuming there is no item of key `key',
-- insert `value' with `key'.
local
l_value: JSON_STRING
do
create l_value.make_json_from_string_32 (value.as_string_32)
replace (l_value, key)
end
replace_with_integer (value: INTEGER_64; key: JSON_STRING)
-- Assuming there is no item of key `key',
-- insert `value' with `key'.
local
l_value: JSON_NUMBER
do
create l_value.make_integer (value)
replace (l_value, key)
end
replace_with_with_natural (value: NATURAL_64; key: JSON_STRING)
-- Assuming there is no item of key `key',
-- insert `value' with `key'.
local
l_value: JSON_NUMBER
do
create l_value.make_natural (value)
replace (l_value, key)
end
replace_with_real (value: DOUBLE; key: JSON_STRING)
-- Assuming there is no item of key `key',
-- insert `value' with `key'.
local
l_value: JSON_NUMBER
do
create l_value.make_real (value)
replace (l_value, key)
end
replace_with_boolean (value: BOOLEAN; key: JSON_STRING)
-- Assuming there is no item of key `key',
-- insert `value' with `key'.
local
l_value: JSON_BOOLEAN
do
create l_value.make_boolean (value)
replace (l_value, key)
end
remove (key: JSON_STRING)
-- Remove item indexed by `key' if any.
put (a_value: detachable JSON_VALUE; a_key: JSON_STRING)
-- Assuming there is no item of key `a_key',
-- insert `a_value' with `a_key'.
require
a_key_not_present: not has_key (a_key)
do
object.remove (key)
if a_value = Void then
items.extend (create {JSON_NULL}, a_key)
else
items.extend (a_value, a_key)
end
end
put_string (a_value: READABLE_STRING_GENERAL; a_key: JSON_STRING)
-- Assuming there is no item of key `a_key',
-- insert `a_value' with `a_key'.
require
key_not_present: not has_key (a_key)
local
l_value: JSON_STRING
do
if attached {READABLE_STRING_8} a_value as s then
create l_value.make_from_string (s)
else
create l_value.make_from_string_32 (a_value.as_string_32)
end
put (l_value, a_key)
end
put_integer (a_value: INTEGER_64; a_key: JSON_STRING)
-- Assuming there is no item of key `a_key',
-- insert `a_value' with `a_key'.
require
key_not_present: not has_key (a_key)
local
l_value: JSON_NUMBER
do
create l_value.make_integer (a_value)
put (l_value, a_key)
end
put_natural (a_value: NATURAL_64; a_key: JSON_STRING)
-- Assuming there is no item of key `a_key',
-- insert `a_value' with `a_key'.
require
key_not_present: not has_key (a_key)
local
l_value: JSON_NUMBER
do
create l_value.make_natural (a_value)
put (l_value, a_key)
end
put_real (a_value: DOUBLE; a_key: JSON_STRING)
-- Assuming there is no item of key `a_key',
-- insert `a_value' with `a_key'.
require
key_not_present: not has_key (a_key)
local
l_value: JSON_NUMBER
do
create l_value.make_real (a_value)
put (l_value, a_key)
end
put_boolean (a_value: BOOLEAN; a_key: JSON_STRING)
-- Assuming there is no item of key `a_key',
-- insert `a_value' with `a_key'.
require
key_not_present: not has_key (a_key)
local
l_value: JSON_BOOLEAN
do
create l_value.make (a_value)
put (l_value, a_key)
end
replace (a_value: detachable JSON_VALUE; a_key: JSON_STRING)
-- Assuming there is no item of key `a_key',
-- insert `a_value' with `a_key'.
do
if a_value = Void then
items.force (create {JSON_NULL}, a_key)
else
items.force (a_value, a_key)
end
end
replace_with_string (a_value: READABLE_STRING_GENERAL; a_key: JSON_STRING)
-- Assuming there is no item of key `a_key',
-- insert `a_value' with `a_key'.
local
l_value: JSON_STRING
do
if attached {READABLE_STRING_8} a_value as s then
create l_value.make_from_string (s)
else
create l_value.make_from_string_32 (a_value.as_string_32)
end
replace (l_value, a_key)
end
replace_with_integer (a_value: INTEGER_64; a_key: JSON_STRING)
-- Assuming there is no item of key `a_key',
-- insert `a_value' with `a_key'.
local
l_value: JSON_NUMBER
do
create l_value.make_integer (a_value)
replace (l_value, a_key)
end
replace_with_with_natural (a_value: NATURAL_64; a_key: JSON_STRING)
-- Assuming there is no item of key `a_key',
-- insert `a_value' with `a_key'.
local
l_value: JSON_NUMBER
do
create l_value.make_natural (a_value)
replace (l_value, a_key)
end
replace_with_real (a_value: DOUBLE; a_key: JSON_STRING)
-- Assuming there is no item of key `a_key',
-- insert `a_value' with `a_key'.
local
l_value: JSON_NUMBER
do
create l_value.make_real (a_value)
replace (l_value, a_key)
end
replace_with_boolean (a_value: BOOLEAN; a_key: JSON_STRING)
-- Assuming there is no item of key `a_key',
-- insert `a_value' with `a_key'.
local
l_value: JSON_BOOLEAN
do
create l_value.make (a_value)
replace (l_value, a_key)
end
remove (a_key: JSON_STRING)
-- Remove item indexed by `a_key' if any.
do
items.remove (a_key)
end
wipe_out
-- Reset all items to default values; reset status.
-- Reset all items to default values; reset status.
do
object.wipe_out
items.wipe_out
end
feature -- Status report
has_key (a_key: JSON_STRING): BOOLEAN
-- has the JSON_OBJECT contains a specific key `a_key'.
do
Result := items.has (a_key)
end
has_item (a_value: JSON_VALUE): BOOLEAN
-- has the JSON_OBJECT contain a specfic item `a_value'
do
Result := items.has_item (a_value)
end
feature -- Access
has_key (key: JSON_STRING): BOOLEAN
-- has the JSON_OBJECT contains a specific key 'key'.
do
Result := object.has (key)
end
item (a_key: JSON_STRING): detachable JSON_VALUE
-- the json_value associated with a key `a_key'.
do
Result := items.item (a_key)
end
has_item (value: JSON_VALUE): BOOLEAN
-- has the JSON_OBJECT contain a specfic item 'value'
do
Result := object.has_item (value)
end
current_keys: ARRAY [JSON_STRING]
-- Array containing actually used keys.
do
Result := items.current_keys
end
item (key: JSON_STRING): detachable JSON_VALUE
-- the json_value associated with a key.
do
Result := object.item (key)
end
current_keys: ARRAY [JSON_STRING]
-- array containing actually used keys
do
Result := object.current_keys
end
representation: STRING
local
t: HASH_TABLE [JSON_VALUE, JSON_STRING]
do
create Result.make (2)
Result.append_character ('{')
from
t := map_representation
t.start
until
t.after
loop
Result.append (t.key_for_iteration.representation)
Result.append_character (':')
Result.append (t.item_for_iteration.representation)
t.forth
if not t.after then
Result.append_character (',')
end
end
Result.append_character ('}')
end
representation: STRING
-- <Precursor>
do
create Result.make (2)
Result.append_character ('{')
across
items as ic
loop
if Result.count > 1 then
Result.append_character (',')
end
Result.append (ic.key.representation)
Result.append_character (':')
Result.append (ic.item.representation)
end
Result.append_character ('}')
end
feature -- Mesurement
count: INTEGER
-- Number of field
-- Number of field.
do
Result := object.count
Result := items.count
end
feature -- Access
@@ -252,7 +263,7 @@ feature -- Access
new_cursor: TABLE_ITERATION_CURSOR [JSON_VALUE, JSON_STRING]
-- Fresh cursor associated with current structure
do
Result := object.new_cursor
Result := items.new_cursor
end
feature -- Status report
@@ -260,58 +271,61 @@ feature -- Status report
is_empty: BOOLEAN
-- Is empty object?
do
Result := object.is_empty
Result := items.is_empty
end
feature -- Visitor pattern
accept (a_visitor: JSON_VISITOR)
-- Accept `a_visitor'.
-- (Call `visit_json_object' procedure on `a_visitor'.)
do
a_visitor.visit_json_object (Current)
end
accept (a_visitor: JSON_VISITOR)
-- Accept `a_visitor'.
-- (Call `visit_json_object' procedure on `a_visitor'.)
do
a_visitor.visit_json_object (Current)
end
feature -- Conversion
map_representation: HASH_TABLE [JSON_VALUE, JSON_STRING]
--A representation that maps keys to values
do
Result := object
end
map_representation: HASH_TABLE [JSON_VALUE, JSON_STRING]
-- A representation that maps keys to values
do
Result := items
end
feature -- Report
hash_code: INTEGER
-- Hash code value
do
from
object.start
Result := object.out.hash_code
until
object.off
loop
Result := ((Result \\ 8388593) |<< 8) + object.item_for_iteration.hash_code
object.forth
end
-- Ensure it is a positive value.
Result := Result.hash_code
end
hash_code: INTEGER
-- Hash code value
do
from
items.start
Result := items.out.hash_code
until
items.off
loop
Result := ((Result \\ 8388593) |<< 8) + items.item_for_iteration.hash_code
items.forth
end
-- Ensure it is a positive value.
Result := Result.hash_code
end
feature -- Status report
debug_output: STRING
-- String that should be displayed in debugger to represent `Current'.
do
Result := count.out + " item(s)"
end
debug_output: STRING
-- String that should be displayed in debugger to represent `Current'.
do
Result := count.out + "item(s)"
end
feature {NONE} -- Implementation
object: HASH_TABLE [JSON_VALUE, JSON_STRING]
-- Value container
items: HASH_TABLE [JSON_VALUE, JSON_STRING]
-- Value container
invariant
object_not_void: object /= Void
items_not_void: items /= Void
note
copyright: "2010-2014, Javier Velilla and others https://github.com/eiffelhub/json."
license: "https://github.com/eiffelhub/json/blob/master/License.txt"
end

View File

@@ -1,70 +1,117 @@
note
description: "[
A JSON_STRING represent a string in JSON.
A string is a collection of zero or more Unicodes characters, wrapped in double
quotes, using blackslash espaces.
]"
author: "Javier Velilla"
date: "2008/08/24"
revision: "Revision 0.1"
license:"MIT (see http://www.opensource.org/licenses/mit-license.php)"
description: "[
A JSON_STRING represent a string in JSON.
A string is a collection of zero or more Unicodes characters, wrapped in double
quotes, using blackslash espaces.
]"
author: "$Author$"
date: "$Date$"
revision: "$Revision$"
license: "MIT (see http://www.opensource.org/licenses/mit-license.php)"
class
JSON_STRING
JSON_STRING
inherit
JSON_VALUE
redefine
is_equal
end
JSON_VALUE
redefine
is_equal
end
create
make_json,
make_json_from_string_32,
make_with_escaped_json
make_from_string, make_from_string_32, make_from_string_general,
make_from_escaped_json_string,
make_with_escaped_json, make_json, make_json_from_string_32
convert
make_json ({READABLE_STRING_8, STRING_8, IMMUTABLE_STRING_8}),
make_json_from_string_32 ({READABLE_STRING_32, STRING_32, IMMUTABLE_STRING_32})
make_from_string ({READABLE_STRING_8, STRING_8, IMMUTABLE_STRING_8}),
make_from_string_32 ({READABLE_STRING_32, STRING_32, IMMUTABLE_STRING_32}),
make_from_string_general ({READABLE_STRING_GENERAL, STRING_GENERAL, IMMUTABLE_STRING_GENERAL})
feature {NONE} -- Initialization
make_json (s: READABLE_STRING_8)
-- Initialize.
require
item_not_void: s /= Void
do
make_with_escaped_json (escaped_json_string (s))
end
make_from_string (s: READABLE_STRING_8)
-- Initialize from ascii string `s'.
require
s_not_void: s /= Void
do
make_from_escaped_json_string (escaped_json_string (s))
end
make_json_from_string_32 (s: READABLE_STRING_32)
-- Initialize from STRING_32 `s'.
require
item_not_void: s /= Void
do
make_with_escaped_json (escaped_json_string_32 (s))
end
make_from_string_32 (s: READABLE_STRING_32)
-- Initialize from unicode string `s'.
require
s_not_void: s /= Void
do
make_from_escaped_json_string (escaped_json_string (s))
end
make_with_escaped_json (s: READABLE_STRING_8)
-- Initialize with an_item already escaped
require
item_not_void: s /= Void
do
item := s
end
make_from_string_general (s: READABLE_STRING_GENERAL)
-- Initialize from string `s'.
require
s_not_void: s /= Void
do
if attached {READABLE_STRING_8} s as s8 then
make_from_string (s8)
else
make_from_string_32 (s.as_string_32)
end
end
make_from_escaped_json_string (a_escaped_string: READABLE_STRING_8)
-- Initialize with `a_escaped_string' already JSON escaped.
require
a_escaped_string_not_void: a_escaped_string /= Void
do
item := a_escaped_string
end
make_with_escaped_json (a_escaped_string: READABLE_STRING_8)
-- Initialize with `a_escaped_string' already JSON escaped.
obsolete
"Use `make_from_escaped_json_string' Sept/2014"
require
a_escaped_string_not_void: a_escaped_string /= Void
do
make_from_escaped_json_string (a_escaped_string)
end
make_from_json_string (a_json: JSON_STRING)
-- Initialize with `a_json' string value.
do
make_from_escaped_json_string (a_json.item)
end
make_json (s: READABLE_STRING_8)
-- Initialize.
obsolete
"Use `make_from_string' Sept/2014"
require
item_not_void: s /= Void
do
make_with_escaped_json (escaped_json_string (s))
end
make_json_from_string_32 (s: READABLE_STRING_32)
-- Initialize from STRING_32 `s'.
obsolete
"Use `make_from_string_32' Sept/2014"
require
item_not_void: s /= Void
do
make_with_escaped_json (escaped_json_string (s))
end
feature -- Access
item: STRING
-- Contents with escaped entities if any
item: STRING
-- Contents with escaped entities if any
feature -- Conversion
unescaped_string_8: STRING_8
-- Unescaped string from `item'.
-- Unescaped ascii string from `item'.
--| note: valid only if `item' does not encode any unicode character.
local
s: like item
@@ -75,7 +122,7 @@ feature -- Conversion
end
unescaped_string_32: STRING_32
-- Unescaped string 32 from `item'
-- Unescaped uncode string from `item'
--| some encoders uses UTF-8 , and not the recommended pure json encoding
--| thus, let's support the UTF-8 encoding during decoding.
local
@@ -86,14 +133,14 @@ feature -- Conversion
unescape_to_string_32 (Result)
end
representation: STRING
-- String representation of `item' with escaped entities if any
do
create Result.make (item.count + 2)
Result.append_character ('%"')
Result.append (item)
Result.append_character ('%"')
end
representation: STRING
-- String representation of `item' with escaped entities if any.
do
create Result.make (item.count + 2)
Result.append_character ('%"')
Result.append (item)
Result.append_character ('%"')
end
unescape_to_string_8 (a_output: STRING_8)
-- Unescape string `item' into `a_output'.
@@ -105,16 +152,23 @@ feature -- Conversion
do
s := item
n := s.count
from i := 1 until i > n loop
c := s[i]
from
i := 1
until
i > n
loop
c := s [i]
if c = '\' then
if i < n then
inspect s[i+1]
inspect s [i + 1]
when '%"' then
a_output.append_character ('%"')
i := i + 2
when '\' then
a_output.append_character ('\')
i := i + 2
when '%"' then
a_output.append_character ('%"')
when '/' then
a_output.append_character ('/')
i := i + 2
when 'b' then
a_output.append_character ('%B')
@@ -132,15 +186,15 @@ feature -- Conversion
a_output.append_character ('%T')
i := i + 2
when 'u' then
--| Leave Unicode \uXXXX unescaped
a_output.append_character ('\')
--| Leave unicode \uXXXX unescaped
a_output.append_character (c) -- '\'
i := i + 1
else
a_output.append_character ('\')
a_output.append_character (c) -- '\'
i := i + 1
end
else
a_output.append_character ('\')
a_output.append_character (c) -- '\'
i := i + 1
end
else
@@ -163,16 +217,23 @@ feature -- Conversion
do
s := item
n := s.count
from i := 1 until i > n loop
from
i := 1
until
i > n
loop
ch := s.item (i)
if ch = '\' then
if i < n then
inspect s[i+1]
inspect s [i + 1]
when '%"' then
a_output.append_character ('%"')
i := i + 2
when '\' then
a_output.append_character ('\')
i := i + 2
when '%"' then
a_output.append_character ('%"')
when '/' then
a_output.append_character ('/')
i := i + 2
when 'b' then
a_output.append_character ('%B')
@@ -194,50 +255,40 @@ feature -- Conversion
if hex.count = 4 then
a_output.append_code (hexadecimal_to_natural_32 (hex))
end
i := i + 6 -- i +2 +4
i := i + 6 -- i+2+4
else
a_output.append_character ('\')
a_output.append_character (ch) -- '\'
i := i + 1
end
else
a_output.append_character ('\')
a_output.append_character (ch) -- '\'
i := i + 1
end
else
c := ch.natural_32_code
if c <= 0x7F then
-- 0xxxxxxx
check ch = c.to_character_32 end
check
ch = c.to_character_32
end
a_output.append_character (ch)
elseif c <= 0xDF then
-- 110xxxxx 10xxxxxx
i := i + 1
if i <= n then
a_output.append_code (
((c & 0x1F) |<< 6) |
(s.code (i) & 0x3F)
)
a_output.append_code (((c & 0x1F) |<< 6) | (s.code (i) & 0x3F))
end
elseif c <= 0xEF then
-- 1110xxxx 10xxxxxx 10xxxxxx
i := i + 2
if i <= n then
a_output.append_code (
((c & 0xF) |<< 12) |
((s.code (i - 1) & 0x3F) |<< 6) |
(s.code (i) & 0x3F)
)
a_output.append_code (((c & 0xF) |<< 12) | ((s.code (i - 1) & 0x3F) |<< 6) | (s.code (i) & 0x3F))
end
elseif c <= 0xF7 then
-- 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
i := i + 3
if i <= n then
a_output.append_code (
((c & 0x7) |<< 18) |
((s.code (i - 2) & 0x3F) |<< 12) |
((s.code (i - 1) & 0x3F) |<< 6) |
(s.code (i) & 0x3F)
)
a_output.append_code (((c & 0x7) |<< 18) | ((s.code (i - 2) & 0x3F) |<< 12) | ((s.code (i - 1) & 0x3F) |<< 6) | (s.code (i) & 0x3F))
end
end
i := i + 1
@@ -247,65 +298,101 @@ feature -- Conversion
feature -- Visitor pattern
accept (a_visitor: JSON_VISITOR)
-- Accept `a_visitor'.
-- (Call `visit_json_string' procedure on `a_visitor'.)
do
a_visitor.visit_json_string (Current)
end
accept (a_visitor: JSON_VISITOR)
-- Accept `a_visitor'.
-- (Call `visit_json_string' procedure on `a_visitor'.)
do
a_visitor.visit_json_string (Current)
end
feature -- Comparison
is_equal (other: like Current): BOOLEAN
-- Is JSON_STRING made of same character sequence as `other'
-- (possibly with a different capacity)?
do
Result := item.same_string (other.item)
end
is_equal (other: like Current): BOOLEAN
-- Is JSON_STRING made of same character sequence as `other'
-- (possibly with a different capacity)?
do
Result := item.same_string (other.item)
end
feature -- Change Element
append (a_string: STRING)
-- Add a_string
require
a_string_not_void: a_string /= Void
do
item.append_string (a_string)
end
append (a_escaped_string: READABLE_STRING_8)
-- Add JSON escaped string `a_escaped_string'
require
a_escaped_string_not_void: a_escaped_string /= Void
do
item.append_string (a_escaped_string)
end
append_json_string (a_json_string: JSON_STRING)
-- Add JSON string `a_json_string'
require
a_json_string_not_void: a_json_string /= Void
do
append (a_json_string.item)
end
append_string (s: READABLE_STRING_8)
-- Add ascii string `s'
require
s_not_void: s /= Void
do
append (escaped_json_string (s))
end
append_string_32 (s: READABLE_STRING_32)
-- Add unicode string `s'
require
s_not_void: s /= Void
do
append (escaped_json_string (s))
end
append_string_general (s: READABLE_STRING_GENERAL)
-- Add unicode string `s'
require
s_not_void: s /= Void
do
if attached {READABLE_STRING_8} s as s8 then
append_string (s.as_string_8)
else
append_string_32 (s.as_string_32)
end
end
feature -- Status report
hash_code: INTEGER
-- Hash code value
do
Result := item.hash_code
end
hash_code: INTEGER
-- Hash code value
do
Result := item.hash_code
end
feature -- Status report
debug_output: STRING
-- String that should be displayed in debugger to represent `Current'.
do
Result := item
end
debug_output: STRING
-- String that should be displayed in debugger to represent `Current'.
do
Result := item
end
feature {NONE} -- Implementation
is_hexadecimal (s: READABLE_STRING_8): BOOLEAN
-- Is `s' an hexadecimal value?
is_hexadecimal (s: READABLE_STRING_8): BOOLEAN
-- Is `s' an hexadecimal value?
local
i: INTEGER
do
do
from
Result := True
i := 1
until
i > s.count or not Result
loop
Result := s[i].is_hexa_digit
Result := s [i].is_hexa_digit
i := i + 1
end
end
end
hexadecimal_to_natural_32 (s: READABLE_STRING_8): NATURAL_32
-- Hexadecimal string `s' converted to NATURAL_32 value
@@ -317,13 +404,11 @@ feature {NONE} -- Implementation
char: CHARACTER
do
nb := s.count
if nb >= 2 and then s.item (2) = 'x' then
i := 3
else
i := 1
end
from
until
i > nb
@@ -339,37 +424,10 @@ feature {NONE} -- Implementation
end
end
escaped_json_string (s: READABLE_STRING_8): STRING_8
-- JSON string with '"' and '\' characters escaped
require
s_not_void: s /= Void
local
i, n: INTEGER
c: CHARACTER_8
do
n := s.count
create Result.make (n + n // 10)
from i := 1 until i > n loop
c := s.item (i)
inspect c
when '%"' then Result.append_string ("\%"")
when '\' then Result.append_string ("\\")
when '%B' then Result.append_string ("\b")
when '%F' then Result.append_string ("\f")
when '%N' then Result.append_string ("\n")
when '%R' then Result.append_string ("\r")
when '%T' then Result.append_string ("\t")
else
Result.extend (c)
end
i := i + 1
end
end
escaped_json_string_32 (s: READABLE_STRING_32): STRING_8
-- JSON string with '"' and '\' characters and Unicode escaped
require
s_not_void: s /= Void
escaped_json_string (s: READABLE_STRING_GENERAL): STRING_8
-- JSON string with '"' and '\' characters and unicode escaped
require
s_not_void: s /= Void
local
i, j, n: INTEGER
uc: CHARACTER_32
@@ -378,25 +436,44 @@ feature {NONE} -- Implementation
do
n := s.count
create Result.make (n + n // 10)
from i := 1 until i > n loop
from
i := 1
until
i > n
loop
uc := s.item (i)
if uc.is_character_8 then
c := uc.to_character_8
inspect c
when '%"' then Result.append_string ("\%"")
when '\' then Result.append_string ("\\")
when '%B' then Result.append_string ("\b")
when '%F' then Result.append_string ("\f")
when '%N' then Result.append_string ("\n")
when '%R' then Result.append_string ("\r")
when '%T' then Result.append_string ("\t")
when '%"' then
Result.append_string ("\%"")
when '\' then
Result.append_string ("\\")
when '/' then
-- To avoid issue with Javascript </script> ...
-- escape only </ to <\/
if s.valid_index (i - 1) and then s.item (i - 1) = '<' then
Result.append_string ("\/")
else
Result.append_string ("/")
end
when '%B' then
Result.append_string ("\b")
when '%F' then
Result.append_string ("\f")
when '%N' then
Result.append_string ("\n")
when '%R' then
Result.append_string ("\r")
when '%T' then
Result.append_string ("\t")
else
Result.extend (c)
end
else
Result.append ("\u")
h := uc.code.to_hex_string
-- Remove first 0 and keep 4 hexa digit
-- Remove first 0 and keep 4 hexa digit
from
j := 1
until
@@ -405,14 +482,15 @@ feature {NONE} -- Implementation
j := j + 1
end
h := h.substring (j, h.count)
from
until
h.count >= 4
loop
h.prepend_integer (0)
end
check h.count = 4 end
check
hexastring_has_4_chars: h.count = 4
end
Result.append (h)
end
i := i + 1
@@ -420,6 +498,9 @@ feature {NONE} -- Implementation
end
invariant
item_not_void: item /= Void
item_not_void: item /= Void
note
copyright: "2010-2014, Javier Velilla and others https://github.com/eiffelhub/json."
license: "https://github.com/eiffelhub/json/blob/master/License.txt"
end

View File

@@ -1,43 +1,46 @@
note
description:"[
JSON_VALUE represent a value in JSON.
A value can be
* a string in double quotes
* a number
* boolean value(true, false )
* null
* an object
* an array
]"
author: "Javier Velilla"
date: "2008/05/19"
revision: "Revision 0.1"
license:"MIT (see http://www.opensource.org/licenses/mit-license.php)"
description: "[
JSON_VALUE represent a value in JSON.
A value can be
* a string in double quotes
* a number
* boolean value(true, false )
* null
* an object
* an array
]"
author: "Javier Velilla"
date: "2008/05/19"
revision: "Revision 0.1"
license: "MIT (see http://www.opensource.org/licenses/mit-license.php)"
deferred class
JSON_VALUE
JSON_VALUE
inherit
HASHABLE
DEBUG_OUTPUT
HASHABLE
DEBUG_OUTPUT
feature -- Access
representation: STRING
-- UTF-8 encoded Unicode string representation of Current
deferred
end
representation: STRING
-- UTF-8 encoded Unicode string representation of Current
deferred
end
feature -- Visitor pattern
accept (a_visitor: JSON_VISITOR)
-- Accept `a_visitor'.
-- (Call `visit_*' procedure on `a_visitor'.)
require
a_visitor_not_void: a_visitor /= Void
deferred
end
accept (a_visitor: JSON_VISITOR)
-- Accept `a_visitor'.
-- (Call `visit_*' procedure on `a_visitor'.)
require
a_visitor_not_void: a_visitor /= Void
deferred
end
note
copyright: "2010-2014, Javier Velilla and others https://github.com/eiffelhub/json."
license: "https://github.com/eiffelhub/json/blob/master/License.txt"
end

View File

@@ -1,513 +0,0 @@
note
description: "Parse serialized JSON data"
author: "jvelilla"
date: "2008/08/24"
revision: "Revision 0.1"
class
JSON_PARSER
inherit
JSON_READER
JSON_TOKENS
create
make_parser
feature {NONE} -- Initialize
make_parser (a_json: STRING)
-- Initialize.
require
json_not_empty: a_json /= Void and then not a_json.is_empty
do
make (a_json)
is_parsed := True
create errors.make
end
feature -- Status report
is_parsed: BOOLEAN
-- Is parsed?
errors: LINKED_LIST [STRING]
-- Current errors
current_errors: STRING
-- Current errors as string
do
create Result.make_empty
from
errors.start
until
errors.after
loop
Result.append_string (errors.item + "%N")
errors.forth
end
end
feature -- Element change
report_error (e: STRING)
-- Report error `e'
require
e_not_void: e /= Void
do
errors.force (e)
end
feature -- Commands
parse_json: detachable JSON_VALUE
-- Parse JSON data `representation'
-- start ::= object | array
do
if is_valid_start_symbol then
Result := parse
if extra_elements then
is_parsed := False
end
else
is_parsed := False
report_error ("Syntax error unexpected token, expecting `{' or `['")
end
end
parse: detachable JSON_VALUE
-- Parse JSON data `representation'
local
c: CHARACTER
do
if is_parsed then
skip_white_spaces
c := actual
inspect c
when j_OBJECT_OPEN then
Result := parse_object
when j_STRING then
Result := parse_string
when j_ARRAY_OPEN then
Result := parse_array
else
if c.is_digit or c = j_MINUS then
Result := parse_number
elseif is_null then
Result := create {JSON_NULL}
next
next
next
elseif is_true then
Result := create {JSON_BOOLEAN}.make_boolean (True)
next
next
next
elseif is_false then
Result := create {JSON_BOOLEAN}.make_boolean (False)
next
next
next
next
else
is_parsed := False
report_error ("JSON is not well formed in parse")
Result := Void
end
end
end
ensure
is_parsed_implies_result_not_void: is_parsed implies Result /= Void
end
parse_object: JSON_OBJECT
-- object
-- {}
-- {"key" : "value" [,]}
local
has_more: BOOLEAN
l_json_string: detachable JSON_STRING
l_value: detachable JSON_VALUE
do
create Result.make
-- check if is an empty object {}
next
skip_white_spaces
if actual = j_OBJECT_CLOSE then
--is an empty object
else
-- a complex object {"key" : "value"}
previous
from has_more := True until not has_more loop
next
skip_white_spaces
l_json_string := parse_string
next
skip_white_spaces
if actual = ':' then
next
skip_white_spaces
else
is_parsed := False
report_error ("%N Input string is a not well formed JSON, expected: : found: " + actual.out)
has_more := False
end
l_value := parse
if is_parsed and then (l_value /= Void and l_json_string /= Void) then
Result.put (l_value, l_json_string)
next
skip_white_spaces
if actual = j_OBJECT_CLOSE then
has_more := False
elseif actual /= ',' then
has_more := False
is_parsed := False
report_error ("JSON Object syntactically malformed expected , found: [" + actual.out + "]")
end
else
has_more := False
-- explain the error
end
end
end
end
parse_string: detachable JSON_STRING
-- Parsed string
local
has_more: BOOLEAN
l_json_string: STRING
l_unicode: STRING
c: like actual
do
create l_json_string.make_empty
if actual = j_STRING then
from
has_more := True
until
not has_more
loop
next
c := actual
if c = j_STRING then
has_more := False
elseif c = '%H' then
next
c := actual
if c = 'u' then
create l_unicode.make_from_string ("\u")
l_unicode.append (read_unicode)
c := actual
if is_valid_unicode (l_unicode) then
l_json_string.append (l_unicode)
else
has_more := False
is_parsed := False
report_error ("Input String is not well formed JSON, expected a Unicode value, found [" + c.out + " ]")
end
elseif (not is_special_character (c) and not is_special_control (c)) or c = '%N' then
has_more := False
is_parsed := False
report_error ("Input String is not well formed JSON, found [" + c.out + " ]")
else
l_json_string.append_character ('\')
l_json_string.append_character (c)
end
else
if is_special_character (c) and c /= '/' then
has_more := False
is_parsed := False
report_error ("Input String is not well formed JSON, found [" + c.out + " ]")
else
l_json_string.append_character (c)
end
end
end
create Result.make_with_escaped_json (l_json_string)
else
Result := Void
end
end
parse_array: JSON_ARRAY
-- array
-- []
-- [elements [,]]
local
flag: BOOLEAN
l_value: detachable JSON_VALUE
c: like actual
do
create Result.make_array
--check if is an empty array []
next
skip_white_spaces
if actual = j_array_close then
--is an empty array
else
previous
from
flag := True
until
not flag
loop
next
skip_white_spaces
l_value := parse
if is_parsed and then l_value /= Void then
Result.add (l_value)
next
skip_white_spaces
c := actual
if c = j_ARRAY_CLOSE then
flag := False
elseif c /= ',' then
flag := False
is_parsed := False
report_error ("Array is not well formed JSON, found [" + c.out + " ]")
end
else
flag := False
report_error ("Array is not well formed JSON, found [" + actual.out + " ]")
end
end
end
end
parse_number: detachable JSON_NUMBER
-- Parsed number
local
sb: STRING
flag: BOOLEAN
is_integer: BOOLEAN
c: like actual
do
create sb.make_empty
sb.append_character (actual)
from
flag := True
until
not flag
loop
next
c := actual
if not has_next or is_close_token (c)
or c = ',' or c = '%N' or c = '%R'
then
flag := False
previous
else
sb.append_character (c)
end
end
if is_valid_number (sb) then
if sb.is_integer then
create Result.make_integer (sb.to_integer)
is_integer := True
elseif sb.is_double and not is_integer then
create Result.make_real (sb.to_double)
end
else
is_parsed := False
report_error ("Expected a number, found: [ " + sb + " ]")
end
end
is_null: BOOLEAN
-- Word at index represents null?
local
l_null: STRING
l_string: STRING
do
l_null := null_id
l_string := json_substring (index,index + l_null.count - 1)
if l_string.is_equal (l_null) then
Result := True
end
end
is_false: BOOLEAN
-- Word at index represents false?
local
l_false: STRING
l_string: STRING
do
l_false := false_id
l_string := json_substring (index, index + l_false.count - 1)
if l_string.is_equal (l_false) then
Result := True
end
end
is_true: BOOLEAN
-- Word at index represents true?
local
l_true: STRING
l_string: STRING
do
l_true := true_id
l_string := json_substring (index,index + l_true.count - 1)
if l_string.is_equal (l_true) then
Result := True
end
end
read_unicode: STRING
-- Read Unicode and return value
local
i: INTEGER
do
create Result.make_empty
from
i := 1
until
i > 4 or not has_next
loop
next
Result.append_character (actual)
i := i + 1
end
end
feature {NONE} -- Implementation
is_valid_number (a_number: STRING): BOOLEAN
-- is 'a_number' a valid number based on this regular expression
-- "-?(?: 0|[1-9]\d+)(?: \.\d+)?(?: [eE][+-]?\d+)?\b"?
local
s: detachable STRING
c: CHARACTER
i,n: INTEGER
do
create s.make_empty
n := a_number.count
if n = 0 then
Result := False
else
Result := True
i := 1
--| "-?"
c := a_number[i]
if c = '-' then
s.extend (c); i := i + 1; c := a_number[i]
end
--| "0|[1-9]\d*
if c.is_digit then
if c = '0' then
--| "0"
s.extend (c); i := i + 1; c := a_number[i]
else
--| "[1-9]"
s.extend (c); i := i + 1; c := a_number[i]
--| "\d*"
from until i > n or not c.is_digit loop
s.extend (c); i := i + 1; c := a_number[i]
end
end
end
end
if Result then
--| "(\.\d+)?"
if c = '.' then
--| "\.\d+" = "\.\d\d*"
s.extend (c); i := i + 1; c := a_number[i]
if c.is_digit then
from until i > n or not c.is_digit loop
s.extend (c); i := i + 1; c := a_number[i]
end
else
Result := False --| expecting digit
end
end
end
if Result then --| "(?:[eE][+-]?\d+)?\b"
if c = 'e' or c = 'E' then
--| "[eE][+-]?\d+"
s.extend (c); i := i + 1; c := a_number[i]
if c = '+' or c = '-' then
s.extend (c); i := i + 1; c := a_number[i]
end
if c.is_digit then
from until i > n or not c.is_digit loop
s.extend (c); i := i + 1; c := a_number[i]
end
else
Result := False --| expecting digit
end
end
end
if Result then --| "\b"
from until i > n or not c.is_space loop
s.extend (c); i := i + 1; c := a_number[i]
end
Result := i > n and then s.same_string (a_number)
end
end
is_valid_unicode (a_unicode: STRING): BOOLEAN
-- is 'a_unicode' a valid Unicode based on this regular expression
-- "\\u[0-9a-fA-F]{4}"
local
i: INTEGER
do
if
a_unicode.count = 6 and then
a_unicode[1] = '\' and then
a_unicode[2] = 'u'
then
from
Result := True
i := 3
until
i > 6 or Result = False
loop
inspect a_unicode[i]
when '0'..'9', 'a'..'f', 'A'..'F' then
else
Result := False
end
i := i + 1
end
end
end
extra_elements: BOOLEAN
-- has more elements?
local
c: like actual
do
if has_next then
next
end
from
c := actual
until
c /= ' ' or c /= '%R' or c /= '%U' or c /= '%T' or c /= '%N' or not has_next
loop
next
end
Result := has_next
end
is_valid_start_symbol : BOOLEAN
-- expecting `{' or `[' as start symbol
do
if attached representation as s and then s.count > 0 then
Result := s[1] = '{' or s[1] = '['
end
end
feature {NONE} -- Constants
false_id: STRING = "false"
true_id: STRING = "true"
null_id: STRING = "null"
end

View File

@@ -1,77 +0,0 @@
note
description: ""
author: "jvelilla"
date: "2008/08/24"
revision: "0.1"
class
JSON_TOKENS
feature -- Access
j_OBJECT_OPEN: CHARACTER = '{'
j_ARRAY_OPEN: CHARACTER = '['
j_OBJECT_CLOSE: CHARACTER = '}'
j_ARRAY_CLOSE: CHARACTER = ']'
j_STRING: CHARACTER = '"'
j_PLUS: CHARACTER = '+'
j_MINUS: CHARACTER = '-'
j_DOT: CHARACTER = '.'
feature -- Status report
is_open_token (c: CHARACTER): BOOLEAN
-- Characters which open a type
do
inspect c
when j_OBJECT_OPEN, j_ARRAY_OPEN, j_STRING, j_PLUS, j_MINUS, j_DOT then
Result := True
else
end
end
is_close_token (c: CHARACTER): BOOLEAN
-- Characters which close a type
do
inspect c
when j_OBJECT_CLOSE, j_ARRAY_CLOSE, j_STRING then
Result := True
else
end
end
is_special_character (c: CHARACTER): BOOLEAN
-- Control Characters
-- %F Form feed
-- %H backslasH
-- %N Newline
-- %R carriage Return
-- %T horizontal Tab
-- %B Backspace
-- / Solidus
-- " Quotation
do
inspect c
when '%F', '%H', '%N', '%R', '%T', '%B', '/', '"' then
Result := True
else
end
end
is_special_control (c: CHARACTER): BOOLEAN
--Control Characters
-- \b\f\n\r\t
do
inspect c
when 'b', 'f', 'n', 'r', 't' then
Result := True
else
end
end
end

View File

@@ -1,38 +0,0 @@
note
description: "[
Shared factory class for creating JSON objects. Maps JSON
objects to ELKS HASH_TABLEs and JSON arrays to ELKS
LINKED_LISTs. Use non-conforming inheritance from this
class to ensure that your classes share the same
JSON_FACTORY instance.
]"
author: "Paul Cohen"
date: "$Date$"
revision: "$Revision: 89185 $"
file: "$HeadURL: $"
class SHARED_EJSON
feature
json: EJSON
-- A shared EJSON instance with default converters for
--LINKED_LIST [ANY] and HASH_TABLE [ANY, HASHABLE]
local
jalc: JSON_ARRAYED_LIST_CONVERTER
jllc: JSON_LINKED_LIST_CONVERTER
jhtc: JSON_HASH_TABLE_CONVERTER
once
create Result
create jalc.make
Result.add_converter (jalc)
create jllc.make
Result.add_converter (jllc)
create jhtc.make
Result.add_converter (jhtc)
end
end -- class SHARED_EJSON

View File

@@ -0,0 +1,4 @@
${NOTE_KEYWORD}
copyright: "2010-${YEAR}, Javier Velilla and others https://github.com/eiffelhub/json."
license: "https://github.com/eiffelhub/json/blob/master/License.txt"

View File

@@ -0,0 +1,679 @@
note
description: "Parse serialized JSON data"
author: "$Author$"
date: "$Date$"
revision: "$Revision$"
class
JSON_PARSER
inherit
JSON_READER
rename
make as make_reader,
reset as reset_reader
end
JSON_TOKENS
create
make_with_string,
make_parser
feature {NONE} -- Initialize
make_with_string (a_content: STRING)
-- Initialize parser with JSON content `a_content'.
require
a_content_not_empty: a_content /= Void and then not a_content.is_empty
do
create errors.make
make_reader (a_content)
reset
end
make_parser (a_json: STRING)
-- Initialize.
obsolete
"Use `make_with_string' [sept/2014]."
do
make_with_string (a_json)
end
feature -- Status report
is_parsed: BOOLEAN
-- Is parsed ?
is_valid: BOOLEAN
-- Is valid?
do
Result := not has_error
end
has_error: BOOLEAN
-- Has error?
errors: LINKED_LIST [STRING]
-- Current errors
errors_as_string: STRING
-- String representation of `errors'.
do
create Result.make_empty
across
errors as ic
loop
Result.append_string (ic.item)
Result.append_character ('%N')
end
end
current_errors: STRING
-- Current errors as string
obsolete
"USe errors_as_string [sept/2014]"
do
Result := errors_as_string
end
feature -- Access
parsed_json_value: detachable JSON_VALUE
-- Parsed json value if any.
require
is_parsed: is_parsed
attribute
ensure
attached_result_if_valid: is_valid implies Result /= Void
end
parsed_json_object: detachable JSON_OBJECT
-- parsed json value as a JSON_OBJECT if it is an object.
require
is_parsed: is_parsed
do
if attached {JSON_OBJECT} parsed_json_value as j_object then
Result := j_object
end
end
parsed_json_array: detachable JSON_ARRAY
-- parsed json value as a JSON_OBJECT if it is an array.
require
is_parsed: is_parsed
do
if attached {JSON_ARRAY} parsed_json_value as j_array then
Result := j_array
end
end
feature -- Commands
reset
-- Reset parsing values.
do
parsed_json_value := Void
errors.wipe_out
has_error := False
is_parsed := False
end
parse_content
-- Parse JSON content `representation'.
-- start ::= object | array
do
reset
reset_reader
if is_valid_start_symbol then
parsed_json_value := next_json_value
if extra_elements then
report_error ("Remaining element outside the main json value!")
end
else
report_error ("Syntax error unexpected token, expecting `{' or `['")
end
is_parsed := is_valid
end
feature -- Element change
report_error (e: STRING)
-- Report error `e'
require
e_not_void: e /= Void
do
has_error := True
errors.force (e)
ensure
has_error: has_error
is_not_valid: not is_valid
end
feature -- Obsolete commands
parse_json: detachable JSON_VALUE
-- Parse JSON data `representation'
-- start ::= object | array
obsolete
"Use `parse_content' and `parsed_json_value' [sept/2014]."
do
parse_content
if is_parsed then
Result := parsed_json_value
end
end
parse_object: detachable JSON_OBJECT
-- Parse JSON data `representation'
-- start ::= object | array
obsolete
"Use `parse_content' and `parsed_json_value' [nov/2014]."
do
parse_content
if is_parsed and then attached {JSON_OBJECT} parsed_json_value as jo then
Result := jo
end
end
parse: detachable JSON_VALUE
-- Next JSON value from current position on `representation'.
obsolete
"Use restricted `next_parsed_json_value' [sept/2014]."
do
Result := next_parsed_json_value
is_parsed := is_valid
end
feature {JSON_PARSER_ACCESS} -- Obsolete commands: restricted area
next_parsed_json_value: detachable JSON_VALUE
-- Return next json value from current position.
--| this does not call `reset_reader'.
do
reset
Result := next_json_value
end
feature {NONE} -- Implementation: parsing
next_json_value: detachable JSON_VALUE
-- Next JSON value from current position on `representation'.
local
c: CHARACTER
do
if not has_error then
skip_white_spaces
c := actual
inspect c
when token_object_open then
Result := next_json_object
when token_double_quote then
Result := parse_string
when token_array_open then
Result := parse_array
else
if c.is_digit or c = token_minus then
Result := parse_number
elseif is_null then
Result := create {JSON_NULL}
next
next
next
elseif is_true then
Result := create {JSON_BOOLEAN}.make_true
next
next
next
elseif is_false then
Result := create {JSON_BOOLEAN}.make_false
next
next
next
next
else
report_error ("JSON is not well formed in parse")
Result := Void
end
end
end
ensure
is_parsed_implies_result_not_void: not has_error implies Result /= Void
end
next_json_object: JSON_OBJECT
-- object
-- {}
-- {"key" : "value" [,]}
local
has_more: BOOLEAN
l_json_string: detachable JSON_STRING
l_value: detachable JSON_VALUE
do
create Result.make
--| check if is an empty object {}
next
skip_white_spaces
if actual = token_object_close then
--| is an empty object
else
--| a complex object {"key" : "value"}
previous
from
has_more := True
until
not has_more
loop
next
skip_white_spaces
l_json_string := parse_string
next
skip_white_spaces
if actual = token_colon then --| token_colon = ':'
next
skip_white_spaces
else
report_error ("%N Input string is a not well formed JSON, expected: : found: " + actual.out)
has_more := False
end
l_value := next_json_value
if not has_error and then (l_value /= Void and l_json_string /= Void) then
Result.put (l_value, l_json_string)
next
skip_white_spaces
if actual = token_object_close then
has_more := False
elseif actual /= token_comma then
has_more := False
report_error ("JSON Object syntactically malformed expected , found: [" + actual.out + "]")
end
else
has_more := False
-- explain the error
end
end
end
end
parse_string: detachable JSON_STRING
-- Parsed string
local
has_more: BOOLEAN
l_json_string: STRING
l_unicode: STRING
c: like actual
do
create l_json_string.make_empty
if actual = token_double_quote then
from
has_more := True
until
not has_more
loop
next
c := actual
if c = token_double_quote then
has_more := False
elseif c = '%H' then -- '%H' = '\' = reverse solidus
next
c := actual
if c = 'u' then
create l_unicode.make_from_string ("\u")
l_unicode.append (read_unicode)
c := actual
if is_valid_unicode (l_unicode) then
l_json_string.append (l_unicode)
else
has_more := False
report_error ("Input String is not well formed JSON, expected a Unicode value, found [" + c.out + " ]")
end
elseif (not is_special_character (c) and not is_special_control (c)) or c = '%N' then
has_more := False
report_error ("Input String is not well formed JSON, found [" + c.out + " ]")
else
l_json_string.append_character ('\')
l_json_string.append_character (c)
end
else
if is_special_character (c) and c /= '/' then
has_more := False
report_error ("Input String is not well formed JSON, found [" + c.out + " ]")
else
l_json_string.append_character (c)
end
end
end
create Result.make_from_escaped_json_string (l_json_string)
else
Result := Void
end
end
parse_array: JSON_ARRAY
-- array
-- []
-- [elements [,]]
local
flag: BOOLEAN
l_value: detachable JSON_VALUE
c: like actual
do
create Result.make_empty
-- check if is an empty array []
next
skip_white_spaces
if actual = token_array_close then
-- is an empty array
else
previous
from
flag := True
until
not flag
loop
next
skip_white_spaces
l_value := next_json_value
if not has_error and then l_value /= Void then
Result.add (l_value)
next
skip_white_spaces
c := actual
if c = token_array_close then
flag := False
elseif c /= token_comma then
flag := False
report_error ("Array is not well formed JSON, found [" + c.out + " ]")
end
else
flag := False
report_error ("Array is not well formed JSON, found [" + actual.out + " ]")
end
end
end
end
parse_number: detachable JSON_NUMBER
-- Parsed number
local
sb: STRING
flag: BOOLEAN
is_integer: BOOLEAN
c: like actual
do
create sb.make_empty
sb.append_character (actual)
from
flag := True
until
not flag
loop
next
c := actual
if not has_next or is_close_token (c) or c = token_comma or c = '%N' or c = '%R' then
flag := False
previous
else
sb.append_character (c)
end
end
if is_valid_number (sb) then
if sb.is_integer then
create Result.make_integer (sb.to_integer)
is_integer := True
elseif sb.is_double and not is_integer then
create Result.make_real (sb.to_double)
end
else
report_error ("Expected a number, found: [ " + sb + " ]")
end
end
is_null: BOOLEAN
-- Word at index represents null?
local
l_null: STRING
l_string: STRING
do
l_null := null_id
l_string := json_substring (index, index + l_null.count - 1)
if l_string.is_equal (l_null) then
Result := True
end
end
is_false: BOOLEAN
-- Word at index represents false?
local
l_false: STRING
l_string: STRING
do
l_false := false_id
l_string := json_substring (index, index + l_false.count - 1)
if l_string.is_equal (l_false) then
Result := True
end
end
is_true: BOOLEAN
-- Word at index represents true?
local
l_true: STRING
l_string: STRING
do
l_true := true_id
l_string := json_substring (index, index + l_true.count - 1)
if l_string.is_equal (l_true) then
Result := True
end
end
read_unicode: STRING
-- Read unicode and return value.
local
i: INTEGER
do
create Result.make_empty
from
i := 1
until
i > 4 or not has_next
loop
next
Result.append_character (actual)
i := i + 1
end
end
feature {NONE} -- Implementation
is_valid_number (a_number: STRING): BOOLEAN
-- is 'a_number' a valid number based on this regular expression
-- "-?(?: 0|[1-9]\d+)(?: \.\d+)?(?: [eE][+-]?\d+)?\b"?
local
s: detachable STRING
c: CHARACTER
i, n: INTEGER
do
create s.make_empty
n := a_number.count
if n = 0 then
Result := False
else
Result := True
i := 1
--| "-?"
c := a_number [i]
if c = token_minus then
s.extend (c)
i := i + 1
if i > n then
Result := False
else
c := a_number [i]
end
end
--| "0|[1-9]\d*
if Result and c.is_digit then
if c = '0' then
--| "0"
s.extend (c)
i := i + 1
if i <= n then
c := a_number [i]
end
else
--| "[1-9]"
s.extend (c)
--| "\d*"
i := i + 1
if i <= n then
c := a_number [i]
from
until
i > n or not c.is_digit
loop
s.extend (c)
i := i + 1
if i <= n then
c := a_number [i]
end
end
end
end
end
end
if i > n then
-- Exit
else
if Result then
--| "(\.\d+)?"
if c = token_dot then
--| "\.\d+" = "\.\d\d*"
s.extend (c)
i := i + 1
c := a_number [i]
if c.is_digit then
from
until
i > n or not c.is_digit
loop
s.extend (c)
i := i + 1
if i <= n then
c := a_number [i]
end
end
else
Result := False --| expecting digit
end
end
end
if Result then --| "(?:[eE][+-]?\d+)?\b"
if is_exp_token (c) then
--| "[eE][+-]?\d+"
s.extend (c)
i := i + 1
c := a_number [i]
if c = token_plus or c = token_minus then
s.extend (c)
i := i + 1
if i <= n then
c := a_number [i]
end
end
if c.is_digit then
from
until
i > n or not c.is_digit
loop
s.extend (c)
i := i + 1
if i <= n then
c := a_number [i]
end
end
else
Result := False --| expecting digit
end
end
end
if Result then --| "\b"
from
until
i > n or not c.is_space
loop
s.extend (c)
i := i + 1
if i <= n then
c := a_number [i]
end
end
Result := i > n and then s.same_string (a_number)
end
end
end
is_valid_unicode (a_unicode: STRING): BOOLEAN
-- is 'a_unicode' a valid unicode based on the regular expression "\\u[0-9a-fA-F]{4}" .
local
i: INTEGER
do
if a_unicode.count = 6 and then a_unicode [1] = '\' and then a_unicode [2] = 'u' then
from
Result := True
i := 3
until
i > 6 or Result = False
loop
inspect a_unicode [i]
when '0'..'9', 'a'..'f', 'A'..'F' then
else
Result := False
end
i := i + 1
end
end
end
extra_elements: BOOLEAN
-- has more elements?
local
c: like actual
do
if has_next then
next
end
from
c := actual
until
c /= ' ' or c /= '%R' or c /= '%U' or c /= '%T' or c /= '%N' or not has_next
loop
next
end
Result := has_next
end
is_valid_start_symbol: BOOLEAN
-- expecting `{' or `[' as start symbol
do
if attached representation as s and then s.count > 0 then
Result := s [1] = token_object_open or s [1] = token_array_open
end
end
feature {NONE} -- Constants
false_id: STRING = "false"
true_id: STRING = "true"
null_id: STRING = "null"
note
copyright: "2010-2015, Javier Velilla and others https://github.com/eiffelhub/json."
license: "https://github.com/eiffelhub/json/blob/master/License.txt"
end

View File

@@ -0,0 +1,12 @@
note
description: "Inherit to access restricted feature from {JSON_PARSER}."
date: "$Date$"
revision: "$Revision$"
deferred class
JSON_PARSER_ACCESS
note
copyright: "2010-2014, Javier Velilla and others https://github.com/eiffelhub/json."
license: "https://github.com/eiffelhub/json/blob/master/License.txt"
end

View File

@@ -12,22 +12,28 @@ create
feature {NONE} -- Initialization
make (a_json: STRING)
-- Initialize Reader
do
set_representation (a_json)
end
make (a_json: STRING)
-- Initialize Reader
do
set_representation (a_json)
end
feature -- Commands
set_representation (a_json: STRING)
-- Set `representation'.
do
a_json.left_adjust
a_json.right_adjust
reset
-- Reset reader
do
index := 1
end
set_representation (a_json: STRING)
-- Set `representation'.
do
a_json.left_adjust
a_json.right_adjust
representation := a_json
index := 1
end
reset
end
read: CHARACTER
-- Read character
@@ -65,7 +71,7 @@ feature -- Commands
from
c := actual
until
(c /= ' ' and c /= '%N' and c /= '%R' and c /= '%U' and c /= '%T' ) or not has_next
(c /= ' ' and c /= '%N' and c /= '%R' and c /= '%U' and c /= '%T') or not has_next
loop
next
c := actual
@@ -115,4 +121,7 @@ feature {NONE} -- Implementation
invariant
representation_not_void: representation /= Void
note
copyright: "2010-2014, Javier Velilla and others https://github.com/eiffelhub/json."
license: "https://github.com/eiffelhub/json/blob/master/License.txt"
end

View File

@@ -0,0 +1,90 @@
note
description: "Token used by the JSON_PARSER"
author: "$Author$"
date: "$Date$"
revision: "$Revision$"
class
JSON_TOKENS
feature -- Access
token_object_open: CHARACTER = '{'
token_object_close: CHARACTER = '}'
token_array_open: CHARACTER = '['
token_array_close: CHARACTER = ']'
token_double_quote: CHARACTER = '"'
token_plus: CHARACTER = '+'
token_minus: CHARACTER = '-'
token_dot: CHARACTER = '.'
token_exp: CHARACTER = 'e'
token_comma: CHARACTER = ','
token_colon: CHARACTER = ':'
feature -- Status report
is_open_token (c: CHARACTER): BOOLEAN
-- Characters which open a type
do
inspect c
when token_object_open, token_array_open, token_double_quote, token_plus, token_minus, token_dot then
Result := True
else
end
end
is_close_token (c: CHARACTER): BOOLEAN
-- Characters which close a type
do
inspect c
when token_object_close, token_array_close, token_double_quote then
Result := True
else
end
end
is_special_character (c: CHARACTER): BOOLEAN
-- Control Characters
-- %F Form feed
-- %H backslasH
-- %N Newline
-- %R carriage Return
-- %T horizontal Tab
-- %B Backspace
-- / Solidus
-- " Quotation
do
inspect c
when '"', '%H' , '/', '%B', '%F', '%N', '%R', '%T' then -- '%H' = '\' = reverse solidus
Result := True
else
end
end
is_special_control (c: CHARACTER): BOOLEAN
-- Control Characters
-- \b\f\n\r\t
do
inspect c
when 'b', 'f', 'n', 'r', 't' then
Result := True
else
end
end
is_exp_token (c: CHARACTER): BOOLEAN
-- Is number exposant token?
do
Result := c = token_exp or else c.as_lower = token_exp
end
note
copyright: "2010-2014, Javier Velilla and others https://github.com/eiffelhub/json."
license: "https://github.com/eiffelhub/json/blob/master/License.txt"
end

View File

@@ -0,0 +1,49 @@
note
description: "Objects that ..."
author: ""
date: "$Date$"
revision: "$Revision$"
class
JSON_FILE_READER
feature -- Access
read_json_from (a_path: READABLE_STRING_GENERAL): detachable STRING
local
l_file: PLAIN_TEXT_FILE
l_last_string: detachable STRING
l_file_count: INTEGER
l_fetch_done: BOOLEAN
do
create l_file.make_with_name (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.out + "' does not exist%N") -- FIXME: unicode may be truncated
else
if not l_file.is_readable then
print ("error: '" + a_path.out + "' is not readable.%N") -- FIXME: unicode may be truncated
else
l_file_count := l_file.count
l_file.open_read
from
create Result.make (l_file_count)
until
l_fetch_done
loop
l_file.read_stream (1_024)
l_last_string := l_file.last_string
l_fetch_done := l_file.exhausted or l_file.end_of_file or l_last_string.count < 1_024
if not l_last_string.is_empty then
Result.append (l_last_string)
end
end
l_file.close
end
end
end
note
copyright: "2010-2014, Javier Velilla and others https://github.com/eiffelhub/json."
license: "https://github.com/eiffelhub/json/blob/master/License.txt"
end

View File

@@ -1,11 +1,8 @@
note
description:
"JSON Iterator"
description: "JSON Iterator"
pattern: "Iterator visitor"
author: "Jocelyn Fiat"
license:"MIT (see http://www.opensource.org/licenses/mit-license.php)"
license: "MIT (see http://www.opensource.org/licenses/mit-license.php)"
date: "2013/08/01"
revision: "Revision 0.1"
@@ -13,6 +10,7 @@ deferred class
JSON_ITERATOR
inherit
JSON_VISITOR
feature -- Visitor Pattern
@@ -52,9 +50,12 @@ feature -- Visitor Pattern
end
end
visit_json_string (a_json_string: JSON_STRING)
visit_json_string (a_json_string: JSON_STRING)
-- Visit `a_json_string'.
do
end
note
copyright: "2010-2014, Javier Velilla and others https://github.com/eiffelhub/json."
license: "https://github.com/eiffelhub/json/blob/master/License.txt"
end

View File

@@ -6,6 +6,7 @@ class
JSON_PRETTY_STRING_VISITOR
inherit
JSON_VISITOR
create
@@ -26,21 +27,58 @@ feature -- Initialization
output := a_output
create indentation.make_empty
indentation_step := "%T"
object_count_inlining := a_object_count_inlining
array_count_inlining := a_array_count_inlining
end
feature -- Access
output: STRING_32
-- JSON representation
output: STRING_GENERAL
-- JSON representation
indentation: like output
feature -- Settings
indentation_step: like indentation
indentation_step: STRING
-- Text used for indentation.
--| by default a tabulation "%T"
line_number: INTEGER
object_count_inlining: INTEGER
-- Inline where object item count is under `object_count_inlining'.
--| ex 3:
--| { "a", "b", "c" }
--| ex 2:
--| {
--| "a",
--| "b",
--| "c"
--| }
array_count_inlining: INTEGER
-- Inline where array item count is under `object_count_inlining'.
feature -- Element change
set_indentation_step (a_step: STRING)
-- Set `indentation_step' to `a_step'.
do
indentation_step := a_step
end
set_object_count_inlining (a_nb: INTEGER)
-- Set `object_count_inlining' to `a_nb'.
do
object_count_inlining := a_nb
end
set_array_count_inlining (a_nb: INTEGER)
-- Set `array_count_inlining' to `a_nb'.
do
array_count_inlining := a_nb
end
feature {NONE} -- Implementation
indentation: STRING
indent
do
@@ -59,8 +97,7 @@ feature -- Access
line_number := line_number + 1
end
object_count_inlining: INTEGER
array_count_inlining: INTEGER
line_number: INTEGER
feature -- Visitor Pattern
@@ -71,10 +108,14 @@ feature -- Visitor Pattern
l_json_array: ARRAYED_LIST [JSON_VALUE]
l_line: like line_number
l_multiple_lines: BOOLEAN
l_output: like output
do
l_output := output
l_json_array := a_json_array.array_representation
l_multiple_lines := l_json_array.count >= array_count_inlining or across l_json_array as p some attached {JSON_OBJECT} p.item or attached {JSON_ARRAY} p.item end
output.append ("[")
l_multiple_lines := l_json_array.count >= array_count_inlining
or across l_json_array as p some attached {JSON_OBJECT} p.item or attached {JSON_ARRAY} p.item end
l_output.append_code (91) -- '[' : 91
l_line := line_number
indent
from
@@ -82,27 +123,21 @@ feature -- Visitor Pattern
until
l_json_array.off
loop
if
line_number > l_line or
l_multiple_lines
then
if line_number > l_line or l_multiple_lines then
new_line
end
value := l_json_array.item
value.accept (Current)
l_json_array.forth
if not l_json_array.after then
output.append (", ")
l_output.append (", ")
end
end
exdent
if
line_number > l_line or
l_json_array.count >= array_count_inlining
then
if line_number > l_line or l_json_array.count >= array_count_inlining then
new_line
end
output.append ("]")
l_output.append_code (93) -- ']' : 93
end
visit_json_boolean (a_json_boolean: JSON_BOOLEAN)
@@ -129,10 +164,12 @@ feature -- Visitor Pattern
l_pairs: HASH_TABLE [JSON_VALUE, JSON_STRING]
l_line: like line_number
l_multiple_lines: BOOLEAN
l_output: like output
do
l_output := output
l_pairs := a_json_object.map_representation
l_multiple_lines := l_pairs.count >= object_count_inlining or across l_pairs as p some attached {JSON_OBJECT} p.item or attached {JSON_ARRAY} p.item end
output.append ("{")
l_output.append_code (123) -- '{' : 123
l_line := line_number
indent
from
@@ -140,36 +177,36 @@ feature -- Visitor Pattern
until
l_pairs.off
loop
if
line_number > l_line or
l_multiple_lines
then
if line_number > l_line or l_multiple_lines then
new_line
end
l_pairs.key_for_iteration.accept (Current)
output.append (": ")
l_output.append (": ")
l_pairs.item_for_iteration.accept (Current)
l_pairs.forth
if not l_pairs.after then
output.append (", ")
l_output.append (", ")
end
end
exdent
if
line_number > l_line or
l_pairs.count >= object_count_inlining
then
if line_number > l_line or l_pairs.count >= object_count_inlining then
new_line
end
output.append ("}")
l_output.append_code (125) -- '}' : 125
end
visit_json_string (a_json_string: JSON_STRING)
visit_json_string (a_json_string: JSON_STRING)
-- Visit `a_json_string'.
local
l_output: like output
do
output.append ("%"")
output.append (a_json_string.item)
output.append ("%"")
l_output := output
l_output.append_code (34) -- '%"' : 34
l_output.append (a_json_string.item)
l_output.append_code (34) -- '%"' : 34
end
note
copyright: "2010-2014, Javier Velilla and others https://github.com/eiffelhub/json."
license: "https://github.com/eiffelhub/json/blob/master/License.txt"
end

View File

@@ -1,11 +1,8 @@
note
description:
"JSON Visitor"
description: "JSON Visitor"
pattern: "Visitor"
author: "Javier Velilla"
license:"MIT (see http://www.opensource.org/licenses/mit-license.php)"
license: "MIT (see http://www.opensource.org/licenses/mit-license.php)"
date: "2008/08/24"
revision: "Revision 0.1"
@@ -49,11 +46,14 @@ feature -- Visitor Pattern
deferred
end
visit_json_string (a_json_string: JSON_STRING)
visit_json_string (a_json_string: JSON_STRING)
-- Visit `a_json_string'.
require
a_json_string_not_void: a_json_string /= Void
deferred
end
note
copyright: "2010-2014, Javier Velilla and others https://github.com/eiffelhub/json."
license: "https://github.com/eiffelhub/json/blob/master/License.txt"
end

View File

@@ -8,9 +8,11 @@ class
PRINT_JSON_VISITOR
inherit
JSON_VISITOR
create make
create
make
feature -- Initialization
@@ -23,7 +25,7 @@ feature -- Initialization
feature -- Access
to_json: STRING
-- JSON representation
-- JSON representation
feature -- Visitor Pattern
@@ -33,7 +35,7 @@ feature -- Visitor Pattern
value: JSON_VALUE
l_json_array: ARRAYED_LIST [JSON_VALUE]
do
l_json_array:=a_json_array.array_representation
l_json_array := a_json_array.array_representation
to_json.append ("[")
from
l_json_array.start
@@ -44,7 +46,7 @@ feature -- Visitor Pattern
value.accept (Current)
l_json_array.forth
if not l_json_array.after then
to_json.append(",")
to_json.append (",")
end
end
to_json.append ("]")
@@ -71,7 +73,7 @@ feature -- Visitor Pattern
visit_json_object (a_json_object: JSON_OBJECT)
-- Visit `a_json_object'.
local
l_pairs: HASH_TABLE[JSON_VALUE,JSON_STRING]
l_pairs: HASH_TABLE [JSON_VALUE, JSON_STRING]
do
l_pairs := a_json_object.map_representation
to_json.append ("{")
@@ -91,7 +93,7 @@ feature -- Visitor Pattern
to_json.append ("}")
end
visit_json_string (a_json_string: JSON_STRING)
visit_json_string (a_json_string: JSON_STRING)
-- Visit `a_json_string'.
do
to_json.append ("%"")
@@ -99,4 +101,7 @@ feature -- Visitor Pattern
to_json.append ("%"")
end
note
copyright: "2010-2014, Javier Velilla and others https://github.com/eiffelhub/json."
license: "https://github.com/eiffelhub/json/blob/master/License.txt"
end

View File

@@ -0,0 +1,16 @@
package json
project
json_safe = "library/json-safe.ecf"
json = "library/json.ecf"
json_gobo_extension = "library/json_gobo_extension.ecf"
note
title: Eiffel JSON
description: Eiffel JSON parser and visitors
tags: json,parser,text
license: MIT
copyright: Copyright (c) 2010-2014 Javier Velilla, Jocelyn Fiat and others,
link[github]: "project" https://github.com/eiffelhub/json
end

View File

@@ -1,12 +1,13 @@
note
description : "test_suite application root class"
date : "$Date$"
revision : "$Revision$"
description: "test_suite application root class"
date: "$Date$"
revision: "$Revision$"
class
APPLICATION
inherit
ARGUMENTS
create
@@ -17,7 +18,7 @@ feature {NONE} -- Initialization
make
-- Run application.
do
--| Add your code here
--| Add your code here
print ("Hello Eiffel World!%N")
end

View File

@@ -1,24 +1,32 @@
class AUTHOR
class
AUTHOR
create
make
make
feature {NONE} -- Initialization
make (a_name: STRING_32)
do
set_name (a_name)
end
make (a_name: STRING_32)
-- Create an author with `a_name' as `name'.
do
set_name (a_name)
ensure
name_set: name = a_name
end
feature -- Access
name: STRING_32
name: STRING_32
-- Author name
feature -- Status setting
feature -- Change
set_name (a_name: STRING_32)
do
name := a_name
end
set_name (a_name: STRING_32)
-- Set `name' with `a_name'.
do
name := a_name
ensure
name_set: name = a_name
end
end -- class AUTHOR

View File

@@ -1,40 +1,59 @@
class BOOK
class
BOOK
create
make
make
feature {NONE} -- Initialization
make (a_title: STRING_32; an_author: AUTHOR; an_isbn: STRING_32)
do
set_title (a_title)
set_author (an_author)
set_isbn (an_isbn)
end
make (a_title: STRING_32; a_author: AUTHOR; a_isbn: STRING_32)
-- Create a book with `a_title' as `title',
-- `a_author' as `author', and `a_isbn' as `isbn'.
do
set_title (a_title)
set_author (a_author)
set_isbn (a_isbn)
ensure
title_set: title = a_title
author_set: author = a_author
isbn_set: isbn = a_isbn
end
feature -- Access
title: STRING_32
title: STRING_32
-- Main title.
isbn: STRING_32
isbn: STRING_32
-- ISBN.
author: AUTHOR
author: AUTHOR
-- Author.
feature -- Status setting
feature -- Change
set_title (a_title: STRING_32)
do
title := a_title
end
set_title (a_title: STRING_32)
-- Set `title' with `a_title'.
do
title := a_title
ensure
title_set: title = a_title
end
set_author (an_author: AUTHOR)
do
author := an_author
end
set_author (a_author: AUTHOR)
-- Set `author' with `a_author'.
do
author := a_author
ensure
author_set: author = a_author
end
set_isbn (an_isbn: STRING_32)
do
isbn := an_isbn
end
set_isbn (a_isbn: STRING_32)
-- Set `isbn' with `a_isbn'.
do
isbn := a_isbn
ensure
isbn_set: isbn = a_isbn
end
end -- class BOOK

View File

@@ -1,80 +1,82 @@
class BOOK_COLLECTION
class
BOOK_COLLECTION
create
make
make
feature {NONE} -- Initialization
make (a_name: STRING_32)
do
set_name (a_name)
create book_index.make (10)
end
make (a_name: STRING_32)
-- Create a book collection with `a_name' as `name'.
do
set_name (a_name)
create book_index.make (10)
ensure
name_set: name = a_name
end
feature -- Access
name: STRING_32
name: STRING_32
-- Name.
books: LIST [BOOK]
do
from
create {LINKED_LIST [BOOK]} Result.make
book_index.start
until
book_index.after
loop
Result.append (book_index.item_for_iteration)
book_index.forth
end
end
books: LIST [BOOK]
-- collection of book.
do
create {LINKED_LIST [BOOK]} Result.make
across
book_index as it
loop
Result.append (it.item)
end
end
books_by_author (an_author: STRING_32): detachable LIST [BOOK]
do
if book_index.has (an_author) then
Result := book_index @ an_author
else
create {LINKED_LIST [BOOK]} Result.make
end
end
books_by_author (a_author: STRING_32): LIST [BOOK]
-- Books wrote by `a_author' in this collection.
do
if attached book_index [a_author] as l_result then
Result := l_result
else
create {LINKED_LIST [BOOK]} Result.make
end
end
feature -- Status setting
feature -- Change
set_name (a_name: STRING_32)
do
name := a_name
end
set_name (a_name: STRING_32)
-- Set `name' with `a_name'.
do
name := a_name
ensure
name_set: name = a_name
end
add_book (a_book: BOOK)
local
l: detachable LIST [BOOK]
do
if book_index.has (a_book.author.name) then
l := book_index.at ( a_book.author.name )
else
create {LINKED_LIST [BOOK]} l.make
book_index.put (l, a_book.author.name)
end
if attached l as la then
la.force (a_book)
end
add_book (a_book: BOOK)
-- Extend collection with `a_book'.
local
l: detachable LIST [BOOK]
do
l := book_index.at (a_book.author.name)
if l = Void then
create {LINKED_LIST [BOOK]} l.make
book_index.put (l, a_book.author.name)
end
l.force (a_book)
end
end
add_books (book_list: like books)
do
from
book_list.start
until
book_list.after
loop
add_book (book_list.item)
book_list.forth
end
end
add_books (book_list: like books)
-- Append collection with `book_list'.
do
across
book_list as it
loop
add_book (it.item)
end
end
feature {NONE} -- Implementation
book_index: HASH_TABLE [LIST [BOOK], STRING_32]
book_index: HASH_TABLE [LIST [BOOK], STRING_32]
-- Association of author name and its books.
end -- class BOOK_COLLECTION

View File

@@ -1,53 +1,54 @@
note
description: "A JSON converter for AUTHOR"
author: "Paul Cohen"
date: "$Date$"
revision: "$Revision$"
description: "A JSON converter for AUTHOR"
author: "Paul Cohen"
date: "$Date$"
revision: "$Revision$"
class JSON_AUTHOR_CONVERTER
class
JSON_AUTHOR_CONVERTER
inherit
JSON_CONVERTER
JSON_CONVERTER
create
make
make
feature {NONE} -- Initialization
make
local
ucs: STRING_32
do
create ucs.make_from_string ("")
create object.make (ucs)
end
make
local
ucs: STRING_32
do
create ucs.make_from_string ("")
create object.make (ucs)
end
feature -- Access
object: AUTHOR
object: AUTHOR
feature -- Conversion
from_json (j: like to_json): detachable like object
local
ucs: detachable STRING_32
do
ucs ?= json.object (j.item (name_key), Void)
check ucs /= Void end
create Result.make (ucs)
end
from_json (j: like to_json): detachable like object
do
if attached {STRING_32} json.object (j.item (name_key), Void) as l_name then
create Result.make (l_name)
end
end
to_json (o: like object): JSON_OBJECT
do
create Result.make
Result.put (json.value (o.name), name_key)
end
to_json (o: like object): JSON_OBJECT
do
create Result.make
Result.put (json.value (o.name), name_key)
end
feature {NONE} -- Implementation
feature {NONE} -- Implementation
name_key: JSON_STRING
once
create Result.make_json ("name")
end
name_key: JSON_STRING
-- Author's name label.
once
create Result.make_from_string ("name")
end
end -- class JSON_AUTHOR_CONVERTER

View File

@@ -1,78 +1,82 @@
note
description: "A JSON converter for BOOK_COLLECTION"
author: "Paul Cohen"
date: "$Date$"
revision: "$Revision$"
description: "A JSON converter for BOOK_COLLECTION"
author: "Paul Cohen"
date: "$Date$"
revision: "$Revision$"
class JSON_BOOK_COLLECTION_CONVERTER
class
JSON_BOOK_COLLECTION_CONVERTER
inherit
JSON_CONVERTER
JSON_CONVERTER
create
make
make
feature {NONE} -- Initialization
make
local
ucs: STRING_32
do
create ucs.make_from_string ("")
create object.make (ucs)
end
make
local
ucs: STRING_32
do
create ucs.make_from_string ("")
create object.make (ucs)
end
feature -- Access
object: BOOK_COLLECTION
object: BOOK_COLLECTION
feature -- Conversion
from_json (j: like to_json): detachable like object
local
ucs: detachable STRING_32
ll: LINKED_LIST [BOOK]
b: detachable BOOK
ja: detachable JSON_ARRAY
i: INTEGER
do
ucs ?= json.object (j.item (name_key), Void)
check ucs /= Void end
create Result.make (ucs)
ja ?= j.item (books_key)
check ja /= Void end
from
i := 1
create ll.make
until
i > ja.count
loop
b ?= json.object (ja [i], "BOOK")
check b /= Void end
ll.force (b)
i := i + 1
end
check ll /= Void end
Result.add_books (ll)
end
from_json (j: like to_json): detachable like object
local
l_books: LINKED_LIST [BOOK]
do
if
attached {STRING_32} json.object (j.item (name_key), Void) as l_name and
attached {JSON_ARRAY} j.item (books_key) as l_json_array
then
create Result.make (l_name)
create l_books.make
across
l_json_array as it
until
Result = Void
loop
if attached {BOOK} json.object (it.item, "BOOK") as l_book then
l_books.extend (l_book)
else
Result := Void
-- Failed
end
end
if Result /= Void then
Result.add_books (l_books)
end
end
end
to_json (o: like object): JSON_OBJECT
do
create Result.make
Result.put (json.value (o.name), name_key)
Result.put (json.value (o.books), books_key)
end
to_json (o: like object): JSON_OBJECT
do
create Result.make_with_capacity (2)
Result.put (json.value (o.name), name_key)
Result.put (json.value (o.books), books_key)
end
feature {NONE} -- Implementation
feature {NONE} -- Implementation
name_key: JSON_STRING
once
create Result.make_json ("name")
end
name_key: JSON_STRING
-- Collection's name label.
once
create Result.make_from_string ("name")
end
books_key: JSON_STRING
once
create Result.make_json ("books")
end
books_key: JSON_STRING
-- Book list label.
once
create Result.make_from_string ("books")
end
end -- class JSON_BOOK_COLLECTION_CONVERTER

View File

@@ -1,72 +1,74 @@
note
description: "A JSON converter for BOOK"
author: "Paul Cohen"
date: "$Date$"
revision: "$Revision$"
description: "A JSON converter for BOOK"
author: "Paul Cohen"
date: "$Date$"
revision: "$Revision$"
class JSON_BOOK_CONVERTER
class
JSON_BOOK_CONVERTER
inherit
JSON_CONVERTER
JSON_CONVERTER
create
make
make
feature {NONE} -- Initialization
make
local
ucs: STRING_32
a: AUTHOR
do
create ucs.make_from_string ("")
create a.make (ucs)
create object.make (ucs, a, ucs)
end
make
local
ucs: STRING_32
a: AUTHOR
do
create ucs.make_from_string ("")
create a.make (ucs)
create object.make (ucs, a, ucs)
end
feature -- Access
object: BOOK
object: BOOK
feature -- Conversion
from_json (j: like to_json): detachable like object
local
ucs1, ucs2: detachable STRING_32
a: detachable AUTHOR
do
ucs1 ?= json.object (j.item (title_key), Void)
check ucs1 /= Void end
ucs2 ?= json.object (j.item (isbn_key), Void)
check ucs2 /= Void end
a ?= json.object (j.item (author_key), "AUTHOR")
check a /= Void end
create Result.make (ucs1, a, ucs2)
end
from_json (j: like to_json): detachable like object
do
if
attached {STRING_32} json.object (j.item (title_key), Void) as l_title and
attached {STRING_32} json.object (j.item (isbn_key), Void) as l_isbn and
attached {AUTHOR} json.object (j.item (author_key), "AUTHOR") as l_author
then
create Result.make (l_title, l_author, l_isbn)
end
end
to_json (o: like object): JSON_OBJECT
do
create Result.make
Result.put (json.value (o.title), title_key)
Result.put (json.value (o.isbn), isbn_key)
Result.put (json.value (o.author), author_key)
end
to_json (o: like object): JSON_OBJECT
do
create Result.make_with_capacity (3)
Result.put (json.value (o.title), title_key)
Result.put (json.value (o.isbn), isbn_key)
Result.put (json.value (o.author), author_key)
end
feature {NONE} -- Implementation
feature {NONE} -- Implementation
title_key: JSON_STRING
once
create Result.make_json ("title")
end
title_key: JSON_STRING
-- Book's title label.
once
create Result.make_from_string ("title")
end
isbn_key: JSON_STRING
once
create Result.make_json ("isbn")
end
isbn_key: JSON_STRING
-- Book ISBN label.
once
create Result.make_from_string ("isbn")
end
author_key: JSON_STRING
once
create Result.make_json ("author")
end
author_key: JSON_STRING
-- Author label.
once
create Result.make_from_string ("author")
end
end -- class JSON_BOOK_CONVERTER

View File

@@ -1,74 +1,72 @@
class TEST_DS
note
description: "Linked list and hash table converters test."
date: "$Date$"
revision: "$Revision$"
class
TEST_DS
inherit
SHARED_EJSON
rename default_create as shared_default_create end
EQA_TEST_SET
select default_create end
SHARED_EJSON
undefine
default_create
end
EQA_TEST_SET
feature -- Test
test_linked_list_converter
local
jc: JSON_LINKED_LIST_CONVERTER
l: LINKED_LIST [STRING]
l2: detachable LINKED_LIST [detachable ANY]
s: STRING
jv: detachable JSON_VALUE
do
create jc.make
json.add_converter (jc)
create l.make
s := "foo"
l.force (s)
s := "bar"
l.force (s)
jv := json.value (l)
assert ("jv /= Void", jv /= Void)
if attached jv as l_jv then
s := jv.representation
l2 ?= json.object (jv, "LINKED_LIST")
assert ("l2 /= Void", l2 /= Void)
end
end
test_linked_list_converter
-- Convert a linked list to a json value and
-- convert this one to a linked list.
local
l: LINKED_LIST [STRING]
s: STRING
do
create l.make
l.force ("foo")
l.force ("bar")
if attached json.value (l) as l_value then
s := l_value.representation
assert ("JSON array converted to LINKED_LIST", attached {LINKED_LIST [detachable ANY]} json.object (l_value, "LINKED_LIST"))
else
assert ("LINKED_LIST converted to a JSON value", False)
end
end
test_hash_table_converter
local
tc: JSON_HASH_TABLE_CONVERTER
t: HASH_TABLE [STRING, STRING]
t2: detachable HASH_TABLE [ANY, HASHABLE]
s: STRING
ucs_key, ucs_value: detachable STRING_32
jv: detachable JSON_VALUE
do
create tc.make
json.add_converter (tc)
create t.make (2)
t.put ("foo", "1")
t.put ("bar", "2")
jv := json.value (t)
assert ("jv /= Void", jv /= Void)
if attached jv as l_jv then
s := l_jv.representation
t2 ?= json.object (l_jv, "HASH_TABLE")
assert ("t2 /= Void", t2 /= Void)
end
create ucs_key.make_from_string ("1")
if attached t2 as l_t2 then
ucs_value ?= t2 @ ucs_key
assert ("ucs_value /= Void", ucs_value /= Void)
if attached ucs_value as l_ucs_value then
assert ("ucs_value.string.is_equal (%"foo%")", l_ucs_value.string.is_equal ("foo"))
end
create ucs_key.make_from_string ("2")
ucs_value ?= t2 @ ucs_key
assert ("ucs_value /= Void", ucs_value /= Void)
if attached ucs_value as l_ucs_value then
assert ("ucs_value.string.is_equal (%"bar%")", l_ucs_value.string.is_equal ("bar"))
end
end
end
test_hash_table_converter
-- Convert a hash table to a json value and
-- convert this one to a hash table.
local
t: HASH_TABLE [STRING, STRING]
s: STRING
l_ucs_key: detachable STRING_32
do
create t.make (2)
t.put ("foo", "1")
t.put ("bar", "2")
if attached json.value (t) as l_value then
s := l_value.representation
if attached {HASH_TABLE [ANY, HASHABLE]} json.object (l_value, "HASH_TABLE") as t2 then
create l_ucs_key.make_from_string ("1")
if attached {STRING_32} t2 [l_ucs_key] as l_ucs_value then
assert ("ucs_value.string.is_equal (%"foo%")", l_ucs_value.same_string_general ("foo"))
else
assert ("ucs_value /= Void", False)
end
create l_ucs_key.make_from_string ("2")
if attached {STRING_32} t2 [l_ucs_key] as l_ucs_value then
assert ("ucs_value.string.is_equal (%"bar%")", l_ucs_value.same_string_general ("bar"))
else
assert ("ucs_value /= Void", False)
end
else
assert ("JSON object converted to HASH_TABLE", False);
end
else
assert ("HASH_TABLE converted to a JSON value", False)
end
end
end -- class TEST_DS

View File

@@ -1,42 +1,52 @@
class TEST_JSON_CUSTOM_CLASSES
note
description: "Parsing and converter of book collection test."
date: "$Date$"
revision: "$Revision$"
class
TEST_JSON_CUSTOM_CLASSES
inherit
SHARED_EJSON
rename default_create as shared_default_create end
SHARED_EJSON
undefine
default_create
end
EQA_TEST_SET
select default_create end
feature -- Test
test_custom_classes
local
bc: detachable BOOK_COLLECTION
jbc: JSON_BOOK_CONVERTER
jbcc: JSON_BOOK_COLLECTION_CONVERTER
jac: JSON_AUTHOR_CONVERTER
jo: detachable JSON_OBJECT
parser: JSON_PARSER
jrep: STRING
do
create jbc.make
json.add_converter (jbc)
create jbcc.make
json.add_converter (jbcc)
create jac.make
json.add_converter (jac)
jrep := "{%"name%":%"Test collection%",%"books%":[{%"title%":%"eJSON: The Definitive Guide%",%"isbn%":%"123123-413243%",%"author%":{%"name%":%"Foo Bar%"}}]}"
create parser.make_parser (jrep)
jo := Void
jo ?= parser.parse
assert ("jo /= Void", jo /= Void)
bc := Void
bc ?= json.object (jo, "BOOK_COLLECTION")
assert ("bc /= Void", bc /= Void)
jo ?= json.value (bc)
assert ("jo /= Void", jo /= Void)
if attached jo as l_jo then
assert ("JSON representation is correct", l_jo.representation.same_string ("{%"name%":%"Test collection%",%"books%":[{%"title%":%"eJSON: The Definitive Guide%",%"isbn%":%"123123-413243%",%"author%":{%"name%":%"Foo Bar%"}}]}"))
end
end
test_custom_classes
-- Parse JSON representation to JSON_OBJECT and test book collection converter.
local
jbc: JSON_BOOK_CONVERTER
jbcc: JSON_BOOK_COLLECTION_CONVERTER
jac: JSON_AUTHOR_CONVERTER
parser: JSON_PARSER
jrep: STRING
do
create jbc.make
json.add_converter (jbc)
create jbcc.make
json.add_converter (jbcc)
create jac.make
json.add_converter (jac)
jrep := "{%"name%":%"Test collection%",%"books%":[{%"title%":%"eJSON: The Definitive Guide%",%"isbn%":%"123123-413243%",%"author%":{%"name%":%"Foo Bar%"}}]}"
create parser.make_parser (jrep)
if attached {JSON_OBJECT} parser.parse as l_json_object then
if attached {BOOK_COLLECTION} json.object (l_json_object, "BOOK_COLLECTION") as l_collection then
if attached {JSON_OBJECT} json.value (l_collection) as l_json_object_2 then
assert ("JSON representation is correct", l_json_object_2.representation.same_string (jrep))
else
assert ("BOOK_COLLECTION converted to JSON_OBJECT", False)
end
else
assert ("JSON_OBJECT converted to BOOK_COLLECTION", False)
end
else
assert ("JSON object representation to JSON_OBJECT", False)
end
end
end -- class TEST_JSON_CUSTOM_CLASS

View File

@@ -1,4 +1,4 @@
note
note
description: "[
Eiffel tests that can be executed by testing tool.
]"
@@ -33,8 +33,8 @@ feature -- Tests Pass
do
if attached json_file_from ("pass1.json") as json_file then
parse_json := new_json_parser (json_file)
json_value := parse_json.parse_json
assert ("pass1.json",parse_json.is_parsed = True)
parse_json.parse_content
assert ("pass1.json", parse_json.is_valid)
end
end
@@ -45,8 +45,8 @@ feature -- Tests Pass
do
if attached json_file_from ("pass2.json") as json_file then
parse_json := new_json_parser (json_file)
json_value := parse_json.parse_json
assert ("pass2.json",parse_json.is_parsed = True)
parse_json.parse_content
assert ("pass2.json",parse_json.is_valid)
end
end
@@ -57,8 +57,8 @@ feature -- Tests Pass
do
if attached json_file_from ("pass3.json") as json_file then
parse_json := new_json_parser (json_file)
json_value := parse_json.parse_json
assert ("pass3.json",parse_json.is_parsed = True)
parse_json.parse_content
assert ("pass3.json",parse_json.is_valid)
end
end
@@ -68,20 +68,16 @@ feature -- Tests Pass
utf: UTF_CONVERTER
s: READABLE_STRING_32
do
s := {STRING_32} "{ %"nihaoma%": %"你好吗\t?%" }"
s := {STRING_32} "{ %"nihaoma%": %"你好吗\t?%" }"
parse_json := new_json_parser (utf.string_32_to_utf_8_string_8 (s))
json_value := parse_json.parse_json
assert ("utf8.pass1.json", parse_json.is_parsed = True)
if
attached {JSON_OBJECT} json_value as jo and then
attached {JSON_STRING} jo.item ("nihaoma") as js
then
assert ("utf8.nihaoma", js.unescaped_string_32.same_string ({STRING_32} "你好吗%T?"))
parse_json.parse_content
assert ("utf8.pass1.json", parse_json.is_valid)
if attached {JSON_OBJECT} parse_json.parsed_json_value as jo and then attached {JSON_STRING} jo.item ("nihaoma") as js then
assert ("utf8.nihaoma", js.unescaped_string_32.same_string ({STRING_32} "你好吗%T?"))
else
assert ("utf8.nihaoma", False)
end
end
end
end
feature -- Tests Failures
test_json_fail1
@@ -91,8 +87,8 @@ feature -- Tests Failures
do
if attached json_file_from ("fail1.json") as json_file then
parse_json := new_json_parser (json_file)
json_value := parse_json.parse_json
assert ("fail1.json",parse_json.is_parsed = False)
parse_json.parse_content
assert ("fail1.json", parse_json.is_valid = False)
end
end
@@ -103,8 +99,8 @@ feature -- Tests Failures
do
if attached json_file_from ("fail2.json") as json_file then
parse_json := new_json_parser (json_file)
json_value := parse_json.parse_json
assert ("fail2.json",parse_json.is_parsed = False)
parse_json.parse_content
assert ("fail2.json",parse_json.is_valid = False)
end
end
@@ -115,8 +111,8 @@ feature -- Tests Failures
do
if attached json_file_from ("fail3.json") as json_file then
parse_json := new_json_parser (json_file)
json_value := parse_json.parse_json
assert ("fail3.json",parse_json.is_parsed = False)
parse_json.parse_content
assert ("fail3.json",parse_json.is_valid = False)
end
end
@@ -127,8 +123,8 @@ feature -- Tests Failures
do
if attached json_file_from ("fail4.json") as json_file then
parse_json := new_json_parser (json_file)
json_value := parse_json.parse_json
assert ("fail4.json",parse_json.is_parsed = False)
parse_json.parse_content
assert ("fail4.json",parse_json.is_valid = False)
end
end
@@ -139,8 +135,8 @@ feature -- Tests Failures
do
if attached json_file_from ("fail5.json") as json_file then
parse_json := new_json_parser (json_file)
json_value := parse_json.parse_json
assert ("fail5.json",parse_json.is_parsed = False)
parse_json.parse_content
assert ("fail5.json",parse_json.is_valid = False)
end
end
@@ -152,8 +148,8 @@ feature -- Tests Failures
do
if attached json_file_from ("fail6.json") as json_file then
parse_json := new_json_parser (json_file)
json_value := parse_json.parse_json
assert ("fail6.json",parse_json.is_parsed = False )
parse_json.parse_content
assert ("fail6.json",parse_json.is_valid = False )
end
end
@@ -164,8 +160,8 @@ feature -- Tests Failures
do
if attached json_file_from ("fail7.json") as json_file then
parse_json := new_json_parser (json_file)
json_value := parse_json.parse_json
assert ("fail7.json",parse_json.is_parsed = False)
parse_json.parse_content
assert ("fail7.json",parse_json.is_valid = False)
end
end
@@ -176,8 +172,8 @@ feature -- Tests Failures
do
if attached json_file_from ("fail8.json") as json_file then
parse_json := new_json_parser (json_file)
json_value := parse_json.parse_json
assert ("fail8.json",parse_json.is_parsed = False )
parse_json.parse_content
assert ("fail8.json",parse_json.is_valid = False )
end
end
@@ -189,8 +185,8 @@ feature -- Tests Failures
do
if attached json_file_from ("fail9.json") as json_file then
parse_json := new_json_parser (json_file)
json_value := parse_json.parse_json
assert ("fail9.json",parse_json.is_parsed = False)
parse_json.parse_content
assert ("fail9.json",parse_json.is_valid = False)
end
end
@@ -202,8 +198,8 @@ feature -- Tests Failures
do
if attached json_file_from ("fail10.json") as json_file then
parse_json := new_json_parser (json_file)
json_value := parse_json.parse_json
assert ("fail10.json",parse_json.is_parsed = False)
parse_json.parse_content
assert ("fail10.json",parse_json.is_valid = False)
end
end
@@ -214,8 +210,8 @@ feature -- Tests Failures
do
if attached json_file_from ("fail11.json") as json_file then
parse_json := new_json_parser (json_file)
json_value := parse_json.parse_json
assert ("fail11.json",parse_json.is_parsed = False)
parse_json.parse_content
assert ("fail11.json",parse_json.is_valid = False)
end
end
@@ -226,8 +222,8 @@ feature -- Tests Failures
do
if attached json_file_from ("fail12.json") as json_file then
parse_json := new_json_parser (json_file)
json_value := parse_json.parse_json
assert ("fail12.json",parse_json.is_parsed = False)
parse_json.parse_content
assert ("fail12.json",parse_json.is_valid = False)
end
end
@@ -238,8 +234,8 @@ feature -- Tests Failures
do
if attached json_file_from ("fail13.json") as json_file then
parse_json := new_json_parser (json_file)
json_value := parse_json.parse_json
assert ("fail13.json",parse_json.is_parsed = False)
parse_json.parse_content
assert ("fail13.json",parse_json.is_valid = False)
end
end
@@ -250,8 +246,8 @@ feature -- Tests Failures
do
if attached json_file_from ("fail14.json") as json_file then
parse_json := new_json_parser (json_file)
json_value := parse_json.parse_json
assert ("fail14.json",parse_json.is_parsed = False)
parse_json.parse_content
assert ("fail14.json",parse_json.is_valid = False)
end
end
@@ -262,8 +258,8 @@ feature -- Tests Failures
do
if attached json_file_from ("fail15.json") as json_file then
parse_json := new_json_parser (json_file)
json_value := parse_json.parse_json
assert ("fail15.json",parse_json.is_parsed = False)
parse_json.parse_content
assert ("fail15.json",parse_json.is_valid = False)
end
end
@@ -274,8 +270,8 @@ feature -- Tests Failures
do
if attached json_file_from ("fail16.json") as json_file then
parse_json := new_json_parser (json_file)
json_value := parse_json.parse_json
assert ("fail16.json",parse_json.is_parsed = False)
parse_json.parse_content
assert ("fail16.json",parse_json.is_valid = False)
end
end
@@ -286,8 +282,8 @@ feature -- Tests Failures
do
if attached json_file_from ("fail17.json") as json_file then
parse_json := new_json_parser (json_file)
json_value := parse_json.parse_json
assert ("fail17.json",parse_json.is_parsed = False)
parse_json.parse_content
assert ("fail17.json",parse_json.is_valid = False)
end
end
@@ -298,8 +294,8 @@ feature -- Tests Failures
do
if attached json_file_from ("fail18.json") as json_file then
parse_json := new_json_parser (json_file)
json_value := parse_json.parse_json
assert ("fail18.json",parse_json.is_parsed = True)
parse_json.parse_content
assert ("fail18.json",parse_json.is_valid = True)
end
end
@@ -310,8 +306,8 @@ feature -- Tests Failures
do
if attached json_file_from ("fail19.json") as json_file then
parse_json := new_json_parser (json_file)
json_value := parse_json.parse_json
assert ("fail19.json",parse_json.is_parsed = False)
parse_json.parse_content
assert ("fail19.json",parse_json.is_valid = False)
end
end
@@ -322,8 +318,8 @@ feature -- Tests Failures
do
if attached json_file_from ("fail20.json") as json_file then
parse_json := new_json_parser (json_file)
json_value := parse_json.parse_json
assert ("fail20.json",parse_json.is_parsed = False)
parse_json.parse_content
assert ("fail20.json",parse_json.is_valid = False)
end
end
@@ -334,8 +330,8 @@ feature -- Tests Failures
do
if attached json_file_from ("fail21.json") as json_file then
parse_json := new_json_parser (json_file)
json_value := parse_json.parse_json
assert ("fail21.json",parse_json.is_parsed = False)
parse_json.parse_content
assert ("fail21.json",parse_json.is_valid = False)
end
end
@@ -347,8 +343,8 @@ feature -- Tests Failures
do
if attached json_file_from ("fail22.json") as json_file then
parse_json := new_json_parser (json_file)
json_value := parse_json.parse_json
assert ("fail22.json",parse_json.is_parsed = False)
parse_json.parse_content
assert ("fail22.json",parse_json.is_valid = False)
end
end
@@ -359,8 +355,8 @@ feature -- Tests Failures
do
if attached json_file_from ("fail23.json") as json_file then
parse_json := new_json_parser (json_file)
json_value := parse_json.parse_json
assert ("fail23.json",parse_json.is_parsed = False)
parse_json.parse_content
assert ("fail23.json",parse_json.is_valid = False)
end
end
@@ -371,8 +367,8 @@ feature -- Tests Failures
do
if attached json_file_from ("fail24.json") as json_file then
parse_json := new_json_parser (json_file)
json_value := parse_json.parse_json
assert ("fail24.json",parse_json.is_parsed = False)
parse_json.parse_content
assert ("fail24.json",parse_json.is_valid = False)
end
end
@@ -383,8 +379,8 @@ feature -- Tests Failures
do
if attached json_file_from ("fail25.json") as json_file then
parse_json := new_json_parser (json_file)
json_value := parse_json.parse_json
assert ("fail25.json",parse_json.is_parsed = False)
parse_json.parse_content
assert ("fail25.json",parse_json.is_valid = False)
end
end
@@ -396,8 +392,8 @@ feature -- Tests Failures
do
if attached json_file_from ("fail26.json") as json_file then
parse_json := new_json_parser (json_file)
json_value := parse_json.parse_json
assert ("fail26.json",parse_json.is_parsed = False)
parse_json.parse_content
assert ("fail26.json",parse_json.is_valid = False)
end
end
@@ -409,8 +405,8 @@ feature -- Tests Failures
do
if attached json_file_from ("fail27.json") as json_file then
parse_json := new_json_parser (json_file)
json_value := parse_json.parse_json
assert ("fail27.json",parse_json.is_parsed = False)
parse_json.parse_content
assert ("fail27.json",parse_json.is_valid = False)
end
end
@@ -422,8 +418,8 @@ feature -- Tests Failures
do
if attached json_file_from ("fail28.json") as json_file then
parse_json := new_json_parser (json_file)
json_value := parse_json.parse_json
assert ("fail28.json",parse_json.is_parsed = False)
parse_json.parse_content
assert ("fail28.json",parse_json.is_valid = False)
end
end
@@ -435,8 +431,8 @@ feature -- Tests Failures
do
if attached json_file_from ("fail29.json") as json_file then
parse_json := new_json_parser (json_file)
json_value := parse_json.parse_json
assert ("fail29.json",parse_json.is_parsed = False )
parse_json.parse_content
assert ("fail29.json",parse_json.is_valid = False )
end
end
@@ -448,8 +444,8 @@ feature -- Tests Failures
do
if attached json_file_from ("fail30.json") as json_file then
parse_json := new_json_parser (json_file)
json_value := parse_json.parse_json
assert ("fail30.json",parse_json.is_parsed = False)
parse_json.parse_content
assert ("fail30.json",parse_json.is_valid = False)
end
end
@@ -460,8 +456,8 @@ feature -- Tests Failures
do
if attached json_file_from ("fail31.json") as json_file then
parse_json := new_json_parser (json_file)
json_value := parse_json.parse_json
assert ("fail31.json",parse_json.is_parsed = False)
parse_json.parse_content
assert ("fail31.json",parse_json.is_valid = False)
end
end
@@ -472,8 +468,8 @@ feature -- Tests Failures
do
if attached json_file_from ("fail32.json") as json_file then
parse_json := new_json_parser (json_file)
json_value := parse_json.parse_json
assert ("fail32.json",parse_json.is_parsed = False)
parse_json.parse_content
assert ("fail32.json",parse_json.is_valid = False)
end
end
@@ -484,8 +480,8 @@ feature -- Tests Failures
do
if attached json_file_from ("fail33.json") as json_file then
parse_json := new_json_parser (json_file)
json_value := parse_json.parse_json
assert ("fail33.json",parse_json.is_parsed = False)
parse_json.parse_content
assert ("fail33.json",parse_json.is_valid = False)
end
end
@@ -493,52 +489,47 @@ feature -- JSON_FROM_FILE
file_reader: JSON_FILE_READER
json_value: detachable JSON_VALUE
json_file_from (fn: STRING): detachable STRING
local
f: RAW_FILE
l_path: STRING
test_dir: STRING
json_file_from (fn: READABLE_STRING_GENERAL): detachable STRING
local
f: RAW_FILE
l_path: PATH
test_dir: PATH
i: INTEGER
do
test_dir := (create {EXECUTION_ENVIRONMENT}).current_working_directory
test_dir.append_character ((create {OPERATING_ENVIRONMENT}).directory_separator)
l_path := test_dir + fn
create f.make_with_name (l_path)
test_dir := (create {EXECUTION_ENVIRONMENT}).current_working_path
l_path := test_dir.extended (fn)
create f.make_with_path (l_path)
if f.exists then
-- Found json file
else
-- before EiffelStudio 7.3 , the current dir of autotest execution was not the parent dir of ecf but something like
-- ..json\test\autotest\test_suite\EIFGENs\test_suite\Testing\execution\TEST_JSON_SUITE.test_json_fail1\..\..\..\..\..\fail1.json
-- before EiffelStudio 7.3 , the current dir of autotest execution was not the parent dir of ecf but something like
-- ..json\test\autotest\test_suite\EIFGENs\test_suite\Testing\execution\TEST_JSON_SUITE.test_json_fail1\..\..\..\..\..\fail1.json
from
i := 5
until
i = 0
loop
test_dir.append_character ('.')
test_dir.append_character ('.')
test_dir.append_character ((create {OPERATING_ENVIRONMENT}).directory_separator)
test_dir := test_dir.extended ("..")
i := i - 1
end
l_path := test_dir + fn
l_path := test_dir.extended (fn)
end
create f.make_with_name (l_path)
create f.make_with_path (l_path)
if f.exists then
Result := file_reader.read_json_from (l_path)
Result := file_reader.read_json_from (l_path.name)
end
assert ("File contains json data", Result /= Void)
end
assert ("File contains json data", Result /= Void)
end
new_json_parser (a_string: STRING): JSON_PARSER
do
create Result.make_parser (a_string)
create Result.make_with_string (a_string)
end
invariant
file_reader /= Void
end

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-8-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-8-0 http://www.eiffel.com/developers/xml/configuration-1-8-0.xsd" name="test_suite" uuid="EA141B17-6A21-4781-8B5F-E9939BAE968A">
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-13-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-13-0 http://www.eiffel.com/developers/xml/configuration-1-13-0.xsd" name="test_suite" uuid="EA141B17-6A21-4781-8B5F-E9939BAE968A">
<target name="test_suite">
<root cluster="test_suite" class="APPLICATION" feature="make"/>
<file_rule>
@@ -7,11 +7,11 @@
<exclude>/CVS$</exclude>
<exclude>/.svn$</exclude>
</file_rule>
<option warning="true" is_attached_by_default="true" void_safety="all" syntax="standard">
<option warning="true" full_class_checking="false" is_attached_by_default="true" void_safety="transitional" syntax="standard">
<assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
</option>
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
<library name="json" location="..\..\..\library\json-safe.ecf"/>
<library name="json" location="..\..\..\library\json-safe.ecf" readonly="false"/>
<library name="testing" location="$ISE_LIBRARY\library\testing\testing-safe.ecf"/>
<cluster name="test_suite" location=".\" recursive="true"/>
</target>

View File

133
doc/wiki/Deployment.md Normal file
View File

@@ -0,0 +1,133 @@
EWF Deployment
==============
##Apache on Windows
###Apache Install
- Check the correct version (Win 32 or Win64)
- Apache Version: Apache 2.4.4
- Windows: http://www.apachelounge.com/download/
###Deploying EWF CGI
####CGI overview
> A new process is started for each HTTP request. So if there are N request to the same CGI
> program, the code of the CGI program is loaded into memory N times.
> When a CGI program finished handling a request, the program terminates
1. Build EWF application.
```
ec -config app.ecf -target app_cgi -finalize -c_compile -project_path .
Note: change app.ecf and target app_cgi based on your own configuration.
```
2. Copy the generated exe file and the www content.
```
Copy the app.exe and the folder www into a folder served by apache2, for example under
<APACHE_PATH>/htdocs
<APACHE_PATH> = path to your apache installation
Edit httpd.conf under c:/<APACHE_PATH>/conf
DocumentRoot "c:/<APACHE_PATH>/htdocs"
<Directory "c:/<APACHE_PATH>/htdocs">
AllowOverride All --
Require all granted -- this is required in Apache 2.4.4
</Directory>
```
3. Check that you have the following modules enabled.
```
LoadModule cgi_module modules/mod_cgi.so
LoadModule rewrite_module modules/mod_rewrite.so
```
*Tip:*
To check the syntax of your httpd.conf file. From command line run the following.
```
$>httpd - t
```
####.htaccess CGI
http://perishablepress.com/stupid-htaccess-trics/
```
Options +ExecCGI +Includes +FollowSymLinks -Indexes
AddHandler cgi-script exe
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ $service [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !$service
RewriteRule ^(.*)$ $service/$1
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
</IfModule
```
Replace $service with the name of your executable service, for example app_service.exe
##Deploying EWF FCGI
- To deploy FCGI you will need to download the mod_fcgi module.
- You can get it from here http://www.apachelounge.com/download/
###FCGI overview
> FastCGI allows a single, long-running process to handle more than one user request while keeping close to
> the CGI programming model, retaining the simplicity while eliminating the overhead of creating a new
> process for each request. Unlike converting an application to a web server plug-in, FastCGI applications
> remain independent of the web server.
1. Build EWF application
```
ec -config app.ecf -target app_fcgi -finalize -c_compile -project_path .
Note: change app.ecf and target app_fcgi based on your own configuration.
```
2. Copy the generated exe file and the www content
```
Copy the app.exe and the folder "www" into a folder served by apache2, for example under
<APACHE_PATH>/htdocs.
<APACHE_PATH> = path to your apache installation
Edit httpd.conf under c:/<APACHE_PATH>/conf
DocumentRoot "c:/<APACHE_PATH>/htdocs"
<Directory "c:/<APACHE_PATH>/htdocs">
AllowOverride All --
Require all granted -- this is required in Apache 2.4.4
</Directory>
```
Check that you have the following modules enabled.
```
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule fcgid_module modules/mod_fcgid.so
```
By default Apache does not comes with fcgid module, so you will need to
download it, and put the module under Apache2/modules
####.htaccess FCGI
http://perishablepress.com/stupid-htaccess-tricks/
```
Options +ExecCGI +Includes +FollowSymLinks -Indexes
<IfModule mod_fcgid.c>
AddHandler fcgid-script .ews
FcgidWrapper $FULL_PATH/$service .ews
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteRule ^$ service.ews [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteCond %{REQUEST_URI} !service.ews
RewriteRule ^(.*)$ service.ews/$1 RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
</IfModule>
```
Replace $service with the name of your executable $service, for example app_service.exe
You will need to create an service.ews file, this file will be located at the same place where you
copy your app service executable.

View File

@@ -1,4 +1,4 @@
Menu :: [[Doc_Getting_Started|Getting Started]] :: [[Doc_Community|Community]]
Menu :: [[Doc_Getting_Started.mediawiki|Getting Started]] :: [[Community-collaboration.md|Community]]
= Getting Started =
This page will help you to get started with EWF. We will first see how to install EWF and then how to compile and run the venerable Hello World example.
@@ -54,4 +54,4 @@ To do this, we will redefine the feature initialize as follows:
After one more compile, you can now launch the application and point your browser to [http://localhost:9090].
You should now see a simple page with Hello World.
You should now see a simple page with Hello World.

View File

@@ -1,7 +1,7 @@
Menu :: [[Doc_Getting_Started|Getting Started]] :: [[Doc_Community|Community]]
Menu :: [[Doc_Getting_Started.mediawiki|Getting Started]] :: [[community.md|Community]]
= Eiffel Web Framework =
Framework to build web applications in Eiffel
[ [http://github.com/EiffelWebFramework/EWF/zipball/ Download Current] ]
[ [http://github.com/EiffelWebFramework/EWF/zipball/release-0.3 Download v0.3] ]
[ [http://github.com/EiffelWebFramework/EWF/zipball/release-0.3 Download v0.3] ]

View File

@@ -1 +0,0 @@
See WSF_ROUTER

View File

@@ -1 +0,0 @@
See WSF_CONNECTOR

View File

@@ -1 +0,0 @@
See WSF_ROUTER

View File

@@ -1,5 +1,5 @@
- See proposed specifications: [EWSGI specification](./EWSGI-specification)
- See [Open questions](./EWSGI-Open-Questions)
- See proposed specifications: [EWSGI specification](EWSGI-specification.md)
- See [Open questions](EWSGI-Open-Questions.md)
- And below the various proposals and associated decision
----

View File

@@ -6,21 +6,21 @@ The official documentation/wiki is located at [https://github.com/EiffelWebFrame
## Organization ##
- Mailing list: please visit and subscribe to the mailing list page [http://groups.google.com/group/eiffel-web-framework](http://groups.google.com/group/eiffel-web-framework) ![logo](http://groups.google.com/intl/en/images/logos/groups_logo_sm.gif)
- Most of the topics are discussed on the mailing list (google group).
- For time to time we have [web meetings](./wiki/Meetings), and less frequently [physical meetings](./wiki/Meetings) that occurs usually during other Eiffel related events.
- For time to time we have [web meetings](project/Meetings.md), and less frequently [physical meetings](project/Meetings.md) that occurs usually during other Eiffel related events.
## Documentation ##
- [Documentation](./Documentation)
- [Documentation](documentation/README.md)
## Contributions ##
- You want to contribute or follow the progress/discussion, see the [collaboration page](./wiki/Community-collaboration)
- Potential tasks/projects on EWF: [Projects page](./wiki/Projects)
- You want to contribute or follow the progress/discussion, see the [collaboration page](community.md)
- Potential tasks/projects on EWF: [Projects page](project/Projects.md)
## See also ##
- [list of tasks, and a potential roadmap](./wiki/Tasks-Roadmap)
- [General source structure of this project](./wiki/Source-structure)
- EWSGI: [Eiffel Web Server Gateway Interface](./wiki/EWSGI)
- [Overview of the server side architecture](./wiki/Spec-Server-Architecture)
- This project is also a collection of [Libraries](./wiki/Libraries) related to the Web
- [list of tasks, and a potential roadmap](project/Tasks-Roadmap.md)
- [General source structure of this project](Source-structure.md)
- EWSGI: [Eiffel Web Server Gateway Interface](EWSGI/README.md)
- [Overview of the server side architecture](Spec-Server-Architecture.md)
- This project is also a collection of [Libraries](Libraries.md) related to the Web
## Note ##
- This wiki needs to be updated, in the meantime, please have a look at the presentation: [https://docs.google.com/presentation/pub?id=1GPFv6aHhTjFSLMnlAt-J4WeIHSGfHdB42dQxmOVOH8s&start=false&loop=false&delayms=3000](https://docs.google.com/presentation/pub?id=1GPFv6aHhTjFSLMnlAt-J4WeIHSGfHdB42dQxmOVOH8s&start=false&loop=false&delayms=3000)

View File

@@ -46,3 +46,6 @@ It's fairly easy to write your own connector. Just inherit from these classes:
* WGI_INPUT_STREAM
* WGI_OUTPUT_STREAM
* WSF_SERVICE_LAUNCHER
See WSF_CONNECTOR

View File

@@ -27,7 +27,7 @@ This is the low level of the framework, at this point, `req` provides access to
The response `res` is the interface to send data back to the client.
For convenience, the framework provides richer service interface that handles the most common needs (filter, router, ...).
> [Learn more about service](Documentation__Service)
> [Learn more about service](Service.md)
<a name="wiki-request"></a><a name="wiki-response"></a><a name="wiki-request-and-response"></a>
<a name="request"></a><a name="response"></a><a name="request-and-response"></a>
@@ -50,7 +50,7 @@ Any incoming http request is represented by an new object of type **WSF_REQUEST*
The **WSF_RESPONSE** represents the communication toward the client, a service need to provide correct headers, and content. For instance the `Content-Type`, and `Content-Length`. It also allows to send data with chunked encoding.
> [Learn more about request](Documentation__Request) and [about response](Documentation__Response)
> [Learn more about request](Request.md) and [about response](Response.md)
<a name="wiki-connector"></a>
<a name="connector"></a>
@@ -66,7 +66,7 @@ Currently 3 main connectors are available:
At compilation time, you can use a default connector (by using the associated default lib), but you can also use a mixed of them and choose which one to execute at runtime.
It is fairly easy to add new connector, it just has to follow the EWSGI interface
> [Learn more about connector](Documentation__Connector)
> [Learn more about connector](Connector.md)
<a name="wiki-router"></a>
<a name="router"></a>
@@ -113,7 +113,7 @@ How we do that in EWF? : Router with (or without context).
Related code: wsf_router, wsf_router_context
Examples
> [Learn more about router](Documentation__Router)
> [Learn more about router](Router.md)
# EWF components
## URI Handler:
@@ -180,25 +180,26 @@ examples
External libraries are included, such as Cypress OAuth (Security), HTML parsing library, Template Engine Smarty.
## server
* __ewsgi__: Eiffel Web Server Gateway Interface read more
* __ewsgi__: Eiffel Web Server Gateway Interface [read more](../EWSGI/index.md).
* connectors: various web server connectors for EWSGI
* __libfcgi__: Wrapper for libfcgi SDK
* __wsf__: Web Server Framework [read more]
* __router__: URL dispatching/routing based on uri, uri_template, or custom read more
* __wsf__: Web Server Framework
* __router__: URL dispatching/routing based on uri, uri_template, or custom [read more](Router.md).
* __filter__: Filter chain [read more](Filter.md).
* __wsf_html__: (html and css) Content generator from the server side.
* CMS example: <https://github.com/EiffelWebFramework/cms/tree/master/example>
## protocol
* __http__: HTTP related classes, constants for status code, content types, ... read more
* __uri_template__: URI Template library (parsing and expander) read more
* __content_negotiation__: CONNEG library (Content-type Negociation) read more
* __http__: HTTP related classes, constants for status code, content types, ...
* __uri_template__: URI Template library (parsing and expander)
* __content_negotiation__: [CONNEG](Library-conneg.md) library (Content-type Negociation)
## Client
* __http_client__: simple HTTP client based on cURL readmore
* __http_client__: simple [HTTP client](HTTP-client.library.md) based on cURL
* __Firebase API__: <https://github.com/EiffelWebFramework/Redwood>
## Text
* __encoder__: Various simple encoders: base64, url-encoder, xml entities, html entities read more
* __encoder__: Various simple encoders: base64, url-encoder, xml entities, html entities
## Utils
* __error__: very simple/basic library to handle error

View File

@@ -1,3 +1,6 @@
The primary goal of the router (class _WSF_ROUTER_) is to dispatch requests according to the request URI.
**TODO**: describe the router interface
See WSF_ROUTER
**TODO**: describe the router interface

View File

@@ -23,4 +23,4 @@ is_system_options_forbidden.
WSF_ROUTED_SKELETON_SERVICE also inherits from WSF_PROXY_USE_POLICY. This determines if the server will require clients to use a proxy server. By default, it will do so for HTTP/1.0 clients. This is a sensible default, as the framework assumes an HTTP/1.1 client throughout. If you are sure that you will only ever have HTTP/1.1 clients, then you can instead inherit from WSF_NO_PROXY_POLICY, as RESTBUCKS_SERVER does. If not, then you need to implement proxy_server.
Next you have to [write your handler(s)](./Writing-the-handlers)
Next you have to [write your handler(s)](Writing-the-handlers.md)

View File

@@ -218,6 +218,6 @@ This routine is called for a normal (updating) PUT request. You have to update t
## Implementing the policies
* [WSF_OPTIONS_POLICY](./WSF_OPTIONS_POLICY)
* [WSF_PREVIOUS_POLICY](./Wsf-previous-policy)
* [WSF_CACHING_POLICY](./Wsf-caching-policy)
* [WSF_OPTIONS_POLICY](WSF_OPTIONS_POLICY.md)
* [WSF_PREVIOUS_POLICY](Wsf-previous-policy.md)
* [WSF_CACHING_POLICY](Wsf-caching-policy.md)

View File

@@ -1,4 +1,4 @@
# Previous and future meetings
* [Web-meeting: 2012-09-18](./Web-meeting-2012-09-18)
* [Web-meeting: 2012-09-18](meetings/Web-meeting-2012-09-18.md)
* For previous meetings, check the ["meeting" topics](https://groups.google.com/forum/?fromgroups=#!tags/eiffel-web-framework/meeting) on the [forum](http://groups.google.com/group/eiffel-web-framework)

View File

@@ -1,5 +1,5 @@
Use this to suggest new projects, or request features.
The content of this page will be moved to the main [Projects](./Projects) page for time to time.
The content of this page will be moved to the main [Projects](Projects.md) page for time to time.
For any entry, please use this template
----

View File

@@ -236,4 +236,4 @@ If you are a student, don't hesitate to pick one, or even suggest a new project,
----
# Feel free to add new idea below this line
----
Use the following page [Projects new suggestions](./Projects new suggestions) to suggest new project, or request a feature.
Use the following page [Projects new suggestions](Projects-new-suggestions.md) to suggest new project, or request a feature.

View File

@@ -1,4 +1,4 @@
Check new roadmap wiki page: [roadmap](./roadmap)
Check new roadmap wiki page: [roadmap](roadmap.md)
## Future
* Focus on REST API
- Hypermedia API
@@ -32,5 +32,5 @@ Check new roadmap wiki page: [roadmap](./roadmap)
* Installation scripts
## Contributors ##
- See [the collaboration page](./Community-collaboration)
- See [the collaboration page](../community.md)

Some files were not shown because too many files have changed in this diff Show More