📄 pageimpl.java
字号:
} public Function getZScriptFunction(Namespace ns, String name, Class[] argTypes) { for (Iterator it = getLoadedInterpreters().iterator(); it.hasNext();) { final Object ip = it.next(); Function mtd = ip instanceof HierachicalAware ? ((HierachicalAware)ip).getFunction(ns, name, argTypes): ((Interpreter)ip).getFunction(name, argTypes); if (mtd != null) return mtd; } return null; } public Function getZScriptFunction( Component comp, String name, Class[] argTypes) { return getZScriptFunction(comp != null ? comp.getNamespace(): null, name, argTypes); } /** @deprecated As of release 3.0.0, replaced by {@link #getZScriptFunction(String,Class[])}. */ public org.zkoss.zk.scripting.Method getZScriptMethod(String name, Class[] argTypes) { final Function fun = getZScriptFunction(name, argTypes); return fun != null ? new FuncMethod(fun): null; } /** @deprecated As of release 3.0.0, replaced by {@link #getZScriptFunction(String,Class[])}. */ public org.zkoss.zk.scripting.Method getZScriptMethod(Namespace ns, String name, Class[] argTypes) { final Function fun = getZScriptFunction(ns, name, argTypes); return fun != null ? new FuncMethod(fun): null; } public Object getZScriptVariable(String name) { for (Iterator it = getLoadedInterpreters().iterator(); it.hasNext();) { final Object val = ((Interpreter)it.next()).getVariable(name); if (val != null) return val; } return null; } public Object getZScriptVariable(Namespace ns, String name) { for (Iterator it = getLoadedInterpreters().iterator(); it.hasNext();) { final Object ip = it.next(); final Object val = ip instanceof HierachicalAware ? ((HierachicalAware)ip).getVariable(ns, name): ((Interpreter)ip).getVariable(name); if (val != null) return val; } return null; } public Object getZScriptVariable(Component comp, String name) { return getZScriptVariable(comp != null ? comp.getNamespace(): null, name); } public Object getXelVariable(String name) { final VariableResolver resolv = getExecution().getVariableResolver(); return resolv != null ? resolv.resolveVariable(name): null; } /** @deprecated As of release of 3.0.0, replaced with {@link #getXelVariable}. */ public Object getELVariable(String name) { return getXelVariable(name); } /** Resolves the variable defined in variable resolvers. */ private Object resolveVariable(String name) { if (_resolvers != null) { for (Iterator it = _resolvers.iterator(); it.hasNext();) { Object o = ((VariableResolver)it.next()).resolveVariable(name); if (o != null) return o; } } return null; } public boolean addVariableResolver(VariableResolver resolver) { if (resolver == null) throw new IllegalArgumentException("null"); if (_resolvers == null) _resolvers = new LinkedList(); else if (_resolvers.contains(resolver)) return false; _resolvers.add(0, resolver); //FILO order return true; } public boolean removeVariableResolver(VariableResolver resolver) { return _resolvers != null && _resolvers.remove(resolver); } public boolean addEventListener(String evtnm, EventListener listener) { if (evtnm == null || listener == null) throw new IllegalArgumentException("null"); if (!Events.isValid(evtnm)) throw new IllegalArgumentException("Invalid event name: "+evtnm); if (_listeners == null) _listeners = new HashMap(3); List l = (List)_listeners.get(evtnm); if (l != null) { for (Iterator it = l.iterator(); it.hasNext();) { final EventListener li = (EventListener)it.next(); if (listener.equals(li)) return false; } } else { _listeners.put(evtnm, l = new LinkedList()); } l.add(listener); return true; } public boolean removeEventListener(String evtnm, EventListener listener) { if (evtnm == null || listener == null) throw new NullPointerException(); if (_listeners != null) { final List l = (List)_listeners.get(evtnm); if (l != null) { for (Iterator it = l.iterator(); it.hasNext();) { final EventListener li = (EventListener)it.next(); if (listener.equals(li)) { if (l.size() == 1) _listeners.remove(evtnm); else it.remove(); return true; } } } } return false; } public Component getFellow(String compId) { final Component comp = (Component)_fellows.get(compId); if (comp == null) if (compId != null && ComponentsCtrl.isAutoId(compId)) throw new ComponentNotFoundException(MZk.AUTO_ID_NOT_LOCATABLE, compId); else throw new ComponentNotFoundException("Fellow component not found: "+compId); return comp; } public Component getFellowIfAny(String compId) { return (Component)_fellows.get(compId); } //-- PageCtrl --// public void init(PageConfig config) { if (_desktop != null) throw new IllegalStateException("Don't init twice"); final Execution exec = Executions.getCurrent(); _desktop = exec.getDesktop(); if (_desktop == null) throw new IllegalArgumentException("null desktop"); initVariables(); if (((ExecutionCtrl)exec).isRecovering()) { final String uuid = config.getUuid(), id = config.getId(); if (uuid == null || id == null) throw new IllegalArgumentException("both id and uuid are required in recovering"); _uuid = uuid; _id = id; } else { final IdGenerator idgen = ((WebAppCtrl)_desktop.getWebApp()).getIdGenerator(); if (idgen != null) _uuid = idgen.nextPageUuid(this); if (_uuid == null) _uuid = ((DesktopCtrl)_desktop).getNextUuid(); if (_id == null) { final String id = config.getId(); if (id != null && id.length() != 0) _id = id; } if (_id != null) _id = (String)exec.evaluate(this, _id, String.class); if (_id != null && _id.length() != 0) { final String INVALID = ".&\\%"; if (Strings.anyOf(_id, INVALID, 0) < _id.length()) throw new IllegalArgumentException("Invalid page ID: "+_id+". Invalid characters: "+INVALID); } else { _id = _uuid; } } String s = config.getHeaders(); if (s != null) _headers = s; s = config.getRootAttributes(); if (s != null) _rootAttrs = s; s = config.getContentType(); if (s != null) _contentType = s; s = config.getDocType(); if (s != null) _docType = s; s = config.getFirstLine(); if (s != null) _firstLine = s; Boolean b = config.getCacheable(); if (b != null) _cacheable = b; if (_title.length() == 0) { s = config.getTitle(); if (s != null) setTitle(s); } if (_style.length() == 0) { s = config.getStyle(); if (s != null) setStyle(s); } ((DesktopCtrl)_desktop).addPage(this); } private void initVariables() { setVariable("log", _zklog); setVariable("page", this); setVariable("pageScope", getAttributes()); setVariable("requestScope", REQUEST_ATTRS); setVariable("spaceOwner", this); if (_desktop != null) { setVariable("desktop", _desktop); setVariable("desktopScope", _desktop.getAttributes()); final WebApp wapp = _desktop.getWebApp(); setVariable("application", wapp); setVariable("applicationScope", wapp.getAttributes()); final Session sess = _desktop.getSession(); setVariable("session", sess); setVariable("sessionScope", sess.getAttributes()); } } public void destroy() { for (Iterator it = getLoadedInterpreters().iterator(); it.hasNext();) { final Interpreter ip = (Interpreter)it.next(); try { ip.destroy(); } catch (Throwable ex) { log.error("Failed to destroy "+ip, ex); } } _ips.clear(); //theorectically, the following is not necessary, but, to be safe... _roots.clear(); _desktop = null; _owner = _defparent = null; _listeners = _attrs = _fellows = _ips = null; _ns = null; _resolvers = null; } private static final Map REQUEST_ATTRS = new AbstractMap() { public Set entrySet() { final Execution exec = Executions.getCurrent(); if (exec == null) return Collections.EMPTY_SET; return exec.getAttributes().entrySet(); } public Object put(Object name, Object value) { final Execution exec = Executions.getCurrent(); if (exec == null) throw new IllegalStateException("No execution at all"); return exec.getAttributes().put(name, value); } public boolean containsKey(Object name) { final Execution exec = Executions.getCurrent(); return exec != null && exec.getAttributes().containsKey(name); } public Object get(Object name) { final Execution exec = Executions.getCurrent(); if (exec == null) return null; return exec.getAttributes().get(name); } public Object remove(Object name) { final Execution exec = Executions.getCurrent(); if (exec == null) return null; return exec.getAttributes().remove(name); } }; public String getHeaders() { return _headers; } public String getRootAttributes() { return _rootAttrs; } public void setRootAttributes(String rootAttrs) { _rootAttrs = rootAttrs; } public String getContentType() { return _contentType; } public void setContentType(String contentType) { _contentType = contentType; } public String getDocType() { return _docType; } public void setDocType(String docType) { _docType = docType; } public String getFirstLine() { return _firstLine; } public void setFirstLine(String firstLine) { _firstLine = firstLine; } public Boolean getCacheable() { return _cacheable; } public void setCacheable(Boolean cacheable) { _cacheable = cacheable; } public final Desktop getDesktop() { return _desktop; } public void addRoot(Component comp) { assert D.OFF || comp.getParent() == null; for (Iterator it = _roots.iterator(); it.hasNext();) if (comp == it.next()) return; _roots.add(comp); } public void removeRoot(Component comp) { for (Iterator it = _roots.iterator(); it.hasNext();) if (comp == it.next()) { it.remove(); return; } } public void moveRoot(Component comp, Component refRoot) { if (comp.getPage() != this || comp.getParent() != null) return; //nothing to do boolean added = false, found = false; for (ListIterator it = _roots.listIterator(); it.hasNext();) { final Object o = it.next(); if (o == comp) { if (!added) { if (!it.hasNext()) return; //last if (it.next() == refRoot) return; //same position it.previous(); it.previous(); it.next(); //restore cursor } it.remove(); found = true; if (added || refRoot == null) break; //done } else if (o == refRoot) { it.previous(); it.add(comp); it.next(); added = true; if (found) break; //done } } if (!added) _roots.add(comp); } public void addFellow(Component comp) { final String compId = comp.getId(); assert D.OFF || !ComponentsCtrl.isAutoId(compId); final Object old = _fellows.put(compId, comp); if (old != comp) { //possible due to recursive call if (old != null) { _fellows.put(((Component)old).getId(), old); //recover throw new InternalError("Called shall prevent replicated ID for roots"); } } } public void removeFellow(Component comp) { _fellows.remove(comp.getId()); } public boolean hasFellow(String compId) { return _fellows.containsKey(compId); } public void redraw(Collection responses, Writer out) throws IOException { if (log.debugable()) log.debug("Redrawing page: "+this+", roots="+_roots); final Execution exec = getExecution(); final ExecutionCtrl execCtrl = (ExecutionCtrl)exec; final boolean asyncUpdate = execCtrl.getVisualizer().isEverAsyncUpdate(); final boolean bIncluded = asyncUpdate || exec.isIncluded() || exec.getAttribute(ATTR_REDRAW_BY_INCLUDE) != null; final String uri = (String) (bIncluded ? _pgURI: _dkURI) .getValue(_langdef.getEvaluator(), this); //desktop and page URI is defined in language final Map attrs = new HashMap(6); attrs.put("page", this); attrs.put("asyncUpdate", Boolean.valueOf(asyncUpdate)); attrs.put("action", _desktop.getUpdateURI(null)); attrs.put("responses",
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -