Chapter 3. Generating content

Table of Contents

Markup
(X)HTML Core Procedures
XML Core Procedures
Extended SXML
Extended HTML markup
Plain Text
Forwarding Requests
Images
GraphViz Graphs
Graphviz Procedures
DotML
HTTP errors

SISCweb programs can generate HTTP responses of a variety of data types -- HTML/XML/XHTML represented in SXML notation, images --, or they can forward requests to standard JSPs/Servlet components. Procedures to generate HTTP errors are also available. Other response types can be easily plugged on top of a basic set of response procedures.

The procedures that produce HTTP responses are in the form send-*/*, with the first pattern indicating the type of response, and the latter determining whether or not to save the execution state, and whether or not to clear previously saved states.

All the procedures accept an optional association list of HTTP response headers as the first, optional argument. The association list is in the form ((name value) ...). This can be used to override the default Content-Type, to set caching options, etc.

SISCweb provides a number of modules with an uniform API to produce HTML, XHTML and XML markup. Their procedures accept documents in SXML syntax, and in the case of HTML and XHTML, a few extra elements and attributes are used to assist with continuation-based programming (see the section called “Extended HTML markup”.)

Requires: (import siscweb/html)
Requires: (import siscweb/xhtml)
Located in: siscweb-sxml.jar

The core procedures to send (X)HTML content follow the basic send-html/* and send-xhtml/* patterns. They differ in whether or not they clear the continuation table, and whether or not they return after the user interacts with the page.

Note

The XHTML and HTML modules serialize SXML differently, with the former producing pure XML, and the latter producing markup tweaked to display properly in known browsers. When producing XHTML for common user agents, it is advisable to keep the HTML Compatibility Guidelines in mind.

Also, while the XHTML module implements the complete SXML specification, the HTML module is more limited in that only understands DTD declarations, *VERBATIM* and *COMMENT* elements besides the basic element+attribute syntax. Also, while the XHTML module considers the *TOP* element functional, the HTML module silently ignores it.

The HTML and XHTML modules support a number of extra attributes to support continuation-centric programming and interaction with the J2EE environment.

attribute: `(object (@ (type "graphviz") (layout ,layout) (format ,format) ...) (graph (@ (id ,id) ...))

If the attribute type "graphviz" is specified for the object element, a Graphviz graph will be embedded in the document.

The layout and format attributes are analogous to the omonymous parameters to the send-graphviz/* functions (see the section called “Graphviz Procedures”.) However, the value of format determines how the content is included:

  • gif, jpg, png: The graph is embedded as an img tag, and a corresponding image map is generated. Links associated to nodes, edges and records will be mapped appropriately. Just as for other document elements, the @href[-[p|c|e]] and @bindings attributes are available, and behave as described in the section called “Extended HTML markup”.
  • ps, svg, etc.: The graph is embedded as an object tag. The appropriate mime type is automatically set, and needs not be specified explicitely.

In both cases, any attribute specified for the object tag will be applied toward the generated object or img tag.

(send-html/suspend
 (lambda (k-url)
  `(html
    (head
     (title "Embedded Graphviz")
    (body
    (h3 "Embedded Graphviz")

    (object (@ (type "graphviz")
               (layout dot) (format png))
      (graph (@ (id "G"))
        (node (@ (id "c") (label "scissors") (href "http://www.google.com/search?q=scissors")))
        (node (@ (id "p") (label "paper") (href "http://www.google.com/search?q=paper")))
        (node (@ (id "s") (label "stone") (href "http://www.google.com/search?q=stone")))
        (edge (@ (from "c") (to "p") (label "cut") (href-p ,cut)))
        (edge (@ (from "p") (to "s") (label "wraps") (href-c "/")))
        (edge (@ (from "s") (to "c") (label "breaks") (href-e ,k-url))))))))))
        

Requires: (import siscweb/text)
Located in: siscweb.jar

This module provides functions to send plain text responses.

Requires: (import siscweb/forward)
Located in: siscweb.jar

Since SISCweb lives in a J2EE environment, it is sometimes convenient to generate content using traditional techniques such as JSPs and servlets rather than SXML.

The send-forward/* procedures dispatch the request to the indicated context-relative URL. Bindings can be attached in the form of <bindings> objects or a-lists. The forward/store! function can also be used to pass URLs mapped to closures in the style of the @[action|data|href|src]-p tags. Coupled with the URL corresponding to the current-continuation being set in the siscweb.kURL request attribute, this enables one to use SISCweb for control and JSP/Servlets for presentation without losing too many features.

See the section called “Extracting Bindings from Java” for details on how to access bindings from Java.

Requires: (import siscweb/image)
Located in: siscweb.jar

This module provides procedures to send images from java.awt.image.RenderedImage or files.

Requires: (import siscweb/graphviz)
Located in: siscweb-sxml.jar

This module provides procedures to send graphs in various formats as generated by Graphviz (http://www.graphviz.org). Most of the functions accept a markup representation of DOT, the GraphViz language, in the form of DotML (see the section called “DotML”.)

The GraphViz programs (dot, neato, etc.) should be installed somewhere in the system path. This is usually the case in UNIX. Alternatively, it is possible to set the absolute paths to the GraphViz programs by using the graphiz/put-layout-command! function.

Graphs can be generated either using the send-graphviz/* functions, or by embedding the @type="graphviz" attribute in the (X)HTML object tag (see the section called “Extended HTML markup”.)

Both send-graphviz/* procedures accept the same three parameters:

The send-graphviz/* procedures accept a graph description expressed in DotML. DotML was created by Martin Loetzsch, and an exhaustive description rich with excellent examples is at http://www.martin-loetzsch.de/DOTML.

SISCweb does not use code from the DotML project, but it implements the same markup syntax in sxml form. There are a few differences between SISCweb's implementation and the original:

  • The generated DOT code (which is then fed into GraphViz) is somewhat different.
  • The graph, sub-graph, cluster and node elements must always specify an id attribute.
  • The id attribute values at the moment are limited to strings of alphanumeric characters and underscore.
  • The enclosing record elements must specify an id attribute, but nested record and node elements do not have to.

Requires: (import siscweb/error)
Located in: siscweb.jar

HTTP error responses can be generated using two functions, which differ in how the affect the continuation table. Neither function returns. The error codes should abide to the RFC2616 specifications.