Languages"

From Documentation
Line 10: Line 10:
 
=Identify a Language=
 
=Identify a Language=
  
===Identify by Filename's Extension===
+
==Filename Extension==
  
 
First, when a ZUML file is parsed, the language will be decided based on the extension of the filename (<javadoc method="getByExtension(java.lang.String)">org.zkoss.zk.ui.metainfo.LanguageDefinition</javadoc>). For example, the extensions associated with <code>xul/html</code> are <code>zul</code> and <code>xul</code>. Thus, if any file whose extension is <code>zul</code> or <code>xul</code>, the default language used to parse it will be assumed to be the <code>xul/html</code> language.
 
First, when a ZUML file is parsed, the language will be decided based on the extension of the filename (<javadoc method="getByExtension(java.lang.String)">org.zkoss.zk.ui.metainfo.LanguageDefinition</javadoc>). For example, the extensions associated with <code>xul/html</code> are <code>zul</code> and <code>xul</code>. Thus, if any file whose extension is <code>zul</code> or <code>xul</code>, the default language used to parse it will be assumed to be the <code>xul/html</code> language.
  
 
Another example: <code>xhtml</code> is another language (aka., a component set). It is associated with the extensions including <code>zhtml</code>, <code>html</code>, <code>html</code>, and <code>xhtml</code>. Thus, any file whose extension matches one of them will be considered as applying the <code>zhtml</code> language as default.
 
Another example: <code>xhtml</code> is another language (aka., a component set). It is associated with the extensions including <code>zhtml</code>, <code>html</code>, <code>html</code>, and <code>xhtml</code>. Thus, any file whose extension matches one of them will be considered as applying the <code>zhtml</code> 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 <code>WEB-INF/web.xml</code> correctly. For example, if you want to map all XUL files to ZK Loader, you could add the following to <code>WEB-INF/web.xml</code>:
 
'''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 <code>WEB-INF/web.xml</code> correctly. For example, if you want to map all XUL files to ZK Loader, you could add the following to <code>WEB-INF/web.xml</code>:
Line 25: Line 27:
 
</source>
 
</source>
  
===Identify by XML Namespace===
+
==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.
 
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.
Line 54: Line 56:
 
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 [[ZK Developer's Reference/UI Composing/ZUML/Native Namespace|Native Namespace]] section.
 
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 [[ZK Developer's Reference/UI Composing/ZUML/Native Namespace|Native Namespace]] section.
  
===Identify by XML Namespace with Shortcut===
+
== 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, <code>zul</code> for <code>http://www.zkoss.org/2005/zul</code>, and <code>xhtml</code> for http://www.w3.org/1999/xhtml. Thus, we can simply the previous example as follows.
 
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, <code>zul</code> for <code>http://www.zkoss.org/2005/zul</code>, and <code>xhtml</code> for http://www.w3.org/1999/xhtml. Thus, we can simply the previous example as follows.
  

Revision as of 08:46, 5 November 2010

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].

Identify a Language

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.