org.zkoss.zk.ui.metainfo
Class LanguageDefinition

java.lang.Object
  extended by org.zkoss.zk.ui.metainfo.LanguageDefinition

public class LanguageDefinition
extends java.lang.Object

A definition of a language, such as xul.

Author:
tomyeh

Field Summary
static java.lang.String ANNO_NAMESPACE
          The namespace for ZK annotations.
static java.lang.String CLIENT_NAMESPACE
          The namespace for ZK client namespace.
static java.lang.String NATIVE_NAMESPACE
          The namespace for ZK native namespace.
static java.lang.String NATIVE_NAMESPACE_PREFIX
          The namespace for ZK native namespace prefix.
static java.lang.String ZK_NAMESPACE
          The namespace for ZK.
 
Constructor Summary
LanguageDefinition(java.lang.String deviceType, java.lang.String name, java.lang.String namespace, java.util.List extensions, PageRenderer pageRenderer, boolean ignoreCase, boolean bNative, Locator locator)
          Constructs a language defintion.
 
Method Summary
 void addComponentDefinition(ComponentDefinition compdef)
          Adds a component definition.
 void addCSSURI(java.lang.String cssURI)
          Adds the URI of a CSS file that is part of this language.
 void addDeferJavaScriptPackage(java.lang.String pkg)
          Adds a deferrable JavaScript package required by this langauge.
 void addEachTimeScript(java.lang.String zslang, java.lang.String script)
          Adds the script that shall execute each time before evaluating zscript.
static void addExtension(java.lang.String ext, java.lang.String lang)
          Associates an extension to a language.
 void addInitScript(java.lang.String zslang, java.lang.String script)
          Adds the script that shall execute when a page's interpreter is initialized.
 void addJavaScript(JavaScript js)
          Adds a JavaScript required by this language.
 void addJavaScriptModule(java.lang.String name, java.lang.String version)
          Adds the definition of a JavaScript module to this language.
 void addStyleSheet(StyleSheet ss)
          Adds a StyleSheet required by this language.
 void addTaglib(Taglib taglib)
          Adds a tag lib.
 void addWidgetDefinition(WidgetDefinition wgtdef)
          Adds a widget definition.
static boolean exists(java.lang.String name)
          Returns whether the specified language exists.
static java.util.List getAll()
          Returns a readonly list of all language definitions regardless of the device type.
static java.util.List getByDeviceType(java.lang.String deviceType)
          Returns a readonly list of language definitions belong to the specified device type.
static LanguageDefinition getByExtension(java.lang.String ext)
          Returns the language definition by specifying an extension.
 ComponentDefinition getComponentDefinition(java.lang.Class klass)
          Returns ComponentDefinition of the specified class.
 ComponentDefinition getComponentDefinition(java.lang.String name)
          Returns ComponentDefinition of the specified name.
 ComponentDefinition getComponentDefinitionIfAny(java.lang.String name)
          Returns ComponentDefinition of the specified name, or null if not found.
 ComponentDefinitionMap getComponentDefinitionMap()
          Returns the map of components defined in this language (never null).
 java.util.Collection getComponentDefinitions()
          Returns a readonly collection of all component definitions in this language.
 java.util.Collection getCSSURIs()
          Returns a readonly collection of the URIs of CSS files of this language.
 java.util.Collection getDeferJavaScriptPackages()
          Returns a list of deferrable JavaScript package (String) required by this language.
 java.lang.String getDeviceType()
          Returns the device type that this definition belongs to.
static java.util.Collection getDeviceTypes()
          Returns a readonly collection of all device types.
 ComponentDefinition getDynamicTagDefinition()
          Returns the component defintion of the dynamic tag, or null if this language doesn't support the dynamic tag.
 java.lang.String getEachTimeScript(java.lang.String zslang)
          Returns the each-time scripts of the specified language, or null if no scripts.
 Evaluator getEvaluator()
          Returns the evaluator based on this language definition (never null).
 EvaluatorRef getEvaluatorRef()
          Returns the evaluator reference (never null).
 java.util.List getExtensions()
          Returns the readonly list of extensions that this language definition is associated with (never null).
 java.lang.String getInitScript(java.lang.String zslang)
          Returns the intial scripts of the specified language, or null if no script.
 java.util.Map getJavaScriptModules()
          Returns a map of definitions of JavaScript modules, (String name, String version).
 java.util.Collection getJavaScripts()
          Returns a readonly list of all JavaScript required by this language.
 ComponentDefinition getMacroDefinition(java.lang.String name, java.lang.String macroURI, boolean inline, PageDefinition pgdef)
          Instantiates and returns the component definition for the specified condition.
 java.lang.String getName()
          Returns name of this language.
 java.lang.String getNamespace()
          Returns the name space.
 ComponentDefinition getNativeDefinition()
          Returns the component definition for the native components.
 PageRenderer getPageRenderer()
          Returns the page render for this language.
 java.util.Collection getStyleSheets()
          Returns a readonly list of all StyleSheet required by this language.
 WidgetDefinition getWidgetDefinition(java.lang.String widgetClass)
          Returns the widget of the specified class name.
 WidgetDefinition getWidgetDefinitionIfAny(java.lang.String widgetClass)
          Returns the widget of the specified class name, or null if not found.
 boolean hasComponentDefinition(java.lang.String name)
          Returns whether the specified component is defined.
 boolean hasWidgetDefinition(java.lang.String widgetClass)
          Returns whether the specified widget is defined.
 boolean isCaseInsensitive()
          Returns whether the component names are case-insensitive.
 boolean isDynamicReservedAttributes(java.lang.String attr)
          Returns whether a reserved attribute is used by the dynamic tag (getDynamicTagDefinition()).
 boolean isNative()
          Returns whether this is a native language.
 boolean isRawLabel()
          Returns whether this language prefers the raw label.
static LanguageDefinition lookup(java.lang.String name)
          Returns the language definition of the specified name or namespace.
 ComponentInfo newLabelInfo(ComponentInfo parent, java.lang.String text)
          Constructs and returns an ComponentInfo for the specified parent and text,
 void setDynamicTagInfo(java.lang.String compnm, java.util.Set reservedAttrs)
          Adds the definition for the dynamic tag.
 void setLabelTemplate(java.lang.String compName, java.lang.String propName, boolean raw)
          Sets the component and attribute names used to represent a label.
 void setMacroTemplate(java.lang.Class klass)
          Sets the macro template.
 void setNativeTemplate(java.lang.Class klass)
          Sets the native template.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ZK_NAMESPACE

public static final java.lang.String ZK_NAMESPACE
The namespace for ZK. It is mainly used to resolve special components and attributes, such as zscript and use.

See Also:
Constant Field Values

ANNO_NAMESPACE

public static final java.lang.String ANNO_NAMESPACE
The namespace for ZK annotations.

See Also:
Constant Field Values

NATIVE_NAMESPACE

public static final java.lang.String NATIVE_NAMESPACE
The namespace for ZK native namespace.

Since:
3.0.0
See Also:
Constant Field Values

CLIENT_NAMESPACE

public static final java.lang.String CLIENT_NAMESPACE
The namespace for ZK client namespace. It is used to specify the client attributes, such as the event listener.

Since:
5.0.0
See Also:
Constant Field Values

NATIVE_NAMESPACE_PREFIX

public static final java.lang.String NATIVE_NAMESPACE_PREFIX
The namespace for ZK native namespace prefix. If a namespace starts with NATIVE_NAMESPACE_PREFIX ("native:"), it means it is also a native space (NATIVE_NAMESPACE but the namespace prefix and uri will be generated.

For example,

<s:svg xmlns:s="native:http://www.w3.org/2000/svg"/>

generates the following output:

<s:svg xmlns:s="http://www.w3.org/2000/svg"/>
where the prefix s and URI http://www.w3.org/2000/svg are both generated.

Since:
3.0.0
See Also:
Constant Field Values
Constructor Detail

LanguageDefinition

public LanguageDefinition(java.lang.String deviceType,
                          java.lang.String name,
                          java.lang.String namespace,
                          java.util.List extensions,
                          PageRenderer pageRenderer,
                          boolean ignoreCase,
                          boolean bNative,
                          Locator locator)
Constructs a language defintion.

Note: the name and namespace of any language cannot be the same. In other words, each language has two names, name and namespace. You can find the language back by either of them via lookup(java.lang.String).

Parameters:
deviceType - the device type; never null or empty
pageRenderer - the page renderer used to render a page; never null.
ignoreCase - whether the component name is case-insensitive
bNative - whether it is native (i.e., all tags are Native). If native, the namespaces found in a ZUML page is no longer used to specified a language. Rather, it is output to the client directly.
Since:
5.0.0
Method Detail

exists

public static boolean exists(java.lang.String name)
Returns whether the specified language exists.


lookup

public static final LanguageDefinition lookup(java.lang.String name)
Returns the language definition of the specified name or namespace.

Note: the name and namespace of any language cannot be the same.

Parameters:
name - the name or the namespace; If null or empty, "xul/html" is assumed.
Throws:
DefinitionNotFoundException - is thrown if the definition is not found

getByExtension

public static final LanguageDefinition getByExtension(java.lang.String ext)
Returns the language definition by specifying an extension.

Parameters:
ext - the extension, e.g., "zul". If null, "zul" is assumed.
Throws:
DefinitionNotFoundException - is thrown if the definition is not found

addExtension

public static final void addExtension(java.lang.String ext,
                                      java.lang.String lang)
Associates an extension to a language.

Parameters:
lang - the language name. It cannot be null.
ext - the extension, e.g., "svg". It cannot be null.
Since:
3.0.0

getByDeviceType

public static final java.util.List getByDeviceType(java.lang.String deviceType)
Returns a readonly list of language definitions belong to the specified device type.

A device type identifies the type of a client. For example, "ajax" represents all Web browsers with Ajax support, while "mil" represents clients that supports Mobile User interface markup Language (on Limited Connected Device, such as mobile phones).

Parameters:
deviceType - the device type, e.g., "ajax".
See Also:
getDeviceType(), getAll()

getAll

public static final java.util.List getAll()
Returns a readonly list of all language definitions regardless of the device type.

Since:
2.4.1
See Also:
getByDeviceType(java.lang.String)

getDeviceTypes

public static final java.util.Collection getDeviceTypes()
Returns a readonly collection of all device types.

See Also:
getByDeviceType(java.lang.String)

getDeviceType

public java.lang.String getDeviceType()
Returns the device type that this definition belongs to.

A device type identifies the type of a client. For example, "ajax" represents all HTML compatible clients (aka., browsers), while "mil" represents clients that supports Mobile Interactive markup Language (on Limited Connected Device, such as mobile phones).


isNative

public boolean isNative()
Returns whether this is a native language. If true, it means all tags in a ZUML page is considered as native and all namespaces (except ZK namespace) are output the client directly.

Since:
3.0.0

getName

public java.lang.String getName()
Returns name of this language. Each language definition has a unique name and namespace.


getNamespace

public java.lang.String getNamespace()
Returns the name space. Each language definition has a unique name and namespace.


getExtensions

public java.util.List getExtensions()
Returns the readonly list of extensions that this language definition is associated with (never null).

Since:
2.4.1

getComponentDefinitions

public java.util.Collection getComponentDefinitions()
Returns a readonly collection of all component definitions in this language.

Since:
3.6.3

getComponentDefinitionMap

public ComponentDefinitionMap getComponentDefinitionMap()
Returns the map of components defined in this language (never null).


getComponentDefinition

public ComponentDefinition getComponentDefinition(java.lang.String name)
Returns ComponentDefinition of the specified name.

Note: anonymous component definition won't be returned by this method.

Parameters:
name - the name of the component definition.
Throws:
DefinitionNotFoundException - is thrown if the definition is not found

getComponentDefinitionIfAny

public ComponentDefinition getComponentDefinitionIfAny(java.lang.String name)
Returns ComponentDefinition of the specified name, or null if not found. It is the same as getComponentDefinition(java.lang.String), except this method won't throw any exception.

Parameters:
name - the name of the component definition.
Since:
3.0.2

getComponentDefinition

public ComponentDefinition getComponentDefinition(java.lang.Class klass)
Returns ComponentDefinition of the specified class.

Note: anonymous component definition won't be returned by this method.

Parameters:
klass - the class that implements the component.
Throws:
DefinitionNotFoundException - is thrown if the definition is not found

hasComponentDefinition

public boolean hasComponentDefinition(java.lang.String name)
Returns whether the specified component is defined.


addComponentDefinition

public void addComponentDefinition(ComponentDefinition compdef)
Adds a component definition.


hasWidgetDefinition

public boolean hasWidgetDefinition(java.lang.String widgetClass)
Returns whether the specified widget is defined.

Parameters:
widgetClass - the name of the widget class (JavaScript class), including the package name.
Since:
5.0.0

getWidgetDefinition

public WidgetDefinition getWidgetDefinition(java.lang.String widgetClass)
Returns the widget of the specified class name.

Parameters:
widgetClass - the name of the widget class (JavaScript class), including the package name.
Throws:
DefinitionNotFoundException - is thrown if the definition is not found
Since:
5.0.0

getWidgetDefinitionIfAny

public WidgetDefinition getWidgetDefinitionIfAny(java.lang.String widgetClass)
Returns the widget of the specified class name, or null if not found. It is the same as getWidgetDefinition(java.lang.String), except this method won't throw any exception.

Parameters:
widgetClass - the name of the widget class (JavaScript class), including the package name.
Since:
5.0.0

addWidgetDefinition

public void addWidgetDefinition(WidgetDefinition wgtdef)
Adds a widget definition.

Since:
5.0.0

addInitScript

public void addInitScript(java.lang.String zslang,
                          java.lang.String script)
Adds the script that shall execute when a page's interpreter is initialized. In other words, they are evaluated only once for each page.

Note: it doesn't test the existence of the specified language, such that you can add the scripting language later.

Parameters:
zslang - the scripting language, say, Java.

getInitScript

public java.lang.String getInitScript(java.lang.String zslang)
Returns the intial scripts of the specified language, or null if no script.


addEachTimeScript

public void addEachTimeScript(java.lang.String zslang,
                              java.lang.String script)
Adds the script that shall execute each time before evaluating zscript.

Note: it doesn't test the existence of the specified language, such that you can add the scripting language later.

Parameters:
zslang - the scripting language, say, Java.

getEachTimeScript

public java.lang.String getEachTimeScript(java.lang.String zslang)
Returns the each-time scripts of the specified language, or null if no scripts.

The each-time script is evaluated each time before evaluating zscript.


addJavaScript

public void addJavaScript(JavaScript js)
Adds a JavaScript required by this language.


getJavaScripts

public java.util.Collection getJavaScripts()
Returns a readonly list of all JavaScript required by this language.


addDeferJavaScriptPackage

public void addDeferJavaScriptPackage(java.lang.String pkg)
Adds a deferrable JavaScript package required by this langauge.

Parameters:
pkg - the package name, such as "foo.fly"
Since:
5.0.0

getDeferJavaScriptPackages

public java.util.Collection getDeferJavaScriptPackages()
Returns a list of deferrable JavaScript package (String) required by this language.

Since:
5.0.0

addJavaScriptModule

public void addJavaScriptModule(java.lang.String name,
                                java.lang.String version)
Adds the definition of a JavaScript module to this language.

A JavaScript module represents a JavaScript file. This definition is mainly used to define its version, such that ZK could encode its URL such that browsers know when to reload it.


getJavaScriptModules

public java.util.Map getJavaScriptModules()
Returns a map of definitions of JavaScript modules, (String name, String version).


addStyleSheet

public void addStyleSheet(StyleSheet ss)
Adds a StyleSheet required by this language.


getStyleSheets

public java.util.Collection getStyleSheets()
Returns a readonly list of all StyleSheet required by this language.


isCaseInsensitive

public boolean isCaseInsensitive()
Returns whether the component names are case-insensitive.


getPageRenderer

public PageRenderer getPageRenderer()
Returns the page render for this language.

Since:
5.0.0

setMacroTemplate

public void setMacroTemplate(java.lang.Class klass)
Sets the macro template.

Since:
5.0.0

getMacroDefinition

public ComponentDefinition getMacroDefinition(java.lang.String name,
                                              java.lang.String macroURI,
                                              boolean inline,
                                              PageDefinition pgdef)
Instantiates and returns the component definition for the specified condition.

Parameters:
pgdef - the page definition the macro definitioin belongs to. If null, it belongs to this language definition.
macroURI - the ZUML page's URI that is used to render instances of this macro definition.
Throws:
java.lang.UnsupportedOperationException - if this language doesn't support the macros
Since:
3.0.0

setNativeTemplate

public void setNativeTemplate(java.lang.Class klass)
Sets the native template.

Since:
3.0.0

getNativeDefinition

public ComponentDefinition getNativeDefinition()
Returns the component definition for the native components.

Throws:
java.lang.UnsupportedOperationException - if this language doesn't support the native namespace
Since:
3.0.0

setLabelTemplate

public void setLabelTemplate(java.lang.String compName,
                             java.lang.String propName,
                             boolean raw)
Sets the component and attribute names used to represent a label. Since label is used a lot in a page, there is a simple way to create an ComponentInfo by calling newLabelInfo(org.zkoss.zk.ui.metainfo.ComponentInfo, java.lang.String).

To be able to call newLabelInfo(org.zkoss.zk.ui.metainfo.ComponentInfo, java.lang.String), this method must be called to define the component and attribute names used to create an ComponentInfo for a label.


newLabelInfo

public ComponentInfo newLabelInfo(ComponentInfo parent,
                                  java.lang.String text)
Constructs and returns an ComponentInfo for the specified parent and text,


isRawLabel

public boolean isRawLabel()
Returns whether this language prefers the raw label. By raw labels we mean the text shall not be trimmed and shall be generated directly to the output (rather than wrapping with, say, SPAN).


setDynamicTagInfo

public void setDynamicTagInfo(java.lang.String compnm,
                              java.util.Set reservedAttrs)
Adds the definition for the dynamic tag.

Parameters:
compnm - the component name used to represent any of dynamic tags for this language. If null, it means this language definition doesn't support the dynamic tag.
reservedAttrs - a set of reserved attributes that the dynamic tag support. The reserved attributes are the if, unless and use attributes.

getDynamicTagDefinition

public ComponentDefinition getDynamicTagDefinition()
Returns the component defintion of the dynamic tag, or null if this language doesn't support the dynamic tag.

Throws:
DefinitionNotFoundException - is thrown if the definition is not found

isDynamicReservedAttributes

public boolean isDynamicReservedAttributes(java.lang.String attr)
Returns whether a reserved attribute is used by the dynamic tag (getDynamicTagDefinition()).


addTaglib

public void addTaglib(Taglib taglib)
Adds a tag lib.


getEvaluator

public Evaluator getEvaluator()
Returns the evaluator based on this language definition (never null).

Since:
3.0.0

getEvaluatorRef

public EvaluatorRef getEvaluatorRef()
Returns the evaluator reference (never null).

This method is used only for implementation only.

Since:
3.0.0

addCSSURI

public void addCSSURI(java.lang.String cssURI)
Adds the URI of a CSS file that is part of this language.

Parameters:
cssURI - the URI of a CSS file
Since:
5.0.0

getCSSURIs

public java.util.Collection getCSSURIs()
Returns a readonly collection of the URIs of CSS files of this language.

Since:
5.0.0

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 2005-2009 Potix Corporation. All Rights Reserved. SourceForge.net Logo