Compare commits
699 Commits
release-0.
...
v1.0.1
| Author | SHA1 | Date | |
|---|---|---|---|
| fffa763d05 | |||
| d015c065f6 | |||
| 8ea443c115 | |||
| 019393fdb1 | |||
| da8028f8b3 | |||
| 20ed000879 | |||
|
|
24620b228c | ||
|
|
9c7e29b836 | ||
|
|
a0e9a41e21 | ||
|
|
dd9aff03d3 | ||
|
|
dc35925eb0 | ||
| a1a620a9c3 | |||
| d8ea9ba63c | |||
| c42af5b2de | |||
| d9cbc72058 | |||
| 7e057b20b1 | |||
| 3165c1e5c6 | |||
| 89e26519e4 | |||
| 9d20e85c03 | |||
| 48cb99498c | |||
| 8246bc1444 | |||
| 9e1083eba8 | |||
| 4907bc3085 | |||
| 7d2ce8a77f | |||
| b4a9c92ffc | |||
| bf0eb9a02d | |||
| ddf73077b3 | |||
| 3da80fce0d | |||
| 0970de5dc6 | |||
| 557b11f4e6 | |||
| 7f27a6c797 | |||
| c778e454cd | |||
| 44757b73eb | |||
| 525978db1d | |||
| 71c90a2f39 | |||
| 8057dca032 | |||
| 91d7b956b9 | |||
| 881625a0f6 | |||
| b7a12eddaf | |||
|
|
44b1ccbc3c | ||
|
|
30261632f6 | ||
|
|
08db0748f4 | ||
|
|
9dc22bee24 | ||
|
|
c4d362ff31 | ||
|
|
4a35ff7b77 | ||
|
|
871e9792a5 | ||
| 5f4ab50bf9 | |||
| f0a49aaf0a | |||
| 1aae58e00b | |||
| f81e5251e8 | |||
| b26504b4a1 | |||
| 4eddad0bcb | |||
| 1b9aa0c598 | |||
| 6e52774507 | |||
| e5403462bc | |||
| 33b555ff27 | |||
| 4c552671c1 | |||
| 25a362d043 | |||
| 023e03bb8f | |||
| 0caad2105f | |||
| f14fdc2a69 | |||
| 440d3f9c91 | |||
| 975ef90bab | |||
| 8c63e74b81 | |||
| 6b9d248542 | |||
| 6d2318ac9b | |||
|
|
0f76518b63 | ||
|
|
bb5faec3c6 | ||
|
|
22301fc15d | ||
|
|
f482ef06d5 | ||
|
|
4f62da8f90 | ||
|
|
eaa3dd435a | ||
|
|
e1d1d52260 | ||
| 0cc0ba047f | |||
| 641e114fed | |||
| 73d45c9817 | |||
| 519b959073 | |||
| 2cc751f326 | |||
| 99588faf40 | |||
|
|
9c6b6b978a | ||
| 0647a74875 | |||
|
|
de9d99e6bc | ||
| ae9f67391c | |||
| 82f832a556 | |||
| 19dbbf89e7 | |||
|
|
5d6e3c69ee | ||
|
|
984d04e972 | ||
|
|
83486ae0cc | ||
|
|
4fe5c5da7e | ||
|
|
ec1d8ca52f | ||
|
|
0404627153 | ||
|
|
de282948e6 | ||
|
|
93f1fed997 | ||
| f6ebd414d6 | |||
| ff19adc6c8 | |||
|
|
41d24c91b4 | ||
| 0427f7a8d3 | |||
| 985a5e5ce7 | |||
| fe4c283336 | |||
|
|
20e704604a | ||
|
|
0db02a8c52 | ||
| 1b4b50ee80 | |||
| 446c692f97 | |||
| 7dfc6ea67a | |||
|
|
a5a257f452 | ||
|
|
bde0e2900b | ||
|
|
361773101e | ||
|
|
052860b62c | ||
|
|
c5e1b1ee69 | ||
| 0b1697f20d | |||
| add71543a4 | |||
| 66a1e0629c | |||
| 425c976032 | |||
|
|
397dcc6128 | ||
| a3c403323d | |||
| 942896aa0c | |||
| 93c92c0e38 | |||
| 394ca46f03 | |||
| 67641da44d | |||
|
|
a826051979 | ||
|
|
ce4c62a989 | ||
| b59966595e | |||
| fcf8b63666 | |||
| cad9322839 | |||
| 31fcd61401 | |||
|
|
0b11663da4 | ||
| 5a179f514c | |||
| f099a70b87 | |||
| 1163b99f39 | |||
| ca6ccc7291 | |||
| bb11c24681 | |||
| d158579bdc | |||
| 02f5a09689 | |||
| cb3de17be9 | |||
| fd66d79ecb | |||
| d6b77e938b | |||
| 3c8dc0a9e1 | |||
| fdfeea508e | |||
| 99d0340e1b | |||
| a74cda2f33 | |||
| 322fd80f40 | |||
| 7168941495 | |||
| 161607cf8a | |||
| d45cd032a7 | |||
|
|
9db9a4957a | ||
|
|
d089921ef5 | ||
|
|
7f3ece2da9 | ||
| 4b497060a0 | |||
| d40131f863 | |||
| 9999b5e400 | |||
| 6e27f66306 | |||
| a4c1263190 | |||
| 46920fb991 | |||
| d50b3cb28c | |||
| 6481d2ec7d | |||
| f94820c824 | |||
| 1d0a2363d8 | |||
|
|
2100b856b0 | ||
|
|
e687affd17 | ||
|
|
195f3b4f68 | ||
| cc7d268610 | |||
|
|
acc8cda04f | ||
|
|
7c5637c063 | ||
|
|
b87392906b | ||
|
|
4e7e1e9c45 | ||
| da92d2d365 | |||
| ae0ba66416 | |||
| 718cebc700 | |||
| a2cbcbbbc6 | |||
|
|
c5363c948c | ||
|
|
4f7086a6de | ||
|
|
3c4e15b386 | ||
|
|
6685b3679b | ||
|
|
d6a27c26aa | ||
|
|
e7c4b949f5 | ||
|
|
f89e0abe69 | ||
|
|
cbcf9550f8 | ||
|
|
d4b877f18e | ||
|
|
605a094910 | ||
|
|
a16a7358d1 | ||
|
|
655c95158f | ||
| 9eca723dc5 | |||
| bbc2bab0eb | |||
|
|
fe913b0072 | ||
|
|
9ec2baf7d3 | ||
| cc6d2f3023 | |||
| 2ac717592d | |||
|
|
7ca62463b7 | ||
| 95971618ca | |||
| cb881877ac | |||
|
|
2cc26f98c6 | ||
|
|
47b4357a72 | ||
|
|
a60bd19e58 | ||
|
|
439e43fad9 | ||
|
|
7abbc96347 | ||
|
|
e9b4a8abd5 | ||
| cb7c20a0b7 | |||
| f5c2f9e017 | |||
|
|
45ddc47b0e | ||
|
|
8f148f2a5e | ||
|
|
5c9edeeae8 | ||
|
|
13349d07a8 | ||
| 991389e9b9 | |||
| d8487e6c12 | |||
|
|
b7750b9d06 | ||
|
|
d82cacc18f | ||
|
|
564248284a | ||
|
|
ee473d8844 | ||
|
|
2fb0d73439 | ||
|
|
5dd8a83081 | ||
|
|
f83a8db25c | ||
|
|
a3e5da052e | ||
|
|
942db6d708 | ||
|
|
48deb869de | ||
|
|
69b67b3b4b | ||
|
|
6acdcb4e6d | ||
|
|
e832478b76 | ||
|
|
c8e9a835f5 | ||
|
|
06c5f068db | ||
|
|
b81207e42e | ||
|
|
b312d69afa | ||
|
|
d1238a441d | ||
|
|
580739d0b4 | ||
|
|
093dec1808 | ||
|
|
2fb521aa42 | ||
|
|
992504a49f | ||
|
|
8696681710 | ||
|
|
73ce700ece | ||
|
|
c766881052 | ||
|
|
8bd14f5f21 | ||
|
|
45cd633e12 | ||
|
|
0744e13132 | ||
|
|
320584a693 | ||
|
|
514a44e022 | ||
|
|
191a00649f | ||
|
|
ecfd5738ce | ||
|
|
25fe7c8725 | ||
|
|
dbcb1def29 | ||
|
|
c4acbf563f | ||
|
|
c9599f449f | ||
|
|
e675e8aad9 | ||
|
|
37aac7053a | ||
|
|
9c9a132329 | ||
|
|
ce305d4e54 | ||
|
|
d3c66cd7fe | ||
|
|
7bf95cd927 | ||
|
|
05d4f24f6f | ||
|
|
d9c837918b | ||
|
|
5adee83350 | ||
|
|
720e26d19d | ||
|
|
29356c0b61 | ||
|
|
b39dd5c40d | ||
|
|
1ae44e74e7 | ||
|
|
7a5d1e378d | ||
| c68f6a30e6 | |||
| 07ec0d001f | |||
| 4f15745647 | |||
| 20367851cc | |||
| 2978ec33b7 | |||
| 3d126b04a9 | |||
| 33fd3c8009 | |||
| ea1c8a23cd | |||
| 1827723ccc | |||
|
|
949d3514b8 | ||
|
|
7818b9dc1c | ||
|
|
d15da0ffd4 | ||
|
|
a0665313ed | ||
|
|
8a7bd30ce0 | ||
| f2da98c387 | |||
|
|
51c4e8ab9e | ||
|
|
f369b26d88 | ||
|
|
40bb88a55f | ||
|
|
72e7493842 | ||
|
|
6213021f45 | ||
|
|
eb3fb7e5f7 | ||
|
|
1ec14ec397 | ||
|
|
38f422896d | ||
|
|
3895cf4399 | ||
|
|
7e69fddac9 | ||
| e6f1a06545 | |||
| e20dd076c3 | |||
|
|
a2cc3d8b29 | ||
|
|
fa4cbd8fa8 | ||
|
|
884b6b1339 | ||
|
|
9576779cce | ||
|
|
0721384b60 | ||
|
|
0d79799a5d | ||
|
|
86339d8163 | ||
|
|
64bde6220c | ||
|
|
3406780f65 | ||
|
|
597e0e82b9 | ||
|
|
137af843af | ||
|
|
8a96ed87b1 | ||
|
|
59b0d0d9fa | ||
|
|
c9102af0aa | ||
|
|
6838089570 | ||
|
|
aba60a473a | ||
|
|
9a392ba292 | ||
|
|
85369d5247 | ||
|
|
7c11de3073 | ||
|
|
4d07a6330d | ||
|
|
dad4191c40 | ||
|
|
b70450cfe9 | ||
|
|
10b950a7e7 | ||
|
|
1b831375ef | ||
|
|
a979bf24d4 | ||
|
|
4b11bbb73d | ||
|
|
f1cefd6173 | ||
|
|
ac31e1c29e | ||
|
|
61f032a819 | ||
| 026f8ae608 | |||
| ab07c2e0ce | |||
| 637303930a | |||
|
|
78ee9872bd | ||
| 4dd1731e60 | |||
|
|
2c2770b4f1 | ||
|
|
8c04a9183f | ||
|
|
373e13208f | ||
|
|
250d41c2d7 | ||
|
|
9329ea946e | ||
| ddd19023b0 | |||
| 9b329c8b8a | |||
| 6f48cf80f2 | |||
| 464cbcae80 | |||
| 8c57856232 | |||
| 4f490aaacc | |||
| 3065637c80 | |||
| cf01756c1c | |||
| 58dc2ec792 | |||
| 88e6837222 | |||
| d376f99832 | |||
| 3072ce7dec | |||
|
|
82fdd53adb | ||
|
|
b97073b14a | ||
|
|
9a10e6f2a3 | ||
|
|
60d77892e5 | ||
|
|
9e11931b44 | ||
|
|
8fe7f4db82 | ||
|
|
26e6a62e6b | ||
|
|
d26c68cd1e | ||
|
|
01327a4b06 | ||
|
|
d3299f8e06 | ||
|
|
1100328fee | ||
|
|
cb1a4825d2 | ||
|
|
aa9f4c4ed8 | ||
|
|
c6d59d3366 | ||
|
|
8353f34c45 | ||
|
|
b6c082e1fe | ||
|
|
48251fb872 | ||
|
|
f14728c1a7 | ||
|
|
295e6e9198 | ||
|
|
e21af4a0e8 | ||
|
|
805ac5dacf | ||
|
|
93f8cd789f | ||
|
|
7b0d264aab | ||
|
|
4d0dc964da | ||
|
|
95fd5f93fc | ||
| 0f7dca0701 | |||
| 843955b7b8 | |||
| 88192335b6 | |||
| b04159fb35 | |||
| 1d0eb14918 | |||
|
|
113df6efe1 | ||
|
|
e7951338c9 | ||
|
|
83329ca4b7 | ||
|
|
f51201eae1 | ||
|
|
c52a513378 | ||
|
|
6908bfe7bf | ||
|
|
a5fa428e98 | ||
|
|
24f760c043 | ||
|
|
3f089d6811 | ||
|
|
7e673b4628 | ||
|
|
ca633d3524 | ||
|
|
7dd726ca42 | ||
|
|
3f6caa76dc | ||
|
|
5a18cb4246 | ||
|
|
b33de9985f | ||
|
|
3a9ede6e8c | ||
|
|
87569ccee9 | ||
|
|
16b79ef193 | ||
|
|
f360e8a867 | ||
|
|
57dd4ce259 | ||
|
|
252b5ff758 | ||
|
|
b19598d902 | ||
|
|
b5ef1fbbb5 | ||
|
|
bc864bde39 | ||
|
|
0a2883e040 | ||
|
|
24474e6b31 | ||
| dd31970b01 | |||
| f31ed103d0 | |||
|
|
6c0eeebf27 | ||
| 48f5cb78d5 | |||
|
|
20a768749f | ||
|
|
2d964b1137 | ||
|
|
a1245b77fd | ||
|
|
f2ee91764d | ||
| fff08a29e7 | |||
|
|
a6260ed5a2 | ||
| 2f3a462c42 | |||
|
|
37e6d74a34 | ||
| f8a0bbf88b | |||
|
|
cbd7dc8176 | ||
|
|
1da678f726 | ||
|
|
fccb6776b0 | ||
|
|
f2e85aca42 | ||
|
|
2fbffb8c9e | ||
|
|
dd8bddd45c | ||
|
|
358fe04699 | ||
|
|
647beea245 | ||
|
|
251974fd2f | ||
|
|
81952e7898 | ||
|
|
1ba9792547 | ||
|
|
45e3a6d7cc | ||
|
|
be05edac7d | ||
|
|
6761d22fa8 | ||
|
|
9db93cf4c9 | ||
|
|
15dd993b95 | ||
|
|
0f8444a585 | ||
|
|
6230d643c8 | ||
|
|
cfe452543a | ||
|
|
26ec7d94c6 | ||
|
|
95f823e7a1 | ||
|
|
09544ba6d2 | ||
|
|
15676a7c9e | ||
| b5bdf88bf4 | |||
| 74e96d7816 | |||
| 527e877b30 | |||
|
|
efc1550ab9 | ||
|
|
f53974b138 | ||
|
|
6860860161 | ||
|
|
9c65194d91 | ||
|
|
b1cf630443 | ||
|
|
b3e383ea82 | ||
|
|
36368aff0b | ||
|
|
162735b328 | ||
|
|
27023283e7 | ||
|
|
8fc405fef1 | ||
|
|
44d8903a10 | ||
|
|
113c52f6b0 | ||
|
|
e29a4c8c8a | ||
| 9499601daf | |||
|
|
0887f7d22f | ||
|
|
327ecff63a | ||
|
|
55e91bff7f | ||
|
|
8b179fd98d | ||
|
|
e5841f2dad | ||
|
|
d45405f261 | ||
|
|
133ed9a0be | ||
|
|
33220b2b8e | ||
|
|
f542975872 | ||
| ed9fac0545 | |||
|
|
4dd4678b65 | ||
|
|
bbd48d24e4 | ||
| 3b66d77ddc | |||
| fc5ef995bc | |||
| 4c5fa0ed61 | |||
| ea9161b2f2 | |||
| 3c139315e5 | |||
| 15a96a402d | |||
| 5959099c55 | |||
|
|
9f40c6355c | ||
|
|
0fcb80aa29 | ||
|
|
59a12dcac1 | ||
|
|
eb47c101ca | ||
|
|
c67a7f4982 | ||
|
|
aba394502c | ||
|
|
0c265f4f78 | ||
|
|
32518cfb41 | ||
|
|
225f821206 | ||
|
|
f506d9e925 | ||
|
|
edce18fb1f | ||
|
|
ad15ab13c5 | ||
|
|
f52f6512a0 | ||
|
|
7bdafbd21e | ||
|
|
6486c8c472 | ||
|
|
fb345c5f0c | ||
|
|
deaeaa434d | ||
|
|
f9cc0afb9e | ||
|
|
ee0400463f | ||
|
|
fa35c22d2d | ||
|
|
422b73058c | ||
|
|
c50a46206d | ||
|
|
f866c067cb | ||
|
|
811d087d74 | ||
|
|
633243311d | ||
|
|
f5d5381fae | ||
|
|
bbc3249212 | ||
|
|
625b8803df | ||
|
|
0d8090b6f4 | ||
|
|
718c0af085 | ||
|
|
5a94264dc0 | ||
|
|
8269f3ea5b | ||
|
|
d6333362a7 | ||
|
|
3e43fd52ae | ||
|
|
1111333223 | ||
|
|
ae9952a941 | ||
|
|
3b2ad80dc3 | ||
|
|
1c08439c1a | ||
|
|
16c89180d2 | ||
|
|
bc6b4f90c3 | ||
|
|
275cc7aa21 | ||
|
|
e186475a81 | ||
|
|
595d0c501a | ||
|
|
4e09a15454 | ||
|
|
b7ab840d71 | ||
|
|
b72e6871e8 | ||
|
|
f14ea29636 | ||
|
|
cb7f1f0ee3 | ||
|
|
ef34217a6d | ||
|
|
ab7ee8e4c3 | ||
|
|
1a1df35ff1 | ||
|
|
0c0fb5c9c8 | ||
|
|
c29a6ad195 | ||
|
|
6fdffb7418 | ||
|
|
8db642cf3b | ||
|
|
850a05d6bb | ||
|
|
74995101d1 | ||
|
|
fa5d13e19d | ||
|
|
9f7e72f0a4 | ||
|
|
c224bf1bb1 | ||
|
|
b5b71a3db0 | ||
|
|
cc1abfd1f9 | ||
|
|
771c91227e | ||
|
|
1276ea0d1b | ||
|
|
611ce6eb9c | ||
|
|
2870df8478 | ||
|
|
59b2163a62 | ||
|
|
065318749b | ||
|
|
600ee095cc | ||
|
|
ecb49619da | ||
|
|
b73939d0a0 | ||
|
|
6c83639149 | ||
|
|
e77ee9bdf3 | ||
|
|
9449f0d16e | ||
|
|
4ff29e1fb3 | ||
|
|
4de85df5b6 | ||
|
|
294ccb04d3 | ||
|
|
4f0567ad88 | ||
|
|
65c613d0a4 | ||
|
|
a16bca2f29 | ||
| 517720c99c | |||
|
|
86e942ae0a | ||
| 9938cc941d | |||
| 2651171294 | |||
| 07f71dfc4e | |||
| 51730e0877 | |||
| 9958bb27a1 | |||
|
|
37b94bbf0d | ||
|
|
3ae898476f | ||
|
|
eefe547553 | ||
|
|
2903a1d3cd | ||
|
|
0755e2d2bc | ||
|
|
b5957d0f59 | ||
|
|
143608fd85 | ||
|
|
b2d9fe1a4b | ||
|
|
aff7948c65 | ||
|
|
bcdfcdd468 | ||
|
|
5e62d82e9c | ||
|
|
275c26b55b | ||
|
|
123fc8252e | ||
|
|
c93e50a7e2 | ||
|
|
9c8bc59224 | ||
|
|
b074570e99 | ||
|
|
bf5bae803d | ||
|
|
35224b1b17 | ||
|
|
2ed362f5d3 | ||
|
|
fe971d07ec | ||
|
|
f82456f352 | ||
|
|
bbbf958d7d | ||
|
|
4c901c3130 | ||
|
|
eade6d584c | ||
|
|
9c8a034a04 | ||
|
|
2dac1ff6c9 | ||
|
|
e9013e548b | ||
|
|
bc976c37b1 | ||
|
|
3249c377f1 | ||
|
|
2415a57ab0 | ||
|
|
7e4f51a7ce | ||
|
|
10caa4c1df | ||
|
|
a552b8fcfa | ||
|
|
9395e31c53 | ||
|
|
ce04737d46 | ||
|
|
259815467c | ||
|
|
3b517d3c53 | ||
|
|
c261f02c84 | ||
|
|
7815557f84 | ||
|
|
090e294f10 | ||
|
|
33d523e5bf | ||
|
|
7bc09bda8f | ||
|
|
45fd51b4b5 | ||
|
|
f3849679e8 | ||
|
|
bf0a8e8efb | ||
|
|
84c3039806 | ||
|
|
0c4a410ac0 | ||
|
|
b55f363651 | ||
|
|
7dd36014cc | ||
|
|
78ff0134c7 | ||
|
|
69da6c6d06 | ||
|
|
277eb0b4b6 | ||
|
|
8dbd24afd1 | ||
|
|
0a9d208529 | ||
|
|
8ab6dba1c8 | ||
|
|
e0bfdab106 | ||
|
|
fd09b39c1d | ||
| 8e743f3253 | |||
| 8d9dca1a94 | |||
| 5753af3e43 | |||
|
|
63f1976663 | ||
|
|
4b87a00637 | ||
|
|
8d12d1c0bc | ||
|
|
2c3d5b6f59 | ||
|
|
e8c66fa769 | ||
|
|
09f32e7025 | ||
|
|
0fca8daeb1 | ||
|
|
285e295b5a | ||
|
|
e6371c7adc | ||
|
|
ab7ff11cb6 | ||
|
|
ba11e84ed6 | ||
| 2676b16425 | |||
| f7012e5b85 | |||
| a149d8de97 | |||
| eea8894724 | |||
| 5b988ab760 | |||
| 88a38509de | |||
|
|
6dee9e85b5 | ||
|
|
2d795eb3c1 | ||
|
|
717b0f7ba8 | ||
|
|
2d373cab5b | ||
|
|
e20f45b2c3 | ||
|
|
917388b99e | ||
|
|
ed1f899534 | ||
|
|
60a80209dc | ||
|
|
e4f495b282 | ||
|
|
0efcd3cd07 | ||
| c216b96707 | |||
| cb3f983b91 | |||
| dc25723a35 | |||
| 8040dd5826 | |||
|
|
42ba1588c6 | ||
|
|
d0fda6de66 | ||
|
|
cef69039f5 | ||
|
|
cdf3a25f88 | ||
|
|
d1a0229944 | ||
|
|
63beaabfa0 | ||
|
|
caac696465 | ||
|
|
c741e41597 | ||
|
|
60fa076796 | ||
|
|
7dbed3ade1 | ||
|
|
a6cad7e811 | ||
|
|
47da8c17ea | ||
|
|
ad5b52f4e4 | ||
|
|
7679898159 | ||
|
|
d344df6e7e | ||
|
|
e0c3c783fa | ||
|
|
30663dc9fb | ||
|
|
8db7d0daa3 | ||
|
|
48bc71c6e3 | ||
|
|
2d3dadc85e | ||
|
|
e5765d356f | ||
|
|
f8f1773d18 | ||
|
|
15782c7795 | ||
|
|
b777e81ab1 | ||
|
|
e29346dec8 | ||
|
|
8535a8378c | ||
|
|
dcdc700bac | ||
|
|
31c2be768f | ||
|
|
9180667ac4 | ||
|
|
4f79bf2add | ||
|
|
9eaada0bdb | ||
|
|
c7e6fe38fb | ||
|
|
9e8548d65a | ||
|
|
3c41ca0864 | ||
|
|
c344ecceec | ||
|
|
ce2ca051f6 | ||
|
|
c63e307179 | ||
|
|
1daab0598a | ||
|
|
98ad77a57d | ||
|
|
b4ab4875fc | ||
|
|
6ead464a6b | ||
|
|
3d36c353fc | ||
|
|
0eff04c847 | ||
|
|
2b92ba9e62 | ||
|
|
c23bf7a05d | ||
|
|
92cbf48b49 | ||
|
|
1dc6ff6df1 | ||
|
|
e72ffab2ca | ||
|
|
e7a06ebc2e | ||
|
|
e12e0b35ee | ||
|
|
c6dac0384b | ||
|
|
e48cee9b4a | ||
|
|
9229b66091 | ||
|
|
eea428831c | ||
|
|
ad12d3e16d | ||
|
|
b1fcedf501 | ||
|
|
2b00192e87 | ||
|
|
2b82e7f07f | ||
|
|
f820d25a9e | ||
|
|
6e76747772 | ||
|
|
15d12b86aa |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -3,4 +3,5 @@ tests/temp/
|
||||
.svn/
|
||||
*.swp
|
||||
*~
|
||||
*.scm
|
||||
*#
|
||||
|
||||
142
CONTRIBUTING.md
Normal file
142
CONTRIBUTING.md
Normal file
@@ -0,0 +1,142 @@
|
||||
# Contributing to this project
|
||||
|
||||
Please take a moment to review this document in order to make the contribution
|
||||
process easy and effective for everyone involved.
|
||||
|
||||
Following these guidelines helps to communicate that you respect the time of
|
||||
the developers managing and developing this open source project. In return,
|
||||
they should reciprocate that respect in addressing your issue or assessing
|
||||
patches and features.
|
||||
|
||||
|
||||
## Using the issue tracker
|
||||
|
||||
The issue tracker is the preferred channel for [bug reports](#bugs),
|
||||
[features requests](#features) and [submitting pull
|
||||
requests](#pull-requests), but please respect the following restrictions:
|
||||
|
||||
* Please **do not** use the issue tracker for personal support requests (use
|
||||
[Stack Overflow](http://stackoverflow.com) or IRC).
|
||||
|
||||
* Please **do not** derail or troll issues. Keep the discussion on topic and
|
||||
respect the opinions of others.
|
||||
|
||||
|
||||
<a name="bugs"></a>
|
||||
## Bug reports
|
||||
|
||||
A bug is a _demonstrable problem_ that is caused by the code in the repository.
|
||||
Good bug reports are extremely helpful - thank you!
|
||||
|
||||
Guidelines for bug reports:
|
||||
|
||||
1. **Use the GitHub issue search** — check if the issue has already been
|
||||
reported.
|
||||
|
||||
2. **Check if the issue has been fixed** — try to reproduce it using the
|
||||
latest `master` or development branch in the repository.
|
||||
|
||||
3. **Isolate the problem** — ideally create a [reduced test
|
||||
case](http://css-tricks.com/6263-reduced-test-cases/) and a live example.
|
||||
|
||||
A good bug report shouldn't leave others needing to chase you up for more
|
||||
information. Please try to be as detailed as possible in your report. What is
|
||||
your environment? What steps will reproduce the issue? What browser(s) and OS
|
||||
experience the problem? What would you expect to be the outcome? All these
|
||||
details will help people to fix any potential bugs.
|
||||
|
||||
Example:
|
||||
|
||||
> Short and descriptive example bug report title
|
||||
>
|
||||
> A summary of the issue and the browser/OS environment in which it occurs. If
|
||||
> suitable, include the steps required to reproduce the bug.
|
||||
>
|
||||
> 1. This is the first step
|
||||
> 2. This is the second step
|
||||
> 3. Further steps, etc.
|
||||
>
|
||||
> `<url>` - a link to the reduced test case
|
||||
>
|
||||
> Any other information you want to share that is relevant to the issue being
|
||||
> reported. This might include the lines of code that you have identified as
|
||||
> causing the bug, and potential solutions (and your opinions on their
|
||||
> merits).
|
||||
|
||||
|
||||
<a name="features"></a>
|
||||
## Feature requests
|
||||
|
||||
Feature requests are welcome. But take a moment to find out whether your idea
|
||||
fits with the scope and aims of the project. It's up to *you* to make a strong
|
||||
case to convince the project's developers of the merits of this feature. Please
|
||||
provide as much detail and context as possible.
|
||||
|
||||
|
||||
<a name="pull-requests"></a>
|
||||
## Pull requests
|
||||
|
||||
Good pull requests - patches, improvements, new features - are a fantastic
|
||||
help. They should remain focused in scope and avoid containing unrelated
|
||||
commits.
|
||||
|
||||
**Please ask first** before embarking on any significant pull request (e.g.
|
||||
implementing features, refactoring code, porting to a different language),
|
||||
otherwise you risk spending a lot of time working on something that the
|
||||
project's developers might not want to merge into the project.
|
||||
|
||||
Please adhere to the coding conventions used throughout a project (indentation,
|
||||
accurate comments, etc.) and any other requirements (such as test coverage).
|
||||
|
||||
Adhering to the following this process is the best way to get your work
|
||||
included in the project:
|
||||
|
||||
1. [Fork](http://help.github.com/fork-a-repo/) the project, clone your fork,
|
||||
and configure the remotes:
|
||||
|
||||
```bash
|
||||
# Clone your fork of the repo into the current directory
|
||||
git clone https://github.com/<your-username>/<repo-name>
|
||||
# Navigate to the newly cloned directory
|
||||
cd <repo-name>
|
||||
# Assign the original repo to a remote called "upstream"
|
||||
git remote add upstream https://github.com/<upstream-owner>/<repo-name>
|
||||
```
|
||||
|
||||
2. If you cloned a while ago, get the latest changes from upstream:
|
||||
|
||||
```bash
|
||||
git checkout <dev-branch>
|
||||
git pull upstream <dev-branch>
|
||||
```
|
||||
|
||||
3. Create a new topic branch (off the main project development branch) to
|
||||
contain your feature, change, or fix:
|
||||
|
||||
```bash
|
||||
git checkout -b <topic-branch-name>
|
||||
```
|
||||
|
||||
4. Commit your changes in logical chunks. Please adhere to these [git commit
|
||||
message guidelines](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html)
|
||||
or your code is unlikely be merged into the main project. Use Git's
|
||||
[interactive rebase](https://help.github.com/articles/interactive-rebase)
|
||||
feature to tidy up your commits before making them public.
|
||||
|
||||
5. Locally merge (or rebase) the upstream development branch into your topic branch:
|
||||
|
||||
```bash
|
||||
git pull [--rebase] upstream <dev-branch>
|
||||
```
|
||||
|
||||
6. Push your topic branch up to your fork:
|
||||
|
||||
```bash
|
||||
git push origin <topic-branch-name>
|
||||
```
|
||||
|
||||
7. [Open a Pull Request](https://help.github.com/articles/using-pull-requests/)
|
||||
with a clear title and description.
|
||||
|
||||
**IMPORTANT**: By submitting a patch, you agree to allow the project owner to
|
||||
license your work under the same license as that used by the project.
|
||||
121
MIGRATION.md
Normal file
121
MIGRATION.md
Normal file
@@ -0,0 +1,121 @@
|
||||
Date: 2015-mar-31
|
||||
|
||||
# Goal:
|
||||
=======
|
||||
- support safe concurrency with EWF
|
||||
- provide a concurrent standalone connector
|
||||
|
||||
# Status:
|
||||
=========
|
||||
- The current version of EWF has mainly 3 connectors: CGI, libFCGI, and nino.
|
||||
- CGI and libFCGI connectors does not need any concurrency support.
|
||||
- But the nino connector had a pseudo concurrency support with Thread, however one could do write code that result in hasardeous concurrency execution.
|
||||
|
||||
So, it was decided to provide an improved Eiffel web nino connector, and update EWF design to make it concurrency compliant.
|
||||
|
||||
# Decisions:
|
||||
============
|
||||
- instead of updating current nino library, we now have a new "standalone" connector which is inspired by nino, but have support for the 3 concurrency modes: none, thread and SCOOP.
|
||||
|
||||
|
||||
# Overview
|
||||
==========
|
||||
Adding support for SCOOP concurrency mode add constraints to the design, but also helps ensuring the concurrency design of EWF is correct.
|
||||
|
||||
As a consequence, we had to introduce a new interface WSF_EXECUTION which is instantiated for each incoming request. See its simplified interface :
|
||||
<code lang="eiffel">
|
||||
deferred class WSF_EXECUTION
|
||||
|
||||
feature -- Initialization
|
||||
|
||||
make (req: WGI_REQUEST; res: WGI_RESPONSE)
|
||||
do
|
||||
...
|
||||
īnitialize
|
||||
end
|
||||
|
||||
initialize
|
||||
-- Initialize Current object.
|
||||
--| To be redefined if needed.
|
||||
do
|
||||
end
|
||||
|
||||
|
||||
feature -- Access
|
||||
|
||||
request: WSF_REQUEST
|
||||
-- Access to request data.
|
||||
-- Header, Query, Post, Input data..
|
||||
|
||||
response: WSF_RESPONSE
|
||||
-- Access to output stream, back to the client.
|
||||
|
||||
feature -- Execution
|
||||
|
||||
execute
|
||||
-- Execute Current `request',
|
||||
-- getting data from `request'
|
||||
-- and response to client via `response'.
|
||||
deferred
|
||||
ensure
|
||||
is_valid_end_of_execution: is_valid_end_of_execution
|
||||
end
|
||||
|
||||
end
|
||||
</code>
|
||||
|
||||
And the related request execution routines are extracted from WSF_SERVICE which becomes almost useless. The "service" part is not mostly responsible of launching the expected connector and set optional options, and declare the type of "execution" interface.
|
||||
|
||||
As a result, the well known WSF_DEFAULT_SERVICE has now a formal generic that should conform to WSF_EXECUTION with a `make' creation procedure. See update code:
|
||||
|
||||
<code lang="eiffel">
|
||||
class
|
||||
APPLICATION
|
||||
|
||||
inherit
|
||||
WSF_DEFAULT_SERVICE [APPLICATION_EXECUTION]
|
||||
redefine
|
||||
initialize
|
||||
end
|
||||
|
||||
create
|
||||
make_and_launch
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
initialize
|
||||
-- Initialize current service.
|
||||
do
|
||||
set_service_option ("port", 9090)
|
||||
end
|
||||
|
||||
end
|
||||
</code>
|
||||
|
||||
Where APPLICATION_EXECUTION is an implementation of the WSF_EXECUTION interface (with the `make' creation procedure).
|
||||
|
||||
In addition to add better and safer concurrency support, there are other advantages:
|
||||
- we now have a clear separation between the service launcher, and the request execution itself.
|
||||
- the WSF_EXECUTION is created per request, with two main attributes <code>request: WSF_REQUEST</code> and <code>response: WSF_RESPONSE</code>.
|
||||
|
||||
# How to migrate to new design
|
||||
- you can check the various example from the EWF repository, there should all be migrated to new design and comparing previous and new code, this will show you how the migration was done.
|
||||
- a frequent process:
|
||||
- identify the root class of your service, (the class implementing the WSF_SERVICE), let us name it APPLICATION_SERVICE
|
||||
- copy the APPLICATION_SERVICE file to APPLICATION_EXECUTION file.
|
||||
- change the class name to be APPLICATION_EXECUTION, and replace _SERVICE occurences by _EXECUTION (note the new WSF_ROUTED_EXECUTION and so on, which are mainly migration from previous WSF_ROUTED_SERVICE .., and also WSF_FILTERED_ROUTED_EXECUTION which is new.
|
||||
- replace "make_and_launch" by "make", remove the initialize redefinition if any.
|
||||
- in the APPLICATION_SERVICE class, remove most of the ROUTED, FILTERED ... inheritance, and keep WSF_DEFAULT_SERVICE, with a new formal generic i.e WSF_DEFAULT_SERVICE [APPLICATION_EXECUTION].
|
||||
- in the eventual redefined initialize, remove code related to routers, filters, ...
|
||||
- remove all the execution related code.
|
||||
- And you should be done.
|
||||
- To be short, this is mostly creating a new _EXECUTION class, and move the execution related code into this class from the _SERVICE class.
|
||||
- Then, you can replace the usage of nino connector by using the new "Standalone" connector, and switch to SCOOP concurrency mode, to ensure you are not messing up with concurrency. Your own code/libraris may not be SCOOP compliant, we recommend to migrate to SCOOP, but as an intermediate solutioņ, you can use the other concurrency mode (none or thread).
|
||||
|
||||
Note: the new design impacts the _SERVICE classes, connectors, but WSF_REQUEST, WSF_RESPONSE , WSF_ROUTER are compatible, so the migration is really easy.
|
||||
|
||||
We may take the opportunity to update the design deeper according to user feedback, and eventually "wsf" library will be renamed "wsf2".
|
||||
This is work in progress, all comments , feedback, suggestions, bug report are welcome.
|
||||
Hopefully before the final version of the new design is out.
|
||||
|
||||
|
||||
68
README.md
68
README.md
@@ -3,6 +3,27 @@
|
||||
|
||||
## Overview
|
||||
|
||||
The Eiffel Web Framework (EWF) provides Eiffel users with a layer to build anything on top of the http protocol such as websites, web API/services.
|
||||
|
||||
This layer is multi-platform: it can be set on Windows, Linux operating systems, and in addition it can run on top of any httpd servers such as Apache2, IIS, nginx, lighttpd. EWF includes as well a standalone httpd web server component, written in Eiffel, which enables users to run easily a web server on their machine, or even embed this component in any application written with Eiffel.
|
||||
|
||||
Currently EWF offers a collection of Eiffel libraries designed to be integrated with each others, and among other functionalities, it give simple access to the request data, to handle content negotiation, url dispatcher, integrate with openid system, and so on.
|
||||
|
||||
There is a growing ecosystem around EWF, that provides useful components:
|
||||
* OpenID and OAuth consumer library
|
||||
* Various hypermedia format such as HAL, Collection+json, …
|
||||
* Websocket server and client
|
||||
* Template engine
|
||||
* API Auto-documentation with swagger
|
||||
* A simple experimental CMS.
|
||||
* ...
|
||||
|
||||
So if you want to build a website, a web api, RESTful service, …or even if you want to consume other web api, EWF is a solution.
|
||||
|
||||
EWF brings with it all the advantages of the Eiffel technology and tools with its powerful features such as Design by Contract, debugging, testing tools which enable to build efficient systems expected to be repeatedly refined, extended, and improved in a predictable and controllable way so as to become with time bugfree systems. Enjoy the full power of debugging your web server application from the IDE.
|
||||
|
||||
## Project
|
||||
|
||||
Official project site for Eiffel Web Framework:
|
||||
|
||||
* http://eiffelwebframework.github.com/EWF/
|
||||
@@ -14,26 +35,21 @@ For more information please have a look at the related wiki:
|
||||
For download, check
|
||||
* https://github.com/EiffelWebFramework/EWF/downloads
|
||||
|
||||
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.0
|
||||
* Developped using EiffelStudio 7.1 (on Windows, Linux)
|
||||
* Tested using EiffelStudio 7.1 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?
|
||||
|
||||
Using git version >= 1.6.5
|
||||
* git clone --recursive https://github.com/EiffelWebFramework/EWF.git
|
||||
|
||||
Otherwise, try
|
||||
Using git
|
||||
* git clone https://github.com/EiffelWebFramework/EWF.git
|
||||
* cd Eiffel-Web-Framework
|
||||
* git submodule update --init
|
||||
* git submodule foreach --recursive git checkout master
|
||||
|
||||
An alternative to the last 2 instructions is to use the script from tools folder:
|
||||
* cd tools
|
||||
* update_git_working_copy
|
||||
|
||||
* And to build the required and related Clibs
|
||||
* cd contrib/ise_library/cURL
|
||||
@@ -51,7 +67,7 @@ An alternative to the last 2 instructions is to use the script from tools folder
|
||||
### protocol
|
||||
* __http__: HTTP related classes, constants for status code, content types, ... [read more](library/protocol/http)
|
||||
* __uri_template__: URI Template library (parsing and expander) [read more](library/protocol/uri_template)
|
||||
* __CONNEG__: CONNEG library (Content-type Negociation) [read more](library/protocol/CONNEG)
|
||||
* __CONNEG__: Content negotiation library (Content-type Negociation) [read more](library/protocol/content_negotiation)
|
||||
|
||||
### client
|
||||
* __http_client__: simple HTTP client based on cURL [read more](library/client/http_client)
|
||||
@@ -59,10 +75,6 @@ An alternative to the last 2 instructions is to use the script from tools folder
|
||||
### text
|
||||
* __encoder__: Various simpler encoders: base64, url-encoder, xml entities, html entities [read more](library/text/encoder)
|
||||
|
||||
### crypto
|
||||
* eel
|
||||
* eapml
|
||||
|
||||
### Others
|
||||
* error: very simple/basic library to handle error
|
||||
|
||||
@@ -75,6 +87,24 @@ An alternative to the last 2 instructions is to use the script from tools folder
|
||||
## Examples
|
||||
..
|
||||
|
||||
## Contributing to this project
|
||||
|
||||
Anyone and everyone is welcome to contribute. Please take a moment to
|
||||
review the [guidelines for contributing](CONTRIBUTING.md).
|
||||
|
||||
* [Bug reports](CONTRIBUTING.md#bugs)
|
||||
* [Feature requests](CONTRIBUTING.md#features)
|
||||
* [Pull requests](CONTRIBUTING.md#pull-requests)
|
||||
|
||||
## Community
|
||||
|
||||
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)
|
||||
|
||||
|
||||
For more information please have a look at the related wiki:
|
||||
* https://github.com/EiffelWebFramework/EWF/wiki
|
||||
|
||||
@@ -29,7 +29,6 @@
|
||||
|
||||
<target name="_build_tpl_" >
|
||||
<argument name="_target_name" />
|
||||
<geant target="${_target_name}" dir="cURL" file="build.eant" reuse_variables="true" />
|
||||
</target>
|
||||
|
||||
</project>
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -77,6 +78,6 @@ feature -- Status report
|
||||
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
|
||||
|
||||
@@ -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="nino" uuid="32C1D67D-33DE-4F1E-864B-D45388F2E3E6" library_target="nino">
|
||||
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-12-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-12-0 http://www.eiffel.com/developers/xml/configuration-1-12-0.xsd" name="nino" uuid="32C1D67D-33DE-4F1E-864B-D45388F2E3E6" library_target="nino">
|
||||
<target name="nino">
|
||||
<root all_classes="true"/>
|
||||
<file_rule>
|
||||
@@ -8,13 +8,28 @@
|
||||
<exclude>/CVS$</exclude>
|
||||
<exclude>/.svn$</exclude>
|
||||
</file_rule>
|
||||
<option warning="true" is_attached_by_default="true" void_safety="all">
|
||||
<option warning="true" full_class_checking="false" is_attached_by_default="true" void_safety="all" syntax="transitional">
|
||||
<assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
|
||||
</option>
|
||||
<setting name="concurrency" value="thread"/>
|
||||
<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>
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
|
||||
10
contrib/library/text/parser/json/.gitattributes
vendored
Normal file
10
contrib/library/text/parser/json/.gitattributes
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
# Set default behaviour, in case users don't have core.autocrlf set.
|
||||
# * text=auto
|
||||
|
||||
# Explicitly declare text files we want to always be normalized and converted
|
||||
# to native line endings on checkout.
|
||||
*.e text
|
||||
*.ecf text
|
||||
*.bat text
|
||||
*.json text
|
||||
*.txt text
|
||||
2
contrib/library/text/parser/json/.gitignore
vendored
2
contrib/library/text/parser/json/.gitignore
vendored
@@ -1,2 +1,2 @@
|
||||
*.swp
|
||||
EIFGENs
|
||||
EIFGENs/
|
||||
|
||||
@@ -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++++++++++++++++++++++++++++++++++++++++++++++
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,11 +51,9 @@ 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).
|
||||
@@ -58,6 +61,8 @@ 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.
|
||||
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,6 +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
|
||||
295
contrib/library/text/parser/json/doc/user_guide.mediawiki
Normal file
295
contrib/library/text/parser/json/doc/user_guide.mediawiki
Normal 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.
|
||||
|
||||
83
contrib/library/text/parser/json/examples/basic/basic.e
Normal file
83
contrib/library/text/parser/json/examples/basic/basic.e
Normal 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
|
||||
10
contrib/library/text/parser/json/examples/basic/basic.ecf
Normal file
10
contrib/library/text/parser/json/examples/basic/basic.ecf
Normal 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>
|
||||
@@ -5,9 +5,14 @@ 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
|
||||
redefine
|
||||
object
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -5,9 +5,14 @@ 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
|
||||
redefine
|
||||
object
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -25,7 +30,7 @@ feature -- Access
|
||||
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,22 +61,22 @@ 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
|
||||
if an_object /= Void and then attached converter_for (an_object) as jc then
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -1,38 +0,0 @@
|
||||
note
|
||||
description: "Objects that ..."
|
||||
author: ""
|
||||
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 (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
|
||||
@@ -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="json" uuid="4E21C3BD-7951-4C6E-A673-431E762D7414" library_target="json">
|
||||
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-12-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-12-0 http://www.eiffel.com/developers/xml/configuration-1-12-0.xsd" name="json" uuid="4E21C3BD-7951-4C6E-A673-431E762D7414" library_target="json">
|
||||
<target name="json">
|
||||
<root all_classes="true"/>
|
||||
<file_rule>
|
||||
@@ -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>
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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
|
||||
@@ -1,92 +0,0 @@
|
||||
note
|
||||
description: "A JSON converter for HASH_TABLE [ANY, HASHABLE]"
|
||||
author: "Paul Cohen"
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
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
|
||||
local
|
||||
keys: ARRAY [JSON_STRING]
|
||||
i: INTEGER
|
||||
h: detachable HASHABLE
|
||||
jv: detachable JSON_VALUE
|
||||
a: detachable ANY
|
||||
do
|
||||
keys := j.current_keys
|
||||
create Result.make (keys.count)
|
||||
from
|
||||
i := 1
|
||||
until
|
||||
i > keys.count
|
||||
loop
|
||||
h ?= json.object (keys [i], Void)
|
||||
check h /= Void end
|
||||
jv := j.item (keys [i])
|
||||
if jv /= Void then
|
||||
a := json.object (jv, Void)
|
||||
if a /= Void then
|
||||
Result.put (a, h)
|
||||
else
|
||||
check a_attached: a /= Void end
|
||||
end
|
||||
else
|
||||
check j_has_item: False end
|
||||
end
|
||||
i := i + 1
|
||||
end
|
||||
end
|
||||
|
||||
to_json (o: like object): detachable JSON_OBJECT
|
||||
local
|
||||
c: HASH_TABLE_ITERATION_CURSOR [ANY, HASHABLE]
|
||||
js: JSON_STRING
|
||||
jv: detachable JSON_VALUE
|
||||
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
|
||||
jv := json.value (c.item)
|
||||
if jv /= Void 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
|
||||
@@ -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
|
||||
@@ -7,28 +7,45 @@ note
|
||||
[]
|
||||
[elements]
|
||||
]"
|
||||
|
||||
author: "Javier Velilla"
|
||||
date: "2008/08/24"
|
||||
revision: "Revision 0.1"
|
||||
author: "$Author$"
|
||||
date: "$date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
JSON_ARRAY
|
||||
|
||||
inherit
|
||||
|
||||
JSON_VALUE
|
||||
|
||||
ITERABLE [JSON_VALUE]
|
||||
|
||||
DEBUG_OUTPUT
|
||||
|
||||
create
|
||||
make, make_empty,
|
||||
make_array
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
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
|
||||
create values.make (10)
|
||||
make (10)
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
@@ -38,24 +55,19 @@ feature -- Access
|
||||
require
|
||||
is_valid_index: valid_index (i)
|
||||
do
|
||||
Result := values.i_th (i)
|
||||
Result := items.i_th (i)
|
||||
end
|
||||
|
||||
representation: STRING
|
||||
local
|
||||
i: INTEGER
|
||||
do
|
||||
Result := "["
|
||||
from
|
||||
i := 1
|
||||
until
|
||||
i > count
|
||||
across
|
||||
items as ic
|
||||
loop
|
||||
Result.append (i_th (i).representation)
|
||||
i := i + 1
|
||||
if i <= count then
|
||||
if Result.count > 1 then
|
||||
Result.append_character (',')
|
||||
end
|
||||
Result.append (ic.item.representation)
|
||||
end
|
||||
Result.append_character (']')
|
||||
end
|
||||
@@ -69,12 +81,20 @@ feature -- Visitor pattern
|
||||
a_visitor.visit_json_array (Current)
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
new_cursor: ITERATION_CURSOR [JSON_VALUE]
|
||||
-- Fresh cursor associated with current structure
|
||||
do
|
||||
Result := items.new_cursor
|
||||
end
|
||||
|
||||
feature -- Mesurement
|
||||
|
||||
count: INTEGER
|
||||
-- Number of items.
|
||||
do
|
||||
Result := values.count
|
||||
Result := items.count
|
||||
end
|
||||
|
||||
feature -- Status report
|
||||
@@ -87,39 +107,67 @@ feature -- Status report
|
||||
|
||||
feature -- Change Element
|
||||
|
||||
add (value: JSON_VALUE)
|
||||
put_front (v: JSON_VALUE)
|
||||
require
|
||||
value_not_null: value /= void
|
||||
v_not_void: v /= Void
|
||||
do
|
||||
values.extend (value)
|
||||
items.put_front (v)
|
||||
ensure
|
||||
has_new_value: old values.count + 1 = values.count and
|
||||
values.has (value)
|
||||
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
|
||||
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
|
||||
items.prune_all (v)
|
||||
ensure
|
||||
not_has_new_value: not items.has (v)
|
||||
end
|
||||
|
||||
wipe_out
|
||||
-- Remove all items.
|
||||
do
|
||||
items.wipe_out
|
||||
end
|
||||
|
||||
feature -- Report
|
||||
|
||||
hash_code: INTEGER
|
||||
-- Hash code value
|
||||
local
|
||||
l_started: BOOLEAN
|
||||
do
|
||||
from
|
||||
values.start
|
||||
Result := values.item.hash_code
|
||||
until
|
||||
values.off
|
||||
across
|
||||
items as ic
|
||||
loop
|
||||
Result:= ((Result \\ 8388593) |<< 8) + values.item.hash_code
|
||||
values.forth
|
||||
if l_started then
|
||||
Result := ((Result \\ 8388593) |<< 8) + ic.item.hash_code
|
||||
else
|
||||
Result := ic.item.hash_code
|
||||
l_started := True
|
||||
end
|
||||
Result := Result \\ values.count
|
||||
end
|
||||
Result := Result \\ items.count
|
||||
end
|
||||
|
||||
feature -- Conversion
|
||||
|
||||
array_representation: ARRAYED_LIST [JSON_VALUE]
|
||||
-- Representation as a sequences of values
|
||||
-- Representation as a sequences of values.
|
||||
-- be careful, modifying the return object may have impact on the original JSON_ARRAY object.
|
||||
do
|
||||
Result := values
|
||||
Result := items
|
||||
end
|
||||
|
||||
feature -- Status report
|
||||
@@ -127,15 +175,18 @@ feature -- Status report
|
||||
debug_output: STRING
|
||||
-- String that should be displayed in debugger to represent `Current'.
|
||||
do
|
||||
Result := count.out
|
||||
Result := count.out + " item(s)"
|
||||
end
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
values: ARRAYED_LIST [JSON_VALUE]
|
||||
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
|
||||
|
||||
@@ -1,24 +1,47 @@
|
||||
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
|
||||
|
||||
inherit
|
||||
|
||||
JSON_VALUE
|
||||
|
||||
create
|
||||
make,
|
||||
make_true, make_false,
|
||||
make_boolean
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make_boolean (an_item: BOOLEAN)
|
||||
--Initialize.
|
||||
make (a_value: BOOLEAN)
|
||||
-- Initialize Current JSON boolean with `a_boolean'.
|
||||
do
|
||||
item := an_item
|
||||
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
|
||||
@@ -58,4 +81,7 @@ feature -- Status report
|
||||
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
|
||||
|
||||
@@ -8,6 +8,7 @@ class
|
||||
JSON_NULL
|
||||
|
||||
inherit
|
||||
|
||||
JSON_VALUE
|
||||
|
||||
feature --Access
|
||||
@@ -44,4 +45,7 @@ feature {NONE}-- Implementation
|
||||
|
||||
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
|
||||
|
||||
@@ -1,24 +1,22 @@
|
||||
note
|
||||
|
||||
description: "JSON Numbers, octal and hexadecimal formats are not used."
|
||||
author: "Javier Velilla"
|
||||
date: "2008/08/24"
|
||||
revision: "Revision 0.1"
|
||||
author: "$Author$"
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
license: "MIT (see http://www.opensource.org/licenses/mit-license.php)"
|
||||
|
||||
class
|
||||
JSON_NUMBER
|
||||
|
||||
inherit
|
||||
|
||||
JSON_VALUE
|
||||
redefine
|
||||
is_equal
|
||||
end
|
||||
|
||||
create
|
||||
make_integer,
|
||||
make_natural,
|
||||
make_real
|
||||
make_integer, make_natural, make_real
|
||||
|
||||
feature {NONE} -- initialization
|
||||
|
||||
@@ -26,21 +24,21 @@ feature {NONE} -- initialization
|
||||
-- Initialize an instance of JSON_NUMBER from the integer value of `an_argument'.
|
||||
do
|
||||
item := an_argument.out
|
||||
numeric_type := INTEGER_TYPE
|
||||
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
|
||||
numeric_type := natural_type
|
||||
end
|
||||
|
||||
make_real (an_argument: DOUBLE)
|
||||
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
|
||||
numeric_type := double_type
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
@@ -48,6 +46,9 @@ feature -- Access
|
||||
item: STRING
|
||||
-- Content
|
||||
|
||||
numeric_type: INTEGER
|
||||
-- Type of number (integer, natural or real).
|
||||
|
||||
hash_code: INTEGER
|
||||
--Hash code value
|
||||
do
|
||||
@@ -59,6 +60,52 @@ feature -- Access
|
||||
Result := item
|
||||
end
|
||||
|
||||
feature -- Conversion
|
||||
|
||||
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
|
||||
|
||||
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)
|
||||
@@ -87,13 +134,16 @@ feature -- Status report
|
||||
|
||||
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
|
||||
|
||||
note
|
||||
copyright: "2010-2014, Javier Velilla and others https://github.com/eiffelhub/json."
|
||||
license: "https://github.com/eiffelhub/json/blob/master/License.txt"
|
||||
end
|
||||
|
||||
@@ -1,114 +1,251 @@
|
||||
note
|
||||
|
||||
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}
|
||||
{"key": "value"}
|
||||
]"
|
||||
author: "Javier Velilla"
|
||||
date: "2008/08/24"
|
||||
revision: "Revision 0.1"
|
||||
author: "$Author$"
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
license: "MIT (see http://www.opensource.org/licenses/mit-license.php)"
|
||||
|
||||
class
|
||||
JSON_OBJECT
|
||||
|
||||
inherit
|
||||
|
||||
JSON_VALUE
|
||||
|
||||
TABLE_ITERABLE [JSON_VALUE, JSON_STRING]
|
||||
|
||||
DEBUG_OUTPUT
|
||||
|
||||
create
|
||||
make
|
||||
make_empty, make_with_capacity, make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make
|
||||
-- Initialize
|
||||
make_with_capacity (nb: INTEGER)
|
||||
-- Initialize with a capacity of `nb' items.
|
||||
do
|
||||
create object.make (10)
|
||||
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'.
|
||||
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
|
||||
key_not_present: not has_key (key)
|
||||
local
|
||||
l_value: like value
|
||||
a_key_not_present: not has_key (a_key)
|
||||
do
|
||||
l_value := value
|
||||
if l_value = Void then
|
||||
create {JSON_NULL} l_value
|
||||
if a_value = Void then
|
||||
items.extend (create {JSON_NULL}, a_key)
|
||||
else
|
||||
items.extend (a_value, a_key)
|
||||
end
|
||||
object.extend (l_value, key)
|
||||
end
|
||||
|
||||
replace (value: detachable JSON_VALUE; key: JSON_STRING)
|
||||
-- Assuming there is no item of key `key',
|
||||
-- insert `value' with `key'.
|
||||
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: like value
|
||||
l_value: JSON_STRING
|
||||
do
|
||||
l_value := value
|
||||
if l_value = Void then
|
||||
create {JSON_NULL} l_value
|
||||
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
|
||||
object.force (l_value, key)
|
||||
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.
|
||||
do
|
||||
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'.
|
||||
item (a_key: JSON_STRING): detachable JSON_VALUE
|
||||
-- the json_value associated with a key `a_key'.
|
||||
do
|
||||
Result := object.has (key)
|
||||
end
|
||||
|
||||
has_item (value: JSON_VALUE): BOOLEAN
|
||||
-- has the JSON_OBJECT contain a specfic item 'value'
|
||||
do
|
||||
Result := object.has_item (value)
|
||||
end
|
||||
|
||||
item (key: JSON_STRING): detachable JSON_VALUE
|
||||
-- the json_value associated with a key.
|
||||
do
|
||||
Result := object.item (key)
|
||||
Result := items.item (a_key)
|
||||
end
|
||||
|
||||
current_keys: ARRAY [JSON_STRING]
|
||||
-- array containing actually used keys
|
||||
-- Array containing actually used keys.
|
||||
do
|
||||
Result := object.current_keys
|
||||
Result := items.current_keys
|
||||
end
|
||||
|
||||
representation: STRING
|
||||
local
|
||||
t: HASH_TABLE [JSON_VALUE, JSON_STRING]
|
||||
-- <Precursor>
|
||||
do
|
||||
Result := "{"
|
||||
from
|
||||
t := map_representation
|
||||
t.start
|
||||
until
|
||||
t.after
|
||||
create Result.make (2)
|
||||
Result.append_character ('{')
|
||||
across
|
||||
items as ic
|
||||
loop
|
||||
Result.append (t.key_for_iteration.representation)
|
||||
Result.append (":")
|
||||
Result.append (t.item_for_iteration.representation)
|
||||
t.forth
|
||||
if not t.after then
|
||||
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
|
||||
@@ -116,9 +253,9 @@ feature -- Access
|
||||
feature -- Mesurement
|
||||
|
||||
count: INTEGER
|
||||
-- Number of field
|
||||
-- Number of field.
|
||||
do
|
||||
Result := object.count
|
||||
Result := items.count
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
@@ -126,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
|
||||
@@ -134,7 +271,7 @@ feature -- Status report
|
||||
is_empty: BOOLEAN
|
||||
-- Is empty object?
|
||||
do
|
||||
Result := object.is_empty
|
||||
Result := items.is_empty
|
||||
end
|
||||
|
||||
feature -- Visitor pattern
|
||||
@@ -151,7 +288,7 @@ feature -- Conversion
|
||||
map_representation: HASH_TABLE [JSON_VALUE, JSON_STRING]
|
||||
-- A representation that maps keys to values
|
||||
do
|
||||
Result := object
|
||||
Result := items
|
||||
end
|
||||
|
||||
feature -- Report
|
||||
@@ -160,13 +297,13 @@ feature -- Report
|
||||
-- Hash code value
|
||||
do
|
||||
from
|
||||
object.start
|
||||
Result := object.out.hash_code
|
||||
items.start
|
||||
Result := items.out.hash_code
|
||||
until
|
||||
object.off
|
||||
items.off
|
||||
loop
|
||||
Result := ((Result \\ 8388593) |<< 8) + object.item_for_iteration.hash_code
|
||||
object.forth
|
||||
Result := ((Result \\ 8388593) |<< 8) + items.item_for_iteration.hash_code
|
||||
items.forth
|
||||
end
|
||||
-- Ensure it is a positive value.
|
||||
Result := Result.hash_code
|
||||
@@ -177,15 +314,18 @@ feature -- Status report
|
||||
debug_output: STRING
|
||||
-- String that should be displayed in debugger to represent `Current'.
|
||||
do
|
||||
Result := object.count.out
|
||||
Result := count.out + "item(s)"
|
||||
end
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
object: HASH_TABLE [JSON_VALUE, JSON_STRING]
|
||||
items: HASH_TABLE [JSON_VALUE, JSON_STRING]
|
||||
-- Value container
|
||||
|
||||
invariant
|
||||
object_not_null: 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
|
||||
|
||||
@@ -1,39 +1,92 @@
|
||||
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"
|
||||
author: "$Author$"
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
license: "MIT (see http://www.opensource.org/licenses/mit-license.php)"
|
||||
|
||||
|
||||
class
|
||||
JSON_STRING
|
||||
|
||||
inherit
|
||||
|
||||
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_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_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_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
|
||||
@@ -42,18 +95,12 @@ feature {NONE} -- Initialization
|
||||
|
||||
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_32 (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
|
||||
make_with_escaped_json (escaped_json_string (s))
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
@@ -61,103 +108,33 @@ feature -- Access
|
||||
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
|
||||
i, n: INTEGER
|
||||
c: CHARACTER
|
||||
do
|
||||
s := item
|
||||
n := s.count
|
||||
create Result.make (n)
|
||||
from i := 1 until i > n loop
|
||||
c := s[i]
|
||||
if c = '\' then
|
||||
if i < n then
|
||||
inspect s[i+1]
|
||||
when '\' then
|
||||
Result.append_character ('\')
|
||||
i := i + 2
|
||||
when '%"' then
|
||||
Result.append_character ('%"')
|
||||
i := i + 2
|
||||
when 'n' then
|
||||
Result.append_character ('%N')
|
||||
i := i + 2
|
||||
when 'r' then
|
||||
Result.append_character ('%R')
|
||||
i := i + 2
|
||||
when 'u' then
|
||||
--| Leave unicode \uXXXX unescaped
|
||||
Result.append_character ('\')
|
||||
i := i + 1
|
||||
else
|
||||
Result.append_character ('\')
|
||||
i := i + 1
|
||||
end
|
||||
else
|
||||
Result.append_character ('\')
|
||||
i := i + 1
|
||||
end
|
||||
else
|
||||
Result.append_character (c)
|
||||
i := i + 1
|
||||
end
|
||||
end
|
||||
create Result.make (s.count)
|
||||
unescape_to_string_8 (Result)
|
||||
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
|
||||
s: like item
|
||||
i, n: INTEGER
|
||||
c: CHARACTER
|
||||
hex: STRING
|
||||
s: READABLE_STRING_8
|
||||
do
|
||||
s := item
|
||||
n := s.count
|
||||
create Result.make (n)
|
||||
from i := 1 until i > n loop
|
||||
c := s[i]
|
||||
if c = '\' then
|
||||
if i < n then
|
||||
inspect s[i+1]
|
||||
when '\' then
|
||||
Result.append_character ('\')
|
||||
i := i + 2
|
||||
when '%"' then
|
||||
Result.append_character ('%"')
|
||||
i := i + 2
|
||||
when 'n' then
|
||||
Result.append_character ('%N')
|
||||
i := i + 2
|
||||
when 'r' then
|
||||
Result.append_character ('%R')
|
||||
i := i + 2
|
||||
when 'u' then
|
||||
hex := s.substring (i+2, i+2+4 - 1)
|
||||
if hex.count = 4 then
|
||||
Result.append_code (hexadecimal_to_natural_32 (hex))
|
||||
end
|
||||
i := i + 2 + 4
|
||||
else
|
||||
Result.append_character ('\')
|
||||
i := i + 1
|
||||
end
|
||||
else
|
||||
Result.append_character ('\')
|
||||
i := i + 1
|
||||
end
|
||||
else
|
||||
Result.append_character (c.to_character_32)
|
||||
i := i + 1
|
||||
end
|
||||
end
|
||||
create Result.make (s.count)
|
||||
unescape_to_string_32 (Result)
|
||||
end
|
||||
|
||||
representation: STRING
|
||||
-- String representation of `item' with escaped entities if any
|
||||
-- String representation of `item' with escaped entities if any.
|
||||
do
|
||||
create Result.make (item.count + 2)
|
||||
Result.append_character ('%"')
|
||||
@@ -165,6 +142,160 @@ feature -- Access
|
||||
Result.append_character ('%"')
|
||||
end
|
||||
|
||||
unescape_to_string_8 (a_output: STRING_8)
|
||||
-- Unescape string `item' into `a_output'.
|
||||
--| note: valid only if `item' does not encode any unicode character.
|
||||
local
|
||||
s: like item
|
||||
i, n: INTEGER
|
||||
c: CHARACTER
|
||||
do
|
||||
s := item
|
||||
n := s.count
|
||||
from
|
||||
i := 1
|
||||
until
|
||||
i > n
|
||||
loop
|
||||
c := s [i]
|
||||
if c = '\' then
|
||||
if i < n then
|
||||
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 ('/')
|
||||
i := i + 2
|
||||
when 'b' then
|
||||
a_output.append_character ('%B')
|
||||
i := i + 2
|
||||
when 'f' then
|
||||
a_output.append_character ('%F')
|
||||
i := i + 2
|
||||
when 'n' then
|
||||
a_output.append_character ('%N')
|
||||
i := i + 2
|
||||
when 'r' then
|
||||
a_output.append_character ('%R')
|
||||
i := i + 2
|
||||
when 't' then
|
||||
a_output.append_character ('%T')
|
||||
i := i + 2
|
||||
when 'u' then
|
||||
--| Leave unicode \uXXXX unescaped
|
||||
a_output.append_character (c) -- '\'
|
||||
i := i + 1
|
||||
else
|
||||
a_output.append_character (c) -- '\'
|
||||
i := i + 1
|
||||
end
|
||||
else
|
||||
a_output.append_character (c) -- '\'
|
||||
i := i + 1
|
||||
end
|
||||
else
|
||||
a_output.append_character (c)
|
||||
i := i + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
unescape_to_string_32 (a_output: STRING_32)
|
||||
-- Unescape string `item' into `a_output' string 32.
|
||||
--| some encoders uses UTF-8 , and not the recommended pure json encoding
|
||||
--| thus, let's support the UTF-8 encoding during decoding.
|
||||
local
|
||||
s: READABLE_STRING_8
|
||||
i, n: INTEGER
|
||||
c: NATURAL_32
|
||||
ch: CHARACTER_8
|
||||
hex: READABLE_STRING_8
|
||||
do
|
||||
s := item
|
||||
n := s.count
|
||||
from
|
||||
i := 1
|
||||
until
|
||||
i > n
|
||||
loop
|
||||
ch := s.item (i)
|
||||
if ch = '\' then
|
||||
if i < n then
|
||||
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 ('/')
|
||||
i := i + 2
|
||||
when 'b' then
|
||||
a_output.append_character ('%B')
|
||||
i := i + 2
|
||||
when 'f' then
|
||||
a_output.append_character ('%F')
|
||||
i := i + 2
|
||||
when 'n' then
|
||||
a_output.append_character ('%N')
|
||||
i := i + 2
|
||||
when 'r' then
|
||||
a_output.append_character ('%R')
|
||||
i := i + 2
|
||||
when 't' then
|
||||
a_output.append_character ('%T')
|
||||
i := i + 2
|
||||
when 'u' then
|
||||
hex := s.substring (i + 2, i + 5) -- i+2 , i+2+4-1
|
||||
if hex.count = 4 then
|
||||
a_output.append_code (hexadecimal_to_natural_32 (hex))
|
||||
end
|
||||
i := i + 6 -- i+2+4
|
||||
else
|
||||
a_output.append_character (ch) -- '\'
|
||||
i := i + 1
|
||||
end
|
||||
else
|
||||
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
|
||||
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))
|
||||
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))
|
||||
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))
|
||||
end
|
||||
end
|
||||
i := i + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Visitor pattern
|
||||
|
||||
accept (a_visitor: JSON_VISITOR)
|
||||
@@ -185,12 +316,48 @@ feature -- Comparison
|
||||
|
||||
feature -- Change Element
|
||||
|
||||
append (a_string: STRING)
|
||||
-- Add a_string
|
||||
append (a_escaped_string: READABLE_STRING_8)
|
||||
-- Add JSON escaped string `a_escaped_string'
|
||||
require
|
||||
a_string_not_void: a_string /= Void
|
||||
a_escaped_string_not_void: a_escaped_string /= Void
|
||||
do
|
||||
item.append_string (a_string)
|
||||
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
|
||||
@@ -213,8 +380,18 @@ feature {NONE} -- Implementation
|
||||
|
||||
is_hexadecimal (s: READABLE_STRING_8): BOOLEAN
|
||||
-- Is `s' an hexadecimal value?
|
||||
local
|
||||
i: INTEGER
|
||||
do
|
||||
Result := across s as scur all scur.item.is_hexa_digit end
|
||||
from
|
||||
Result := True
|
||||
i := 1
|
||||
until
|
||||
i > s.count or not Result
|
||||
loop
|
||||
Result := s [i].is_hexa_digit
|
||||
i := i + 1
|
||||
end
|
||||
end
|
||||
|
||||
hexadecimal_to_natural_32 (s: READABLE_STRING_8): NATURAL_32
|
||||
@@ -227,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
|
||||
@@ -249,31 +424,7 @@ 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 '%R' then Result.append_string ("\r")
|
||||
when '%N' then Result.append_string ("\n")
|
||||
else
|
||||
Result.extend (c)
|
||||
end
|
||||
i := i + 1
|
||||
end
|
||||
end
|
||||
|
||||
escaped_json_string_32 (s: READABLE_STRING_32): STRING_8
|
||||
escaped_json_string (s: READABLE_STRING_GENERAL): STRING_8
|
||||
-- JSON string with '"' and '\' characters and unicode escaped
|
||||
require
|
||||
s_not_void: s /= Void
|
||||
@@ -285,15 +436,37 @@ 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 '%R' then Result.append_string ("\r")
|
||||
when '%N' then Result.append_string ("\n")
|
||||
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
|
||||
@@ -309,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
|
||||
@@ -326,4 +500,7 @@ feature {NONE} -- Implementation
|
||||
invariant
|
||||
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
|
||||
|
||||
@@ -14,11 +14,11 @@ note
|
||||
revision: "Revision 0.1"
|
||||
license: "MIT (see http://www.opensource.org/licenses/mit-license.php)"
|
||||
|
||||
|
||||
deferred class
|
||||
JSON_VALUE
|
||||
|
||||
inherit
|
||||
|
||||
HASHABLE
|
||||
|
||||
DEBUG_OUTPUT
|
||||
@@ -40,4 +40,7 @@ feature -- Visitor pattern
|
||||
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
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
4
contrib/library/text/parser/json/library/license.lic
Normal file
4
contrib/library/text/parser/json/library/license.lic
Normal 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"
|
||||
|
||||
679
contrib/library/text/parser/json/library/parser/json_parser.e
Normal file
679
contrib/library/text/parser/json/library/parser/json_parser.e
Normal 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
|
||||
@@ -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
|
||||
@@ -20,13 +20,19 @@ feature {NONE} -- Initialization
|
||||
|
||||
feature -- Commands
|
||||
|
||||
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
|
||||
reset
|
||||
end
|
||||
|
||||
read: CHARACTER
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -0,0 +1,61 @@
|
||||
note
|
||||
description: "JSON Iterator"
|
||||
pattern: "Iterator visitor"
|
||||
author: "Jocelyn Fiat"
|
||||
license: "MIT (see http://www.opensource.org/licenses/mit-license.php)"
|
||||
date: "2013/08/01"
|
||||
revision: "Revision 0.1"
|
||||
|
||||
deferred class
|
||||
JSON_ITERATOR
|
||||
|
||||
inherit
|
||||
|
||||
JSON_VISITOR
|
||||
|
||||
feature -- Visitor Pattern
|
||||
|
||||
visit_json_array (a_json_array: JSON_ARRAY)
|
||||
-- Visit `a_json_array'.
|
||||
do
|
||||
across
|
||||
a_json_array as c
|
||||
loop
|
||||
c.item.accept (Current)
|
||||
end
|
||||
end
|
||||
|
||||
visit_json_boolean (a_json_boolean: JSON_BOOLEAN)
|
||||
-- Visit `a_json_boolean'.
|
||||
do
|
||||
end
|
||||
|
||||
visit_json_null (a_json_null: JSON_NULL)
|
||||
-- Visit `a_json_null'.
|
||||
do
|
||||
end
|
||||
|
||||
visit_json_number (a_json_number: JSON_NUMBER)
|
||||
-- Visit `a_json_number'.
|
||||
do
|
||||
end
|
||||
|
||||
visit_json_object (a_json_object: JSON_OBJECT)
|
||||
-- Visit `a_json_object'.
|
||||
do
|
||||
across
|
||||
a_json_object as c
|
||||
loop
|
||||
c.item.accept (Current)
|
||||
end
|
||||
end
|
||||
|
||||
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
|
||||
@@ -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
|
||||
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 `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
|
||||
@@ -1,8 +1,5 @@
|
||||
note
|
||||
description:
|
||||
|
||||
"JSON Visitor"
|
||||
|
||||
description: "JSON Visitor"
|
||||
pattern: "Visitor"
|
||||
author: "Javier Velilla"
|
||||
license: "MIT (see http://www.opensource.org/licenses/mit-license.php)"
|
||||
@@ -56,4 +53,7 @@ feature -- Visitor Pattern
|
||||
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
|
||||
@@ -8,9 +8,11 @@ class
|
||||
PRINT_JSON_VISITOR
|
||||
|
||||
inherit
|
||||
|
||||
JSON_VISITOR
|
||||
|
||||
create make
|
||||
create
|
||||
make
|
||||
|
||||
feature -- Initialization
|
||||
|
||||
@@ -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
|
||||
16
contrib/library/text/parser/json/package.iron
Normal file
16
contrib/library/text/parser/json/package.iron
Normal 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
|
||||
@@ -7,6 +7,7 @@ class
|
||||
APPLICATION
|
||||
|
||||
inherit
|
||||
|
||||
ARGUMENTS
|
||||
|
||||
create
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
class AUTHOR
|
||||
class
|
||||
AUTHOR
|
||||
|
||||
create
|
||||
make
|
||||
@@ -6,19 +7,26 @@ create
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
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
|
||||
-- Author name
|
||||
|
||||
feature -- Status setting
|
||||
feature -- Change
|
||||
|
||||
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
|
||||
|
||||
@@ -1,40 +1,59 @@
|
||||
class BOOK
|
||||
class
|
||||
BOOK
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make (a_title: STRING_32; an_author: AUTHOR; an_isbn: STRING_32)
|
||||
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 (an_author)
|
||||
set_isbn (an_isbn)
|
||||
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
|
||||
-- Main title.
|
||||
|
||||
isbn: STRING_32
|
||||
-- ISBN.
|
||||
|
||||
author: AUTHOR
|
||||
-- Author.
|
||||
|
||||
feature -- Status setting
|
||||
feature -- Change
|
||||
|
||||
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)
|
||||
set_author (a_author: AUTHOR)
|
||||
-- Set `author' with `a_author'.
|
||||
do
|
||||
author := an_author
|
||||
author := a_author
|
||||
ensure
|
||||
author_set: author = a_author
|
||||
end
|
||||
|
||||
set_isbn (an_isbn: STRING_32)
|
||||
set_isbn (a_isbn: STRING_32)
|
||||
-- Set `isbn' with `a_isbn'.
|
||||
do
|
||||
isbn := an_isbn
|
||||
isbn := a_isbn
|
||||
ensure
|
||||
isbn_set: isbn = a_isbn
|
||||
end
|
||||
|
||||
end -- class BOOK
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
class BOOK_COLLECTION
|
||||
class
|
||||
BOOK_COLLECTION
|
||||
|
||||
create
|
||||
make
|
||||
@@ -6,75 +7,76 @@ create
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
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.
|
||||
|
||||
books: LIST [BOOK]
|
||||
-- collection of book.
|
||||
do
|
||||
from
|
||||
create {LINKED_LIST [BOOK]} Result.make
|
||||
book_index.start
|
||||
until
|
||||
book_index.after
|
||||
across
|
||||
book_index as it
|
||||
loop
|
||||
Result.append (book_index.item_for_iteration)
|
||||
book_index.forth
|
||||
Result.append (it.item)
|
||||
end
|
||||
end
|
||||
|
||||
books_by_author (an_author: STRING_32): detachable LIST [BOOK]
|
||||
books_by_author (a_author: STRING_32): LIST [BOOK]
|
||||
-- Books wrote by `a_author' in this collection.
|
||||
do
|
||||
if book_index.has (an_author) then
|
||||
Result := book_index @ an_author
|
||||
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)
|
||||
-- Set `name' with `a_name'.
|
||||
do
|
||||
name := a_name
|
||||
ensure
|
||||
name_set: name = a_name
|
||||
end
|
||||
|
||||
add_book (a_book: BOOK)
|
||||
-- Extend collection with `a_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
|
||||
if l = Void then
|
||||
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
|
||||
|
||||
l.force (a_book)
|
||||
end
|
||||
|
||||
add_books (book_list: like books)
|
||||
|
||||
-- Append collection with `book_list'.
|
||||
do
|
||||
from
|
||||
book_list.start
|
||||
until
|
||||
book_list.after
|
||||
across
|
||||
book_list as it
|
||||
loop
|
||||
add_book (book_list.item)
|
||||
book_list.forth
|
||||
add_book (it.item)
|
||||
end
|
||||
end
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
book_index: HASH_TABLE [LIST [BOOK], STRING_32]
|
||||
-- Association of author name and its books.
|
||||
|
||||
end -- class BOOK_COLLECTION
|
||||
|
||||
@@ -4,9 +4,11 @@ note
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class JSON_AUTHOR_CONVERTER
|
||||
class
|
||||
JSON_AUTHOR_CONVERTER
|
||||
|
||||
inherit
|
||||
|
||||
JSON_CONVERTER
|
||||
|
||||
create
|
||||
@@ -29,12 +31,10 @@ feature -- Access
|
||||
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)
|
||||
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
|
||||
@@ -46,8 +46,9 @@ feature -- Conversion
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
name_key: JSON_STRING
|
||||
-- Author's name label.
|
||||
once
|
||||
create Result.make_json ("name")
|
||||
create Result.make_from_string ("name")
|
||||
end
|
||||
|
||||
end -- class JSON_AUTHOR_CONVERTER
|
||||
|
||||
@@ -4,9 +4,11 @@ note
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class JSON_BOOK_COLLECTION_CONVERTER
|
||||
class
|
||||
JSON_BOOK_COLLECTION_CONVERTER
|
||||
|
||||
inherit
|
||||
|
||||
JSON_CONVERTER
|
||||
|
||||
create
|
||||
@@ -30,35 +32,35 @@ 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
|
||||
l_books: LINKED_LIST [BOOK]
|
||||
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
|
||||
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
|
||||
i > ja.count
|
||||
Result = Void
|
||||
loop
|
||||
b ?= json.object (ja [i], "BOOK")
|
||||
check b /= Void end
|
||||
ll.force (b)
|
||||
i := i + 1
|
||||
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
|
||||
check ll /= Void end
|
||||
Result.add_books (ll)
|
||||
end
|
||||
|
||||
to_json (o: like object): JSON_OBJECT
|
||||
do
|
||||
create Result.make
|
||||
create Result.make_with_capacity (2)
|
||||
Result.put (json.value (o.name), name_key)
|
||||
Result.put (json.value (o.books), books_key)
|
||||
end
|
||||
@@ -66,13 +68,15 @@ feature -- Conversion
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
name_key: JSON_STRING
|
||||
-- Collection's name label.
|
||||
once
|
||||
create Result.make_json ("name")
|
||||
create Result.make_from_string ("name")
|
||||
end
|
||||
|
||||
books_key: JSON_STRING
|
||||
-- Book list label.
|
||||
once
|
||||
create Result.make_json ("books")
|
||||
create Result.make_from_string ("books")
|
||||
end
|
||||
|
||||
end -- class JSON_BOOK_COLLECTION_CONVERTER
|
||||
|
||||
@@ -4,9 +4,11 @@ note
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class JSON_BOOK_CONVERTER
|
||||
class
|
||||
JSON_BOOK_CONVERTER
|
||||
|
||||
inherit
|
||||
|
||||
JSON_CONVERTER
|
||||
|
||||
create
|
||||
@@ -31,22 +33,19 @@ feature -- Access
|
||||
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)
|
||||
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
|
||||
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)
|
||||
@@ -55,18 +54,21 @@ feature -- Conversion
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
title_key: JSON_STRING
|
||||
-- Book's title label.
|
||||
once
|
||||
create Result.make_json ("title")
|
||||
create Result.make_from_string ("title")
|
||||
end
|
||||
|
||||
isbn_key: JSON_STRING
|
||||
-- Book ISBN label.
|
||||
once
|
||||
create Result.make_json ("isbn")
|
||||
create Result.make_from_string ("isbn")
|
||||
end
|
||||
|
||||
author_key: JSON_STRING
|
||||
-- Author label.
|
||||
once
|
||||
create Result.make_json ("author")
|
||||
create Result.make_from_string ("author")
|
||||
end
|
||||
|
||||
end -- class JSON_BOOK_CONVERTER
|
||||
|
||||
@@ -1,73 +1,71 @@
|
||||
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
|
||||
-- Convert a linked list to a json value and
|
||||
-- convert this one to a linked list.
|
||||
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)
|
||||
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
|
||||
-- Convert a hash table to a json value and
|
||||
-- convert this one to a hash table.
|
||||
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
|
||||
l_ucs_key: detachable STRING_32
|
||||
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)
|
||||
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 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"))
|
||||
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
|
||||
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"))
|
||||
else
|
||||
assert ("JSON object converted to HASH_TABLE", False);
|
||||
end
|
||||
|
||||
else
|
||||
assert ("HASH_TABLE converted to a JSON value", False)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1,10 +1,19 @@
|
||||
class TEST_JSON_CORE
|
||||
class
|
||||
TEST_JSON_CORE
|
||||
|
||||
inherit
|
||||
|
||||
SHARED_EJSON
|
||||
rename default_create as shared_default_create end
|
||||
undefine
|
||||
default_create
|
||||
end
|
||||
|
||||
EQA_TEST_SET
|
||||
select default_create end
|
||||
|
||||
JSON_PARSER_ACCESS
|
||||
undefine
|
||||
default_create
|
||||
end
|
||||
|
||||
feature -- Test
|
||||
|
||||
@@ -31,15 +40,15 @@ feature -- Test
|
||||
-- that can represent the value of the JSON number, in this case
|
||||
-- we know it is INTEGER_8 since the value is 42
|
||||
jrep := "42"
|
||||
create parser.make_parser (jrep)
|
||||
if attached {JSON_NUMBER} parser.parse as l_jn then
|
||||
create parser.make_with_string (jrep)
|
||||
if attached {JSON_NUMBER} parser.next_parsed_json_value as l_jn then
|
||||
if attached {INTEGER_8} json.object (jn, Void) as l_i8 then
|
||||
assert ("l_i8 = 42", l_i8 = 42)
|
||||
else
|
||||
assert ("json.object (jn, Void) is a INTEGER_8", False)
|
||||
end
|
||||
else
|
||||
assert ("parser.parse is a JSON_NUMBER", False)
|
||||
assert ("parser.next_parsed_json_value is a JSON_NUMBER", False)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -66,15 +75,15 @@ feature -- Test
|
||||
-- that can represent the value of the JSON number, in this case
|
||||
-- we know it is INTEGER_8 since the value is 42
|
||||
jrep := "42"
|
||||
create parser.make_parser (jrep)
|
||||
if attached {JSON_NUMBER} parser.parse as l_jn then
|
||||
create parser.make_with_string (jrep)
|
||||
if attached {JSON_NUMBER} parser.next_parsed_json_value as l_jn then
|
||||
if attached {INTEGER_8} json.object (jn, Void) as l_i8 then
|
||||
assert ("l_i8 = 42", l_i8 = 42)
|
||||
else
|
||||
assert ("json.object (jn, Void) is a INTEGER_8", False)
|
||||
end
|
||||
else
|
||||
assert ("parser.parse is a JSON_NUMBER", False)
|
||||
assert ("parser.next_parsed_json_value is a JSON_NUMBER", False)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -101,15 +110,15 @@ feature -- Test
|
||||
-- that can represent the value of the JSON number, in this case
|
||||
-- we know it is INTEGER_16 since the value is 300
|
||||
jrep := "300"
|
||||
create parser.make_parser (jrep)
|
||||
if attached {JSON_NUMBER} parser.parse as l_jn then
|
||||
create parser.make_with_string (jrep)
|
||||
if attached {JSON_NUMBER} parser.next_parsed_json_value as l_jn then
|
||||
if attached {INTEGER_16} json.object (jn, Void) as l_i16 then
|
||||
assert ("l_i16 = 300", l_i16 = 300)
|
||||
else
|
||||
assert ("json.object (jn, Void) is a INTEGER_16", False)
|
||||
end
|
||||
else
|
||||
assert ("parser.parse is a JSON_NUMBER", False)
|
||||
assert ("parser.next_parsed_json_value is a JSON_NUMBER", False)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -136,15 +145,15 @@ feature -- Test
|
||||
-- that can represent the value of the JSON number, in this case
|
||||
-- we know it is INTEGER_32 since the value is 100000
|
||||
jrep := "100000"
|
||||
create parser.make_parser (jrep)
|
||||
if attached {JSON_NUMBER} parser.parse as l_jn then
|
||||
create parser.make_with_string (jrep)
|
||||
if attached {JSON_NUMBER} parser.next_parsed_json_value as l_jn then
|
||||
if attached {INTEGER_32} json.object (jn, Void) as l_i32 then
|
||||
assert ("l_i32 = 100000", l_i32 = 100000)
|
||||
else
|
||||
assert ("json.object (jn, Void) is a INTEGER_32", False)
|
||||
end
|
||||
else
|
||||
assert ("parser.parse is a JSON_NUMBER", False)
|
||||
assert ("parser.next_parsed_json_value is a JSON_NUMBER", False)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -171,15 +180,15 @@ feature -- Test
|
||||
-- that can represent the value of the JSON number, in this case
|
||||
-- we know it is INTEGER_32 since the value is 42949672960
|
||||
jrep := "42949672960"
|
||||
create parser.make_parser (jrep)
|
||||
if attached {JSON_NUMBER} parser.parse as l_jn then
|
||||
create parser.make_with_string (jrep)
|
||||
if attached {JSON_NUMBER} parser.next_parsed_json_value as l_jn then
|
||||
if attached {INTEGER_64} json.object (jn, Void) as l_i64 then
|
||||
assert ("l_i64 = 42949672960", l_i64 = 42949672960)
|
||||
else
|
||||
assert ("json.object (jn, Void) is a INTEGER_64", False)
|
||||
end
|
||||
else
|
||||
assert ("parser.parse is a JSON_NUMBER", False)
|
||||
assert ("parser.next_parsed_json_value is a JSON_NUMBER", False)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -206,15 +215,15 @@ feature -- Test
|
||||
-- that can represent the value of the JSON number, in this case
|
||||
-- we know it is INTEGER_16 since the value is 200
|
||||
jrep := "200"
|
||||
create parser.make_parser (jrep)
|
||||
if attached {JSON_NUMBER} parser.parse as l_jn then
|
||||
create parser.make_with_string (jrep)
|
||||
if attached {JSON_NUMBER} parser.next_parsed_json_value as l_jn then
|
||||
if attached {INTEGER_16} json.object (jn, Void) as i16 then
|
||||
assert ("i16 = 200", i16 = 200)
|
||||
else
|
||||
assert ("json.object (jn, Void) is an INTEGER_16", False)
|
||||
end
|
||||
else
|
||||
assert ("parser.parse is a JSON_NUMBER", False)
|
||||
assert ("parser.next_parsed_json_value is a JSON_NUMBER", False)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -241,15 +250,15 @@ feature -- Test
|
||||
-- that can represent the value of the JSON number, in this case
|
||||
-- we know it is INTEGER_32 since the value is 32768
|
||||
jrep := "32768"
|
||||
create parser.make_parser (jrep)
|
||||
if attached {JSON_NUMBER} parser.parse as l_jn then
|
||||
create parser.make_with_string (jrep)
|
||||
if attached {JSON_NUMBER} parser.next_parsed_json_value as l_jn then
|
||||
if attached {INTEGER_32} json.object (jn, Void) as i32 then
|
||||
assert ("i32 = 32768", i32 = 32768)
|
||||
else
|
||||
assert ("json.object (jn, Void) is a INTEGER_32", False)
|
||||
end
|
||||
else
|
||||
assert ("parser.parse is a JSON_NUMBER", False)
|
||||
assert ("parser.next_parsed_json_value is a JSON_NUMBER", False)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -276,15 +285,15 @@ feature -- Test
|
||||
-- that can represent the value of the JSON number, in this case
|
||||
-- we know it is INTEGER_64 since the value is 2147483648
|
||||
jrep := "2147483648"
|
||||
create parser.make_parser (jrep)
|
||||
if attached {JSON_NUMBER} parser.parse as l_jn then
|
||||
create parser.make_with_string (jrep)
|
||||
if attached {JSON_NUMBER} parser.next_parsed_json_value as l_jn then
|
||||
if attached {INTEGER_64} json.object (jn, Void) as i64 then
|
||||
assert ("i64 = 2147483648", i64 = 2147483648)
|
||||
else
|
||||
assert ("json.object (jn, Void) is a INTEGER_64", False)
|
||||
end
|
||||
else
|
||||
assert ("parser.parse is a JSON_NUMBER", False)
|
||||
assert ("parser.next_parsed_json_value is a JSON_NUMBER", False)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -311,15 +320,15 @@ feature -- Test
|
||||
-- that can represent the value of the JSON number, in this case
|
||||
-- we know it is INTEGER_32 since the value is 42949672960
|
||||
jrep := "9223372036854775808" -- 1 higher than largest positive number that can be represented by INTEGER 64
|
||||
create parser.make_parser (jrep)
|
||||
if attached {JSON_NUMBER} parser.parse as l_jn then
|
||||
create parser.make_with_string (jrep)
|
||||
if attached {JSON_NUMBER} parser.next_parsed_json_value as l_jn then
|
||||
if attached {NATURAL_64} json.object (jn, Void) as l_n64 then
|
||||
assert ("l_n64 = 9223372036854775808", l_n64 = 9223372036854775808)
|
||||
else
|
||||
assert ("json.object (jn, Void) is a NATURAL_64", False)
|
||||
end
|
||||
else
|
||||
assert ("parser.parse is a JSON_NUMBER", False)
|
||||
assert ("parser.next_parsed_json_value is a JSON_NUMBER", False)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -345,15 +354,15 @@ feature -- Test
|
||||
-- Note: The JSON_FACTORY will always return a REAL_64 if the value
|
||||
-- of the JSON number is a floating point number
|
||||
jrep := "3.14"
|
||||
create parser.make_parser (jrep)
|
||||
if attached {JSON_NUMBER} parser.parse as l_jn then
|
||||
create parser.make_with_string (jrep)
|
||||
if attached {JSON_NUMBER} parser.next_parsed_json_value as l_jn then
|
||||
if attached {REAL_64} json.object (jn, Void) as r64 then
|
||||
assert ("3.14 <= r64 and r64 <= 3.141", 3.14 <= r64 and r64 <= 3.141)
|
||||
else
|
||||
assert ("json.object (jn, Void) is a REAL_64", False)
|
||||
end
|
||||
else
|
||||
assert ("parser.parse is a JSON_NUMBER", False)
|
||||
assert ("parser.next_parsed_json_value is a JSON_NUMBER", False)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -377,15 +386,15 @@ feature -- Test
|
||||
|
||||
-- JSON representation -> JSON value -> Eiffel value
|
||||
jrep := "3.1400001049041748"
|
||||
create parser.make_parser (jrep)
|
||||
if attached {JSON_NUMBER} parser.parse as l_jn then
|
||||
create parser.make_with_string (jrep)
|
||||
if attached {JSON_NUMBER} parser.next_parsed_json_value as l_jn then
|
||||
if attached {REAL_64} json.object (l_jn, Void) as r64 then
|
||||
assert ("r64 = 3.1400001049041748", r64 = 3.1400001049041748)
|
||||
else
|
||||
assert ("json.object (l_jn, Void) is a REAL_64", False)
|
||||
end
|
||||
else
|
||||
assert ("parser.parse is a JSON_NUMBER", False)
|
||||
assert ("parser.next_parsed_json_value is a JSON_NUMBER", False)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -410,15 +419,15 @@ feature -- Test
|
||||
|
||||
-- JSON representation -> JSON value -> Eiffel value
|
||||
jrep := "3.1415926535897931"
|
||||
create parser.make_parser (jrep)
|
||||
if attached {JSON_NUMBER} parser.parse as l_jn then
|
||||
create parser.make_with_string (jrep)
|
||||
if attached {JSON_NUMBER} parser.next_parsed_json_value as l_jn then
|
||||
if attached {REAL_64} json.object (jn, Void) as l_r64 then
|
||||
assert ("l_r64 = 3.1415926535897931", l_r64 = 3.1415926535897931)
|
||||
else
|
||||
assert ("json.object (jn, Void) is a REAL_64", False)
|
||||
end
|
||||
else
|
||||
assert ("parser.parse is a JSON_NUMBER", False)
|
||||
assert ("parser.next_parsed_json_value is a JSON_NUMBER", False)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -430,7 +439,7 @@ feature -- Test
|
||||
do
|
||||
-- Eiffel value -> JSON value -> JSON representation
|
||||
b := True
|
||||
create jb.make_boolean (b)
|
||||
create jb.make (b)
|
||||
assert ("jb.representation.is_equal (%"true%")", jb.representation.is_equal ("true"))
|
||||
-- Eiffel value -> JSON value -> JSON representation with factory
|
||||
if attached {JSON_BOOLEAN} json.value (b) as l_jb then
|
||||
@@ -440,20 +449,20 @@ feature -- Test
|
||||
end
|
||||
|
||||
-- JSON representation -> JSON value -> Eiffel value
|
||||
create parser.make_parser ("true")
|
||||
if attached {JSON_BOOLEAN} parser.parse as l_jb then
|
||||
create parser.make_with_string ("true")
|
||||
if attached {JSON_BOOLEAN} parser.next_parsed_json_value as l_jb then
|
||||
if attached {BOOLEAN} json.object (l_jb, Void) as l_b then
|
||||
assert ("l_b = True", l_b = True)
|
||||
else
|
||||
assert ("json.object (l_jb, Void) is BOOLEAN", False)
|
||||
end
|
||||
else
|
||||
assert ("parser.parse is a JSON_BOOLEAN", False)
|
||||
assert ("parser.next_parsed_json_value is a JSON_BOOLEAN", False)
|
||||
end
|
||||
|
||||
-- Eiffel value -> JSON value -> JSON representation
|
||||
b := False
|
||||
create jb.make_boolean (b)
|
||||
create jb.make (b)
|
||||
assert ("jb.representation.same_string (%"false%")", jb.representation.same_string ("false"))
|
||||
-- Eiffel value -> JSON value -> JSON representation with factory
|
||||
if attached {JSON_BOOLEAN} json.value (b) as l_jb then
|
||||
@@ -463,78 +472,72 @@ feature -- Test
|
||||
end
|
||||
|
||||
-- JSON representation -> JSON value -> Eiffel value
|
||||
create parser.make_parser ("false")
|
||||
if attached {JSON_BOOLEAN} parser.parse as l_jb then
|
||||
create parser.make_with_string ("false")
|
||||
if attached {JSON_BOOLEAN} parser.next_parsed_json_value as l_jb then
|
||||
if attached {BOOLEAN} json.object (l_jb, Void) as l_b then
|
||||
assert ("l_b = False", l_b = False)
|
||||
else
|
||||
assert ("json.object (l_jb, Void) is a BOOLEAN", False)
|
||||
end
|
||||
else
|
||||
assert ("parser.parse is a JSON_BOOLEAN", False)
|
||||
assert ("parser.next_parsed_json_value is a JSON_BOOLEAN", False)
|
||||
end
|
||||
end
|
||||
|
||||
test_json_null
|
||||
local
|
||||
a: detachable ANY
|
||||
dummy_object: STRING
|
||||
jn: detachable JSON_NULL
|
||||
jrep: STRING
|
||||
jn: JSON_NULL
|
||||
parser: JSON_PARSER
|
||||
do
|
||||
-- Eiffel value -> JSON value -> JSON representation
|
||||
create jn
|
||||
assert ("jn /= Void", jn /= Void)
|
||||
assert ("jn.representation.is_equal (%"%"null%"%")", jn.representation.is_equal ("null"))
|
||||
jrep := "null"
|
||||
assert ("jn.representation.is_equal (%"%"null%"%")", jn.representation.is_equal (jrep))
|
||||
-- Eiffel value -> JSON value -> JSON representation with factory
|
||||
jn ?= json.value (Void)
|
||||
assert ("jn /= Void", jn /= Void)
|
||||
if attached jn as l_jn then
|
||||
assert ("jn.representation.is_equal (%"null%")", l_jn.representation.is_equal ("null"))
|
||||
if attached {JSON_NULL} json.value (Void) as l_json_null then
|
||||
assert ("jn.representation.is_equal (%"null%")", l_json_null.representation.is_equal ("null"))
|
||||
else
|
||||
assert ("json.value (Void) /= Void", False)
|
||||
end
|
||||
|
||||
-- JSON representation -> JSON value -> Eiffel value
|
||||
jrep := "null"
|
||||
create parser.make_parser (jrep)
|
||||
jn := Void
|
||||
jn ?= parser.parse
|
||||
assert ("jn /= Void", jn /= Void)
|
||||
create dummy_object.make_empty
|
||||
a := dummy_object
|
||||
a ?= json.object (jn, Void)
|
||||
assert ("a = Void", a = Void)
|
||||
create parser.make_with_string (jrep)
|
||||
if attached parser.next_parsed_json_value as l_json_null then
|
||||
assert ("a = Void", json.object (l_json_null, Void) = Void)
|
||||
else
|
||||
assert ("parser.next_parsed_json_value /= Void", False)
|
||||
end
|
||||
end
|
||||
|
||||
test_json_string_and_character
|
||||
local
|
||||
c: CHARACTER
|
||||
js: detachable JSON_STRING
|
||||
jrep: STRING
|
||||
js: JSON_STRING
|
||||
parser: JSON_PARSER
|
||||
do
|
||||
c := 'a'
|
||||
-- Eiffel value -> JSON value -> JSON representation
|
||||
create js.make_json (c.out)
|
||||
assert ("js /= Void", js /= Void)
|
||||
create js.make_from_string (c.out)
|
||||
assert ("js.representation.is_equal (%"%"a%"%")", js.representation.is_equal ("%"a%""))
|
||||
-- Eiffel value -> JSON value -> JSON representation with factory
|
||||
js ?= json.value (c)
|
||||
assert ("js /= Void", js /= Void)
|
||||
if attached js as l_js then
|
||||
assert ("js.representation.is_equal (%"%"a%"%")", l_js.representation.is_equal ("%"a%""))
|
||||
if attached {JSON_STRING} json.value (c) as l_json_str then
|
||||
assert ("js.representation.is_equal (%"%"a%"%")", l_json_str.representation.is_equal ("%"a%""))
|
||||
else
|
||||
assert ("json.value (c) /= Void", False)
|
||||
end
|
||||
|
||||
-- JSON representation -> JSON value -> Eiffel value
|
||||
jrep := "%"a%""
|
||||
create parser.make_parser (jrep)
|
||||
js := Void
|
||||
js ?= parser.parse
|
||||
assert ("js /= Void", js /= Void)
|
||||
if attached {STRING_32} json.object (js, Void) as ucs then
|
||||
create parser.make_with_string (jrep)
|
||||
if attached {JSON_STRING} parser.next_parsed_json_value as l_json_str then
|
||||
if attached {STRING_32} json.object (l_json_str, Void) as ucs then
|
||||
assert ("ucs.string.is_equal (%"a%")", ucs.string.is_equal ("a"))
|
||||
end
|
||||
|
||||
else
|
||||
assert ("parser.next_parsed_json_value /= Void", False)
|
||||
end
|
||||
end
|
||||
|
||||
test_json_string_and_string
|
||||
@@ -545,25 +548,26 @@ feature -- Test
|
||||
parser: JSON_PARSER
|
||||
do
|
||||
s := "foobar"
|
||||
jrep := "%"foobar%""
|
||||
|
||||
-- Eiffel value -> JSON value -> JSON representation
|
||||
create js.make_json (s)
|
||||
assert ("js /= Void", js /= Void)
|
||||
assert ("js.representation.is_equal (%"%"foobar%"%")", js.representation.is_equal ("%"foobar%""))
|
||||
create js.make_from_string (s)
|
||||
assert ("js.representation.is_equal (%"%"foobar%"%")", js.representation.is_equal (jrep))
|
||||
-- Eiffel value -> JSON value -> JSON representation with factory
|
||||
js ?= json.value (s)
|
||||
assert ("js /= Void", js /= Void)
|
||||
if attached js as l_js then
|
||||
assert ("js.representation.is_equal (%"%"foobar%"%")", js.representation.is_equal ("%"foobar%""))
|
||||
if attached {JSON_STRING} json.value (s) as l_js then
|
||||
assert ("js.representation.is_equal (%"%"foobar%"%")", js.representation.is_equal (jrep))
|
||||
else
|
||||
assert ("json.value (s) /= Void", False)
|
||||
end
|
||||
|
||||
-- JSON representation -> JSON value -> Eiffel value
|
||||
jrep := "%"foobar%""
|
||||
create parser.make_parser (jrep)
|
||||
js := Void
|
||||
js ?= parser.parse
|
||||
assert ("js /= Void", js /= Void)
|
||||
if attached {STRING_32} json.object (js, Void) as l_ucs then
|
||||
assert ("ucs.string.is_equal (%"foobar%")", l_ucs.string.is_equal ("foobar"))
|
||||
create parser.make_with_string (jrep)
|
||||
if attached {JSON_STRING} parser.next_parsed_json_value as l_js then
|
||||
if attached {STRING_32} json.object (l_js, Void) as l_ucs then
|
||||
assert ("ucs.string.is_equal (%"foobar%")", l_ucs.string.is_equal (s))
|
||||
end
|
||||
else
|
||||
assert ("parser.next_parsed_json_value /= Void", False)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -571,31 +575,34 @@ feature -- Test
|
||||
local
|
||||
js: detachable JSON_STRING
|
||||
ucs: detachable STRING_32
|
||||
jrep: STRING
|
||||
jrep, s: STRING
|
||||
parser: JSON_PARSER
|
||||
do
|
||||
create ucs.make_from_string ("foobar")
|
||||
s := "foobar"
|
||||
jrep := "%"foobar%""
|
||||
create ucs.make_from_string (s)
|
||||
|
||||
-- Eiffel value -> JSON value -> JSON representation
|
||||
create js.make_json (ucs)
|
||||
assert ("js /= Void", js /= Void)
|
||||
assert ("js.representation.is_equal (%"%"foobar%"%")", js.representation.is_equal ("%"foobar%""))
|
||||
create js.make_from_string (ucs)
|
||||
assert ("js.representation.is_equal (%"%"foobar%"%")", js.representation.is_equal (jrep))
|
||||
|
||||
-- Eiffel value -> JSON value -> JSON representation with factory
|
||||
js ?= json.value (ucs)
|
||||
assert ("js /= Void", js /= Void)
|
||||
if attached js as l_js then
|
||||
assert ("js.representation.is_equal (%"%"foobar%"%")", l_js.representation.is_equal ("%"foobar%""))
|
||||
if attached {JSON_STRING} json.value (ucs) as l_js then
|
||||
assert ("js.representation.is_equal (%"%"foobar%"%")", l_js.representation.is_equal (jrep))
|
||||
else
|
||||
assert ("json.value (ucs) /= Void", False)
|
||||
end
|
||||
|
||||
-- JSON representation -> JSON value -> Eiffel value
|
||||
jrep := "%"foobar%""
|
||||
create parser.make_parser (jrep)
|
||||
js := Void
|
||||
js ?= parser.parse
|
||||
assert ("js /= Void", js /= Void)
|
||||
ucs := Void
|
||||
ucs ?= json.object (js, Void)
|
||||
if attached ucs as l_ucs then
|
||||
assert ("ucs.string.is_equal (%"foobar%")", l_ucs.string.is_equal ("foobar"))
|
||||
create parser.make_with_string (jrep)
|
||||
if attached {JSON_STRING} parser.next_parsed_json_value as l_js then
|
||||
if attached {STRING_32} json.object (l_js, Void) as l_ucs then
|
||||
assert ("ucs.string.is_equal (%"foobar%")", l_ucs.string.is_equal (s))
|
||||
else
|
||||
assert ("json.object (js, Void) /= Void", False)
|
||||
end
|
||||
else
|
||||
assert ("parser.next_parsed_json_value /= Void", False)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -603,52 +610,103 @@ feature -- Test
|
||||
local
|
||||
js: detachable JSON_STRING
|
||||
s: detachable STRING_8
|
||||
ucs: detachable STRING_32
|
||||
jrep: STRING
|
||||
parser: JSON_PARSER
|
||||
do
|
||||
jrep := "%"foo\\bar%""
|
||||
create s.make_from_string ("foo\bar")
|
||||
create js.make_json (s)
|
||||
|
||||
assert ("js.representation.same_string (%"%"foo\\bar%"%")", js.representation.same_string ("%"foo\\bar%""))
|
||||
create js.make_from_string (s)
|
||||
assert ("js.representation.same_string (%"%"foo\\bar%"%")", js.representation.same_string (jrep))
|
||||
|
||||
-- Eiffel value -> JSON value -> JSON representation with factory
|
||||
js ?= json.value (s)
|
||||
assert ("js /= Void", js /= Void)
|
||||
if js /= Void then
|
||||
assert ("js.representation.is_equal (%"%"foobar%"%")", js.representation.same_string ("%"foo\\bar%""))
|
||||
if attached {JSON_STRING} json.value (s) as l_js then
|
||||
assert ("js.representation.is_equal (%"%"foobar%"%")", l_js.representation.same_string (jrep))
|
||||
else
|
||||
assert ("json.value (s) /= Void", False)
|
||||
end
|
||||
|
||||
-- JSON representation -> JSON value -> Eiffel value
|
||||
jrep := "%"foo\\bar%""
|
||||
create parser.make_parser (jrep)
|
||||
js ?= parser.parse
|
||||
assert ("js /= Void", js /= Void)
|
||||
ucs ?= json.object (js, Void)
|
||||
if ucs /= Void then
|
||||
assert ("ucs.same_string (%"foo\bar%")", ucs.same_string ("foo\bar"))
|
||||
create parser.make_with_string (jrep)
|
||||
if attached {JSON_STRING} parser.next_parsed_json_value as l_js then
|
||||
if attached {STRING_32} json.object (l_js, Void) as l_ucs then
|
||||
assert ("ucs.same_string (%"foo\bar%")", l_ucs.same_string ("foo\bar"))
|
||||
end
|
||||
else
|
||||
assert ("parser.next_parsed_json_value /= Void", False)
|
||||
end
|
||||
|
||||
jrep := "%"foo\\bar%""
|
||||
create parser.make_parser (jrep)
|
||||
if attached {JSON_STRING} parser.parse as jstring then
|
||||
create parser.make_with_string (jrep)
|
||||
if attached {JSON_STRING} parser.next_parsed_json_value as jstring then
|
||||
assert ("unescaped string %"foo\\bar%" to %"foo\bar%"", jstring.unescaped_string_8.same_string ("foo\bar"))
|
||||
else
|
||||
assert ("parser.next_parsed_json_value /= Void", False)
|
||||
end
|
||||
|
||||
create js.make_json_from_string_32 ({STRING_32}"%/20320/%/22909/")
|
||||
create js.make_from_string_32 ({STRING_32} "你好")
|
||||
assert ("escaping unicode string32 %"%%/20320/%%/22909/%" %"\u4F60\u597D%"", js.item.same_string ("\u4F60\u597D"))
|
||||
|
||||
jrep := "%"\u4F60\u597D%"" --| Ni hao
|
||||
create parser.make_parser (jrep)
|
||||
if attached {JSON_STRING} parser.parse as jstring then
|
||||
assert ("same unicode string32 %"%%/20320/%%/22909/%"", jstring.unescaped_string_32.same_string ({STRING_32}"%/20320/%/22909/"))
|
||||
create parser.make_with_string (jrep)
|
||||
if attached {JSON_STRING} parser.next_parsed_json_value as jstring then
|
||||
assert ("same unicode string32 %"%%/20320/%%/22909/%"", jstring.unescaped_string_32.same_string ({STRING_32} "你好"))
|
||||
else
|
||||
assert ("parser.next_parsed_json_value /= Void", False)
|
||||
end
|
||||
end
|
||||
|
||||
test_json_string_and_special_characters_2
|
||||
local
|
||||
js: detachable JSON_STRING
|
||||
s,j: STRING
|
||||
do
|
||||
s := "foo%Tbar"
|
||||
j := "foo\tbar"
|
||||
create js.make_from_string (s)
|
||||
assert ("string %"" + s + "%" to json %"" + j + "%"", js.item.same_string (j))
|
||||
create js.make_from_escaped_json_string (js.item)
|
||||
assert ("json %"" + j + "%" to string %"" + s + "%"", js.unescaped_string_8.same_string (s))
|
||||
|
||||
s := "tab=%T cr=%R newline=%N backslash=%H slash=/ end"
|
||||
j := "tab=\t cr=\r newline=\n backslash=\\ slash=/ end"
|
||||
create js.make_from_string (s)
|
||||
assert ("string %"" + s + "%" to json %"" + j + "%"", js.item.same_string (j))
|
||||
create js.make_from_escaped_json_string (js.item)
|
||||
assert ("json %"" + j + "%" to string %"" + s + "%"", js.unescaped_string_8.same_string (s))
|
||||
|
||||
s := "<script>tab=%T cr=%R newline=%N backslash=%H slash=/ end</script>"
|
||||
j := "<script>tab=\t cr=\r newline=\n backslash=\\ slash=/ end<\/script>"
|
||||
create js.make_from_string (s)
|
||||
assert ("string %"" + s + "%" to json %"" + j + "%"", js.item.same_string (j))
|
||||
create js.make_from_escaped_json_string (js.item)
|
||||
assert ("json %"" + j + "%" to string %"" + s + "%"", js.unescaped_string_8.same_string (s))
|
||||
|
||||
create js.make_from_escaped_json_string ("tab=\t")
|
||||
assert ("js.item.same_string (%"tab=\t%")", js.item.same_string ("tab=\t"))
|
||||
create js.make_from_escaped_json_string (js.item)
|
||||
assert ("js.item.same_string (%"tab=\t%")", js.item.same_string ("tab=\t"))
|
||||
|
||||
|
||||
-- <\/script>
|
||||
create js.make_from_escaped_json_string ("<script>tab=\t<\/script>")
|
||||
assert ("js.item.same_string (%"<script>tab=\t<\/script>%")", js.item.same_string ("<script>tab=\t<\/script>"))
|
||||
assert ("js.unescaped_string_8.same_string (%"<script>tab=%%T</script>%")", js.unescaped_string_8.same_string ("<script>tab=%T</script>"))
|
||||
|
||||
create js.make_from_escaped_json_string (js.item)
|
||||
assert ("js.item.same_string (%"<script>tab=\t<\/script>%")", js.item.same_string ("<script>tab=\t<\/script>"))
|
||||
assert ("js.unescaped_string_8.same_string (%"<script>tab=%%T</script>%")", js.unescaped_string_8.same_string ("<script>tab=%T</script>"))
|
||||
|
||||
-- </script>
|
||||
create js.make_from_escaped_json_string ("<script>tab=\t</script>")
|
||||
assert ("js.item.same_string (%"<script>tab=\t</script>%")", js.item.same_string ("<script>tab=\t</script>"))
|
||||
assert ("js.unescaped_string_8.same_string (%"<script>tab=%%T</script>%")", js.unescaped_string_8.same_string ("<script>tab=%T</script>"))
|
||||
|
||||
create js.make_from_escaped_json_string (js.item)
|
||||
assert ("js.item.same_string (%"<script>tab=\t<\/script>%")", js.item.same_string ("<script>tab=\t</script>"))
|
||||
assert ("js.unescaped_string_8.same_string (%"<script>tab=%%T</script>%")", js.unescaped_string_8.same_string ("<script>tab=%T</script>"))
|
||||
|
||||
end
|
||||
|
||||
test_json_array
|
||||
local
|
||||
ll: LINKED_LIST [INTEGER_8]
|
||||
ll2: detachable LINKED_LIST [detachable ANY]
|
||||
ja: detachable JSON_ARRAY
|
||||
jn: JSON_NUMBER
|
||||
jrep: STRING
|
||||
@@ -664,7 +722,7 @@ feature -- Test
|
||||
ll.extend (5)
|
||||
-- Note: Currently there is no simple way of creating a JSON_ARRAY
|
||||
-- from an LINKED_LIST.
|
||||
create ja.make_array
|
||||
create ja.make (ll.count)
|
||||
from
|
||||
ll.start
|
||||
until
|
||||
@@ -677,11 +735,10 @@ feature -- Test
|
||||
assert ("ja /= Void", ja /= Void)
|
||||
assert ("ja.representation.is_equal (%"[0,1,1,2,3,5]%")", ja.representation.is_equal ("[0,1,1,2,3,5]"))
|
||||
-- Eiffel value -> JSON value -> JSON representation with factory
|
||||
ja := Void
|
||||
ja ?= json.value (ll)
|
||||
assert ("ja /= Void", ja /= Void)
|
||||
if attached ja as l_ja then
|
||||
if attached {JSON_ARRAY} json.value (ll) as l_ja then
|
||||
assert ("ja.representation.is_equal (%"[0,1,1,2,3,5]%")", l_ja.representation.is_equal ("[0,1,1,2,3,5]"))
|
||||
else
|
||||
assert ("json.value (ll) /= Void", False)
|
||||
end
|
||||
|
||||
-- JSON representation -> JSON value -> Eiffel value
|
||||
@@ -690,23 +747,21 @@ feature -- Test
|
||||
-- it means we will get an LINKED_LIST [ANY] containing the INTEGER_8
|
||||
-- values 0, 1, 1, 2, 3, 5
|
||||
jrep := "[0,1,1,2,3,5]"
|
||||
create parser.make_parser (jrep)
|
||||
ja := Void
|
||||
ja ?= parser.parse
|
||||
assert ("ja /= Void", ja /= Void)
|
||||
ll2 ?= json.object (ja, Void)
|
||||
assert ("ll2 /= Void", ll2 /= Void)
|
||||
--ll.compare_objects
|
||||
--ll2.compare_objects
|
||||
if attached ll2 as l_ll2 then
|
||||
create parser.make_with_string (jrep)
|
||||
if attached {JSON_ARRAY} parser.next_parsed_json_value as l_ja then
|
||||
if attached {LINKED_LIST [detachable ANY]} json.object (ja, Void) as l_ll2 then
|
||||
assert ("ll2.is_equal (ll)", l_ll2.is_equal (ll))
|
||||
else
|
||||
assert ("json.object (ja, Void) /= Void", False)
|
||||
end
|
||||
else
|
||||
assert ("parser.next_parsed_json_value /= Void", False)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
test_json_object
|
||||
local
|
||||
t, t2: detachable HASH_TABLE [detachable ANY, STRING_GENERAL]
|
||||
t: detachable HASH_TABLE [detachable ANY, STRING_GENERAL]
|
||||
i: INTEGER
|
||||
ucs_key, ucs: STRING_32
|
||||
a: ARRAY [INTEGER]
|
||||
@@ -722,14 +777,14 @@ feature -- Test
|
||||
-- a HASH_TABLE, so we do it manually.
|
||||
-- t = {"name": "foobar", "size": 42, "contents", [0, 1, 1, 2, 3, 5]}
|
||||
create jo.make
|
||||
create js_key.make_json ("name")
|
||||
create js.make_json ("foobar")
|
||||
create js_key.make_from_string ("name")
|
||||
create js.make_from_string ("foobar")
|
||||
jo.put (js, js_key)
|
||||
create js_key.make_json ("size")
|
||||
create js_key.make_from_string ("size")
|
||||
create jn.make_integer (42)
|
||||
jo.put (jn, js_key)
|
||||
create js_key.make_json ("contents")
|
||||
create ja.make_array
|
||||
create js_key.make_from_string ("contents")
|
||||
create ja.make (6)
|
||||
create jn.make_integer (0)
|
||||
ja.add (jn)
|
||||
create jn.make_integer (1)
|
||||
@@ -745,6 +800,7 @@ feature -- Test
|
||||
jo.put (ja, js_key)
|
||||
assert ("jo /= Void", jo /= Void)
|
||||
assert ("jo.representation.is_equal (%"{%"name%":%"foobar%",%"size%":42,%"contents%":[0,1,1,2,3,5]}%")", jo.representation.is_equal ("{%"name%":%"foobar%",%"size%":42,%"contents%":[0,1,1,2,3,5]}"))
|
||||
|
||||
-- Eiffel value -> JSON value -> JSON representation with factory
|
||||
create t.make (3)
|
||||
create ucs_key.make_from_string ("name")
|
||||
@@ -756,26 +812,28 @@ feature -- Test
|
||||
create ucs_key.make_from_string ("contents")
|
||||
a := <<0, 1, 1, 2, 3, 5>>
|
||||
t.put (a, ucs_key)
|
||||
jo := Void
|
||||
jo ?= json.value (t)
|
||||
assert ("jo /= Void", jo /= Void)
|
||||
if attached jo as l_jo then
|
||||
if attached {JSON_OBJECT} json.value (t) as l_jo then
|
||||
assert ("jo.representation.is_equal (%"{%"name%":%"foobar%",%"size%":42,%"contents%":[0,1,1,2,3,5]}%")", l_jo.representation.is_equal ("{%"name%":%"foobar%",%"size%":42,%"contents%":[0,1,1,2,3,5]}"))
|
||||
end
|
||||
-- JSON representation -> JSON value -> Eiffel value -> JSON value -> JSON representation
|
||||
jrep := "{%"name%":%"foobar%",%"size%":42,%"contents%":[0,1,1,2,3,5]}"
|
||||
create parser.make_parser (jrep)
|
||||
jo := Void
|
||||
jo ?= parser.parse
|
||||
assert ("jo /= Void", jo /= Void)
|
||||
t2 ?= json.object (jo, Void)
|
||||
assert ("t2 /= Void", t2 /= Void)
|
||||
jo ?= json.value (t2)
|
||||
assert ("jo /= Void", jo /= Void)
|
||||
if attached jo as l_jo then
|
||||
assert ("jrep.is_equal (jo.representation)", jrep.is_equal (jo.representation))
|
||||
else
|
||||
assert ("json.value (t) /= Void", False)
|
||||
end
|
||||
|
||||
-- JSON representation -> JSON value -> Eiffel value -> JSON value -> JSON representation
|
||||
jrep := "{%"name%":%"foobar%",%"size%":42,%"contents%":[0,1,1,2,3,5]}"
|
||||
create parser.make_with_string (jrep)
|
||||
if attached {JSON_OBJECT} parser.next_parsed_json_value as l_jo then
|
||||
if attached {HASH_TABLE [detachable ANY, STRING_GENERAL]} json.object (l_jo, Void) as l_t2 then
|
||||
if attached json.value (l_t2) as l_jo_2 then
|
||||
assert ("jrep.is_equal (jo.representation)", jrep.is_equal (l_jo_2.representation))
|
||||
else
|
||||
assert ("json.value (t2) /= Void", False)
|
||||
end
|
||||
else
|
||||
assert ("json.object (jo, Void) /= Void", False)
|
||||
end
|
||||
else
|
||||
assert ("parser.next_parsed_json_value /= Void", jo /= Void)
|
||||
end
|
||||
end
|
||||
|
||||
test_json_object_hash_code
|
||||
@@ -802,7 +860,6 @@ feature -- Test
|
||||
jv := json.value (gv)
|
||||
else
|
||||
assert ("exceptions.is_developer_exception", json.is_developer_exception)
|
||||
-- assert ("exceptions.is_developer_exception_of_name", json.is_developer_exception_of_name ("eJSON exception: Failed to convert Eiffel object to a JSON_VALUE: OPERATING_ENVIRONMENT"))
|
||||
end
|
||||
rescue
|
||||
exception := True
|
||||
@@ -813,17 +870,15 @@ feature -- Test
|
||||
-- Test converting from a JSON value to an Eiffel object based on a
|
||||
-- class for which no JSON converter has been registered.
|
||||
local
|
||||
gv : detachable OPERATING_ENVIRONMENT
|
||||
gv: detachable ANY
|
||||
jo: JSON_OBJECT
|
||||
exception: BOOLEAN
|
||||
do
|
||||
if not exception then
|
||||
create jo.make
|
||||
gv ?= json.object (jo, "OPERATING_ENVIRONMENT")
|
||||
gv := json.object (jo, "OPERATING_ENVIRONMENT")
|
||||
else
|
||||
assert ("exceptions.is_developer_exception", json.is_developer_exception)
|
||||
-- assert ("exceptions.is_developer_exception_of_name", json.is_developer_exception_of_name ("eJSON exception: Failed to convert JSON_VALUE to an Eiffel object: JSON_OBJECT -> OPERATING_ENVIRONMENT"))
|
||||
|
||||
end
|
||||
rescue
|
||||
exception := True
|
||||
|
||||
@@ -1,19 +1,28 @@
|
||||
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
|
||||
undefine
|
||||
default_create
|
||||
end
|
||||
|
||||
EQA_TEST_SET
|
||||
select default_create end
|
||||
|
||||
feature -- Test
|
||||
|
||||
test_custom_classes
|
||||
-- Parse JSON representation to JSON_OBJECT and test book collection converter.
|
||||
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
|
||||
@@ -25,18 +34,19 @@ feature -- Test
|
||||
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%"}}]}"))
|
||||
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
|
||||
|
||||
@@ -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,25 @@ 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
|
||||
|
||||
test_json_utf_8_pass1
|
||||
local
|
||||
parse_json: like new_json_parser
|
||||
utf: UTF_CONVERTER
|
||||
s: READABLE_STRING_32
|
||||
do
|
||||
s := {STRING_32} "{ %"nihaoma%": %"ä½ å¥½å—\t?%" }"
|
||||
parse_json := new_json_parser (utf.string_32_to_utf_8_string_8 (s))
|
||||
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
|
||||
|
||||
@@ -70,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
|
||||
|
||||
@@ -82,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
|
||||
|
||||
@@ -94,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
|
||||
|
||||
@@ -106,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
|
||||
|
||||
@@ -118,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
|
||||
|
||||
@@ -131,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
|
||||
|
||||
@@ -143,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
|
||||
|
||||
@@ -155,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
|
||||
|
||||
@@ -168,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
|
||||
|
||||
@@ -181,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
|
||||
|
||||
@@ -193,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
|
||||
|
||||
@@ -205,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
|
||||
|
||||
@@ -217,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
|
||||
|
||||
@@ -229,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
|
||||
|
||||
@@ -241,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
|
||||
|
||||
@@ -253,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
|
||||
|
||||
@@ -265,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
|
||||
|
||||
@@ -277,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
|
||||
|
||||
@@ -289,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
|
||||
|
||||
@@ -301,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
|
||||
|
||||
@@ -313,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
|
||||
|
||||
@@ -326,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
|
||||
|
||||
@@ -338,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
|
||||
|
||||
@@ -350,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
|
||||
|
||||
@@ -362,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
|
||||
|
||||
@@ -375,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
|
||||
|
||||
@@ -388,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
|
||||
|
||||
@@ -401,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
|
||||
|
||||
@@ -414,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
|
||||
|
||||
@@ -427,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
|
||||
|
||||
@@ -439,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
|
||||
|
||||
@@ -451,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
|
||||
|
||||
@@ -463,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
|
||||
|
||||
@@ -472,38 +489,42 @@ feature -- JSON_FROM_FILE
|
||||
|
||||
file_reader: JSON_FILE_READER
|
||||
|
||||
json_value: detachable JSON_VALUE
|
||||
|
||||
json_file_from (fn: STRING): detachable STRING
|
||||
do
|
||||
Result := file_reader.read_json_from (test_dir + fn)
|
||||
assert ("File contains json data", Result /= Void)
|
||||
end
|
||||
|
||||
new_json_parser (a_string: STRING): JSON_PARSER
|
||||
do
|
||||
create Result.make_parser (a_string)
|
||||
end
|
||||
|
||||
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
|
||||
Result := (create {EXECUTION_ENVIRONMENT}).current_working_directory
|
||||
Result.append_character ((create {OPERATING_ENVIRONMENT}).directory_separator)
|
||||
-- The should looks like
|
||||
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
|
||||
from
|
||||
i := 5
|
||||
until
|
||||
i = 0
|
||||
loop
|
||||
Result.append_character ('.')
|
||||
Result.append_character ('.')
|
||||
Result.append_character ((create {OPERATING_ENVIRONMENT}).directory_separator)
|
||||
test_dir := test_dir.extended ("..")
|
||||
i := i - 1
|
||||
end
|
||||
-- Result := "/home/jvelilla/work/project/Eiffel/ejson_dev/trunk/test/autotest/test_suite/"
|
||||
l_path := test_dir.extended (fn)
|
||||
end
|
||||
create f.make_with_path (l_path)
|
||||
if f.exists then
|
||||
Result := file_reader.read_json_from (l_path.name)
|
||||
end
|
||||
assert ("File contains json data", Result /= Void)
|
||||
end
|
||||
|
||||
|
||||
new_json_parser (a_string: STRING): JSON_PARSER
|
||||
do
|
||||
create Result.make_with_string (a_string)
|
||||
end
|
||||
|
||||
invariant
|
||||
|
||||
@@ -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>
|
||||
|
||||
0
contrib/library/text/parser/json/test/getest/ec_compile.sh
Executable file → Normal file
0
contrib/library/text/parser/json/test/getest/ec_compile.sh
Executable file → Normal file
133
doc/wiki/Deployment.md
Normal file
133
doc/wiki/Deployment.md
Normal 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.
|
||||
57
doc/wiki/Doc_Getting_Started.mediawiki
Normal file
57
doc/wiki/Doc_Getting_Started.mediawiki
Normal file
@@ -0,0 +1,57 @@
|
||||
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.
|
||||
|
||||
== Installation ==
|
||||
=== EiffelStudio 7.2 ===
|
||||
EWF is already included in EiffelStudio 7.2: you don't have to do anything in this case! This is the recommanded solution if you are a new developer or are new to Eiffel.
|
||||
|
||||
=== Other EiffelStudio versions ===
|
||||
If you have another version of EiffelStudio than 7.2, you have to
|
||||
|
||||
* dowload EWF
|
||||
* create a directory where you will put your custum Eiffel libraries
|
||||
* extract EWF in the newly created directory
|
||||
* define the environment variable EIFFEL_LIBRARY to point to the newly created directory
|
||||
|
||||
=== Source code ===
|
||||
The source code is available on Github. You can get it by running the command:
|
||||
|
||||
<code>git clone git://github.com/EiffelWebFramework/EWF.git</code>
|
||||
|
||||
== Hello World ==
|
||||
The hello world example is located in the directory $ISE_EIFFEL/contrib/examples/web/ewf/simple. Just double click on the simple.ecf file and select the simple target or if you prefer the command line, run the command:
|
||||
<code>estudio -config simple.ecf -target simple</code>
|
||||
|
||||
Once the project is compiled, we will adapt the root class to point to port number 9090.
|
||||
|
||||
'''Note''': By default, the application listens on port 80, which is often already used by standard webservers (Apache, nginx, ...). Moreover, on Linux, ports below 1024 can only be opened by root.
|
||||
|
||||
To do this, we will redefine the feature initialize as follows:
|
||||
|
||||
|
||||
class
|
||||
APPLICATION
|
||||
|
||||
inherit
|
||||
WSF_DEFAULT_SERVICE
|
||||
redefine
|
||||
initialize
|
||||
end
|
||||
|
||||
create
|
||||
make_and_launch
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
initialize
|
||||
-- Initialize current service
|
||||
do
|
||||
set_service_option ("port", 9090)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
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.
|
||||
7
doc/wiki/Doc_Index.mediawiki
Normal file
7
doc/wiki/Doc_Index.mediawiki
Normal file
@@ -0,0 +1,7 @@
|
||||
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] ]
|
||||
@@ -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
|
||||
|
||||
----
|
||||
@@ -4,7 +4,7 @@
|
||||
## Preface
|
||||
This specification is a proposition based on recent discussion on the mailing list.
|
||||
This is work in progress, so far nothing had been decided.
|
||||
You can find another proposal at http://eiffel.seibostudios.se/wiki/EWSGI , it has common background and goal, however still differ on specific parts.
|
||||
You can find another proposal at [http://eiffel.seibostudios.se/wiki/EWSGI](http://eiffel.seibostudios.se/wiki/EWSGI) , it has common background and goal, however still differ on specific parts.
|
||||
The main goal for now is to unified those 2 specifications.
|
||||
|
||||
---
|
||||
@@ -12,7 +12,7 @@ Note the following is work in progress, and reflect a specification proposal, ra
|
||||
2011-08-01
|
||||
---
|
||||
For now, the specification from EWF is done in Eiffel interface
|
||||
please see: https://github.com/Eiffel-World/Eiffel-Web-Framework/tree/master/library/server/ewsgi/specification
|
||||
please see: [https://github.com/Eiffel-World/Eiffel-Web-Framework/tree/master/library/server/ewsgi/specification](https://github.com/Eiffel-World/Eiffel-Web-Framework/tree/master/library/server/ewsgi/specification)
|
||||
|
||||
WGI_APPLICATION
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
# Eiffel-Web-Framework #
|
||||
|
||||
## Location ##
|
||||
The official documentation/wiki is located at https://github.com/EiffelWebFramework/EWF/wiki , if you are visiting a "clone/fork", please always check the [[official wiki|https://github.com/EiffelWebFramework/EWF/wiki]].
|
||||
|
||||
## Organization ##
|
||||
- Mailing list: please visit and subscribe to the mailing list page [[http://groups.google.com/group/eiffel-web-framework]] 
|
||||
- Most of the topics are discussed on the mailing list (google group).
|
||||
- For time to time we have web meeting, and less frequently physical meetings that occurs usually during other Eiffel related events.
|
||||
|
||||
## Documentation ##
|
||||
- to redo
|
||||
|
||||
## Contributions ##
|
||||
- You want to contribute or follow the progress/discussion, see the [[collaboration page| Community-collaboration]]
|
||||
- Potential tasks/projects on EWF: [[Projects page| Projects]]
|
||||
|
||||
## See also ##
|
||||
- [[list of tasks, and a potential roadmap| Tasks-Roadmap]]
|
||||
- [[General source structure of this project| Source-structure]]
|
||||
- EWSGI: [[Eiffel Web Server Gateway Interface| EWSGI]]
|
||||
- [[Overview of the server side architecture| Spec-Server-Architecture]]
|
||||
- This project is also a collection of [[Libraries]] 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
|
||||
26
doc/wiki/README.md
Normal file
26
doc/wiki/README.md
Normal file
@@ -0,0 +1,26 @@
|
||||
# Eiffel-Web-Framework #
|
||||
|
||||
## Location ##
|
||||
The official documentation/wiki is located at [https://github.com/EiffelWebFramework/EWF/wiki](https://github.com/EiffelWebFramework/EWF/wiki) , if you are visiting a "clone/fork", please always check the [official wiki](https://github.com/EiffelWebFramework/EWF/wiki).
|
||||
|
||||
## 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) 
|
||||
- Most of the topics are discussed on the mailing list (google group).
|
||||
- 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/README.md)
|
||||
|
||||
## Contributions ##
|
||||
- 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](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)
|
||||
@@ -1,13 +1,13 @@
|
||||
This project is a community project
|
||||
|
||||
## Mailing list ##
|
||||
- Google group: http://groups.google.com/group/eiffel-web-framework
|
||||
- Google group: [http://groups.google.com/group/eiffel-web-framework](http://groups.google.com/group/eiffel-web-framework)
|
||||
|
||||
## Materials ##
|
||||
- wiki: github wiki at https://github.com/Eiffel-World/Eiffel-Web-Framework/wiki
|
||||
- Shared documents: on google docs at http://goo.gl/M8WLP
|
||||
- source code: git repository at https://github.com/Eiffel-World/Eiffel-Web-Framework
|
||||
- Proposal from Paul Cohen for a EWSGI spec at http://eiffel.seibostudios.se/wiki/EWSGI
|
||||
- wiki: github wiki at [https://github.com/Eiffel-World/Eiffel-Web-Framework/wiki](https://github.com/Eiffel-World/Eiffel-Web-Framework/wiki)
|
||||
- Shared documents: on google docs at [http://goo.gl/M8WLP](http://goo.gl/M8WLP)
|
||||
- source code: git repository at [https://github.com/Eiffel-World/Eiffel-Web-Framework](https://github.com/Eiffel-World/Eiffel-Web-Framework)
|
||||
- Proposal from Paul Cohen for a EWSGI spec at [http://eiffel.seibostudios.se/wiki/EWSGI](http://eiffel.seibostudios.se/wiki/EWSGI)
|
||||
|
||||
## Main contributors ##
|
||||
- **jfiat**: Jocelyn Fiat (Eiffel Software)
|
||||
51
doc/wiki/documentation/Connectors.md
Normal file
51
doc/wiki/documentation/Connectors.md
Normal file
@@ -0,0 +1,51 @@
|
||||
The main goal of the connectors is to let you choose a target at compile time.
|
||||
This allows you to concentrate on your business during development time and then decide which target you choose at deployment time.
|
||||
The current connectors are:
|
||||
* Nino
|
||||
* FastCGI
|
||||
* CGI
|
||||
* OpenShift
|
||||
|
||||
The most widely used workflow is to use Nino on your development machine and FastCGI on your production server.
|
||||
Nino being a web server written entirely in Eiffel, you can inspect your HTTP requests and respones in EiffelStudio which is great during development.
|
||||
On the other hand, FastCGI is great at handling concurrent requests and coupled with Apache (or another web production server), you don't even need to worry about the lifecyle of your application (creation and destruction) as Apache will do it for you!
|
||||
|
||||
Let's now dig into each of the connecters.
|
||||
|
||||
# Nino
|
||||
|
||||
Nino is a web server entirely written in Eiffel.
|
||||
The goal of Nino is to provide a simple web server for development (like Java, Python and Ruby provide).
|
||||
Nino is currently maintained by Javier Velilla and the repository can be found here: https://github.com/jvelilla/EiffelWebNino
|
||||
|
||||
# FastCGI
|
||||
|
||||
FastCGI is a protocol for interfacing an application server with a web server.
|
||||
It is an improvement over CGI as FastCGI supports long running processes, i.e. processes than can handle multipe requests during their lifecyle. CGI, on the other hand, launches a new process for every new request which is quite time consuming.
|
||||
FastCGI is implemented by every major web servers: Apache, IIS, Nginx, ...
|
||||
We recommend to use FastCGI instead of CGI as it is way more faster.
|
||||
You can read more about FastCGI here: http://www.fastcgi.com/
|
||||
|
||||
# CGI
|
||||
|
||||
CGI predates FastCGI and is also a protocol for interfacing an application server with a web server.
|
||||
His main drawback (and the reason why FastCGI was created) is that it launches a new process for every new request, which is quite time consuming.
|
||||
We recommend to use FastCGI instead of CGI as it is way more faster.
|
||||
|
||||
# OpenShift
|
||||
|
||||
OpenShift is a cloud computing platform as a service product from Red Hat.
|
||||
It basically let's you run your application in the cloud.
|
||||
More informations are available here: https://www.openshift.com
|
||||
|
||||
# Writing your own
|
||||
|
||||
It's fairly easy to write your own connector. Just inherit from these classes:
|
||||
* WGI_CONNECTOR
|
||||
* WGI_ERROR_STREAM
|
||||
* WGI_INPUT_STREAM
|
||||
* WGI_OUTPUT_STREAM
|
||||
* WSF_SERVICE_LAUNCHER
|
||||
|
||||
|
||||
See WSF_CONNECTOR
|
||||
27
doc/wiki/documentation/Filter.md
Normal file
27
doc/wiki/documentation/Filter.md
Normal file
@@ -0,0 +1,27 @@
|
||||
# Introduction
|
||||
|
||||
The basic idea of a filter is to pre-process incoming data and post-process outgoing data.
|
||||
Filters are part of a filter chain, thus following the [chain of responsability design pattern](http://en.wikipedia.org/wiki/Chain-of-responsibility_pattern).
|
||||
|
||||
Each filter decides to call the next filter or not.
|
||||
|
||||
# Levels
|
||||
|
||||
In EWF, there are two levels of filters.
|
||||
|
||||
## WSF_FILTER
|
||||
|
||||
Typical examples of such filters are: logging, compression, routing (WSF_ROUTING_FILTER), ...
|
||||
|
||||
## WSF_FILTER_HANDLER
|
||||
|
||||
Handler that can also play the role of a filter.
|
||||
|
||||
Typical examples of such filters are: authentication, ...
|
||||
|
||||
# References
|
||||
|
||||
Filters (also called middelwares) in other environments:
|
||||
* in Python: http://www.wsgi.org/en/latest/libraries.html
|
||||
* in Node.js: http://expressjs.com/guide.html#middleware
|
||||
* in Apache: http://httpd.apache.org/docs/2.2/en/filter.html
|
||||
210
doc/wiki/documentation/README.md
Normal file
210
doc/wiki/documentation/README.md
Normal file
@@ -0,0 +1,210 @@
|
||||
# Current Status
|
||||
* Official repository: <https://github.com/EiffelWebFramework/EWF>
|
||||
* Official website: <http://eiffelwebframework.github.io/EWF/getting-started/>
|
||||
|
||||
# What is EWF?
|
||||
|
||||
Eiffel Web Framework, is mainly a collection of Eiffel libraries designed to be integrated with each other. One benefit is that it supports all core HTTP features, so enable you embrace HTTP as an application protocol to develop web applications. So you do not need to adapt your applications to the web, instead you use the web power. It means you can build different kind of web applications, from Web APIs following the Hypermedia API style (REST style), CRUD web services or just conventional web applications building a session on top of an stateless protocol.
|
||||
|
||||
# EWF core/kernel
|
||||
> The Web Server Foundation (WSF\_) is the core of the framework. It is compliant with the EWSGI interface (WGI\_).
|
||||
|
||||
To build a web [service](#service), the framework provides a set of core components to launch the service, for each [request](#request-and-response), access the data, and send the [response](#request-and-response).
|
||||
The framework also provides a router component to help dispatching the incoming request.
|
||||
|
||||
A service can be a web api, a web interface, … what ever run on top of HTTP.
|
||||
|
||||
<a name="wiki-service"></a>
|
||||
<a name="service"></a>
|
||||
# Service
|
||||
> see interface: **WSF_SERVICE**
|
||||
|
||||
Each incoming http request is processed by the following routine.
|
||||
|
||||
> `{WSF_SERVICE}.execute (req: WSF_REQUEST; res: WSF_RESPONSE)`
|
||||
|
||||
This is the low level of the framework, at this point, `req` provides access to the query and form parameters, input data, headers, ... as specified by the Common Gateway Interface (CGI).
|
||||
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](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>
|
||||
# Request and Response
|
||||
> see interface: **WSF_REQUEST** and **WSF_RESPONSE**
|
||||
|
||||
Any incoming http request is represented by an new object of type **WSF_REQUEST**.
|
||||
|
||||
**WSF_REQUEST** provides access to
|
||||
+ __meta variables__: CGI variables (coming from the request http header)
|
||||
+ __query parameters__: from the uri ex: `?q=abc&type=pdf`
|
||||
+ __input data__: the message of the request, if this is a web form, this is parsed to build the form parameters. It can be retrieved once.
|
||||
+ __form parameters__: standard parameters from the request input data.
|
||||
- typically available when a web form is sent using POST as content of type `multipart/form-data` or `application/x-www-form-urlencoded`
|
||||
- (advanced usage: it is possible to write mime handler that can processed other type of content, even custom format.)
|
||||
+ __uploaded files__: if files are uploaded, their value will be available from the form parameters, and from the uploaded files as well.
|
||||
+ __cookies variable__: cookies extracted from the http header.
|
||||
+ __path parameters__: note this is related to the router and carry the semantic of the mapping (see the section on router )
|
||||
+ __execution variables__: used by the application to keep value associated with the 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](Request.md) and [about response](Response.md)
|
||||
|
||||
<a name="wiki-connector"></a>
|
||||
<a name="connector"></a>
|
||||
# Connectors:
|
||||
> see **WGI_CONNECTOR**
|
||||
|
||||
Using EWF, your service is built on top of underlying httpd solution/connectors.
|
||||
Currently 3 main connectors are available:
|
||||
* __CGI__: following the CGI interface, this is an easy solution to run the service on any platform.
|
||||
* __libFCGI__: based on the libfcgi solution, this can be used with Apache, IIS, nginx, ...
|
||||
* __nino__: a standalone server: Eiffel Web Nino allow you to embed a web server anywhere, on any platform without any dependencies on other httpd server.
|
||||
|
||||
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](Connector.md)
|
||||
|
||||
<a name="wiki-router"></a>
|
||||
<a name="router"></a>
|
||||
# Router or Request Dispatcher:
|
||||
> Routes HTTP requests to the proper execution code
|
||||
|
||||
A web application needs to have a clean and elegant URL scheme, and EWF provides a router component to design URLs.
|
||||
|
||||
The association between a URL pattern and the code handling the URL request is called a Router mapping in EWF.
|
||||
|
||||
EWF provides 3 main kinds of mappings
|
||||
+ __URI__: any URL with path being the specified uri.
|
||||
- example: “/users/” redirects any “/users/” and “/users/?query=...”
|
||||
+ __URI-template__: any URL matching the specified URI-template
|
||||
- example: “/project/{name}/” redirects any “/project/foo” or “/project/bar”
|
||||
+ __Starts-with__: any URL starting with the specified path
|
||||
|
||||
Note: in the future, a Regular-Expression based kind will be added in the future, and it is possible to use custom mapping on top of EWF.
|
||||
|
||||
Code:
|
||||
|
||||
router.map ( create {WSF_URI_TEMPLATE_MAPPING}.make (
|
||||
“/project/{name}”, project_handler)
|
||||
)
|
||||
-- And precising the request methods
|
||||
router.map_with_request_methods ( ... , router.methods_GET_POST)
|
||||
|
||||
In the previous code, the `project_handler` is an object conforming to **WSF_HANDLER**, that will process the incoming requests matching URI-template “/project/{name}”.
|
||||
|
||||
Usually, the service will inherit from WSF_ROUTED_SERVICE, which has a `router` attribute.
|
||||
Configuring the URL scheme is done by implementing `{WSF_ROUTED_SERVICE}.setup_router`.
|
||||
|
||||
To make life easier, by inheriting from WSF_URI_TEMPLATE_HELPER_FOR_ROUTED_SERVICE, a few help methods are available to `map` URI template with agent, and so on.
|
||||
See
|
||||
+ `map_uri_template (a_tpl: STRING; h: WSF_URI_TEMPLATE_HANDLER)`
|
||||
+ `map_uri_template_agent (a_tpl: READABLE_STRING_8; proc: PROCEDURE [ANY, TUPLE [req: WSF_REQUEST; res: WSF_RESPONSE]])`
|
||||
+ and same with request methods ...
|
||||
|
||||
...
|
||||
|
||||
Check WSF_\*_HELPER_FOR_ROUTED_SERVICE for other available helper classes.
|
||||
|
||||
How we do that in EWF? : Router with (or without context).
|
||||
Related code: wsf_router, wsf_router_context
|
||||
Examples
|
||||
|
||||
> [Learn more about router](Router.md)
|
||||
|
||||
# EWF components
|
||||
## URI Handler:
|
||||
> Parses the details of the URI (scheme, path, query info, etc.) and exposes them for use.
|
||||
|
||||
How we do that in EWF?: URI Templates, but we could also use regex.
|
||||
Related code: uri_template
|
||||
Examples:
|
||||
|
||||
|
||||
## Mime Parser/ Content Negotiation:
|
||||
> Handles the details of determining the media type, language, encoding, compression (conneg).
|
||||
|
||||
How do we do that in EWF? Content_Negotiation library.
|
||||
Example
|
||||
|
||||
|
||||
## Request Handler
|
||||
> target of request dispatcher + uri handler.
|
||||
|
||||
Here is where we handle GET, POST PUT, etc.
|
||||
|
||||
## Representation Mapping
|
||||
> Converts stored data into the proper representation for responses and handles incoming representations from requests.
|
||||
|
||||
We don’t have a representation library, the developer need to do that.
|
||||
If we want to provide different kind of representations: JSON, XML, HTML, the responsibility is let
|
||||
to the developer to map their domain to the target representation.
|
||||
|
||||
## Http Client:
|
||||
> A simple library to make requests and handle responses from other http servers.
|
||||
|
||||
How we do that in EWF? http client library
|
||||
examples:
|
||||
|
||||
## Authentication/Security:
|
||||
> Handle different auth models. (Basic, Digest?, OAuth, OpenId)
|
||||
|
||||
How we do that in EWF? http_authorization, OpenId, and Cypress
|
||||
examples.
|
||||
|
||||
## Caching:
|
||||
> Support for Caching and conditional request
|
||||
|
||||
How we do that in Eiffel? Policy framework on top of EWF. {{{need_review}}}
|
||||
examples
|
||||
|
||||
|
||||
## EWF HTML5 Widgets
|
||||
|
||||
## EWF policy Framework
|
||||
|
||||
## EWF application generators
|
||||
|
||||
|
||||
<a name="wiki-EWSGI"></a>
|
||||
<a name="EWSGI"></a>
|
||||
# EWSGI Specification
|
||||
|
||||
<a name="wiki-libraries"></a>
|
||||
<a name="libraries"></a>
|
||||
# Libraries
|
||||
|
||||
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/index.md).
|
||||
* connectors: various web server connectors for EWSGI
|
||||
* __libfcgi__: Wrapper for libfcgi SDK
|
||||
* __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, ...
|
||||
* __uri_template__: URI Template library (parsing and expander)
|
||||
* __content_negotiation__: [CONNEG](Library-conneg.md) library (Content-type Negociation)
|
||||
|
||||
## Client
|
||||
* __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
|
||||
|
||||
## Utils
|
||||
* __error__: very simple/basic library to handle error
|
||||
|
||||
## Security
|
||||
* __http_authentication__ (under EWF/library/server/authentication)
|
||||
* __open_id__ (under EWF/library/security)
|
||||
* __OAuth__ see <https://github.com/EiffelWebFramework/cypress>
|
||||
9
doc/wiki/documentation/Request-and-response.md
Normal file
9
doc/wiki/documentation/Request-and-response.md
Normal file
@@ -0,0 +1,9 @@
|
||||
# Request
|
||||
The class _WSF_REQUEST_ can be used to access data related to the HTTP request.
|
||||
|
||||
**TODO**: describe the request interface
|
||||
|
||||
# Response
|
||||
The class _WSF_RESPONSE_ is the media to send data back to the client.
|
||||
|
||||
**TODO**: describe the response interface
|
||||
17
doc/wiki/documentation/Request.md
Normal file
17
doc/wiki/documentation/Request.md
Normal file
@@ -0,0 +1,17 @@
|
||||
See WSF_REQUEST
|
||||
|
||||
## About parameters
|
||||
Note that by default there is a smart computation for the query/post/... parameters:
|
||||
for instance
|
||||
- `q=a&q=b` : will create a **WSF_MULTIPLE_STRING** parameter with name **q** and value `[a,b]`
|
||||
- `tab[a]=ewf&tab[b]=demo` : will create a **WSF_TABLE** parameter with name **tab** and value `{ "a": "ewf", "b": "demo"}`
|
||||
- `tab[]=ewf&tab[]=demo` : will create a **WSF_TABLE** parameter with name **tab** and value `{ "1": "ewf", "2": "demo"}`
|
||||
- `tab[foo]=foo&tab[foo]=bar` : will create a **WSF_TABLE** parameter with name **tab** and value `{ "foo": "bar"}` **WARNING: only the last `tab[foo]` is kept**.
|
||||
|
||||
Those rules are applied to query, post, path, .... parameters.
|
||||
|
||||
## How to get the input data (i.e entity-body) ?
|
||||
See `{WSF_REQUEST}.read_input_data_into (buf: STRING)`
|
||||
|
||||
## How to get the raw header data (i.e the http header text) ?
|
||||
See `{WSF_REQUEST}.raw_header_data: detachable READABLE_STRING_32`
|
||||
1
doc/wiki/documentation/Response.md
Normal file
1
doc/wiki/documentation/Response.md
Normal file
@@ -0,0 +1 @@
|
||||
See WSF_RESPONSE
|
||||
6
doc/wiki/documentation/Router.md
Normal file
6
doc/wiki/documentation/Router.md
Normal file
@@ -0,0 +1,6 @@
|
||||
The primary goal of the router (class _WSF_ROUTER_) is to dispatch requests according to the request URI.
|
||||
|
||||
See WSF_ROUTER
|
||||
|
||||
**TODO**: describe the router interface
|
||||
|
||||
2
doc/wiki/documentation/Service.md
Normal file
2
doc/wiki/documentation/Service.md
Normal file
@@ -0,0 +1,2 @@
|
||||
EWF Services
|
||||
> See WSF\_SERVICE
|
||||
@@ -0,0 +1,26 @@
|
||||
# Using the policy driven framework
|
||||
|
||||
## Introduction
|
||||
|
||||
The aim of the policy-driven framework is to allow authors of web-servers to concentrate on the business logic (e.g., in the case of a GET request, generating the content), without having to worry about the details of the HTTP protocol (such as headers and response codes). However, there are so many possibilities in the HTTP protocol, that it is impossible to correctly guess what to do in all cases. Therefore the author has to supply policy decisions to the framework, in areas such as caching decisions. These are implemented as a set of deferred classes for which the author needs to provide effective implementations.
|
||||
|
||||
We aim to provide unconditional compliance [See HTTP/1.1 specification](http://www.w3.org/Protocols/rfc2616/rfc2616-sec1.html#sec1) for you. Note that byte-ranges are not yet supported.
|
||||
|
||||
## Mapping the URI space
|
||||
|
||||
The authors first task is to decide which URIs the server will respond to (we do this using [URI templates](http://tools.ietf.org/html/rfc6570) ) and which methods are supported for each template.This is done in the class that that defines the service (which is often the root class for the application). This class must be a descendant of WSF_ROUTED_SKELETON_SERVICE. Throughout this tutorial, we will refer to the restbucksCRUD example application, which can be found in the EWF distribution in the examples directory. It's root class, RESTBUCKS_SERVER, inherits from WSF_ROUTED_SKELETON_SERVICE, as well as WSF_DEFAULT_SERVICE. The latter class means that you must specify in the ECF which connector you will use by default.This means you can easily change connectors just by changing the ECF and recompiling.
|
||||
|
||||
### Declaring your URI templates
|
||||
|
||||
In order to map your URI space to handlers (which you will write), you need to implement the routine setup_router. You can see in the example that the ORDER_HANDLER handler is associated with two URI templates. The URI /order is associated with the POST method (only). Any requests to /order with the GET method (or any other method) will result in an automatically generated compliant response being sent on your behalf to the client. The other principle methods (you get compliant responses to the HEAD method for free whenever you allow the GET method) are associated with the URI template /order/{orderid}. Here, orderid is a template variable. It's value for any given request is provided to your application as {WSF_REQUEST}.path_parameter ("orderid"). If the client passes a URI of /order/21, then you will see the value 21. If the client passes /order/fred, you will see the value fred. But if the client passes /order/21/new, he will see a compliant error response generated by the framework.
|
||||
|
||||
## Declaring your policy in responding to OPTIONS
|
||||
|
||||
WSF_ROUTED_SKELETON_SERVICE inherits from WSF_SYSTEM_OPTIONS_ACCESS_POLICY. This policy declares that the framework will provide a compliant default response to OPTIONS * requests. If you prefer to not respond to OPTIONS * requests (and I am doubtful if it is fully compliant to make that choice), then you can redefine
|
||||
is_system_options_forbidden.
|
||||
|
||||
## Declaring your policy on requiring use of a proxy server
|
||||
|
||||
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.md)
|
||||
3
doc/wiki/policy-driven-framework/WSF_OPTIONS_POLICY.md
Normal file
3
doc/wiki/policy-driven-framework/WSF_OPTIONS_POLICY.md
Normal file
@@ -0,0 +1,3 @@
|
||||
# Implementing routines in WSF_OPTIONS_POLICY
|
||||
|
||||
This class provides a default response to OPTIONS requests other than OPTIONS *. So you don't have to do anything. The default response just includes the mandatory Allow headers for all the methods that are allowed for the request URI. if you want to include a body text, or additional header, then you should redefine this routine.
|
||||
223
doc/wiki/policy-driven-framework/Writing-the-handlers.md
Normal file
223
doc/wiki/policy-driven-framework/Writing-the-handlers.md
Normal file
@@ -0,0 +1,223 @@
|
||||
# Writing the handlers
|
||||
|
||||
Now you have to implement each handler. You need to inherit from WSF_SKELETON_HANDLER (as ORDER_HANDLER does). This involves implementing a lot of deferred routines. There are other routines for which default implementations are provided, which you might want to override. This applies to both routines defined in this class, and those declared in the three policy classes from which it inherits.
|
||||
|
||||
## Communicating between routines
|
||||
|
||||
Depending upon the connector (Nino, CGI, FastCGI etc.) that you are using, your handler may be invoked concurrently for multiple requests. Therefore it is unsafe to save state in normal attributes. WSF_REQUEST has a pair of getter/setter routines, execution_variable/set_execution_variable, which you can use for this purpose.
|
||||
Internally, the framework uses the following execution variable names, so you must avoid them:
|
||||
|
||||
1. REQUEST_ENTITY
|
||||
1. NEGOTIATED_LANGUAGE
|
||||
1. NEGOTIATED_CHARSET
|
||||
1. NEGOTIATED_MEDIA_TYPE
|
||||
1. NEGOTIATED_ENCODING
|
||||
1. NEGOTIATED_HTTP_HEADER
|
||||
1. CONFLICT_CHECK_CODE
|
||||
1. CONTENT_CHECK_CODE
|
||||
1. REQUEST_CHECK_CODE
|
||||
|
||||
The first one makes the request entity from a PULL or POST request available to your routines.
|
||||
|
||||
The next four make the results of content negotiation available to your routines. The sixth one makes an HTTP_HEADER available to your routines. You should use this rather than create your own, as it may contain a **Vary** header as a by-product of content negotiation.
|
||||
The last three are for reporting the result from check_conflict, check_content and check_request.
|
||||
|
||||
All names are defined as constants in WSF_SKELETON_HANDLER, to make it easier for you to refer to them.
|
||||
|
||||
## Implementing the routines declared directly in WSF_SKELETON_HANDLER
|
||||
|
||||
### check_resource_exists
|
||||
|
||||
Here you check for the existence of the resource named by the request URI. If it does, then you need to call set_resource_exists on the helper argument.
|
||||
Note that if you support multiple representations through content negotiation, then etags are dependent upon
|
||||
the selected variant. If you support etags, then you will need to make the response entity available at this point, rather than in ensure_content_available.
|
||||
|
||||
### is_chunking
|
||||
|
||||
HTTP/1.1 supports streaming responses (and providing you have configured your server to use a proxy server in WSF_PROXY_USE_POLICY, this framework guarantees you have an HTTP/1.1 client to deal with). It is up to you whether or not you choose to make use of it. If so, then you have to serve the response one chunk at a time (but you could generate it all at once, and slice it up as you go). In this routine you just say whether or not you will be doing this. So the framework n=knows which other routines to call.
|
||||
Currently we only support chunking for GET or HEAD routines. This might change in the future, so if you intend to return True, you should call req.is_get_head_request_method.
|
||||
Note that currently this framework does not support writing a trailer.
|
||||
|
||||
### includes_response_entity
|
||||
|
||||
The response to a DELETE, PUT or POST will include HTTP headers. It may or may not include a body. It is up to you, and this is where you tell the framework.
|
||||
|
||||
### conneg
|
||||
|
||||
[The HTTP/1.1 specification](http://www.w3.org/Protocols/rfc2616/rfc2616-sec12.html#sec12.1) defines server-driven content negotiation. Based on the Accept* headers in the request, we can determine whether we have a format for the response entity that is acceptable to the client. You need to indicate what formats you support. The framework does the rest. Normally you will have the same options for all requests, in which case you can use a once object.
|
||||
|
||||
### mime_types_supported
|
||||
|
||||
Here you need to indicate which media types you support for responses. One of the entries must be passed to the creation routine for conneg.
|
||||
|
||||
### languages_supported
|
||||
|
||||
Here you need to indicate which languages you support for responses. One of the entries must be passed to the creation routine for conneg.
|
||||
|
||||
|
||||
### charsets_supported
|
||||
|
||||
Here you need to indicate which character sets you support for responses. One of the entries must be passed to the creation routine for conneg.
|
||||
|
||||
|
||||
### encodings_supported
|
||||
|
||||
Here you need to indicate which compression encodings you support for responses. One of the entries must be passed to the creation routine for conneg.
|
||||
|
||||
### additional_variant_headers
|
||||
|
||||
The framework will write a Vary header if conneg indicates that different formats are supported. This warns caches that they may not be able to use a cached response if the Accept* headers in the request differ. If the author knows that the response may be affected by other request headers in addition to these, then they must be indicated here, so they can be included in a Vary header with the response.
|
||||
|
||||
### predictable_response
|
||||
|
||||
If the response may vary in other ways not predictable from the request headers, then redefine this routine to return True. In that case we will generate a Vary: * header to inform the cache that the response is not necessarily repeatable.
|
||||
|
||||
### matching_etag
|
||||
|
||||
An **ETag** header is a kind of message digest. Clients can use etags to avoid re-fetching responses for unchanged resources, or to avoid updating a resource that may have changed since the client last updated it.
|
||||
You must implement this routine to test for matches **if and only if** you return non-Void responses for the etag routine.
|
||||
Note that if you support multiple representations through content negotiation, then etags are dependent upon
|
||||
the selected variant. Therefore you will need to have the response entity available for this routine. This can be done in check_resource_exists.
|
||||
|
||||
### etag
|
||||
|
||||
You are strongly encouraged to return non-Void for this routine. See [Validation Model](http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html#sec13.3) for more details.
|
||||
Note that if you support multiple representations through content negotiation, then etags are dependent upon
|
||||
the selected variant. Therefore you will need to have the response entity available for this routine. This can be done in check_resource_exists.
|
||||
|
||||
### modified_since
|
||||
|
||||
You need to implement this. If you do not have information about when a resource was last modified, then return True as a precaution. Of course, you return false for a static resource.
|
||||
|
||||
### treat_as_moved_permanently
|
||||
|
||||
This routine when a PUT request is made to a resource that does not exist. See [PUT](http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.6) in the HTTP/1.1 specification for why you might want to return zero.
|
||||
|
||||
### allow_post_to_missing_resource
|
||||
|
||||
POST requests are normally made to an existing entity. However it is possible to create new resources using a POST, if the server allows it. This is where you make that decision.
|
||||
|
||||
If you return True, and the resource is created, a 201 Created response will be returned.
|
||||
|
||||
### content_length
|
||||
|
||||
If you are not streaming the result, the the HTTP protocol requires that the length of the entity is known. You need to implement this routine to provide that information.
|
||||
|
||||
### finished
|
||||
|
||||
If you are streaming the response, then you need to tell the framework when the last chunk has been sent.
|
||||
To implement this routine, you will probably need to call req.set_execution_variable (some-name, True) in ensure_content_avaiable and generate_next_chunk, and call attached {BOOLEAN} req.execution_variable (some-name) in this routine.
|
||||
|
||||
### description
|
||||
|
||||
This is for the automatically generated documentation that the framework will generate in response to a request that you have not mapped into an handler.
|
||||
|
||||
### delete
|
||||
|
||||
This routine is for carrying out a DELETE request to a resource. If it is valid to delete the named resource, then you should either go ahead and do it, or queue a deletion request somewhere (if you do that then you will probably need to call req.set_execution_variable (some-name-or-other, True). Otherwise you should call req.error_handler.add_custom_error to explain why the DELETE could not proceed (you should also do this if the attempt to delete the resource fails).
|
||||
Of course, if you have not mapped any DELETE requests to the URI space of this handler, then you can just do nothing.
|
||||
|
||||
### delete_queued
|
||||
|
||||
If in the delete routine, you elected to queue the request, then you need to return True here. You will probably need to check the execution variable you set in the delete routine.
|
||||
|
||||
### ensure_content_available
|
||||
|
||||
This routine is called for GET and DELETE (when a entity is provided in the response) processing. It's purpose is to make the text of the entity (body of the response) available for future routines (if is_chunking is true, then only the first chunk needs to be made available, although if you only serve, as opposed to generate, the result in chunks, then you will make the entire entity available here). This is necessary so that we can compute the length before we start to serve the response. You would normally save it in an execution variable on the request object (as ORDER_HANDLER does). Note that this usage of execution variables ensures your routines can successfully cope with simultaneous requests. If you encounter a problem generating the content, then add an error to req.error_handler.
|
||||
|
||||
As well as the request object, we provide the results of content negotiation, so you can generate the entity in the agreed format. If you only support one format (i.e. all of mime_types_supported, charsets_supported, encodings_supported and languages_supported are one-element lists), then you are guaranteed that this is what you are being asked for, and so you can ignore them.
|
||||
|
||||
Note that if you support multiple representations through content negotiation, then etags are dependent upon
|
||||
the selected variant. Therefore you will need to have the response entity available for this routine. In such cases, this will have to be done in check_resource_exists, rather than here, as this routine is called later on.
|
||||
|
||||
### content
|
||||
|
||||
When not streaming, this routine provides the entity to the framework (for GET or DELETE). Normally you would just access the execution variable that you set in ensure_content_available. Again, the results of content negotiation are made available, but you probably don't need them at this stage. If you only stream responses (for GET), and if you don't support DELETE, then you don't need to do anything here.
|
||||
|
||||
### generate_next_chunk
|
||||
|
||||
When streaming the response, this routine is called to enable you to generate chunks beyond the first, so that you can incrementally generate the response entity. If you generated the entire response entity in
|
||||
ensure_content_available, then you do nothing here. Otherwise, you will generate the next chunk, and save it in the same execution variable that you use in ensure_content_available (or add an error to req.error_handler). If you don't support streaming, then you don't need to do anything here.
|
||||
|
||||
### next_chunk
|
||||
|
||||
When streaming the response, the framework calls this routine to provides the contents of each generated chunk. If you generated the entire response entity in ensure_content_available, then you need to slice it in this routine (you will have to keep track of where you are with execution variables). If instead you generate the response incrementally, then your task is much easier - you just access the execution variable saved in ensure_content_available/generate_next_chunk.
|
||||
As in all these content-serving routines, we provide the results of content negotiation. This might be necessary, for instance, if you were compressing an incrementally generated response (it might be more convenient to do the compression here rather than in both ensure_content_available and generate_next_chunk).
|
||||
|
||||
### read_entity
|
||||
|
||||
This is called for PUT and POST processing, to read the entity provided in the request. A default implementation is provided. This assumes that no decoding (e.g. decompression or character set conversion) is necessary. And it saves it in the execution variable REQUEST_ENTITY.
|
||||
|
||||
Currently the framework provides very little support for PUT and POST requests (so you may well need to redefine this routine). There are several reasons for this:
|
||||
|
||||
1. I personally don't have much experience with PUT and POST.
|
||||
1. It has taken a long time to develop this framework, and to some extent I was working in the dark (I couldn't check what I was doing until the entire framework was written - it wouldn't even compile before then).
|
||||
1. The idea for the framework came from a code review process on servers I had written for the company that I work for. I had acquired a lot of knowledge of the HTTP protocol in the process, and some of it showed in the code that I had written. It was thought that it would be a good idea if this knowledge were encapsulated in Eiffel, so other developers would be able to write servers without such knowledge. So this framework has been developed in company time. However, at present, we are only using GET requests.
|
||||
|
||||
Experience with converting the restbucksCRUD example to use the framework, shows that it is certainly possible to do POST and PUT processing with it. But enhancements are needed, especially in the area of decoding the request entity.
|
||||
|
||||
### is_entity_too_large
|
||||
|
||||
If your application has limits on the size of entities that it can store, then you implement them here.
|
||||
|
||||
### check_content_headers
|
||||
|
||||
This is called after is_entity_too_large returns False. You are supposed to check the following request headers, and take any appropriate actions (such as setting an error, decompression the entity, or converting it to a different character set):
|
||||
|
||||
* Content-Encoding
|
||||
* Content-Language
|
||||
* Content-MD5
|
||||
* Content-Range
|
||||
* Content-Type
|
||||
|
||||
At the moment, your duty is to set the execution variable CONTENT_CHECK_CODE to zero, or an HTTP error status code. A future enhancement of the framework might be to provide more support for this.
|
||||
|
||||
### content_check_code
|
||||
|
||||
This simply accesses the execution variable CONTENT_CHECK_CODE set in check_content_headers. if you want to use some other mechanism, then you can redefine this routine.
|
||||
|
||||
### create_resource
|
||||
|
||||
This routine is called when a PUT request is made with a URI that refers to a resource that does not exist (PUT is normally used for updating an existing resource), and you have already decided to allow this.
|
||||
In this routine you have the responsibilities of:
|
||||
|
||||
1. Creating the resource using the entity in REQUEST_ENTITY (or some decoded version that you have stored elsewhere).
|
||||
1. Writing the entire response yourself (as I said before, support for PUT and POST processing is poor at present), including setting the status code of 201 Created or 303 See Other or 500 Internal server error).
|
||||
|
||||
### append_resource
|
||||
|
||||
This routine is called for POST requests on an existing resource (normal usage).
|
||||
|
||||
In this routine you have the responsibilities of:
|
||||
|
||||
1. Storing the entity from REQUEST_ENTITY (or some decoded version that you have stored elsewhere), or whatever other action is appropriate for the semantics of POST requests to this URI.
|
||||
1. Writing the entire response yourself (as I said before, support for PUT and POST processing is poor at present), including setting the status code of 200 OK, 204 No Content, 303 See Other or 500 Internal server error).
|
||||
|
||||
### check_conflict
|
||||
|
||||
This is called for a normal (updating) PUT request. You have to check to see if the current state of the resource makes updating impossible. If so, then you need to write the entire response with a status code of 409 Conflict, and set the execution variable CONFLICT_CHECK_CODE to 409.
|
||||
Otherwise you just set the execution variable CONFLICT_CHECK_CODE to 0.
|
||||
|
||||
See [the HTTP/1.1 specification](http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.10) for when you are allowed to use the 409 response, and what to write in the response entity. If this is not appropriate then a 500 Internal server error would be more appropriate (and set CONFLICT_CHECK_CODE to 500 - the framework only tests for non-zero).
|
||||
|
||||
### conflict_check_code
|
||||
|
||||
This is implemented to check CONFLICT_CHECK_CODE from the previous routine. If you choose to use a different mechanism, then you need to redefine this.
|
||||
|
||||
### check_request
|
||||
|
||||
This is called for PUT and POST requests. You need to check that the request entity (available in the execution variable REQUEST_ENTITY) is valid for the semantics of the request URI. You should set the execution variable REQUEST_CHECK_CODE to 0 if it is OK. If not, set it to 400 and write the full response, including a status code of 400 Bad Request.
|
||||
|
||||
### request_check_code
|
||||
|
||||
This routine just checks REQUEST_CHECK_CODE. if you choose to use a different mechanism, then redefine it.
|
||||
|
||||
### update_resource
|
||||
|
||||
This routine is called for a normal (updating) PUT request. You have to update the state of the resource using the entity saved in the execution environment variable REQUEST_ENTITY (or more likely elsewhere - see what ORDER_HANDLER does). Then write the entire response including a status code of 204 No Content or 500 Internal server error.
|
||||
|
||||
## Implementing the policies
|
||||
|
||||
* [WSF_OPTIONS_POLICY](WSF_OPTIONS_POLICY.md)
|
||||
* [WSF_PREVIOUS_POLICY](Wsf-previous-policy.md)
|
||||
* [WSF_CACHING_POLICY](Wsf-caching-policy.md)
|
||||
52
doc/wiki/policy-driven-framework/Wsf-caching-policy.md
Normal file
52
doc/wiki/policy-driven-framework/Wsf-caching-policy.md
Normal file
@@ -0,0 +1,52 @@
|
||||
# Implementing WSF_CACHING_POLICY
|
||||
|
||||
This class contains a large number of routines, some of which have sensible defaults.
|
||||
|
||||
## age
|
||||
|
||||
This is used to generate a **Cache-Control: max-age** header. It says how old the response can before a cache will consider it stale (and therefore will need to revalidate with the server). Common values are zero (always consider it stale) and Never_expires (never always mean up to one year) and 1440 (one day).
|
||||
|
||||
## shared_age
|
||||
|
||||
This defaults to the same as age, so you only have to redefine it if you want a different value. If different from age, then we generate a **Cache-Control: s-max-age** header. This applies to shared caches only. Otherwise it has the same meaning as age. This overrides the value specified in age for shared caches.
|
||||
|
||||
## http_1_0_age
|
||||
|
||||
This generates an **Expires** header, and has the same meaning as age, but is understood by HTTP/1.0 caches. By default it has the same value as age. You only need to redefine this if you want to treat HTTP/1.0 caches differently (you might not trust them so well, so you might want to return 0 here).
|
||||
|
||||
## is_freely_cacheable
|
||||
|
||||
This routine says whether a shared cache can use this response for all client. If True, then it generates a **Cache-Control: public** header. If your data is at all sensitive, then you want to return False here.
|
||||
|
||||
## is_transformable
|
||||
|
||||
Non-transparent proxies are allowed to make some modifications to headers. If your application relies on this _not_ happening, then you want to return False here. This is the default, so you don't have to do anything. This means a **Cache-Control: no-transform** header will be generated.
|
||||
But most applications can return True.
|
||||
|
||||
## must_revalidate
|
||||
|
||||
Some clients request that their private cache ignores server expiry times (and so freely reuse stale responses). If you want to force revalidation anyway in such circumstances, then redefine to return True. In which case, we generate a **Cache-Control: must-revalidate** header.
|
||||
|
||||
## must_proxy_revalidate
|
||||
|
||||
This is the same as must_revalidate, but only applies to shared caches that are configured to serve stale responses. If you redefine to return True, then we generate a **Cache-Control: proxy-revalidate** header.
|
||||
|
||||
## private_headers
|
||||
|
||||
This is used to indicate that parts (or all) of a response are considered private to a single user, and should not be freely served from a shared cache. You must implement this routine. Your choices are:
|
||||
|
||||
1. Return Void. None of the response is considered private.
|
||||
1. Return and empty list. All of the response is considered private.
|
||||
1. Return a list of header names.
|
||||
|
||||
If you don't return Void, then a **Cache-Control: private** header will be generated.
|
||||
|
||||
## non_cacheable_headers
|
||||
|
||||
This is similar to private_headers, and you have the same three choices. the difference is that it is a list of headers (or the whole response) that will not be sent from a cache without revalidation.
|
||||
|
||||
If you don't return Void, then a **Cache-Control: no-cache** header will be generated.
|
||||
|
||||
## is_sensitive
|
||||
|
||||
Is the response to be considered of a sensitive nature? If so, then it will not be archived from a cache. We generate a **Cache-Control: no-store** header.
|
||||
19
doc/wiki/policy-driven-framework/Wsf-previous-policy.md
Normal file
19
doc/wiki/policy-driven-framework/Wsf-previous-policy.md
Normal file
@@ -0,0 +1,19 @@
|
||||
# WSF_PREVIOUS_POLICY
|
||||
|
||||
This class deals with resources that have moved or gone. The default assumes no such resources. It exists as a separate class, rather than have the routines directly in WSF_SKELETON_HANDLER, as sub-classing it may be convenient for an organisation.
|
||||
|
||||
## resource_previously_existed
|
||||
|
||||
Redefining this routine is always necessary if you want to deal with any previous resources.
|
||||
|
||||
## resource_moved_permanently
|
||||
|
||||
Redefine this routine for any resources that have permanently changed location. The framework will generate a 301 Moved Permanently response, and the user agent will automatically redirect the request to (one of) the new location(s) you provide. The user agent will use the new URI for future requests.
|
||||
|
||||
## resource_moved_temporarily
|
||||
|
||||
This is for resource that have only been moved for a short period. The framework will generate a 302 Found response. The only substantial difference between this and resource_moved_permanently, is that the agent will use the old URI for future requests.
|
||||
|
||||
## previous_location
|
||||
|
||||
When you redefine resource_moved_permanently or resource_moved_temporarily, the framework will generate a Location header for the new URI, and a hypertext document to the new URI(s). You **must** redefine this routine to provide those locations (the first one you provide will be in the location header).
|
||||
4
doc/wiki/project/Meetings.md
Normal file
4
doc/wiki/project/Meetings.md
Normal file
@@ -0,0 +1,4 @@
|
||||
# Previous and future meetings
|
||||
|
||||
* [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)
|
||||
@@ -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]] 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
|
||||
|
||||
----
|
||||
@@ -12,3 +12,9 @@ For any entry, please use this template
|
||||
|
||||
----
|
||||
|
||||
## Add support for Swagger
|
||||
* _Suggested by **Olivier**_
|
||||
* _Description_: Build a Swagger Eiffel implementation
|
||||
* _References_: [http://swagger.wordnik.com/](http://swagger.wordnik.com/)
|
||||
|
||||
----
|
||||
@@ -6,13 +6,13 @@ If you are a student, don't hesitate to pick one, or even suggest a new project,
|
||||
|
||||
## Evaluate EWF according to the following constraints ...
|
||||
* _Suggested by **Javier**_
|
||||
* _Description_: According to http://www.amundsen.com/blog/archives/1130 , evaluate the current design of EWF to see if this match the different points. An other option would be to take the following REST implementation toolkit as a guide to evaluate EWF http://code.google.com/p/implementing-rest/wiki/RESTImplementationToolkit.
|
||||
* _Description_: According to [http://www.amundsen.com/blog/archives/1130](http://www.amundsen.com/blog/archives/1130) , evaluate the current design of EWF to see if this match the different points. An other option would be to take the following REST implementation toolkit as a guide to evaluate EWF [http://code.google.com/p/implementing-rest/wiki/RESTImplementationToolkit](http://code.google.com/p/implementing-rest/wiki/RESTImplementationToolkit).
|
||||
|
||||
## Road to Hypermedia API
|
||||
* _Suggested by **Javier**_
|
||||
* _Supervisor_:
|
||||
* _Suitability_:
|
||||
* _Description_: describe differents types of Web API, and how you can build them using EWF. Describing Pros and Cons. This should be on http://martinfowler.com/articles/richardsonMaturityModel.html
|
||||
* _Description_: describe differents types of Web API, and how you can build them using EWF. Describing Pros and Cons. This should be on [http://martinfowler.com/articles/richardsonMaturityModel.html](http://martinfowler.com/articles/richardsonMaturityModel.html)
|
||||
|
||||
## Build a video to demonstrate how an Hypermedia API works, and how to build it using EWF
|
||||
* _Suggested by **Javier**_
|
||||
@@ -55,8 +55,8 @@ If you are a student, don't hesitate to pick one, or even suggest a new project,
|
||||
* _Supervisor_:
|
||||
* _Suitability_: TODO
|
||||
* _Description_: EWF is relying on the notion of "connector" to achieve portability on various platform and underlying httpd server, currently EWF support any CGI or libFCGI system (i.e apache, IIS, ...), and provide a standalone version thanks to Eiffel Web Nino. The goal now, would be to support specific connector for:
|
||||
** LightHTTP (http://www.lighttpd.net/)
|
||||
** nginx (http://nginx.org/en/)
|
||||
** LightHTTP ([http://www.lighttpd.net/](http://www.lighttpd.net/))
|
||||
** nginx ([http://nginx.org/en/](http://nginx.org/en/))
|
||||
|
||||
## Concurrenty and EWF
|
||||
* _Suggested by **Jocelyn**_
|
||||
@@ -75,7 +75,7 @@ If you are a student, don't hesitate to pick one, or even suggest a new project,
|
||||
* _Supervisor_:
|
||||
* _Suitability_: TODO
|
||||
* _Description_: Provide an implementation of websocket with EWF and eventually Eiffel Web Nino, then demonstrate it on a simple example. WebSocket is a web technology providing for bi-directional, full-duplex communications channels over a single TCP connection.
|
||||
* See http://en.wikipedia.org/wiki/Websocket
|
||||
* See [http://en.wikipedia.org/wiki/Websocket](http://en.wikipedia.org/wiki/Websocket)
|
||||
|
||||
----
|
||||
# Usage of EWF
|
||||
@@ -84,18 +84,19 @@ If you are a student, don't hesitate to pick one, or even suggest a new project,
|
||||
* _Suggested by **Javier**_
|
||||
* _Supervisor_:
|
||||
* _Suitability_: TODO
|
||||
* _Description_: Build a HAL browser to discover an API using HAL mediatype. The browser will be able to follow the links, and display the transmitted data. This could be a vision2 application inspired by http://haltalk.herokuapp.com/explorer/hal_browser.html#/. HAL stands for Hypertext Application Language see http://stateless.co/hal_specification.html.
|
||||
* _Description_: Build a HAL browser to discover an API using HAL mediatype. The browser will be able to follow the links, and display the transmitted data. This could be a vision2 application inspired by [http://haltalk.herokuapp.com/explorer/hal_browser.html#/](http://haltalk.herokuapp.com/explorer/hal_browser.html#/). HAL stands for Hypertext Application Language see [http://stateless.co/hal_specification.html](http://stateless.co/hal_specification.html).
|
||||
|
||||
## Collection-JSON browser
|
||||
* _Suggested by **Javier**_
|
||||
* _Supervisor_:
|
||||
* _Suitability_: TODO
|
||||
* _Description_: Build a Collection/JSON browser to discover an API using Collection/JSON mediatype. The browser will be able to follow the links, and display the transmitted data. This could be a vision2 application inspired by http://haltalk.herokuapp.com/explorer/hal_browser.html#/. Collection+JSON is a JSON-based read/write hypermedia-type, see http://www.amundsen.com/media-types/collection/
|
||||
* _Description_: Build a Collection/JSON browser to discover an API using Collection/JSON mediatype. The browser will be able to follow the links, and display the transmitted data. This could be a vision2 application inspired by [http://haltalk.herokuapp.com/explorer/hal_browser.html#/](http://haltalk.herokuapp.com/explorer/hal_browser.html#/). Collection+JSON is a JSON-based read/write hypermedia-type, see [http://www.amundsen.com/media-types/collection/](http://www.amundsen.com/media-types/collection/)
|
||||
|
||||
## Build a simple CMS with EWF
|
||||
* _Suggested by **Jocelyn**_
|
||||
* _Supervisor_:
|
||||
* _Suitability_: TODO
|
||||
* _Status_: started, and open for contribution, collaboration, please contact Jocelyn.
|
||||
* _Description_: Using EWF, Build a simple CMS (Content Management System) framework and then an example. It should provide common features such as:
|
||||
- user management (register, login, lost password -> send email)
|
||||
- page editing
|
||||
@@ -118,7 +119,7 @@ If you are a student, don't hesitate to pick one, or even suggest a new project,
|
||||
* _Suggested by **Javier**_
|
||||
* _Supervisor_:
|
||||
* _Suitability_: TODO
|
||||
* _Description_: Use XHTML as a media type to for hypermedia API. See http://codeartisan.blogspot.com.ar/2012/07/using-html-as-media-type-for-your-api.html
|
||||
* _Description_: Use XHTML as a media type to for hypermedia API. See [http://codeartisan.blogspot.com.ar/2012/07/using-html-as-media-type-for-your-api.html](http://codeartisan.blogspot.com.ar/2012/07/using-html-as-media-type-for-your-api.html)
|
||||
|
||||
## Add support for Mediatype such as RSS, ATOM, ...
|
||||
* _Suggested by **Jocelyn**_
|
||||
@@ -154,24 +155,24 @@ If you are a student, don't hesitate to pick one, or even suggest a new project,
|
||||
* _Suitability_: TODO
|
||||
* _Description_: Design and build a Single Sign On implementation for Eiffel. That should include the authentication server, and at least one Eiffel client component (it would be convenient to also provide php, js, ...). In the same spirit, having Eiffel client for popular SSO server would be appreciated as well.
|
||||
* _Reference_:
|
||||
- http://en.wikipedia.org/wiki/Single_sign-on
|
||||
- http://en.wikipedia.org/wiki/List_of_single_sign-on_implementations
|
||||
- [http://en.wikipedia.org/wiki/Single_sign-on](http://en.wikipedia.org/wiki/Single_sign-on)
|
||||
- [http://en.wikipedia.org/wiki/List_of_single_sign-on_implementations](http://en.wikipedia.org/wiki/List_of_single_sign-on_implementations)
|
||||
|
||||
## library: Template engine
|
||||
* _Suggested by **Jocelyn**_
|
||||
* _Supervisor_:
|
||||
* _Suitability_: TODO
|
||||
* _Description_: Get inspired by any existing template engine, and build one for Eiffel, this should be easily usable within a web application. This could be inspired, or implementation of standard template engine, this way people can reuse existing content, or migrate easily their application to EWF. For inspiration, one can look at:
|
||||
- http://www.smarty.net/
|
||||
- http://mustache.github.com/
|
||||
- http://en.wikipedia.org/wiki/Template_engine_(web) ... they are plenty of them, a comparison of the different engine would help.
|
||||
- [http://www.smarty.net/](http://www.smarty.net/)
|
||||
- [http://mustache.github.com/](http://mustache.github.com/)
|
||||
- [http://en.wikipedia.org/wiki/Web_template_system](http://en.wikipedia.org/wiki/Web_template_system) ... they are plenty of them, a comparison of the different engine would help.
|
||||
* This is not specific to EWF, but it will be very useful in website context.
|
||||
|
||||
## library: Wikitext, markdown parser and render engine
|
||||
* _Suggested by **Jocelyn**_
|
||||
* _Supervisor_:
|
||||
* _Suitability_: TODO
|
||||
* _Description_: Build component to support (read and write, and why not convert), lightweight markup language (see http://en.wikipedia.org/wiki/Lightweight_markup_language) such as wikitext, markdown, and other. The component should be able to read/scan, but also produce an HTML output. Focus first on wikitext, and markdown since they seems to be the most popular.
|
||||
* _Description_: Build component to support (read and write, and why not convert), lightweight markup language (see [http://en.wikipedia.org/wiki/Lightweight_markup_language](http://en.wikipedia.org/wiki/Lightweight_markup_language)) such as wikitext, markdown, and other. The component should be able to read/scan, but also produce an HTML output. Focus first on wikitext, and markdown since they seems to be the most popular.
|
||||
* Then , a nice addition would be to render those lightweight markup lang into Vision2 widget (not related to EWF, but could be useful to build (editor) desktop application)
|
||||
|
||||
## library: Web component to build HTML5 widget
|
||||
@@ -194,16 +195,16 @@ If you are a student, don't hesitate to pick one, or even suggest a new project,
|
||||
* _Suitability_: TODO
|
||||
* _Description_: TODO
|
||||
* Generic client that can be customized (see design in slide 12)
|
||||
* http://s3.amazonaws.com/cimlabs/Oredev-Hypermedia-APIs.pdf
|
||||
* video http://vimeo.com/20781278
|
||||
* [http://s3.amazonaws.com/cimlabs/Oredev-Hypermedia-APIs.pdf](http://s3.amazonaws.com/cimlabs/Oredev-Hypermedia-APIs.pdf)
|
||||
* video [http://vimeo.com/20781278](http://vimeo.com/20781278)
|
||||
|
||||
## Create a Client Cache based on Apache commons Client Cache.
|
||||
* _Suggested by **Javier**_
|
||||
* _Supervisor_:
|
||||
* _Suitability_: TODO
|
||||
* _Description_: TODO
|
||||
* http://hc.apache.org/httpcomponents-client-ga/httpclient-cache/index.html
|
||||
* http://labs.xfinity.com/benchmarking-the-httpclient-caching-module
|
||||
* [http://hc.apache.org/httpcomponents-client-ga/httpclient-cache/index.html](http://hc.apache.org/httpcomponents-client-ga/httpclient-cache/index.html)
|
||||
* [http://labs.xfinity.com/benchmarking-the-httpclient-caching-module](http://labs.xfinity.com/benchmarking-the-httpclient-caching-module)
|
||||
|
||||
## Add SSL support to Eiffel Net
|
||||
* _Suggested by **Jocelyn**_
|
||||
@@ -225,7 +226,14 @@ If you are a student, don't hesitate to pick one, or even suggest a new project,
|
||||
* This should reuse and improve the "http_client" provided by EWF. Eventually also write the EiffelNet implementation to be independant from cURL
|
||||
* **Requirement**: OAuth client eiffel component
|
||||
|
||||
## Build a ESI preprocessor, or proxy
|
||||
* _Suggested by **Jocelyn**_
|
||||
* _Supervisor_:
|
||||
* _Suitability_: TODO
|
||||
* _Description_: TODO
|
||||
* See: [http://en.wikipedia.org/wiki/Edge_Side_Includes](http://en.wikipedia.org/wiki/Edge_Side_Includes)
|
||||
|
||||
----
|
||||
# Feel free to add new idea below this line
|
||||
----
|
||||
Use the following page [[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.
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user