Search:
|
Access:
» Zope with Mozilla - generating XUL using ZopeRelated categories: Software Engineering | XML | Programming in generall Wojciech KurekViewed: 4945 | Article date: 2006-05-13 17:17:19 The majority of content presentation systems currently used on the Web use HTML exclusively. Considering the growing number of browser applications and devices that support a variety of formats, including XHTML, SVG and WML, the use of HTML seems a needless restriction and a serious limitation for Web applications. This article demonstrates how the type of content emitted by the Zope application server can be changed between HTML and XUL.
The majority of content presentation systems currently used on the Web use HTML exclusively. Considering the growing number of browser applications and devices that support a variety of formats, including XHTML, SVG and WML, the use of HTML seems a needless restriction and a serious limitation for Web applications.
Tomasz Rybak is a researcher and lecturer at the Computer Science department of the Białystok Technical University. Contact with the author: bogomips@post.pl However, the solution need by no means lie in creating several different system versions for different device types, nor asking the user to select a format for presenting the requested data. This article demonstrates how the type of content emitted by the Zope application server can be changed between HTML and XUL. Installing Zope under LinuxZope 3.1.0 requires Python 2.3.5. If you have a different Python version, you need to specify the path to your Python interpreter using the --with-python command-line parameter for the configure script. By default, Zope is installed to /usr/local/Zope-3.1.0, but this too can be changed using the --prefix parameter. Installing Zope is a matter of unpacking the sources and issuing the traditional commands: ./configure && make && make install However, before you run make install, it's a good idea to test the compilation and run conformance test by executing make check. After a few minutes, you will (hopefully) be informed of success and can install Zope files. Once the files are installed, you should create a Zope server instance, consisting of the database and directory structure that will be used to store and execute Zope applications. New instances are created by executing the bin/mkzopeinstance script in the Zope installation directory, passing it the user name and password of the instance administrator and the directory to install the instance to. A typical command would be: ./bin/mkzopeinstance -u admin:admin -d /var/Zope. Once the instance has been created, you can start it by changing to the instance directory and running ./bin/runzope. The console will now be running the Zope instance, which you can then shut down by pressing [Ctrl-C]. For automated server usage, it's more convenient to use Zope's zopectl script, which is similar to apachectl. Zope is also available in binary packages. The Debian package is called zope3 as can be installed using apt-get install zope3 (or better aptitude install zope3). The dzhandle script is also installed to allow Zope instance installation and configuration. Configuration is stored in the directory /etc/zope3/instance_name, and the instance files themselves in /var/lib/zope3/instance/instance_name. The zope3 package comes with startup scripts placed in /etc/init.d, making the Zope server run automatically at system start. For development purposes, it's best to install the zope3-sandbox package, which creates a sandbox instance for development and testing. XULThe purpose of the XML User-Interface Language, or XUL for short, is to describe graphical user interfaces. It is used in all applications based on the Gecko engine, i.e. the whole Mozilla suite, Firefox, Thunderbird, Sunbird, Nvu and others. Figure 1. Sample Zope screen seen in Mozilla Firefox There are several ways of displaying XUL files in a Gecko-based browser. The first way is to open a local file by passing it as a command-line parameter or via File->Open. Another way is to have the server send a XUL file. For the Gecko engine to recognise the file as a XUL interface description, the Content-Type header should be set to application/vnd.mozilla.xul+xml. A third way is to install a browser extension (plug-in), allowing XUL files to be opened using URLs starting with chrome://. Finally, there is also a way of displaying XUL using just the Gecko engine itself, without a browser. The XUL Runner project allows XUL files to be displayed and XPCOM modules to be run without a browser, essentially providing a bare Gecko engine without a user application (Web browser, mail client etc.). XUL elements reside in the namespace http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul. The root element for any XUL document is called window and describes the window that will hold other elements and be displayed by the browser. Each element (including all windows) can have an id attribute which should be unique within the file. Presenting data using XULData with an inherent internal structure is typically presented using tables, and the tree element is the most common way of rendering a table. A tree has two subelements: treecols describing table columns and treechildren containing actual table data. Each treecol element within treecols should have the id attribute, used to identify a column when displaying its data, and the label attribute defining the column header label. The treechildren element contains data represented by treeitem elements. Each treeitem should have a treerow child, which in turn should contain a number of treecell elements. Each treecell should have a label attribute to store the data for the column. If there are fewer treecell elements than table columns, the columns are filled with available values from left to right. A different data insertion order can be specified using the ref attribute to indicate the column (identified by its id) that the value should be written to. If table height is not restricted by higher-level elements, it depends on the number of table rows. To specify a minimum tree height regardless of the amount of data, set the rows attribute to the number of rows to be displayed. As the name suggests, the tree element can also be used to display tree-structured data, i.e. data that contains nested content. To make this possible, especially to allow child data display toggling, one of the columns has to have the primary attribute set to true. The column will then contain an icon for shrinking and expanding subtrees, and will always be visible. Hierarchical (tree-structured) data is stored in the same way as table data. If a tree row contains child data, the treeitem element must have the container attribute set to true. After the treerow specifying data to be displayed in the top-level row comes the treechildren element, where the required subtree can be defined. Joining XUL and HTMLHTML content can be embedded into a XUL file. To do this, the XUL file should include the HTML namespace http://www.w3.org/1999/xhtml, typically described using the html: prefix. If this is the case, all HTML element names should be preceded by this prefix. All HTML tags should be XML-compliant, with lower-case element names, all attribute values enclosed in quotes or double quotes and each tag explicitly closed - same as for XHTML, so Readers familiar with XHTML should feel at home. ZopeZope is an application server written in Python. The use of Python eliminates portability issues, both for Zope itself and any user-supplied code running within it. The latest Zope version is 3.1.0. Note that releases from the 3.x branch are backwards incompatible with Zope 2.x, so Zope 3.x is currently marked as Zope X3, with the X signifying backwards incompatibility. However, Zope developers have announced that work on restoring backwards compatibility will start as soon as the current release has matured, allowing older Zope applications to be run with the new release. Zope is a component-based system, allowing component and class code to be easily reused. The role of the programmer is to develop various specialised components and then tell the server how these components should be used and combined into an application. The creators of Zope suggest that components should be very simple, and component developers should not try to create multi-purpose modules. Although a great variety of components are available, for the purpose of this article we will be using just three types:
The component-based architecture allows Zope to support a variety of communication methods, and the base installation comes with several default methods. All object data is accessible through HTTP, FTP and XML-RPC, although access may occasionally require creating a suitable adapter. Due to the system's modular structure, no other efforts are required. As with the majority of modern software, Zope uses interfaces to define service contracts for its components. Objects are accessed via interfaces exclusively, and the only places where you can encounter classes are configuration files that define classes as factories for objects with specified interfaces. Although the Python language itself provides no support for interfaces, they are provided by the Zope framework in the zope.interfaces.Interface class that each interface should extend. To indicate that a class implements an interface, we need to call the zope.interface.implements() method, which takes the names of the implemented interfaces as parameters. The call should come at the very beginning of the class, just after the class signature and doc. The Interface class also provides a few other methods, including providedBy() to check whether a class implements a specific interface and implementedBy() to fetch a list of all interfaces implemented by that class. Although it may sound strange, the primary role of interfaces that describe content components is data storage, so (however bizarre it might seem compared to interfaces in other programming languages) it is quite common to have interfaces that only contain data fields and no methods. Each field is described by its name and type, with the type defining what data that can be stored in the component and how it should be displayed. Some of the most common types are:
All field type constructors can also take the following parameters:
Zope uses field type definitions to generate suitable HTML code, so no manual HTML coding is required. Each class defines two display objects: one to display data and one to fetch data of a given type. Figure 1 presents a typical Zope screen. In the top left corner, you can see a tree structure corresponding to the objects within the current server instance. The particular branches can rolled up or expanded. Below that is a list of objects that can be placed at various locations throughout the object tree. Click an object name to be taken to a page for providing the required information for creating an object instance. At the top of the main panel, you will see lists for selecting the display method and content for the current object. The Introspector tab contains all object implementation code, including classes, superclasses and interfaces, which is very useful both for learning and debugging purposes, as it shows the way Zope sees objects. Below that is a list of commands available for the object, followed by a view of the object itself.
|
|
Copyright C 2006 by Software Developer's Journal. All rights reserved.







SDJ Users:
Shopping Cart









