📄 pagedefinition.java
字号:
/* PageDefinition.java{{IS_NOTE Purpose: Description: History: Tue May 31 11:27:07 2005, Created by tomyeh}}IS_NOTECopyright (C) 2005 Potix Corporation. All Rights Reserved.{{IS_RIGHT This program is distributed under GPL Version 2.0 in the hope that it will be useful, but WITHOUT ANY WARRANTY.}}IS_RIGHT*/package org.zkoss.zk.ui.metainfo;import java.util.Iterator;import java.util.List;import java.util.LinkedList;import java.util.Collections;import java.util.Map;import java.util.HashMap;import java.util.LinkedHashMap;import org.zkoss.lang.Classes;import org.zkoss.lang.Objects;import org.zkoss.util.resource.Locator;import org.zkoss.xel.ExpressionFactory;import org.zkoss.xel.Expressions;import org.zkoss.xel.Function;import org.zkoss.xel.VariableResolver;import org.zkoss.xel.FunctionMapper;import org.zkoss.xel.taglib.Taglibs;import org.zkoss.xel.taglib.Taglib;import org.zkoss.xml.HTMLs;import org.zkoss.zk.ui.Executions;import org.zkoss.zk.ui.Page;import org.zkoss.zk.ui.UiException;import org.zkoss.zk.ui.util.Condition;import org.zkoss.zk.ui.util.Initiator;import org.zkoss.zk.scripting.Namespace;import org.zkoss.zk.scripting.Namespaces;import org.zkoss.zk.ui.sys.ComponentCtrl;import org.zkoss.zk.ui.sys.PageCtrl;import org.zkoss.zk.ui.sys.PageConfig;import org.zkoss.zk.xel.Evaluator;import org.zkoss.zk.xel.ExValue;import org.zkoss.zk.xel.impl.SimpleEvaluator;import org.zkoss.zk.xel.impl.EvaluatorRef;/** * A page definition. * It represents a ZUL page. * * <p>Note: it is not thread-safe. * * <p>Note: it is not serializable. * * @author tomyeh * @see ComponentDefinition */public class PageDefinition extends NodeInfo { private final LanguageDefinition _langdef; private final Locator _locator; private String _id, _title, _style; /** The request path. */ private String _path = ""; /** The zscript language. */ private String _zslang = "Java"; private List _taglibs; /** A map of imported classes for expression, Map<String nm, Class cls>. */ private Map _expimps; /** A map of XEL methods, List<[String prefix, String name, Function func]>. */ private List _xelmtds; /** The evaluator. */ private Evaluator _eval; /** The evaluator reference. */ private EvaluatorRef _evalr; /** The function mapper. */ private FunctionMapper _mapper; /* List(InitiatorInfo). */ private List _initdefs; /** List(VariableResolverInfo). */ private List _resolvdefs; /** List(HeaderInfo). */ private List _headerdefs; /** Map(String name, ExValue value). */ private Map _rootAttrs; private ExValue _contentType, _docType, _firstLine; /** The expression factory (ExpressionFactory).*/ private Class _expfcls; private final ComponentDefinitionMap _compdefs; private Boolean _cacheable; /** Constructor. * @param langdef the default language which is used if no namespace * is specified. Note: a page might have components from different * languages. */ public PageDefinition(LanguageDefinition langdef, Locator locator) { if (langdef == null) throw new IllegalArgumentException("null langdef"); if (locator == null) throw new IllegalArgumentException("null locator"); _langdef = langdef; _locator = locator; _compdefs = new ComponentDefinitionMap( _langdef.getComponentDefinitionMap().isCaseInsensitive()); } /** Constructor. * @param langdef the default language which is used if no namespace * is specified. Note: a page might have components from different * languages. * @param id the identifier. See {@link #setId}. * @param title the title. See {@link #setTitle}. * @param style the CSS style. See {@link #setStyle}. */ public PageDefinition(LanguageDefinition langdef, String id, String title, String style, Locator locator) { this(langdef, locator); setId(id); setTitle(title); setStyle(style); } /** Returns the language definition that this page is default to be. */ public LanguageDefinition getLanguageDefinition() { return _langdef; } /** Returns the parent (always null). */ public NodeInfo getParent() { return null; } /** Returns the locator associated with this page definition. */ public Locator getLocator() { return _locator; } /** Returns the default scripting language which is assumed when * a zscript element doesn't specify any language. * * <p>Default: Java. */ public String getZScriptLanguage() { return _zslang; } /** Sets the default scripting language which is assumed when * a zscript element doesn't specify any language. * * @param zslang the default scripting language. */ public void setZScriptLanguage(String zslang) { if (zslang == null || zslang.length() == 0) throw new IllegalArgumentException("null or empty"); _zslang = zslang; } /** Returns the identitifer that will be assigned to pages created from * this definition, or null if the identifier shall be generated automatically. * <p>Note: the returned value might contain EL expressions. */ public String getId() { return _id; } /** Sets the identifier that will be assigned to pages created from this * definition. * @param id the identifier. It might contain EL expressions. * If null or empty (null is assumed), page's ID is generated automatically. * If not empty, ID (after evaluated) must be unquie in the same request. */ public void setId(String id) { _id = id != null && id.length() > 0 ? id: null; } /** Returns the title that will be assigned to pages created from * this definition, or null if no title is assigned at the beginning. * <p>Note: the returned value might contain EL expressions. */ public String getTitle() { return _title; } /** Sets the title that will be assigned to pages created from * this definition, or null if no title is assigned at the beginning. * @param title the title. If empty, null is assumed. */ public void setTitle(String title) { _title = title != null && title.length() > 0 ? title: null; } /** Returns the CSS style that will be assigned to pages created from * this definition, or null if no style is assigned at the beginning. * <p>Note: the returned value might contain EL expressions. */ public String getStyle() { return _style; } /** Sets the CSS style that will be assigned to pages created from * this definition, or null if no style is assigned at the beginning. * @param style the CSS style. If empty, null is assumed. */ public void setStyle(String style) { _style = style != null && style.length() > 0 ? style: null; } /** Returns the request path of this page definition, or "" * if not available. * <p>It is the same as the servlet path * (javax.servlet.http.HttpServletRequest's getServletPath), if ZK is running * at a servlet container. */ public String getRequestPath() { return _path; } /** Sets the request path of this page definition. */ public void setRequestPath(String path) { _path = path != null ? path: ""; } /** Imports the component definitions from the specified definition. */ public void imports(PageDefinition pgdef) { if (_initdefs != null) for (Iterator it = pgdef._initdefs.iterator(); it.hasNext();) addInitiatorInfo((InitiatorInfo)it.next()); for (Iterator it = pgdef._compdefs.getNames().iterator(); it.hasNext();) { final String name = (String)it.next(); addComponentDefinition(pgdef._compdefs.get(name)); } } /** Adds a defintion of {@link org.zkoss.zk.ui.util.Initiator}. */ public void addInitiatorInfo(InitiatorInfo init) { if (init == null) throw new IllegalArgumentException("null"); if (_initdefs == null) _initdefs = new LinkedList(); _initdefs.add(init); } /** Returns a list of all {@link Initiator} and invokes * its {@link Initiator#doInit} before returning. * It never returns null. */ public List doInit(Page page) { if (_initdefs == null) return Collections.EMPTY_LIST; final List inits = new LinkedList(); for (Iterator it = _initdefs.iterator(); it.hasNext();) { final InitiatorInfo def = (InitiatorInfo)it.next(); try { final Initiator init = def.newInitiator(this, page); if (init != null) { init.doInit(page, def.getArguments(this, page)); inits.add(init); } } catch (Throwable ex) { throw UiException.Aide.wrap(ex); } } return inits; } /** Adds a defintion of {@link VariableResolver}. */ public void addVariableResolverInfo(VariableResolverInfo resolver) { if (resolver == null) throw new IllegalArgumentException("null"); if (_resolvdefs == null) _resolvdefs = new LinkedList(); _resolvdefs.add(resolver); } /** Adds a XEL method. * * @param prefix the prefix of the method name * @param name the method name. The final name is "prefix:name" * @param func the function. * @since 3.0.0 */ public void addXelMethod(String prefix, String name, Function func) { if (name == null || prefix == null || func == null) throw new IllegalArgumentException(); if (_xelmtds == null) _xelmtds = new LinkedList(); _xelmtds.add(new Object[] {prefix, name, func}); _eval = null; //ask for re-gen _mapper = null; //ask for re-parse } /** Initializes XEL context for the specified page. * * @param page the page to initialize the context. It cannot be null. */ public void initXelContext(Page page) { page.addFunctionMapper(getFunctionMapper()); if (_resolvdefs != null) for (Iterator it = _resolvdefs.iterator(); it.hasNext();) { final VariableResolverInfo def = (VariableResolverInfo)it.next(); try { VariableResolver resolver = def.newVariableResolver(this, page); if (resolver != null) page.addVariableResolver(resolver); } catch (Throwable ex) { throw UiException.Aide.wrap(ex); } } } /** Adds a header definition ({@link HeaderInfo}). */ public void addHeaderInfo(HeaderInfo header) { if (header == null) throw new IllegalArgumentException("null"); if (_headerdefs == null)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -