Commit 986b3f3acce98f1c71ba1c9b2307ecf5602ffccc

Authored by Cédric RICARD
1 parent 23f86e1b

Adding Json types

Adding http header to invalidate 'keep-alive' (mandatory by HTTP 1.1)
calexium_lib/web/CXM_dojo.anubis
@@ -255,7 +255,22 @@ define String @@ -255,7 +255,22 @@ define String
255 right then "right" 255 right then "right"
256 }. 256 }.
257 257
  258 +public type BorderContainerDesign:
  259 + headline,
  260 + sidebar.
258 261
  262 +define String
  263 + to_String
  264 + (
  265 + BorderContainerDesign design
  266 + )=
  267 + if design is
  268 + {
  269 + headline then "headline",
  270 + sidebar then "sidebar"
  271 + }.
  272 +
  273 +
259 public define HTML_Off_Form 274 public define HTML_Off_Form
260 dojo_ContentPane 275 dojo_ContentPane
261 ( 276 (
@@ -268,18 +283,7 @@ public define HTML_Off_Form @@ -268,18 +283,7 @@ public define HTML_Off_Form
268 attr("region", to_String(region)), 283 attr("region", to_String(region)),
269 attr("splitter", if splitter then "true" else "false") . attributes ], 284 attr("splitter", if splitter then "true" else "false") . attributes ],
270 content). 285 content).
271 -// sequence([  
272 -// literal("<div id=\"" + id + "\" dojoType=\"dijit.layout.ContentPane\" region=\"" + to_String(region) + "\" splitter=\""  
273 -// +(  
274 -// if splitter then "true"  
275 -// else "false"  
276 -// )+  
277 -// // "\" style=\"overflow: auto;\""+  
278 -// // "\" minSize=\"20em\""+  
279 -// "\">"),  
280 -// content,  
281 -// literal("</div>")  
282 -// ]). 286 +
283 287
284 public define HTML_Off_Form 288 public define HTML_Off_Form
285 dojo_TabContainer 289 dojo_TabContainer
@@ -289,25 +293,22 @@ public define HTML_Off_Form @@ -289,25 +293,22 @@ public define HTML_Off_Form
289 ) = 293 ) =
290 div([attr("dojoType", "dijit.layout.TabContainer") . attributes ], 294 div([attr("dojoType", "dijit.layout.TabContainer") . attributes ],
291 content). 295 content).
292 -// sequence([  
293 -// literal("<div id=\"" + id + "\" dojoType=\"dijit.layout.TabContainer\" style=\"width:70em;height:50em\">"),  
294 -// content,  
295 -// literal("</div>")  
296 -// ]). 296 +
297 297
298 public define HTML_Off_Form 298 public define HTML_Off_Form
299 dojo_BorderContainer 299 dojo_BorderContainer
300 ( 300 (
301 - List(CoreAttrs) attributes,  
302 - String the_title,  
303 - Bool live_splitter,  
304 - Bool persist,  
305 - Bool closable,  
306 - String container,  
307 - HTML_Off_Form content 301 + List(CoreAttrs) attributes,
  302 + String the_title,
  303 + BorderContainerDesign design,
  304 + Bool live_splitter,
  305 + Bool persist,
  306 + Bool closable,
  307 + String container,
  308 + HTML_Off_Form content
308 ) = 309 ) =
309 div([attr("dojoType", "dijit.layout.BorderContainer"), title(the_title), attr("dojoAttachPoint", container), 310 div([attr("dojoType", "dijit.layout.BorderContainer"), title(the_title), attr("dojoAttachPoint", container),
310 - attr("design", "sidebar"), attr("liveSplitters", live_splitter), attr("persist", persist), attr("closable",closable) . attributes ], 311 + attr("design", to_String(design)), attr("liveSplitters", live_splitter), attr("persist", persist), attr("closable",closable) . attributes ],
311 content). 312 content).
312 313
313 314
@@ -317,7 +318,7 @@ public define HTML_Off_Form @@ -317,7 +318,7 @@ public define HTML_Off_Form
317 List(CoreAttrs) attributes, 318 List(CoreAttrs) attributes,
318 )= 319 )=
319 div_empty(attributes). 320 div_empty(attributes).
320 -// literal("<div id=\"" + id + "\"</div>"). 321 +
321 322
322 323
323 public define HTML_Off_Form 324 public define HTML_Off_Form
@@ -328,11 +329,7 @@ public define HTML_Off_Form @@ -328,11 +329,7 @@ public define HTML_Off_Form
328 )= 329 )=
329 div([attr("dojoType", "dijit.Toolbar") . attributes ], 330 div([attr("dojoType", "dijit.Toolbar") . attributes ],
330 content). 331 content).
331 -// sequence([  
332 -// literal("<div dojoType=\"dijit.Toolbar\" region=\"top\" id =\"" + id + "\">"),  
333 -// content,  
334 -// literal("</div>")  
335 -// ]). 332 +
336 333
337 334
338 public define HTML_Off_Form 335 public define HTML_Off_Form
@@ -345,7 +342,12 @@ public define HTML_Off_Form @@ -345,7 +342,12 @@ public define HTML_Off_Form
345 String execute, 342 String execute,
346 )= 343 )=
347 literal(" 344 literal("
348 - <button dojoType=\"dijit.form.Button\" id=\"" + html_id.id + "\" iconClass=\"" + iconclass + "\" onclick=\"" + execute + "\">" + name + "</button>" + 345 + <button dojoType=\"dijit.form.Button\" id=\"" + html_id.id + "\" iconClass=\"" + iconclass + "\" >"
  346 + + name
  347 + + "<script type=\"dojo/method\" event=\"onClick\">"
  348 + + execute
  349 + + "</script>"
  350 + + "</button>" +
349 if tip_msg is 351 if tip_msg is
350 { 352 {
351 failure then "", 353 failure then "",
calexium_lib/web/CXM_json.anubis 0 → 100644
  1 +/*
  2 + * Created by PyramIDE.
  3 + * User: ricard
  4 + * Date: 18/08/2008
  5 + * Time: 08:12
  6 + *
  7 + * To change this template use Tools | Options | Coding | Edit Standard Headers.
  8 + */
  9 +
  10 +read tools/basis.anubis
  11 +
  12 +public type JsonMember:...
  13 +
  14 +
  15 +public type JsonValue:
  16 + json_object(List(JsonMember)),
  17 + json_array(List(JsonValue)),
  18 + json_int(Int value),
  19 + json_float(Float value, Int precision),
  20 + json_string(String value),
  21 + json_bool(Bool value),
  22 + json_null.
  23 +
  24 +
  25 +public type JsonMember:
  26 + json_member(String name,
  27 + JsonValue value).
  28 +
  29 +//-------------------------------
  30 +// helpers
  31 +
  32 +public define JsonMember
  33 + json_member
  34 + (
  35 + String name,
  36 + List(JsonMember) value,
  37 + ) =
  38 + json_member(name, json_object(value)).
  39 +
  40 +
  41 +public define JsonMember
  42 + json_member
  43 + (
  44 + String name,
  45 + List(JsonValue) value,
  46 + ) =
  47 + json_member(name, json_array(value)).
  48 +
  49 +public define JsonMember
  50 + json_member
  51 + (
  52 + String name,
  53 + Int value,
  54 + ) =
  55 + json_member(name, json_int(value)).
  56 +
  57 +public define JsonMember
  58 + json_member
  59 + (
  60 + String name,
  61 + Float value,
  62 + Int precision,
  63 + ) =
  64 + json_member(name, json_float(value, precision)).
  65 +
  66 +public define JsonMember
  67 + json_member
  68 + (
  69 + String name,
  70 + String value,
  71 + ) =
  72 + json_member(name, json_string(value)).
  73 +
  74 +public define JsonMember
  75 + json_member
  76 + (
  77 + String name,
  78 + Bool value,
  79 + ) =
  80 + json_member(name, json_bool(value)).
  81 +
  82 +public define JsonMember
  83 + json_null
  84 + (
  85 + String name,
  86 + ) =
  87 + json_member(name, json_null).
  88 +
  89 +//-------------------------------------------
  90 +// Outputing Json to Printable_tree
  91 +
  92 +define List(Word8)
  93 + _format_json_esc
  94 + (
  95 + List(Word8) original,
  96 + List(Word8) new_string,
  97 + ) =
  98 + if original is
  99 + {
  100 + [] then new_string,
  101 + [h . t] then
  102 + if (h >=+ 32 & h +=< 33) | (h >=+ 35 & h +=< 38) |(h >=+ 40 & h +=< 91) | h >=+ 93 then // Allowed characters for JSON see RFC4627 + " ' "
  103 + _format_json_esc(t, [h . new_string])
  104 + else
  105 + _format_json_esc(t, [h, '\\' . new_string])
  106 + }.
  107 +
  108 +public define String
  109 + format_json_esc
  110 + (
  111 + String original,
  112 + ) =
  113 + implode(reverse(_format_json_esc(explode(original), [],))).
  114 +
  115 +
  116 +public define Printable_tree
  117 + format_json
  118 + (
  119 + JsonValue json
  120 + ).
  121 +
  122 +public define Printable_tree
  123 + format_json_member
  124 + (
  125 + JsonMember member
  126 + ) =
  127 + if member is json_member(name, value) then
  128 + [ "'", name, "':" . format_json(value) ].
  129 +
  130 +
  131 +define Printable_tree
  132 + format_json_object
  133 + (
  134 + List(JsonMember) members
  135 + ) =
  136 + if members is
  137 + {
  138 + [] then [],
  139 + [h . t] then [ format_json_member(h), (if t is [] then "" else ",") . format_json_object(t) ]
  140 + }.
  141 +
  142 +define Printable_tree
  143 + format_json_array
  144 + (
  145 + List(JsonValue) values
  146 + ) =
  147 + if values is
  148 + {
  149 + [] then [],
  150 + [h . t] then [ format_json(h), (if t is [] then "" else ",") . format_json_array(t) ]
  151 + }.
  152 +
  153 +public define Printable_tree
  154 + format_json
  155 + (
  156 + JsonValue json
  157 + ) =
  158 + if json is
  159 + {
  160 + json_object(members) then [ "{", format_json_object(members), "}" . [] ],
  161 + json_array(values) then [ "[", format_json_array(values), "]" . [] ],
  162 + json_int(i) then int_pt(i, []),
  163 + json_float(f, p) then str_pt(float_to_string(f, p), []),
  164 + json_string(s) then str_pt("'" + format_json_esc(s) + "'", []),
  165 + json_bool(b) then str_pt(if b then "true" else "false", []),
  166 + json_null then str_pt("null", [])
  167 + }.
  168 +
calexium_lib/web/CXM_making_a_web_site.anubis
@@ -990,6 +990,27 @@ public type TextAreaOption: @@ -990,6 +990,27 @@ public type TextAreaOption:
990 disabled, 990 disabled,
991 read_only, 991 read_only,
992 wrap_lines. 992 wrap_lines.
  993 +
  994 +public type CSS_Style:
  995 + text_options(List(Text_Option)).
  996 +
  997 +public type CSS_File:
  998 + css_file(String file_name).
  999 +
  1000 +public type JS_Attribute:
  1001 + attr (String, String).
  1002 +
  1003 +public type JS_File:
  1004 + js_file(String file_name,
  1005 + List(JS_Attribute) attributes).
  1006 +
  1007 +public define JS_File
  1008 + js_file
  1009 + (
  1010 + String file_name
  1011 + ) =
  1012 + js_file(file_name, []).
  1013 +
993 1014
994 public type HTML_In_Form: 1015 public type HTML_In_Form:
995 literal_pt (Printable_tree), 1016 literal_pt (Printable_tree),
@@ -1174,6 +1195,7 @@ public define HTML_In_Form @@ -1174,6 +1195,7 @@ public define HTML_In_Form
1174 file_upload (WebArgName name, Int width) 1195 file_upload (WebArgName name, Int width)
1175 = file_upload([], "", htmlId(""), name, width). 1196 = file_upload([], "", htmlId(""), name, width).
1176 1197
  1198 +public type HTML_Body:...
1177 1199
1178 public type HTML_Off_Form: 1200 public type HTML_Off_Form:
1179 literal_pt (Printable_tree), 1201 literal_pt (Printable_tree),
@@ -1209,7 +1231,12 @@ public type HTML_Off_Form: @@ -1209,7 +1231,12 @@ public type HTML_Off_Form:
1209 String action_name, List((String,String)) extra_ops, 1231 String action_name, List((String,String)) extra_ops,
1210 HTML_In_Form content), 1232 HTML_In_Form content),
1211 div (List(CoreAttrs), HTML_Off_Form content), 1233 div (List(CoreAttrs), HTML_Off_Form content),
1212 - div_empty (List(CoreAttrs)). 1234 + div_empty (List(CoreAttrs)),
  1235 + iframe (List(CoreAttrs),
  1236 + List(CSS_Style) /*styles*/,
  1237 + List(CSS_File) /*css_files*/,
  1238 + List(JS_File) /*js_files*/,
  1239 + HTML_Body /*body*/).
1213 1240
1214 'HTML_Off_Form' defines all the elements you may put outside any form. 1241 'HTML_Off_Form' defines all the elements you may put outside any form.
1215 1242
@@ -1401,25 +1428,6 @@ public define HTML_Row(HTML_In_Form) @@ -1401,25 +1428,6 @@ public define HTML_Row(HTML_In_Form)
1401 1428
1402 1429
1403 1430
1404 -public type CSS_Style:  
1405 - text_options(List(Text_Option)).  
1406 -  
1407 -public type CSS_File:  
1408 - css_file(String file_name).  
1409 -  
1410 -public type JS_Attribute:  
1411 - attr (String, String).  
1412 -  
1413 -public type JS_File:  
1414 - js_file(String file_name,  
1415 - List(JS_Attribute) attributes).  
1416 -  
1417 -public define JS_File  
1418 - js_file  
1419 - (  
1420 - String file_name  
1421 - ) =  
1422 - js_file(file_name, []).  
1423 1431
1424 define String 1432 define String
1425 format 1433 format
@@ -3729,6 +3737,92 @@ define Printable_tree @@ -3729,6 +3737,92 @@ define Printable_tree
3729 ]. 3737 ].
3730 3738
3731 3739
  3740 +
  3741 +define Printable_tree
  3742 + format
  3743 + (
  3744 + Body_Option o
  3745 + ) =
  3746 + if o is
  3747 + {
  3748 + core_attrs(core_attr_list) then [" " + format_attrs(core_attr_list)],
  3749 + background_color(c) then [" bgcolor=\"" , (String)html_format(c), "\""],
  3750 + background_image(n) then [" background=", n],
  3751 + background_image(n,o2) then [" style=\"background: url(",n,")",format(o2),"\""]
  3752 +
  3753 + }.
  3754 +
  3755 +
  3756 +
  3757 +define Printable_tree
  3758 + format
  3759 + (
  3760 + List(Body_Option) l
  3761 + ) =
  3762 + if l is
  3763 + {
  3764 + [ ] then [ ],
  3765 + [h . t] then [format(h) . format(t)]
  3766 + }.
  3767 +
  3768 +define Printable_tree
  3769 + add_css_files
  3770 + (
  3771 + List(CSS_File) l
  3772 + ) =
  3773 + if l is
  3774 + {
  3775 + [ ] then [ ],
  3776 + [h . t] then
  3777 + [ ["<link rel=\"stylesheet\" type=\"text/css\" href=\"" + file_name(h) + "\" />\n" ]
  3778 + . add_css_files(t)]
  3779 + }.
  3780 +
  3781 +define Printable_tree
  3782 + add_js_files_attributes
  3783 + (
  3784 + List(JS_Attribute) l
  3785 + ) =
  3786 + if l is
  3787 + {
  3788 + [ ] then [ ],
  3789 + [h . t] then
  3790 + if h is attr(name, value) then
  3791 + [ " " + name + "=\"" + value + "\""
  3792 + . add_js_files_attributes(t)]
  3793 + }.
  3794 +
  3795 +
  3796 +define Printable_tree
  3797 + add_js_files
  3798 + (
  3799 + List(JS_File) l
  3800 + ) =
  3801 + if l is
  3802 + {
  3803 + [ ] then [ ],
  3804 + [h . t] then
  3805 + [ ["<script src=\""+ file_name(h) +"\" type=\"text/javascript\""
  3806 + . add_js_files_attributes(attributes(h)) ]
  3807 + . ["></script>\n"
  3808 + . add_js_files(t)] ]
  3809 + }.
  3810 +
  3811 +define Printable_tree
  3812 + add_css_styles
  3813 + (
  3814 + List(CSS_Style) css_styles
  3815 + ) =
  3816 +
  3817 + if css_styles is
  3818 + {
  3819 + [] then [],
  3820 + [_ . _] then [ "<style type=\"text/css\"><!--\n",
  3821 + format_css_styles(css_styles),
  3822 + " --></style>\n"
  3823 + ]
  3824 + }.
  3825 +
3732 3826
3733 // The function below formats a datum of type 'HTML_Any($T)'. 3827 // The function below formats a datum of type 'HTML_Any($T)'.
3734 3828
@@ -4086,9 +4180,24 @@ define Printable_tree @@ -4086,9 +4180,24 @@ define Printable_tree
4086 "</form>" 4180 "</form>"
4087 ] 4181 ]
4088 div(options, e) then 4182 div(options, e) then
4089 - format(cinfo,sn,ic_v,any_div(options, e),format_element,is_https), 4183 + format(cinfo,sn,ic_v,any_div(options, e),format_element,is_https),
4090 div_empty(options) then 4184 div_empty(options) then
4091 - format(cinfo,sn,ic_v,any_div_empty(options),format_element,is_https), 4185 + format(cinfo,sn,ic_v,any_div_empty(options),format_element,is_https),
  4186 + iframe(options, css_styles, css_files, js_files, body) then
  4187 + if body is body(body_options,element) then
  4188 + [ "<iframe", format_attrs(options), ">\n",
  4189 + "<html style=\"margin: 0pt; padding: 0pt;\">\n",
  4190 + "<head>\n",
  4191 + add_css_styles(css_styles),
  4192 + add_css_files(css_files),
  4193 + add_js_files(js_files),
  4194 + "</head>\n",
  4195 + "<body ", format(body_options), ">\n", // format body options
  4196 + format(cinfo,sn,ic_v,element,is_https),
  4197 + "</body>\n",
  4198 + "</html>\n",
  4199 + "</iframe>\n",
  4200 + ],
4092 4201
4093 }. 4202 }.
4094 4203
@@ -4154,91 +4263,7 @@ define Printable_tree @@ -4154,91 +4263,7 @@ define Printable_tree
4154 . format(cinfo,state_name,t,is_https,charset)] 4263 . format(cinfo,state_name,t,is_https,charset)]
4155 }. 4264 }.
4156 4265
4157 -  
4158 -define Printable_tree  
4159 - format  
4160 - (  
4161 - Body_Option o  
4162 - ) =  
4163 - if o is  
4164 - {  
4165 - core_attrs(core_attr_list) then [" " + format_attrs(core_attr_list)],  
4166 - background_color(c) then [" bgcolor=\"" , (String)html_format(c), "\""],  
4167 - background_image(n) then [" background=", n],  
4168 - background_image(n,o2) then [" style=\"background: url(",n,")",format(o2),"\""]  
4169 -  
4170 - }.  
4171 -  
4172 -  
4173 -  
4174 -define Printable_tree  
4175 - format  
4176 - (  
4177 - List(Body_Option) l  
4178 - ) =  
4179 - if l is  
4180 - {  
4181 - [ ] then [ ],  
4182 - [h . t] then [format(h) . format(t)]  
4183 - }.  
4184 -  
4185 -define Printable_tree  
4186 - add_css_files  
4187 - (  
4188 - List(CSS_File) l  
4189 - ) =  
4190 - if l is  
4191 - {  
4192 - [ ] then [ ],  
4193 - [h . t] then  
4194 - [ ["<link rel=\"stylesheet\" type=\"text/css\" href=\"" + file_name(h) + "\" />\n" ]  
4195 - . add_css_files(t)]  
4196 - }.  
4197 -  
4198 -define Printable_tree  
4199 - add_js_files_attributes  
4200 - (  
4201 - List(JS_Attribute) l  
4202 - ) =  
4203 - if l is  
4204 - {  
4205 - [ ] then [ ],  
4206 - [h . t] then  
4207 - if h is attr(name, value) then  
4208 - [ " " + name + "=\"" + value + "\""  
4209 - . add_js_files_attributes(t)]  
4210 - }.  
4211 -  
4212 4266
4213 -define Printable_tree  
4214 - add_js_files  
4215 - (  
4216 - List(JS_File) l  
4217 - ) =  
4218 - if l is  
4219 - {  
4220 - [ ] then [ ],  
4221 - [h . t] then  
4222 - [ ["<script src=\""+ file_name(h) +"\" type=\"text/javascript\""  
4223 - . add_js_files_attributes(attributes(h)) ]  
4224 - . ["></script>\n"  
4225 - . add_js_files(t)] ]  
4226 - }.  
4227 -  
4228 -define Printable_tree  
4229 - add_css_styles  
4230 - (  
4231 - List(CSS_Style) css_styles  
4232 - ) =  
4233 -  
4234 - if css_styles is  
4235 - {  
4236 - [] then [],  
4237 - [_ . _] then [ "<style type=\"text/css\"><!--\n",  
4238 - format_css_styles(css_styles),  
4239 - " --></style>\n"  
4240 - ]  
4241 - }.  
4242 4267
4243 define Printable_tree 4268 define Printable_tree
4244 format 4269 format
calexium_lib/web/CXM_multihost_http_server.anubis
@@ -2306,7 +2306,8 @@ public define List(HTTP_header) @@ -2306,7 +2306,8 @@ public define List(HTTP_header)
2306 = 2306 =
2307 [ 2307 [
2308 http_header("Date", format_http_date(now)), 2308 http_header("Date", format_http_date(now)),
2309 - http_header("Server", "Anubis Embedded Server v" + major_version_number + "." + minor_version_number) 2309 + http_header("Server", "Anubis Embedded Server v" + major_version_number + "." + minor_version_number),
  2310 + http_header("Connection", "close"),
2310 ]. 2311 ].
2311 2312
2312 public define List(HTTP_header) 2313 public define List(HTTP_header)