CGI Framework
Tag Interpreters

Basics

Docs

Components

Templates

Tools

Demos


SourceForge.net Logo

Brasil
   

Tag Interpreters

TPageBuilder is the central CGI Framework component, but in my opinion TTagInterpreter and its descendants are the most interesting ones.

TTagInterpreter basics

You learned the basic behavior of a PageBuilder: read a template file, pick tags with name spaces and call OnHTMLTag for every one found.

You can change that basic behavior by changing values of "NameSpace" and "OnlyRegisteredNamespaces" properties of your PageBuilder. Assigning a value to "NameSpace" makes that value a "registered name space". Changing the default value of "OnlyRegisteredNamespaces" from false to true makes your page producer cares only about the registered name space. The advantage? You can organize your code by providing different PageBuilders to respond to tags on different name spaces.

A TagInterpreter provides a way to register multiple name spaces in one PageBuilder. The most basic TagInterpreter have just one useful property: "NameSpace". And allow just one event handler: "OnHTMLTag". TagInterpreters does not parses html code. It's a somewhat passive component. To turn active, a TagInterpreter must be tied to a PageBuilder.

When linked to a PageBuilder, the TagInterpreter name space got registered on the list of PageBuilder name spaces and the PageBuilder will now cares about their own name space and the namespaces of all TagInterpreter hooked on it.

A PageBuilder may have many TagInterpreters and a TagInterpreter may be linked to many different PageBuilders. A image may provide a better understanding:

Suppose all the PageBuilders on the example have OnlyRegisteredNamespaces set to true. In that case, PageBuilder1 will react to tags with name space "CC" or "PB". PageBuilder2, does not have a name space by its own, but the links to TagInterpreter1 and TagInterpreter2 makes it cares about tags on "BP" or "DB" name spaces. Finally, PageBuilder3 reacts to tags on "EC", "PB" and "DB" name spaces.

The links from a PageBuilder to their TagInterpreters, are stored on TagInterpreters property. TagInterpreters holds a instance of TTagInterpreterCollection, a descendant of TCollection and behaves like the Actions property of a WebModule. Selecting that property and clicking on the ellipses button we have something like that:

The possibility of having different components for processing tags on different name spaces give us many advantages:

Organize code
Highly coupled tags can be joined together in a common name space and processed by a separate instance of TagInterpreter.
Reuse code more easily
TagInterpreter can be subclassed to create specialized tag interpreters for problems commonly found on every CGI system, such as menus, category lists, database browsing, etc. Specialized tag interpreters can even substitute completely server side scripting.
Improve modularization
Complex TagInterpreters can be relocated to a separate DataModule and linked to PageBuilders on the main WebModule.
 


Copyleft (2002) Ivan C. Cruz
Site contents may be reproduced in all or in part since you provide a clear statement citing that site as your source.

That site was built and tested with Mozilla. If some components looks misalligned or not properly rendered, it may be your browser fault. In that case, please, consider an upgrade.