Languages

From Documentation

Overview

A language (LanguageDefinition) is a collection of component definitions. It is also known as a component set.

For example, Window, Button and Combobox all belong to the same language called xul/html. It is a ZK variant of XUL (and also known as zul).

Component designers are free to designate a component definition to any component set they prefer, as long as there is no name conflict[1].

Language Identification

When parsing a ZUML document, ZK Loader have to decide the language that a XML element is associated, such that the correct component definition (ComponentDefinition) can be resolved. For example, in the following example, ZK needs to know window</window> belongs to the xul/html language.

<window>

Thus, ZK Loader takes the following steps to decide the language a XML element is associated with:

  1. It assumes a default language for a ZUML document. The default language is decided by filename's extension (see below).
  2. If a XML element has no namespace prefix, then
    1. Handle it specially, if the element is a special ZK element, such as zk and attribute.
    2. Look up the component definition belonging to the default language, otherwise.
  3. If a XML element has a prefix, then the XML namespace is used to resolve:
    1. Handle it specially, if the XML namespace is one of the standard namespaces, such as native and client.
    2. Look up the language with the given XML namespace, otherwise
    3. Then, look up the component definition from the language found in the previous step

Filename Extension

First, when a ZUML file is parsed, the language will be decided based on the extension of the filename (LanguageDefinition.getByExtension(String)). For example, the extensions associated with xul/html are zul and xul. Thus, if any file whose extension is zul or xul, the default language used to parse it will be assumed to be the xul/html language.

Another example: xhtml is another language (aka., a component set). It is associated with the extensions including zhtml, html, html, and xhtml. Thus, any file whose extension matches one of them will be considered as applying the zhtml language as default.

Filename Extension vs URL Mapping

Notice that the association of filename's extension with a language is about how ZK Loader processes a ZUML page. To really have ZK Loader to process a file, you have to configure WEB-INF/web.xml correctly. For example, if you want to map all XUL files to ZK Loader, you could add the following to WEB-INF/web.xml:

<servlet-mapping>
	<servlet-name>zkLoader</servlet-name>
	<url-pattern>*.xul</url-pattern>
</servlet-mapping>

XML Namespace

If you map ZK Loader to a filename's extension that is not recognized, you could use XML namespaces to specify the language used to parse it. Each language is associated with a unique XML namespace that you can identify it easily in a ZUML document.

For example, you map ZK Loader to *.foo, then you could specify the xul/html language's namespace, which is http://www.zkoss.org/2005/zul:

<window xmlns="http://www.zkoss.org/2005/zul">
...

where the xmlns attribute declares a XML namespace to associate all element without explicit prefix, such as window in this case.

If you want to several languages in the same XML document, you could use XML namespaces to distinguish them too. For example, the xhtml language's namespace is http://www.w3.org/1999/xhtml, and we could do as follows.

<window xmlns:h="http://www.w3.org/1999/xhtml">
    <h:table>
        <h:tr>
            <h:td>
                <button/>
            </h:td>
        </h:tr>
    </h:table>
</window>

Notice that table, tr and td are also components though they are very simple -- a simple wrapper of HTML tags. There is a better way to generate HTML tags: the native namespace. For more information please refer to the Native Namespace section.

XML Namespace with Shortcut

To make it easy to specify a namespace, ZK Loader allows shortcut. That is, you need to only specify the last word of the namespace. For example, zul for http://www.zkoss.org/2005/zul, and xhtml for http://www.w3.org/1999/xhtml. Thus, we can simply the previous example as follows.

<window xmlns:h="xhtml">
    <h:span>
        <h:tr>
            <h:td>
                <button/>
            </h:td>
        </h:tr>
    </h:table>
</window>

Standard Languages

ZK provides three different languages (aka., component sets): xul/xhtml, xhtml and xml. The xul/xhtml and xhtml langauges can be used for any modern browser (Ajax assumed), while the zml language is used for generating XML document (non-Ajax). Developers are free to add their own language.

Language Description
xul/html
Name: xul/html
File Extensions: zul, xul
Namespace: http://www.zkoss.org/2005/zul
Namespace shortcut: zul
Device: Ajax

XUL-compliant component sets. We adopt XUL for this language, if the specification is applicable. For more information, please refer to the ZUL Language section and ZK Component Reference.

xhtml
Name: xhtml
File Extensions: zhtml, xhtml, html, htm
Namespace: http://www.w3.org/1999/xhtml
Namespace shortcut: xhtml
Device: Ajax

XHTML-compliant component sets. It is one-to-one mapping of XHTML tags to ZK components. Since they are components, you can add and remove them dynamically (and control it at the server). For more information please refer to the XHTML Namespace section or ZK Component Reference.

Performance Tip: The XHTML language is designed to allow application to modify the client dynamically (at the server). If you don't need it (it is generally true), you shall use the Native namespace instead. For more information, please refer to Performance Tips.

xml
Name: xml
File Extensions: xml
Namespace: http://www.zkoss.org/2007/xml
Namespace shortcut: xml
Device: XML
Available only ZK EE

XML component sets. It is used to generate (static) XML document. For more information please refer to the XML section.


Subsections:



  1. For more information please refer to ZK Component Development Essentials

Version History

Last Update : 2010/11/5

Version Date Content
     



Last Update : 2010/11/05

Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.