Package org.zkoss.zk.ui.metainfo

## Class ZScript

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

- All Implemented Interfaces:
    `java.io.Serializable`

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

  Represents a zscript content.
  Author:
    tomyeh
  See Also:
    Serialized Form

- - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `ZScript​(java.lang.String zslang, java.lang.String content)` | Creates a zscript with the content directly.
    `ZScript​(java.lang.String zslang, java.net.URL url)` | Creates a zscript with an URL that is used to load the content.
    `ZScript​(EvaluatorRef evalr, java.lang.String zslang, java.lang.String url, Locator locator)` | Creates a zscript with an URL that is used to load the content.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `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.
    `static ZScript` | `parseContent​(java.lang.String content)` | Parses the content into a `ZScript` instance.
    `static ZScript` | `parseContent​(java.lang.String content, int lineno)` | Parses the content into a `ZScript` instance.
    `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)

      Creates a zscript with the content directly.
      Parameters:
        `zslang` - the scripting language. If null, it is the same as `Page.getZScriptLanguage()`.
        `content` - the zscript content
      See Also:
        `parseContent(java.lang.String)`

    - #### ZScript

          public ZScript​(java.lang.String zslang,
                         java.net.URL url)

      Creates a zscript with an URL that is used to load the content.

    - #### ZScript

          public ZScript​(EvaluatorRef evalr,
                         java.lang.String zslang,
                         java.lang.String url,
                         Locator locator)

      Creates a zscript with an URL that is used to load the content.
      Parameters:
        `evalr` - the evaluator used to evaluate
      Throws:
        `java.lang.IllegalArgumentException` - if url or locator is null, or url contains EL and evalr is null.

  - ### Method Detail

    - #### parseContent

          public static final ZScript parseContent​(java.lang.String content)

      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
      Since:
        3.0.0

    - #### parseContent

          public static final ZScript parseContent​(java.lang.String content,
                                                   int lineno)

      Parses the content into a `ZScript` instance.

      It is similar to `parseContent(String)` except it allows the caller to specify the line number of the first line of the content.

      Parameters:
        `content` - the content of zscript codes
        `lineno` - the line number of the first line. Ignored if zero (or negative).
      Since:
        3.6.1

    - #### 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 (`ZScript(String, String)`. 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.
      Parameters:
        `page` - the page when this zscript is interpreted. Used only if this object is constructed with `ZScript(EvaluatorRef, String, String, Locator)`.
        `comp` - the component when this zscript is interpreted. Used only if this object is constructed with `ZScript(EvaluatorRef, String, String, Locator)`.
      Throws:
        `UiException` - if failed to load the content

    - #### toString

          public java.lang.String toString()

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