Package org.zkoss.zk.ui.metainfo

## Class ZScriptInfo

- java.lang.Object
- - org.zkoss.zk.ui.metainfo.ZScriptInfo

- All Implemented Interfaces:
    `java.io.Serializable`, `NodeInfo`, `Condition`

      public class ZScriptInfo
      extends java.lang.Object

  Represents a zscript element.
  Since:
    6.0.0
  Author:
    tomyeh
  See Also:
    Serialized Form

- - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `ZScriptInfo​(NodeInfo parent, java.lang.String zslang, java.lang.String url, Locator locator, ConditionImpl cond)` | Constructs a `ZScriptInfo` with an URL, which might contain an EL expression.
    `ZScriptInfo​(NodeInfo parent, java.lang.String zslang, java.lang.String content, ConditionImpl cond)` | Creates a `ZScriptInfo` with the content directly.
    `ZScriptInfo​(NodeInfo parent, java.lang.String zslang, java.net.URL url, ConditionImpl cond)` | Create a `ZScriptInfo` with an URL that is used to load the content.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `void` | `appendChild​(NodeInfo child)` | Append a child
    `java.util.List<NodeInfo>` | `getChildren()` | Returns a readonly list of children.
    `java.lang.String` | `getContent​(Page page, Component comp)` | Returns the content of zscript.
    `Evaluator` | `getEvaluator()` | Returns the evaluator.
    `EvaluatorRef` | `getEvaluatorRef()` | Returns the evaluator reference.
    `java.lang.String` | `getLanguage()` | Returns the scripting language, or null if the default scripting language is preferred.
    `PageDefinition` | `getPageDefinition()` | Returns the page definition, i.e., the root node, or null if not available.
    `NodeInfo` | `getParent()` | Returns the parent, or null if it has no parent.
    `java.lang.String` | `getRawContent()` | Returns the raw content.
    `ZScript` | `getZScript()` | Returns the `ZScript` object hold in this info.
    `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.
    `boolean` | `removeChild​(NodeInfo child)` | Removes a child.
    `void` | `setCondition​(ConditionImpl cond)` | Sets the effectiveness condition.
    `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()` |
    `boolean` | `withCondition()` | Tests if the condition is set

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### ZScriptInfo

          public ZScriptInfo​(NodeInfo parent,
                             java.lang.String zslang,
                             java.lang.String content,
                             ConditionImpl cond)

      Creates a `ZScriptInfo` with the content directly.
      Parameters:
        `zslang` - the scripting language. If null, it is the same as `Page.getZScriptLanguage()`.
        `content` - the zscript content

    - #### ZScriptInfo

          public ZScriptInfo​(NodeInfo parent,
                             java.lang.String zslang,
                             java.net.URL url,
                             ConditionImpl cond)

      Create a `ZScriptInfo` with an URL that is used to load the content.
      Parameters:
        `url` - the URL to load the content of zscript.

    - #### ZScriptInfo

          public ZScriptInfo​(NodeInfo parent,
                             java.lang.String zslang,
                             java.lang.String url,
                             Locator locator,
                             ConditionImpl cond)

      Constructs a `ZScriptInfo` with an URL, which might contain an EL expression.
      Parameters:
        `url` - the URL. It may contain XEL expressions.
        `locator` - the locator used to locate the zscript file

  - ### Method Detail

    - #### getZScript

          public ZScript getZScript()

      Returns the `ZScript` object hold in this info.

    - #### 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 constructor (`ZScriptInfo(NodeInfo, String, String, ConditionImpl)`. If URL is specified in the constructor, 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 constructor, or null if URL is specified instead.

    - #### getContent

          public java.lang.String getContent​(Page page,
                                             Component comp)

      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 `Condition.isEffective(Component)` or `Condition.isEffective(Page)` first.

      Parameters:
        `page` - the page when this zscript is interpreted. Used only if this object is constructed with `ZScriptInfo(NodeInfo, String, String, Locator, ConditionImpl)`.
        `comp` - the component when this zscript is interpreted. Used only if this object is constructed with `ZScriptInfo(NodeInfo, String, String, Locator, ConditionImpl)`.
      Throws:
        `UiException` - if failed to load the content

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

    - #### toString

          public java.lang.String toString()

      Overrides:
        `toString` in class `java.lang.Object`

    - #### setCondition

          public void setCondition​(ConditionImpl cond)

      Sets the effectiveness condition.

    - #### withCondition

          public boolean withCondition()

      Tests if the condition is set

    - #### 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. 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. Ignored if null.

    - #### getEvaluatorRef

          public EvaluatorRef getEvaluatorRef()

      Description copied from interface: `NodeInfo`
      Returns the evaluator reference.
      Specified by:
        `getEvaluatorRef` in interface `NodeInfo`

    - #### getPageDefinition

          public PageDefinition getPageDefinition()

      Description copied from interface: `NodeInfo`
      Returns the page definition, i.e., the root node, or null if not available.
      Specified by:
        `getPageDefinition` in interface `NodeInfo`

    - #### getEvaluator

          public Evaluator getEvaluator()

      Description copied from interface: `NodeInfo`
      Returns the evaluator.

      All nodes in the same ZUML tree has the same evaluator reference (inherited from the root node, `PageDefinition.getEvaluatorRef()`).

      Specified by:
        `getEvaluator` in interface `NodeInfo`

    - #### getParent

          public NodeInfo getParent()

      Description copied from interface: `NodeInfo`
      Returns the parent, or null if it has no parent.
      Specified by:
        `getParent` in interface `NodeInfo`

    - #### getChildren

          public java.util.List<NodeInfo> getChildren()

      Description copied from interface: `NodeInfo`
      Returns a readonly list of children.

      Note: the returned list is readonly. To modify, please use `NodeInfo.appendChild(org.zkoss.zk.ui.metainfo.NodeInfo)` and `NodeInfo.removeChild(org.zkoss.zk.ui.metainfo.NodeInfo)` instead.

      Specified by:
        `getChildren` in interface `NodeInfo`

    - #### appendChild

          public void appendChild​(NodeInfo child)

      Description copied from interface: `NodeInfo`
      Append a child
      Specified by:
        `appendChild` in interface `NodeInfo`

    - #### removeChild

          public boolean removeChild​(NodeInfo child)

      Description copied from interface: `NodeInfo`
      Removes a child.
      Specified by:
        `removeChild` in interface `NodeInfo`