2.1. AOLserver
OpenACS is built atop the mighty AOLserver, the open source, multithreaded HTTP
server that powers http://www.aol.com. AOLserver provides a rich Tcl API, server-side
processing of custom tags via AOLserver Dynamic Pages (ADP), database connection
pooling and a cron-like service for running scheduled code in the background. For more
about AOLserver, please see the AOLserver home page (http://www.aolserver.com).
2.2. Templating system
OpenACS divides responsibility for serving most requests among two or three file types
having distinct purposes. The basic split is between a script file that sets up dynamic
variables and a markup file that renders them. The script file is a Tcl script having a .tcl
extension. The markup file has an .adp extension and looks much like standard HTML.
In fact, HTML is valid ADP, providing a gentle slope for programmers and designers
who are just getting started with the framework. Because they resemble HTML, ADP
files may be edited in standard tools such as Dreamweaver.
The OpenACS templating system supports the ability to work with page fragments via
the <include> tag. The same Tcl/ADP file pair idiom operates at this level. Hence if a
page contains a tag
<include src=”motd”>
the template system will search the current filesystem directory for motd.tcl to set up the
dynamic variables and motd.adp for the markup.
More interestingly, the OpenACS templating system supports a master/slave relationship
among page fragments. A page fragment that specifies a <master> will have its contents
embedded into the master template at a location designated by the <slave> tag in that
template. Master templates are typically used to standardize headers and footers across a
site. A nice property of the master/slave system is that the master template provides a
bird’s eye view of the entire page in a single file. And of course, the same Tcl/ADP file
pair idiom applies to master templates as well.
Before we get too far down the two-file path it’s worth pointing out a third type of file
that also participates in serving most requests: the query file. Query files have an .xql
extension and contain SQL that is specific to the template. The function of these files
will be explored further in the next section.
2.3. Database API
The OpenACS database API is designed to maximize Tcl integration with the database,
allowing data to pass back and forth as simply and naturally as possible. Let’s dive in
and consider a code example:
2.4. Declarative programming
Among other Web development frameworks, OpenACS is still unique, powerful and
simple, and that’s based on the programming advantages created within the OpenACS,
such as declarative programming, which is understood as the opposite of writing the
logic of the program using the normal procedural programming, instead use an special
declarative syntax to reflect how the program will act, based on a possible entry, but not
relied only on that. A positive effect of writing in a declarative syntax is that the
programs usually are more robust in its behavior and more readable by other developers,
since the declarative syntax is standard and always more ordered.
2.4.1. Form processing, ad_form
As an example, for web form management, OpenACS has ad_form. This procedure
implements a high-level, declarative syntax for the generation and handling of HTML
forms. It includes special syntax for the handling of forms tied to database entries,
including the automatic generation and handling of primary keys generated from
sequences. You can declare code blocks to be executed when the form is submitted, new
data is to be added, or existing data modified.
ad_form -name form_name -export {foo {bar none}} -form {
my_table_key:key(my_table_sequence)
{value:text(textarea) {label "Enter text"}
{html {rows 4 cols 50}}}
} -select_query {
select value from my_table where my_table_key = :my_table_key
} -validate {
{value
{[string length $value] >= 3}
"\"value\" must be a string containing three or more
characters"
}
} -new_data {
db_dml do_insert "
insert into my_table
(my_table_key, value)
values
(:key, :value)"
} -edit_data {
db_dml do_update "
update my_table
set value = :value
where my_table_key = :key"
} -after_submit {
ad_returnredirect "somewhere"
ad_script_abort
}
In this example, ad_form will first check to see if my_table_key was passed to the
script. If not, the database will be called to generate a new key value from
my_table_sequence. If defined, the query defined by -select_query will be
used to fill the form elements with existing data.
On submission, the validation block checks that the user has entered at least three
characters into the textarea. If the validation check fails the value element will be
tagged with the error message, which will be displayed in the form when it is rendered. If
the validation check returns true, one of the new_data or edit_data code blocks will
be executed depending on whether or not my_table_key was defined during the initial
request. my_table_key is passed as a hidden form variable and is signed and verified.
This example illustrates how to declare a form, define validation and define a set of
actions to be taken on standard events.
More information about ad_form can be found here: http://openacs.org/api-doc/procview?
proc=ad%5fform, from which part of this sub section has been taken.
2.4.2. List builder
The list-builder is used create sophisticated table-like reports with many popular
capabilities, here is an example.
For this example you see first the -name of the list-builder. Then the declaration of the
-multirow name used for populating the report with data, which is usually extracted
from the database. Then the -elements (columns) to be displayed in the report. Each
element is defined as a name of the variable that is set at the multirow in the case
that the variable will be used as data to be displayed in that column, like
instance_name. Also the element name can be an arbitrary name in the case that
is used the parameter display_template, which is used to include HTML tags or
ADP logic when displaying data passed by the multirow. For each element you always
define label which is the title of the column, and more special parameters such as:
link_url_col that expect a variable name which must be set at the multirow that
contains a link for automatically display the data of that column as a link.
The list builder has many more important features like order by column, filters, bulk
actions, pagination, etc.
And this is the result seen in the browser produce by the list-builder example:
2.4.3. Upgrades
Since OpenACS is a modular system consisting on independent packages, each package
has its own version and can require upgrade scripts when updating the package in a given
OpenACS installation. This is a simple example of a declarative upgrade syntax: