📄 pageimpl.java
字号:
responses != null ? responses: Collections.EMPTY_LIST); if (bIncluded) { exec.include(out, uri, attrs, Execution.PASS_THRU_ATTR); } else {//FUTURE: Consider if config.isKeepDesktopAcrossVisits() implies cacheable//Why yes: the client doesn't need to ask the server for updated content//Why no: browsers seems fail to handle DHTML correctly (when BACK to//a DHTML page), so it is better to let the server handle cache, if any final boolean cacheable = _cacheable != null ? _cacheable.booleanValue(): _desktop.getDevice().isCacheable(); if (!cacheable) { //Bug 1520444 execCtrl.setHeader("Pragma", "no-cache"); // bug 1520444 execCtrl.addHeader("Cache-Control", "no-cache"); execCtrl.addHeader("Cache-Control", "no-store"); //execCtrl.addHeader("Cache-Control", "private"); //execCtrl.addHeader("Cache-Control", "max-age=0"); //execCtrl.addHeader("Cache-Control", "s-maxage=0"); //execCtrl.addHeader("Cache-Control", "must-revalidate"); //execCtrl.addHeader("Cache-Control", "proxy-revalidate"); //execCtrl.addHeader("Cache-Control", "post-check=0"); //execCtrl.addHeader("Cache-Control", "pre-check=0"); execCtrl.setHeader("Expires", "-1"); } exec.forward(out, uri, attrs, Execution.PASS_THRU_ATTR); //Don't use include. Otherwise, headers will be gone. } } public final Namespace getNamespace() { return _ns; } public void interpret(String zslang, String script, Namespace ns) { getInterpreter(zslang).interpret(script, ns); } public Interpreter getInterpreter(String zslang) { zslang = (zslang != null ? zslang: _zslang).toLowerCase(); Interpreter ip = (Interpreter)_ips.get(zslang); if (ip == null) { ip = Interpreters.newInterpreter(zslang, this); _ips.put(zslang, ip); //set first to avoid dead loop if script calls interpret again final String script = _langdef.getInitScript(zslang); if (script != null) { _ns.setVariable("log", _zklog, true); _ns.setVariable("page", this, true); ip.interpret(script, _ns); } //evaluate deferred zscripts, if any try { evalDeferredZScripts(ip, zslang); } catch (IOException ex) { throw new UiException(ex); } } return ip; } public Collection getLoadedInterpreters() { return _ips != null ? _ips.values(): Collections.EMPTY_LIST; //just in case } public String getZScriptLanguage() { return _zslang; } public void setZScriptLanguage(String zslang) throws InterpreterNotFoundException { if (!Objects.equals(zslang, _zslang)) { if (!Interpreters.exists(zslang)) throw new InterpreterNotFoundException(zslang, MZk.NOT_FOUND, zslang); _zslang = zslang; } } public void addDeferredZScript(Component parent, ZScript zscript) { if (zscript != null) { if (_zsDeferred == null) _zsDeferred = new LinkedList(); _zsDeferred.add(new Object[] {parent, zscript}); } } /** Evaluates the deferred zscript. * It is called when the interpreter is loaded */ private void evalDeferredZScripts(Interpreter ip, String zslang) throws IOException { if (_zsDeferred != null) { for (Iterator it = _zsDeferred.iterator(); it.hasNext();) { final Object[] zsInfo = (Object[])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) && isEffective(zscript, parent)) { ip.interpret(zscript.getContent(this, parent), parent != null ? parent.getNamespace(): _ns); } } } if (_zsDeferred.isEmpty()) _zsDeferred = null; } } private boolean isEffective(Condition cond, Component comp) { return comp != null ? cond.isEffective(comp): cond.isEffective(this); } public boolean isListenerAvailable(String evtnm) { if (_listeners != null) { final List l = (List)_listeners.get(evtnm); return l != null && !l.isEmpty(); } return false; } public Iterator getListenerIterator(String evtnm) { if (_listeners != null) { final List l = (List)_listeners.get(evtnm); if (l != null) return new ListenerIterator(l); } return CollectionsX.EMPTY_ITERATOR; } public final Component getOwner() { return _owner; } public final void setOwner(Component comp) { if (_owner != null) throw new IllegalStateException("owner can be set only once"); _owner = comp; } public Component getDefaultParent() { return _defparent; } public void setDefaultParent(Component comp) { _defparent = comp; } public void sessionWillPassivate(Desktop desktop) { for (Iterator it = _roots.iterator(); it.hasNext();) ((ComponentCtrl)it.next()).sessionWillPassivate(this); } public void sessionDidActivate(Desktop desktop) { _desktop = desktop; if (_ownerUuid != null) { _owner = _desktop.getComponentByUuid(_ownerUuid); _ownerUuid = null; } for (Iterator it = _roots.iterator(); it.hasNext();) ((ComponentCtrl)it.next()).sessionDidActivate(this); initVariables(); //since some variables depend on desktop } public LanguageDefinition getLanguageDefinition() { return _langdef; } public ComponentDefinitionMap getComponentDefinitionMap() { return _compdefs; } public ComponentDefinition getComponentDefinition(String name, boolean recur) { final ComponentDefinition compdef = _compdefs.get(name); if (!recur || compdef != null) return compdef; try { return _langdef.getComponentDefinition(name); } catch (DefinitionNotFoundException ex) { } return null; } public ComponentDefinition getComponentDefinition(Class cls, boolean recur) { final ComponentDefinition compdef = _compdefs.get(cls); if (!recur || compdef != null) return compdef; try { return _langdef.getComponentDefinition(cls); } catch (DefinitionNotFoundException ex) { } return null; } //-- Serializable --// //NOTE: they must be declared as private private synchronized void writeObject(java.io.ObjectOutputStream s) throws java.io.IOException { s.defaultWriteObject(); s.writeObject(_langdef != null ? _langdef.getName(): null); s.writeObject(_owner != null ? _owner.getUuid(): null); s.writeObject(_defparent != null ? _defparent.getUuid(): null); willSerialize(_attrs.values()); Serializables.smartWrite(s, _attrs); if (_listeners != null) for (Iterator it = _listeners.entrySet().iterator(); it.hasNext();) { final Map.Entry me = (Map.Entry)it.next(); s.writeObject(me.getKey()); final Collection ls = (Collection)me.getValue(); willSerialize(ls); Serializables.smartWrite(s, ls); } s.writeObject(null); willSerialize(_resolvers); Serializables.smartWrite(s, _resolvers); //handle namespace for (Iterator it = _ns._vars.entrySet().iterator(); it.hasNext();) { final Map.Entry me = (Map.Entry)it.next(); final String nm = (String)me.getKey(); final Object val = me.getValue(); willSerialize(val); //always called even not serializable if (isVariableSerializable(nm, val) && (val instanceof java.io.Serializable || val instanceof java.io.Externalizable)) { s.writeObject(nm); s.writeObject(val); } } s.writeObject(null); //denote end-of-namespace //Handles interpreters for (Iterator it = _ips.entrySet().iterator(); it.hasNext();) { final Map.Entry me = (Map.Entry)it.next(); final Object ip = me.getValue(); if (ip instanceof SerializableAware) { s.writeObject((String)me.getKey()); //zslang ((SerializableAware)ip).write(s, new SerializableAware.Filter() { public boolean accept(String name, Object value) { return isVariableSerializable(name, value); } }); } } s.writeObject(null); //denote end-of-interpreters } private void willSerialize(Collection c) { if (c != null) for (Iterator it = c.iterator(); it.hasNext();) willSerialize(it.next()); } private void willSerialize(Object o) { if (o instanceof PageSerializationListener) ((PageSerializationListener)o).willSerialize(this); } private synchronized void readObject(java.io.ObjectInputStream s) throws java.io.IOException, ClassNotFoundException { s.defaultReadObject(); init(); final String langnm = (String)s.readObject(); if (langnm != null) _langdef = LanguageDefinition.lookup(langnm); _ownerUuid = (String)s.readObject(); //_owner is restored later when sessionDidActivate is called final String pid = (String)s.readObject(); if (pid != null) _defparent = fixDefaultParent(_roots, pid); Serializables.smartRead(s, _attrs); didDeserialize(_attrs.values()); for (;;) { final String evtnm = (String)s.readObject(); if (evtnm == null) break; //no more if (_listeners == null) _listeners = new HashMap(); final Collection ls = Serializables.smartRead(s, (Collection)null); _listeners.put(evtnm, ls); didDeserialize(ls); } _resolvers = (List)Serializables.smartRead(s, _resolvers); //might be null didDeserialize(_resolvers); //handle namespace initVariables(); for (;;) { final String nm = (String)s.readObject(); if (nm == null) break; //no more Object val = s.readObject(); _ns.setVariable(nm, val, true); didDeserialize(val); } fixFellows(_roots); //Handles interpreters for (;;) { final String zslang = (String)s.readObject(); if (zslang == null) break; //no more ((SerializableAware)getInterpreter(zslang)).read(s); } } private void didDeserialize(Collection c) { if (c != null) for (Iterator it = c.iterator(); it.hasNext();) didDeserialize(it.next()); } private void didDeserialize(Object o) { if (o instanceof PageSerializationListener) ((PageSerializationListener)o).didDeserialize(this); } private static boolean isVariableSerializable(String name, Object value) { return !_nonSerNames.contains(name) && !(value instanceof Component); } private final static Set _nonSerNames = new HashSet(); static { final String[] nms = {"log", "page", "desktop", "pageScope", "desktopScope", "applicationScope", "requestScope", "spaceOwner", "session", "sessionScope"}; for (int j = 0; j < nms.length; ++j) _nonSerNames.add(nms[j]); } private final void fixFellows(Collection c) { for (Iterator it = c.iterator(); it.hasNext();) { final Component comp = (Component)it.next(); final String compId = comp.getId(); if (!ComponentsCtrl.isAutoId(compId)) addFellow(comp); if (!(comp instanceof IdSpace)) fixFellows(comp.getChildren()); //recursive } } private static final Component fixDefaultParent(Collection c, String uuid) { for (Iterator it = c.iterator(); it.hasNext();) { Component comp = (Component)it.next(); if (uuid.equals(comp.getUuid())) return comp; //found comp = fixDefaultParent(comp.getChildren(), uuid); if (comp != null) return comp; } return null; } //-- Object --// public String toString() { return "[Page "+_id+']'; } private class NS extends AbstractNamespace { private final Map _vars = new HashMap(); //Namespace// public Set getVariableNames() { return _vars.keySet(); } public boolean containsVariable(String name, boolean local) { return _vars.containsKey(name) || _fellows.containsKey(name) || resolveVariable(name) != null; } public Object getVariable(String name, boolean local) { Object val = _vars.get(name); if (val != null || _vars.containsKey(name)) return val; val = _fellows.get(name); return val != null ? val: resolveVariable(name); } public void setVariable(String name, Object value, boolean local) { _vars.put(name, value); notifyAdd(name, value); } public void unsetVariable(String name, boolean local) { _vars.remove(name); notifyRemove(name); } public Namespace getParent() { return null; } public void setParent(Namespace parent) { throw new UnsupportedOperationException(); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -