/** Creates a {@link ZScriptInfo} with the content directly. * * @param zslang the scripting language. If null, it is the same as * {@link Page#getZScriptLanguage}. * @param content the zscript content */ public ZScriptInfo(NodeInfo parent, String zslang, String content, ConditionImpl cond) { super(parent, cond); _zs = new ZScript(zslang, content); }
/** 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. * * <p>Note: before evaluating the returned script, you have to invoke * {@link #isEffective(Component)} or {@link #isEffective(Page)} first. * * @param page the page when this zscript is interpreted. * Used only if this object is constructed with {@link #ZScriptInfo(NodeInfo, String, String, Locator, ConditionImpl)}. * @param comp the component when this zscript is interpreted. * Used only if this object is constructed with {@link #ZScriptInfo(NodeInfo, String, String, Locator, ConditionImpl)}. * @exception org.zkoss.zk.ui.UiException if failed to load the content */ public String getContent(Page page, Component comp) { _zs.setEvaluatorRef(_evalr); //in case that this info has been moved return _zs.getContent(page, comp); }
/** Returns the scripting language, or null if the default scripting language * is preferred. */ public String getLanguage() { return _zs.getLanguage(); }
public void interpret(Page page, Component comp, ZScript zs) { final Scope scope = Scopes.beforeInterpret(comp != null ? (Scope)comp: page); try { page.interpret(zs.getLanguage(), zs.getContent(page, comp), scope); } finally { Scopes.afterInterpret(); } } public void setPageOnly(Execution exec) {
checkZScriptEnabled(xl); final int lno = xl != null ? xl.getLineNumber() : 0; final ZScript zscript = ZScript.parseContent(value, lno); if (zscript.getLanguage() == null) zscript.setLanguage(compInfo.getPageDefinition().getZScriptLanguage());
/** * A useful method use to invoke zscript. * @param page page instance. * @param parent The owner of zscript segment. * @param zs A ZScript object. * @throws IOException */ public static void processZScript(Page page, Component parent, ZScript zs) throws IOException { if (zs.getLanguage() == null) zs.setLanguage(page.getZScriptLanguage()); if (zs.isDeferred()) ((PageCtrl)page).addDeferredZScript(parent, zs); else ZkProxy.getProxy().interpret(page, parent, zs); }
/** Parses the content into a {@link ZScript} instance. * * <p>This method assumes the content is in the following format:<br/> * <code>lang:codes</code><br/> * <code>codes</code> * * <p>For example, "javascript:var m = 0;" returns "javascript", while * "var m = 0;" returns null. * * <p>Note: if the language doesn't exist, null is returned. * Reason: the above syntax may be conflict with some scripting languages. * * <p>Note: no space is allowed. * * @param content the content of zscript codes * @since 3.0.0 */ public static final ZScript parseContent(String content) { return parseContent(content, 0); }
/** Sets the scripting language. * * @param zslang the scripting language. If null, the default scripting * language is assume. */ public void setLanguage(String zslang) { _zs.setLanguage(zslang); }
/** Returns the {@link ZScript} object hold in this info. */ public ZScript getZScript() { _zs.setEvaluatorRef(_evalr); //in case that this info has been moved return _zs; }
/** Returns the raw content. * It is the content specified in the constructor * ({@link #ZScriptInfo(NodeInfo, String, String, ConditionImpl)}. * If URL is specified in the constructor, null is returned. * * <p>On the other hand, {@link #getContent} will load the content * automatically if URL is specified. * * @return the raw content specified in the constructor, or null * if URL is specified instead. */ public String getRawContent() { return _zs.getRawContent(); }
final String o = getCache().get(url);
public void doInit(Page page, Map<String, Object> args) throws Exception { final Scope scope = Scopes.beforeInterpret(page); try { page.interpret(_zscript.getLanguage(), _zscript.getContent(page, null), scope); } finally { Scopes.afterInterpret(); } } }
final ZScript zscript = ZScript.parseContent((String)entry.getValue()); ((ComponentCtrl)_comp).addEventHandler( (String)entry.getKey(), new EventHandler(zscript,null));
/** @deprecated */ public void interpret(Page page, Component comp, ZScript zs) { final Map backup = new HashMap(); final org.zkoss.zk.scripting.Namespace ns = comp != null ? org.zkoss.zk.scripting.Namespaces.beforeInterpret(backup, comp, false): org.zkoss.zk.scripting.Namespaces.beforeInterpret(backup, page, false); try { page.interpret(zs.getLanguage(), zs.getContent(page, comp), ns); } finally { org.zkoss.zk.scripting.Namespaces.afterInterpret(backup, ns, false); } } /** @deprecated */
/** Create a {@link ZScriptInfo} with an URL that is used to load the content. * * @param url the URL to load the content of zscript. */ public ZScriptInfo(NodeInfo parent, String zslang, URL url, ConditionImpl cond) { super(parent, cond); _zs = new ZScript(zslang, url); }
/** Evaluates the deferred zscript. * It is called when the interpreter is loaded */ private void evalDeferredZScripts(Interpreter ip, String zslang) { if (_zsDeferred != null) { for (Iterator<Object[]> it = _zsDeferred.iterator(); it.hasNext();) { final Object[] zsInfo = it.next(); final ZScript zscript = (ZScript) zsInfo[1]; String targetlang = zscript.getLanguage(); if (targetlang == null) targetlang = _zslang; //use default if (targetlang.equalsIgnoreCase(zslang)) { //case insensitive it.remove(); //done final Component parent = (Component) zsInfo[0]; if (parent == null || parent.getPage() == this) { final Scope scope = Scopes.beforeInterpret(parent != null ? (Scope) parent : this); try { ip.interpret(zscript.getContent(this, parent), scope); } finally { Scopes.afterInterpret(); } } } } if (_zsDeferred.isEmpty()) _zsDeferred = null; } }
/** Constructs a {@link ZScriptInfo} with an URL, which might contain an EL * expression. * * @param url the URL. It may contain XEL expressions. * @param locator the locator used to locate the zscript file */ public ZScriptInfo(NodeInfo parent, String zslang, String url, Locator locator, ConditionImpl cond) { super(parent, cond); _zs = new ZScript(parent.getEvaluatorRef(), zslang, url, locator); }
if (zscript != null) { execinf.update(null, null, zscript); page.interpret(zscript.getLanguage(), zscript.getContent(page, this), scope); if (!event.isPropagatable()) return; //done
public void doInit(Page page, Map args) throws Exception { final String zslang = page.getZScriptLanguage(); final URL url = Jsps.getPageContext( getJspContext()).getServletContext().getResource(_zscript); if (url == null) throw new UiException("File not found: "+_zscript); ZScript zs = new ZScript(null, zslang, url, null); RootTag.processZScript(page, null, zs); } public void doAfterCompose(Page page) throws Exception {}
return new ZScript(zslang, prefix != null && content.length() > 0 ? prefix + content : content);