Commit 9144e4041370ddfb1c21cfb090ad9b1f2f45423e

Authored by Steve MARECHAL
1 parent debd0caf

a page in CXM_making_a_web_site may be a html page, a plain text page ....

calexium_lib/web/CXM_dojo.anubis
... ... @@ -20,6 +20,10 @@ read common/language_management.anubis
20 20 read tools/mf_loggers.anubis
21 21 read calexium_lib/net_services_protocols/logger_service.anubis
22 22 read system/logger.anubis
  23 +
  24 +public type Dojo_Grid_Data :
  25 + grid_data(String).
  26 +
23 27 public define HTML_Off_Form
24 28 dojo_dialog
25 29 (
... ... @@ -48,7 +52,28 @@ public define HTML_Off_Form
48 52  
49 53 .
50 54  
51   -
  55 +public define HTML_Off_Form
  56 + dojo_grid
  57 + (
  58 + String id,
  59 + String colum1,
  60 + String colum2,
  61 + String colum3,
  62 + String colum4,
  63 + )
  64 + =
  65 + literal("<script>
  66 + (function(){
  67 + create_dojo_list();
  68 + }
  69 + )();
  70 + dojo.addOnLoad(function(){
  71 + init_dojo_grid(\""+colum1+"\",\""+colum2+"\", \""+colum3+"\", \""+colum4+"\");
  72 + }
  73 + );
  74 + </script>
  75 +<div id=\"gridContainer\"></div>")
  76 +.
52 77  
53 78  
54 79 public define HTML_Off_Form
... ...
calexium_lib/web/CXM_making_a_web_site.anubis
... ... @@ -45,6 +45,7 @@
45 45  
46 46  
47 47 read tools/basis.anubis
  48 +read system/string.anubis
48 49 read system/logger.anubis
49 50 read CXM_common.anubis
50 51 read CXM_multihost_http_server.anubis
... ... @@ -330,12 +331,12 @@ public type Web_Action($SessionTicket, $State):
330 331 must be sent to the client. To that end, you must provide a function (named below
331 332 'compute_page') of type:
332 333  
333   - $State -> HTML_Page
  334 + $State -> HTTP_Answer
334 335  
335   - where the type 'HTML_Page' (defined below in this file) abstractly represents HTML
  336 + where the type 'HTTP_Answer' (defined below in this file) abstractly represents HTML
336 337 pages.
337 338  
338   -public type HTML_Page:...
  339 +public type HTTP_Answer:...
339 340  
340 341 It should be clear that states and pages are deeply linked together. Indeed, we really
341 342 understand the page shown to the client as a representation of the current state of the
... ... @@ -438,7 +439,7 @@ public define Web_Site
438 439 List(Web_arg),
439 440 Bool is_https) -> (Maybe($SessionTicket), Maybe($State), List(HTTP_header)) ticket_lost_state,
440 441 List(Web_Action($SessionTicket, $State)) actions,
441   - (Maybe($SessionTicket), Maybe($State), List(Web_arg) lwa) -> HTML_Page compute_page,
  442 + (Maybe($SessionTicket), Maybe($State), List(Web_arg) lwa) -> HTTP_Answer compute_page,
442 443 Int timeout, // seconds (todo: minutes)
443 444 List(Redirection) redirections,
444 445 String charset,
... ... @@ -1460,15 +1461,21 @@ public type HTML_Body:
1460 1461 body(List(Body_Option) options, HTML_Off_Form content).
1461 1462  
1462 1463  
1463   -public type HTML_Page:
  1464 +public type HTTP_Answer:
1464 1465 html_page(String title,
1465 1466 List(HTML_Meta) meta_tags,
1466 1467 List(CSS_Style) styles,
1467 1468 List(CSS_File) css_files,
1468 1469 List(JS_File) js_files,
1469   - HTML_Body body).
1470   -
1471   -public define HTML_Page
  1470 + HTML_Body body),
  1471 + plain_text (String text),
  1472 + custom_text(String mime_type,
  1473 + String content),
  1474 + custom_binary(String mime_type,
  1475 + ByteArray content),
  1476 + http_raw(Printable_tree).
  1477 +
  1478 +public define HTTP_Answer
1472 1479 html_page
1473 1480 (
1474 1481 String title,
... ... @@ -1477,7 +1484,7 @@ public define HTML_Page
1477 1484 ) =
1478 1485 html_page(title,metas,[],[],[],body).
1479 1486  
1480   -public define HTML_Page
  1487 +public define HTTP_Answer
1481 1488 html_page
1482 1489 (
1483 1490 String title,
... ... @@ -1487,7 +1494,7 @@ public define HTML_Page
1487 1494 ) =
1488 1495 html_page(title, metas, styles, [], [], body).
1489 1496  
1490   - 'HTML_Page' represents the final product of the construction of a web page.
  1497 + 'HTTP_Answer' represents the final product of the construction of a web page.
1491 1498  
1492 1499  
1493 1500  
... ... @@ -2176,11 +2183,12 @@ type CommonInfo:
2176 2183 public define Printable_tree
2177 2184 format
2178 2185 (
2179   - CommonInfo cinfo,
2180   - String state_name,
2181   - HTML_Page page,
2182   - Bool is_https,
2183   - String charset
  2186 + CommonInfo cinfo,
  2187 + String state_name,
  2188 + List(HTTP_header) headers,
  2189 + HTTP_Answer page,
  2190 + Bool is_https,
  2191 + String charset
2184 2192 ).
2185 2193  
2186 2194  
... ... @@ -2215,7 +2223,7 @@ public define Web_Site
2215 2223 List(Web_arg),
2216 2224 Bool is_https) -> (Maybe($SessionTicket), Maybe($State), List(HTTP_header)) ticket_lost_state,
2217 2225 List(Web_Action($SessionTicket, $State)) actions,
2218   - (Maybe($SessionTicket), Maybe($State), List(Web_arg) lwa) -> HTML_Page compute_page,
  2226 + (Maybe($SessionTicket), Maybe($State), List(Web_arg) lwa) -> HTTP_Answer compute_page,
2219 2227 Int timeout,
2220 2228 Redirections redirections,
2221 2229 String charset,
... ... @@ -2251,7 +2259,7 @@ public define Web_Site
2251 2259 HTTP_Info http_info,
2252 2260 List(Web_arg) lwa,
2253 2261 Bool is_https) |->
2254   - ((List(HTTP_header),Printable_tree))
  2262 + (Printable_tree)
2255 2263 if separate_web_args(lwa) is
2256 2264 {
2257 2265 swa(mb_previous_state,mb_action_name,operands) then
... ... @@ -2288,12 +2296,12 @@ public define Web_Site
2288 2296 },
2289 2297 if state_and_headers is (session_ticket, mb_new_state, headers) then
2290 2298 with state_name = save_state(mb_new_state),
2291   - (headers,
2292   - format(info(host_name, http_port, https_port, site_directory, secret),
2293   - state_name,
2294   - compute_page(session_ticket, mb_new_state, operands),
2295   - is_https,
2296   - charset))
  2299 + format(info(host_name, http_port, https_port, site_directory, secret),
  2300 + state_name,
  2301 + headers,
  2302 + compute_page(session_ticket, mb_new_state, operands),
  2303 + is_https,
  2304 + charset)
2297 2305 }),
2298 2306 //
2299 2307 // make the delete_out_of_date function
... ... @@ -4229,7 +4237,8 @@ define Printable_tree
4229 4237 (
4230 4238 CommonInfo cinfo,
4231 4239 String state_name,
4232   - HTML_Page page,
  4240 + List(HTTP_header) additional_headers,
  4241 + HTTP_Answer page,
4233 4242 Bool is_https,
4234 4243 String charset
4235 4244 ) =
... ... @@ -4239,38 +4248,69 @@ define Printable_tree
4239 4248 {
4240 4249 html_page(title,metas,css_styles, css_files, js_files, body) then
4241 4250 if body is body(options,element) then
4242   - [ doctype_w3c_header,
4243   - "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n",
4244   - "<head>\n",
4245   - add_css_styles(css_styles),
4246   - add_css_files(css_files),
4247   - add_js_files(js_files),
4248   - "<link rel=\"shortcut icon\" href=\"favicon.ico\" />\n",
4249   - "<script type = \"text/javascript\" language=\"JavaScript\">",
4250   - " function show_local_popup(divname,stvname) {",
4251   - " if (document.layers) { var d = eval(document.divname); } else\n",
4252   - " if (document.getElementById) { var d = eval(\"document.getElementById(divname)\"); } else\n",
4253   - " if (document.all) { var d = eval(document.all.divname.style)};\n",
4254   - // " alert(typeof(eval(stvname))); ",
4255   - " var s = eval(stvname); ",
4256   - " if (s[0]==0) ",
4257   - " { s[0]=1; d.style.visibility = 'visible'; d.zIndex = 100; } else\n",
4258   - " { s[0]=0; d.style.visibility = 'hidden'; }; }",
4259   - "</script>\n",
4260   - "<title>",title,"</title>\n", // put title
4261   - format(cinfo,state_name,metas,is_https,charset), // format the metas
4262   - "</head>\n",
4263   - "<body ", format(options), ">", // format body options
4264   - //"<center>",
4265   - format(cinfo,state_name,ic_v,element,is_https),
4266   - //"</center>",
4267   - "</body>\n",
4268   - "</html>"
4269   - ]
  4251 + with answer_body =
  4252 + [ doctype_w3c_header,
  4253 + "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n",
  4254 + "<head>\n",
  4255 + add_css_styles(css_styles),
  4256 + add_css_files(css_files),
  4257 + add_js_files(js_files),
  4258 + "<link rel=\"shortcut icon\" href=\"favicon.ico\" />\n",
  4259 + "<script type = \"text/javascript\" language=\"JavaScript\">",
  4260 + " function show_local_popup(divname,stvname) {",
  4261 + " if (document.layers) { var d = eval(document.divname); } else\n",
  4262 + " if (document.getElementById) { var d = eval(\"document.getElementById(divname)\"); } else\n",
  4263 + " if (document.all) { var d = eval(document.all.divname.style)};\n",
  4264 + // " alert(typeof(eval(stvname))); ",
  4265 + " var s = eval(stvname); ",
  4266 + " if (s[0]==0) ",
  4267 + " { s[0]=1; d.style.visibility = 'visible'; d.zIndex = 100; } else\n",
  4268 + " { s[0]=0; d.style.visibility = 'hidden'; }; }",
  4269 + "</script>\n",
  4270 + "<title>",title,"</title>\n", // put title
  4271 + format(cinfo,state_name,metas,is_https,charset), // format the metas
  4272 + "</head>\n",
  4273 + "<body ", format(options), ">", // format body options
  4274 + //"<center>",
  4275 + format(cinfo,state_name,ic_v,element,is_https),
  4276 + //"</center>",
  4277 + "</body>\n",
  4278 + "</html>"
  4279 + ],
  4280 + [ "HTTP/1.1 200 OK", crlf,
  4281 + format_headers(standard_headers),
  4282 + format_headers(standard_headers_for("text/html", length(answer_body), success(charset))),
  4283 + format_headers(additional_headers),
  4284 + crlf
  4285 + . answer_body
  4286 + ],
  4287 +
  4288 + plain_text (String text) then
  4289 + [ "HTTP/1.1 200 OK", crlf,
  4290 + format_headers(standard_headers),
  4291 + format_headers(standard_headers_for("text/plain", length(text), success(charset))),
  4292 + format_headers(additional_headers),
  4293 + crlf,
  4294 + text . (Printable_tree)[]
  4295 + ],
  4296 +
  4297 + custom_text(String mime_type, String content) then
  4298 + [ "HTTP/1.1 200 OK", crlf,
  4299 + format_headers(standard_headers),
  4300 + format_headers(standard_headers_for(mime_type, length(content), success(charset))),
  4301 + format_headers(additional_headers),
  4302 + crlf,
  4303 + content . (Printable_tree)[]
  4304 + ],
  4305 + custom_binary(String mime_type, ByteArray content) then
  4306 + [ "HTTP/1.1 200 OK", crlf,
  4307 + format_headers(standard_headers),
  4308 + format_headers(standard_headers_for(mime_type, length(content), failure)),
  4309 + format_headers(additional_headers),
  4310 + crlf,
  4311 + content . (Printable_tree)[]
  4312 + ],
  4313 +
  4314 + http_raw(Printable_tree content) then content
4270 4315 }.
4271 4316  
4272   -
4273   -
4274   -
4275   -
4276   -
... ...
calexium_lib/web/CXM_multihost_http_server.anubis
... ... @@ -204,8 +204,7 @@ public type Web_Site_Description:
204 204 (String host_name,
205 205 HTTP_Info http_info,
206 206 List(Web_arg) lwa,
207   - Bool is_https) -> (List(HTTP_header),
208   - Printable_tree) awp_handler,
  207 + Bool is_https) -> (Printable_tree) awp_handler,
209 208 (List(Web_arg) lwa) -> One before_send_file).
210 209  
211 210 The component 'common_names' is the list of names of the site, like for example
... ... @@ -1942,7 +1941,7 @@ define Maybe(String)
1942 1941 This is the formating for sending to the client (hence, it has nothing to do with the
1943 1942 component 'journal_headers' in the web site description).
1944 1943  
1945   -define Printable_tree
  1944 +public define Printable_tree
1946 1945 format_headers
1947 1946 (
1948 1947 List(HTTP_header) headers
... ... @@ -2232,7 +2231,7 @@ define One
2232 2231  
2233 2232 Standard headers are for answering ".awp" requests.
2234 2233  
2235   -define List(HTTP_header)
  2234 +public define List(HTTP_header)
2236 2235 standard_headers
2237 2236 =
2238 2237 [
... ... @@ -2240,16 +2239,16 @@ define List(HTTP_header)
2240 2239 http_header("Server", "Anubis Embedded Server v" + major_version_number + "." + minor_version_number)
2241 2240 ].
2242 2241  
2243   -define List(HTTP_header)
2244   - standard_headers_for_html
  2242 +public define List(HTTP_header)
  2243 + standard_headers_for
2245 2244 (
2246   - Int answer_body_size,
2247   - String charset
  2245 + String mime_type,
  2246 + Int answer_body_size,
  2247 + Maybe(String) mb_charset,
2248 2248 ) =
2249 2249 [
2250   - //http_header("Content-Type","text/html"),
2251   - http_header("Content-Type","text/html; charset="+charset),
2252   - http_header("Content-length",to_decimal(answer_body_size))
  2250 + http_header("Content-Type", mime_type + if mb_charset is success(charset) then "; charset="+charset else ""),
  2251 + http_header("Content-length", to_decimal(answer_body_size))
2253 2252 ].
2254 2253  
2255 2254  
... ... @@ -2281,14 +2280,7 @@ define One
2281 2280 all_web_args,
2282 2281 is_SSL(connection)),
2283 2282 //print_delta("After page generation");
2284   - if answer_headers_body is (additional_headers,answer_body) then
2285   - forget(reliable_write(connection,
2286   - [ "HTTP/1.1 200 OK", crlf,
2287   - format_headers(standard_headers),
2288   - format_headers(standard_headers_for_html(length(answer_body),charset(desc))),
2289   - format_headers(additional_headers),
2290   - crlf .
2291   - answer_body]))
  2283 + forget(reliable_write(connection, answer_headers_body))
2292 2284 //print_delta("After sending page")
2293 2285 )
2294 2286 else (send_file(desc,
... ... @@ -2738,13 +2730,7 @@ define One
2738 2730 http_info(ip_addr,uri,headers,generate_tt),
2739 2731 all_web_args,
2740 2732 is_SSL(connection)),
2741   - if answer_headers_body is (additional_headers,answer_body) then
2742   - forget(reliable_write(connection,
2743   - [ "HTTP/1.1 200 OK",crlf,
2744   - format_headers(standard_headers_for_html(length(answer_body),charset(desc))),
2745   - format_headers(additional_headers),
2746   - crlf .
2747   - answer_body])))
  2733 + forget(reliable_write(connection, answer_headers_body)))
2748 2734 else unique
2749 2735 }.
2750 2736  
... ...