org.zkoss.zk.ui.metainfo
Class ZScript

java.lang.Object
  extended by org.zkoss.zk.ui.metainfo.ZScript
All Implemented Interfaces:
java.io.Serializable, Condition

public class ZScript
extends java.lang.Object
implements Condition, java.io.Serializable

Represents a zscript element.

Author:
tomyeh
See Also:
Serialized Form

Constructor Summary
ZScript(java.lang.String zslang, java.lang.String content, Condition cond)
          Creates a zscript object with the content directly.
ZScript(java.lang.String zslang, java.lang.String url, Condition cond, org.zkoss.util.resource.Locator locator)
          Constructs a ZScript with an URL, which might contain an EL expression.
ZScript(java.lang.String zslang, java.net.URL url, Condition cond)
          Create a zscript object with an URL that is used to load the content.
 
Method Summary
 java.lang.String getContent(Page page, Component comp)
          Returns the content of zscript.
 java.lang.String getLanguage()
          Returns the scripting language, or null if the default scripting language is preferred.
 java.lang.String getRawContent()
          Returns the raw content.
 boolean isDeferred()
          Returns whether the evaluation of the zscript shall be deferred.
 boolean isEffective(Component comp)
          Used to evaluate whether it is effective.
 boolean isEffective(Page page)
          Used to evaluate whether it is effective.
static ZScript parseContent(java.lang.String content, Condition cond)
          Parses the content into a ZScript instance.
 void setDeferred(boolean deferred)
          Sets whether the evaluation of the zscript shall be deferred.
 void setLanguage(java.lang.String zslang)
          Sets the scripting language.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ZScript

public ZScript(java.lang.String zslang,
               java.lang.String content,
               Condition cond)
Creates a zscript object with the content directly.

Parameters:
zslang - the scripting language. If null, it is the same as Page.getZScriptLanguage().
content - the zscript content

ZScript

public ZScript(java.lang.String zslang,
               java.net.URL url,
               Condition cond)
Create a zscript object with an URL that is used to load the content.

Parameters:
url - the URL to load the content of zscript.

ZScript

public ZScript(java.lang.String zslang,
               java.lang.String url,
               Condition cond,
               org.zkoss.util.resource.Locator locator)
Constructs a ZScript with an URL, which might contain an EL expression.

Parameters:
locator - the locator used to locate the zscript file
Method Detail

parseContent

public static final ZScript parseContent(java.lang.String content,
                                         Condition cond)
Parses the content into a ZScript instance.

This method assumes the content is in the following format:
lang:codes
codes

For example, "javascript:var m = 0;" returns "javascript", while "var m = 0;" returns null.

Note: if the language doesn't exist, null is returned. Reason: the above syntax may be conflict with some scripting languages.

Note: no space is allowed.

Parameters:
content - the content of zscript codes

getLanguage

public java.lang.String getLanguage()
Returns the scripting language, or null if the default scripting language is preferred.


setLanguage

public void setLanguage(java.lang.String zslang)
Sets the scripting language.

Parameters:
zslang - the scripting language. If null, the default scripting language is assume.

getRawContent

public java.lang.String getRawContent()
Returns the raw content. It is the content specified in the contructor (ZScript(String, String, Condition). If URL is specified in the contructor, null is returned.

On the other hand, getContent(org.zkoss.zk.ui.Page, org.zkoss.zk.ui.Component) will load the content automatically if URL is specified.

Returns:
the raw content specified in the contructor, or null if URL is specified instead.

getContent

public java.lang.String getContent(Page page,
                                   Component comp)
                            throws java.io.IOException
Returns the content of zscript. If URL is specified, this method loads the content from it. If URL is an EL expression, it will be evaluated first.

Note: before evaluating the returned script, you have to invoke isEffective(Component) or isEffective(Page) first.

Parameters:
page - the page when this zscript is interpreted. Used only if this object is contructed with ZScript(String, String, Condition, Locator).
comp - the component when this zscript is interpreted. Used only if this object is contructed with ZScript(String, String, Condition, Locator).
Throws:
java.io.IOException

isDeferred

public boolean isDeferred()
Returns whether the evaluation of the zscript shall be deferred.


setDeferred

public void setDeferred(boolean deferred)
Sets whether the evaluation of the zscript shall be deferred.

Default: false.


isEffective

public boolean isEffective(Component comp)
Description copied from interface: Condition
Used to evaluate whether it is effective.

Specified by:
isEffective in interface Condition
Parameters:
comp - used as the self variable and to retrieve the function mapper. Ignored if null.

isEffective

public boolean isEffective(Page page)
Description copied from interface: Condition
Used to evaluate whether it is effective.

Specified by:
isEffective in interface Condition
Parameters:
page - used as the self variable and to retrieve the function mapper.

toString

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


Copyright © 2005-2007 Potix Corporation. All Rights Reserved.