| Method from org.zkoss.zk.ui.impl.PageImpl Detail: |
public void addDeferredZScript(Component parent,
ZScript zscript) {
if (zscript != null) {
if (_zsDeferred == null)
_zsDeferred = new LinkedList();
_zsDeferred.add(new Object[] {parent, zscript});
}
}
|
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 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 addFunctionMapper(FunctionMapper mapper) {
_mapper = DualFunctionMapper.combine(mapper, _mapper);
}
|
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 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 containsVariable(String name) {
return _ns.containsVariable(name, true);
}
|
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();
_attrs.clear();
_fellows = new HashMap(1); //not clear() since # of fellows might huge
_ips = null; //not clear since it is better to NPE than memory leak
_desktop = null;
_owner = _defparent = null;
_listeners = null;
_ns = null;
_resolvers = null;
}
|
public Object getAttribute(String name) {
return _attrs.get(name);
}
|
public Object getAttribute(String name,
int scope) {
return getAttributes(scope).get(name);
}
|
public Map getAttributes() {
return _attrs;
}
|
public Map getAttributes(int scope) {
switch (scope) {
case DESKTOP_SCOPE:
return _desktop != null ?
_desktop.getAttributes(): Collections.EMPTY_MAP;
case SESSION_SCOPE:
return _desktop != null ?
_desktop.getSession().getAttributes(): Collections.EMPTY_MAP;
case APPLICATION_SCOPE:
return _desktop != null ?
_desktop.getWebApp().getAttributes(): Collections.EMPTY_MAP;
case PAGE_SCOPE:
return _attrs;
case REQUEST_SCOPE:
final Execution exec = getExecution();
if (exec != null) return exec.getAttributes();
//fall thru
default:
return Collections.EMPTY_MAP;
}
}
|
public Boolean getCacheable() {
return _cacheable;
}
|
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;
}
|
public ComponentDefinitionMap getComponentDefinitionMap() {
return _compdefs;
}
|
public String getContentType() {
return _contentType;
}
|
public Component getDefaultParent() {
return _defparent;
}
|
public final Desktop getDesktop() {
return _desktop;
}
|
public String getDocType() {
return _docType;
}
|
public Object getELVariable(String name) {
return getXelVariable(name);
} Deprecated! As - of release of 3.0.0, replaced with #getXelVariable .
|
public Class getExpressionFactoryClass() {
return _expfcls;
}
|
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);
}
|
public Collection getFellows() {
return Collections.unmodifiableCollection(_fellows.values());
}
|
public String getFirstLine() {
return _firstLine;
}
|
public final FunctionMapper getFunctionMapper() {
return _mapper;
}
|
public String getHeaders() {
return _headers;
}
|
public final String getId() {
return _id;
}
|
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 LanguageDefinition getLanguageDefinition() {
return _langdef;
}
|
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 Collection getLoadedInterpreters() {
return _ips != null ? _ips.values(): Collections.EMPTY_LIST; //just in case
}
|
public final Namespace getNamespace() {
return _ns;
}
|
public final Component getOwner() {
return _owner;
}
|
public String getRequestPath() {
return _path;
}
|
public String getRootAttributes() {
return _rootAttrs;
}
|
public Collection getRoots() {
return _roRoots;
}
|
public String getStyle() {
return _style;
}
|
public String getTitle() {
return _title;
}
|
public final String getUuid() {
return _uuid;
}
|
public Object getVariable(String name) {
return _ns.getVariable(name, true);
}
|
public Object getXelVariable(String name) {
final VariableResolver resolv =
getExecution().getVariableResolver();
return resolv != null ? resolv.resolveVariable(name): null;
}
|
public Class getZScriptClass(String clsnm) {
for (Iterator it = getLoadedInterpreters().iterator();
it.hasNext();) {
Class cls = ((Interpreter)it.next()).getClass(clsnm);
if (cls != null)
return cls;
}
try {
return Classes.forNameByThread(clsnm);
} catch (ClassNotFoundException ex) {
return null;
}
}
|
public Function getZScriptFunction(String name,
Class[] argTypes) {
for (Iterator it = getLoadedInterpreters().iterator();
it.hasNext();) {
Function mtd =
((Interpreter)it.next()).getFunction(name, argTypes);
if (mtd != null)
return mtd;
}
return null;
}
|
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);
}
|
public String getZScriptLanguage() {
return _zslang;
}
|
public 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 #getZScriptFunction(String,Class[]) .
|
public Method getZScriptMethod(Namespace ns,
String name,
Class[] argTypes) {
final Function fun = getZScriptFunction(ns, name, argTypes);
return fun != null ? new FuncMethod(fun): null;
} Deprecated! As - of release 3.0.0, replaced by #getZScriptFunction(String,Class[]) .
|
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 boolean hasFellow(String compId) {
return _fellows.containsKey(compId);
}
|
protected void init() {
_ips = new LinkedHashMap(3);
_ns = new NS();
_roRoots = Collections.unmodifiableList(_roots);
_attrs = new HashMap();
_fellows = new HashMap();
}
Initialized the page when contructed or deserialized. |
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;
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);
}
|
public void interpret(String zslang,
String script,
Namespace ns) {
getInterpreter(zslang).interpret(script, ns);
}
|
public void invalidate() {
getUiEngine().addInvalidate(this);
}
|
public boolean isComplete() {
return _complete;
}
|
public boolean isListenerAvailable(String evtnm) {
if (_listeners != null) {
final List l = (List)_listeners.get(evtnm);
return l != null && !l.isEmpty();
}
return false;
}
|
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 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)
(_complete ? _cplURI: 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", "/"); //A non-empty string (backward compatible)
attrs.put("responses",
responses != null ? responses: Collections.EMPTY_LIST);
if (bIncluded) {
attrs.put("included", "true");
//maintain original state since desktop will include page...
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");
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.setAttribute(Attributes.NO_CACHE, Boolean.TRUE);
//so ZkFns.outLangJavaScripts generates zk.keepDesktop correctly
}
exec.forward(out, uri, attrs, Execution.PASS_THRU_ATTR);
//Don't use include. Otherwise, headers will be gone.
}
}
|
public Object removeAttribute(String name) {
return _attrs.remove(name);
}
|
public Object removeAttribute(String name,
int scope) {
final Map attrs = getAttributes(scope);
if (attrs == Collections.EMPTY_MAP)
throw new IllegalStateException("This component doesn't belong to any ID space: "+this);
return attrs.remove(name);
}
|
public void removeComponents() {
for (Iterator it = new ArrayList(getRoots()).iterator();
it.hasNext();)
((Component)it.next()).detach();
}
|
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 void removeFellow(Component comp) {
_fellows.remove(comp.getId());
}
|
public void removeRoot(Component comp) {
for (Iterator it = _roots.iterator(); it.hasNext();)
if (comp == it.next()) {
it.remove();
return;
}
}
|
public boolean removeVariableResolver(VariableResolver resolver) {
return _resolvers != null && _resolvers.remove(resolver);
}
|
public Class resolveClass(String clsnm) throws ClassNotFoundException {
try {
return Classes.forNameByThread(clsnm);
} catch (ClassNotFoundException ex) {
for (Iterator it = getLoadedInterpreters().iterator();
it.hasNext();) {
final Class c = ((Interpreter)it.next()).getClass(clsnm);
if (c != null)
return c;
}
throw ex;
}
}
|
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 void sessionWillPassivate(Desktop desktop) {
for (Iterator it = _roots.iterator(); it.hasNext();)
((ComponentCtrl)it.next()).sessionWillPassivate(this);
}
|
public Object setAttribute(String name,
Object value) {
return value != null ? _attrs.put(name, value): removeAttribute(name);
}
|
public Object setAttribute(String name,
Object value,
int scope) {
if (value != null) {
final Map attrs = getAttributes(scope);
if (attrs == Collections.EMPTY_MAP)
throw new IllegalStateException("This component doesn't belong to any ID space: "+this);
return attrs.put(name, value);
} else {
return removeAttribute(name, scope);
}
}
|
public void setCacheable(Boolean cacheable) {
_cacheable = cacheable;
}
|
public void setComplete(boolean complete) {
_complete = complete;
}
|
public void setContentType(String contentType) {
_contentType = contentType;
}
|
public void setDefaultParent(Component comp) {
_defparent = comp;
}
|
public void setDocType(String docType) {
_docType = docType;
}
|
public void setExpressionFactoryClass(Class expfcls) {
if (expfcls != null && !ExpressionFactory.class.isAssignableFrom(expfcls))
throw new IllegalArgumentException(expfcls+" must implement "+ExpressionFactory.class);
_expfcls = expfcls;
}
|
public void setFirstLine(String firstLine) {
_firstLine = firstLine;
}
|
public void setId(String id) {
if (_desktop != null)
throw new UiException("Unable to change the identifier after the page is initialized");
if (id != null && id.length() > 0) _id = id;
//No need to update client since it is allowed only before init(...)
}
|
public final void setOwner(Component comp) {
if (_owner != null)
throw new IllegalStateException("owner can be set only once");
_owner = comp;
}
|
public void setRootAttributes(String rootAttrs) {
_rootAttrs = rootAttrs != null ? rootAttrs: "";
}
|
public void setStyle(String style) {
if (style == null) style = "";
if (!_style.equals(style)) {
_style = style;
if (_desktop != null) {
final Execution exec = getExecution();
if (_style.length() > 0) {
_style = (String)exec.evaluate(this, _style, String.class);
if (_style == null) _style = "";
}
//FUTURE: might support the change of style dynamically
}
}
}
|
public void setTitle(String title) {
if (title == null) title = "";
if (!_title.equals(title)) {
_title = title;
if (_desktop != null) {
final Execution exec = getExecution();
if (_title.length() > 0) {
_title = (String)exec.evaluate(this, _title, String.class);
if (_title == null) _title = "";
}
if (exec.isAsyncUpdate(this))
getUiEngine().addResponse("setTitle", new AuSetTitle(_title));
}
}
}
|
public void setVariable(String name,
Object val) {
_ns.setVariable(name, val, true);
}
|
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 String toString() {
return "[Page "+_id+']";
}
|
public void unsetVariable(String name) {
_ns.unsetVariable(name, true);
}
|