The Carapace Hub (CHub) provides a multi-threaded Web server allowing pages of HTML/images to be accessible to web browsers on your network.
The Carapace Hub also allows HTML pages to contain embedded script fragments. This allows the web server to generate the HTML pages 'on the fly', giving access to databases or to other systems.
All Carapace script fragments are wrapped up in carapace tags
as in the following example:
<carapace>(time)</carapace>
The only rule is that the text between the opening and closing carapace
tags holds one or more valid Carapace expressions.
On loading a template page each <carapace> tag is evaluated in turn.
If the value is of type
String,
Binary,
Integer or
Real
then the value is substituted for the entire <carapace> tag.
The class HtmlGenerator exists to help with the conversion of Carapace script items to HTML.
In the above example, the time function returns an Integer which is the time in milliseconds since the computer was started. This is then put into place in the generated HTML.
The data submitted by the user's web browser is available to the script as follows. Each expression evaluated in the template can assume the following local variables are defined:
| name | type | description |
|---|---|---|
| url | Url |
the URL of this page as requested by the user |
| formData | List |
any form data submitted by the user is held as an attribute-value list (ie. a list of pairs) where the attribute name is the name of the HTML field. Each attribute and value is a String |
| req | HttpRequest |
the received HTTP request |
| rep | HttpResponse |
the HTTP response object to be filled out |
| monitor | Monitor |
the Monitor within the CHub |
| agentClass | String |
the type of this agent within the CHub |
| agentName | String |
the name of this particular agent within the CHub |
| scratch | HashTable |
the variable scratch is a hash-table which can hold
any temporary values required during evaluation of the template
-- it persists only for the lifetime of that template, and data cannot
be passed between templates in the scratch table
|
| env | WebEnvironment |
if the supplied HTTP request contains a current Carapace
connection identifier then the env
variable is setup to hold the corresponse environment for that session
|
If further local variables are required during the template evaluation, then
the embedded script fragment should introduce them using the
local function.
If an error occurs within the CHub -- eg. there is an error within a script fragment -- then the server tries to report the error to the user as follows.
The CHub configuration defines the name of the HTML template to evaluate and present to the user if an error occurs. When this template is evaluated, the formData variable holds the following attributes & values:
| attribute name | type | description |
|---|---|---|
| errorClass | String | the class of the error |
| errorCode | String | the code of the error |
| errorText | String | a textual description of the error |
| Contents | Index | Current topic: Carapace Hub | Related topics: HTML Generator |