This implements <Text>, <TextField> and the many other
built-in elements. Each of these is just an Object Rexx class,
with a definition for its emit method, probably some
set... and get... methods, and some initialisation
code. WOM provides base classes which implement
important abstractions such as ``triggers'' (elements that respond to
input from the user, such as forms and action links) and ``user inputs''
(elements that contain data, such as fields, menus, and
buttons). Many of the built-ins can be made subclasses of these.
The two examples below show the File class and a version ---
simplified to save space --- of the TextField class.
/* File.cmd */
::class File subclass WebObject public
/* ivars name is_html */
::method setup
expose is_html
self~setup:super
is_html = .false
return
::method getOwnAttributeNames class
return .set~of("Name","IsHTML")
::method emit
expose name is_html
use arg output_stream, envt
input_stream = .stream~new(name)~~open('read')
do while input_stream~lines > 0
line = input_stream~linein
if is_html then
do
line = line~changestr('&','&'),
~changestr('<','<'),
~changestr('>','>')
end
output_stream~lineout( line )
end
input_stream~close
return
::method setName
expose name
use arg _name
name = _name
return
::method getName
expose name
return name
::method setIsHTML
expose is_html
use arg _is_html
is_html = _is_html
return
::method getIsHTML
expose is_html
return is_html
/* TextField.cmd */
::class TextField subclass UserInput public
/* ivars size */
::method setup
expose size
self~setup:super
size = 10
self~setValue( '' )
self~setDisplay( '' )
self~setTypeForProgram( 'string' )
return
::method getOwnAttributeNames class
return .set~of("Size")
::method emit
expose size
use arg output_stream, envt
self~emitPathAsComment(output_stream)
output_stream~charout( '<INPUT',
'TYPE=TEXT',
NAME='||self~getPathForHTML(envt) ),
output_stream~charout( ' VALUE='||self~asHTML(self~getDisplay) ),
output_stream~charout( ' SIZE='||size )
output_stream~charout( '>' )
return
::method setSize
expose size
use arg _size
size = _size
return
::method getSize
expose size
return size
The compiler needs to know which names belong to WOM elements, otherwise it will treat them as unanalysed HTML. This is done in a table-driven fashion. The parser contains a table which, for each WOM element, gives its name, whether it is an instantiation, whether it is a container (this controls whether the parser looks for a closing bracket), and its arguments, including their type and whether they are positional or defaultable Booleans. The WOM implementor can easily update this table when adding new classes.