📄 configuration.java
字号:
* * <p>Default: null. * * <p>There is at most one monitor for each Web application. * The previous monitor will be replaced when this method is called. * * <p>In addition to call this method, you could specify a monitor * in zk.xml * * @param monitor the performance meter. If null, the meter function * is disabled. * @return the previous monitor, or null if not available. */ public Monitor setMonitor(Monitor monitor) { final Monitor old = _monitor; _monitor = monitor; return old; } /** Returns the performance meter for this application, or null if not set. * @since 3.0.0 */ public PerformanceMeter getPerformanceMeter() { return _pfmeter; } /** Sets the performance meter for this application, or null to disable it. * * <p>Default: null. * * <p>There is at most one performance meter for each Web application. * The previous meter will be replaced when this method is called. * * <p>In addition to call this method, you could specify * a performance meter in zk.xml * * @param meter the performance meter. If null, the meter function * is disabled. * @return the previous performance meter, or null if not available. * @since 3.0.0 */ public PerformanceMeter setPerformanceMeter(PerformanceMeter meter) { final PerformanceMeter old = _pfmeter; _pfmeter = meter; return old; } /** Returns the charset used to generate the HTTP response * or null to use the container's default. * It is currently used by {@link org.zkoss.zk.ui.http.DHtmlLayoutServlet}, * * <p>Default: UTF-8. */ public String getResponseCharset() { return _charsetResp; } /** Sets the charset used to generate HTTP response. * It is currently used by {@link org.zkoss.zk.ui.http.DHtmlLayoutServlet}, * * @param charset the charset to use. If null or empty, the container's default * is used. */ public void setResponseCharset(String charset) { _charsetResp = charset != null && charset.length() > 0 ? charset: null; } /** Returns the value of the preference defined in zk.xml, or by * {@link #setPreference}. * * <p>Preference is application specific. You can specify whatever you want * as you specifying context-param for a Web application. * * @param defaultValue the default value that is used if the specified * preference is not found. */ public String getPreference(String name, String defaultValue) { final String value = (String)_prefs.get(name); return value != null ? value: defaultValue; } /** Sets the value of the preference. */ public void setPreference(String name, String value) { if (name == null || value == null) throw new IllegalArgumentException("null"); _prefs.put(name, value); } /** Returns a readonly set of all preference names. */ public Set getPreferenceNames() { return _prefs.keySet(); } /** Adds the definition of a richlet. * * @param name the richlet name * @param params the initial parameters, or null if no initial parameter at all. * Once called, the caller cannot access <code>params</code> any more. * @return the previous richlet class or class-name with the specified name, * or null if no previous richlet. */ public Object addRichlet(String name, Class richletClass, Map params) { if (!Richlet.class.isAssignableFrom(richletClass)) throw new IllegalArgumentException("A richlet class, "+richletClass+", must implement "+Richlet.class.getName()); return addRichlet0(name, richletClass, params); } /** Adds the definition of a richlet. * * @param name the richlet name * @param richletClassName the class name. The class will be loaded * only when the richlet is loaded. * @param params the initial parameters, or null if no initial parameter at all. * Once called, the caller cannot access <code>params</code> any more. * @return the previous richlet class or class-name with the specified name, * or null if no previous richlet. */ public Object addRichlet(String name, String richletClassName, Map params) { if (richletClassName == null || richletClassName.length() == 0) throw new IllegalArgumentException("richletClassName is required"); return addRichlet0(name, richletClassName, params); } private Object addRichlet0(String name, Object richletClass, Map params) { final Object o; synchronized (_richlets) { o = _richlets.put(name, new Object[] {richletClass, params}); } if (o == null) return null; if (o instanceof Richlet) { destroy((Richlet)o); return o.getClass(); } return ((Object[])o)[0]; } /** Adds a richlet mapping. * * @param name the name of the richlet. * @param path the URL pattern. It must start with '/' and may end * with '/*'. * @exception UiException if the richlet is not defined yet. * See {@link #addRichlet}. * @since 2.4.0 */ public void addRichletMapping(String name, String path) { //first, check whether the richlet is defined synchronized (_richlets) { if (!_richlets.containsKey(name)) throw new UiException("Richlet not defined: "+name); } //richletClass was checked before calling this method //Note: "/" is the same as "" if (path == null || path.length() == 0 || "/".equals(path)) path = ""; else if (!path.startsWith("/")) throw new IllegalArgumentException("path must start with '/', not "+path); final boolean wildcard = path.endsWith("/*"); if (wildcard) //wildcard path = path.substring(0, path.length() - 2); //note it might be empty synchronized (_richletmaps) { _richletmaps.put( path, new Object[] {name, Boolean.valueOf(wildcard)}); } } private static void destroy(Richlet richlet) { try { richlet.destroy(); } catch (Throwable ex) { log.error("Unable to destroy "+richlet); } } /** Returns an instance of richlet of the specified name, or null * if not found. */ public Richlet getRichlet(String name) { WaitLock lock = null; final Object[] info; for (;;) { synchronized (_richlets) { Object o = _richlets.get(name); if (o == null || (o instanceof Richlet)) { //not found or loaded return (Richlet)o; } else if (o instanceof WaitLock) { //loading by another thread lock = (WaitLock)o; } else { info = (Object[])o; //going to load in this thread _richlets.put(name, lock = new WaitLock()); break; //then, load it } } //sync(_richlets) if (!lock.waitUntilUnlock(300*1000)) { //5 minute final PotentialDeadLockException ex = new PotentialDeadLockException( "Unable to load richlet "+name+"\nCause: conflict too long."); log.warningBriefly(ex); //very rare, possibly a bug throw ex; } } //for (;;) //load it try { if (info[0] instanceof String) { try { info[0] = Classes.forNameByThread((String)info[0]); } catch (Throwable ex) { throw new UiException("Failed to load "+info[0]); } } final Object o = ((Class)info[0]).newInstance(); if (!(o instanceof Richlet)) throw new UiException(Richlet.class+" must be implemented by "+info[0]); final Richlet richlet = (Richlet)o; richlet.init(new RichletConfigImpl(_wapp, (Map)info[1])); synchronized (_richlets) { _richlets.put(name, richlet); } return richlet; } catch (Throwable ex) { synchronized (_richlets) { _richlets.put(name, info); //remove lock and restore info } throw UiException.Aide.wrap(ex, "Unable to instantiate "+info[0]); } finally { lock.unlock(); } } /** Returns an instance of richlet for the specified path, or * null if not found. */ public Richlet getRichletByPath(String path) { if (path == null || path.length() == 0 || "/".equals(path)) path = ""; else if (path.charAt(0) != '/') path = '/' + path; final int len = path.length(); for (int j = len;;) { final Richlet richlet = getRichletByPath0(path.substring(0, j), j != len); if (richlet != null || j == 0) return richlet; j = path.lastIndexOf('/', j - 1); //j must not -1 } } private Richlet getRichletByPath0(String path, boolean wildcardOnly) { final Object[] info; synchronized (_richletmaps) { info = (Object[])_richletmaps.get(path); } return info != null && (!wildcardOnly || ((Boolean)info[1]).booleanValue()) ? getRichlet((String)info[0]): null; } /** Destroyes all richlets. */ public void detroyRichlets() { synchronized (_richlets) { for (Iterator it = _richlets.values().iterator(); it.hasNext();) { final Object o = it.next(); if (o instanceof Richlet) destroy((Richlet)o); } _richlets.clear(); } } /** Specifies whether to keep the desktops across visits. * If false, the desktops are removed when an user reloads an URL * or browses to another URL. * * <p>Default: false. */ public void setKeepDesktopAcrossVisits(boolean keep) { _keepDesktop = keep; } /** Returns whether to keep the desktops across visits. * If false, the desktops are removed when an user reloads an URL * or browses to another URL. */ public boolean isKeepDesktopAcrossVisits() { return _keepDesktop; } /** Specifies whether to keep the session alive, * when receiving the onTimer event. * * <p>Default: false. * * <p>A session is expired (and then invalidated), if it didn't receive * any client request in the specified timeout interval * ({@link #getSessionMaxInactiveInterval}). * By setting this option to true, the session timeout will be reset * when onTimer is received (just like any other event). * * <p>Note: if true and the timer is shorter than * the session timeout ({@link #getSessionMaxInactiveInterval}), * the session is never expired. * * @param alive whether to keep the session alive when receiving * onTimer * @since 3.0.0 */ public void setTimerKeepAlive(boolean alive) { _timerKeepAlive = alive; } /** Returns whether to keep the session alive, * when receiving the onTimer event. * In other words, it returns whether to reset the session timeout * counter when receiving onTimer, just like any other events. * * @since 3.0.0 */ public boolean isTimerKeepAlive() { return _timerKeepAlive; } /** Sets the implementation of the expression factory that shall * be used by the whole system. * * <p>Default: null -- it means the org.zkoss.xel.el.ELFactory class * (it requires zcommons-el.jar). * * <p>Note: you can only specify an implementation that is compatible * with JSP EL here, since ZK's builtin pages depend on it. * However, you can use any factory you like in an individual page, * as long as all expressions in the page follow the syntax of * the evaluator you are using. * * @param expfcls the implemtation class, or null to use the default. * Note: expfcls must implement {@link ExpressionFactory}. * @since 3.0.0 */ public void setExpressionFactoryClass(Class expfcls) { Expressions.setExpressionFactoryClass(expfcls); } /** Returns the implementation of the expression factory that * is used by the whole system, or null if the sytem default is used. * * @see #setExpressionFactoryClass * @since 3.0.0 */ public Class getExpressionFactoryClass() { return Expressions.getExpressionFactoryClass(); } /** Invokes {@link EventInterceptor#beforeSendEvent} * registered by {@link #addListener} with a class implementing * {@link EventInterceptor}. * <p>Used only internally. * @since 3.0.0 */ public Event beforeSendEvent(Event event) { return _eis.beforeSendEvent(event); } /** Invokes {@link EventInterceptor#beforePostEvent} * registered by {@link #addListener} with a class implementing * {@link EventInterceptor}. * <p>Used only internally. * @since 3.0.0 */ public Event beforePostEvent(Event event) { return _eis.beforePostEvent(event); } /** Invokes {@link EventInterceptor#beforeProcessEvent} * registered by {@link #addListener} with a class implementing * {@link EventInterceptor}. * <p>Used only internally. * @since 3.0.0 */ public Event beforeProcessEvent(Event event) { return _eis.beforeProcessEvent(event); } /** Invokes {@link EventInterceptor#afterProcessEvent} * registered by {@link #addListener} with a class implementing * {@link EventInterceptor}. * <p>Used only internally. * @since 3.0.0 */ public void afterProcessEvent(Event event) { _eis.afterProcessEvent(event); } /** * @deprecated As of release 2.4.1, replaced by {@link #addErrorPage(String, Class, String)} */ public void addErrorPage(Class type, String location) { addErrorPage("ajax", type, location); } /** Adds an error page. * * @param deviceType the device type: ajax or mil * @param type what type of errors the error page is associated with. * @param location where is the error page. * @return the previous location of the same error, or null if not * defined yet. * @since 2.4.1 */ public String addErrorPage(String deviceType, Class type, String location) { if (!Throwable.class.isAssignableFrom(type)) throw new IllegalArgumentException("Throwable or derived is required: "+type); if (location == null || deviceType == null) throw new IllegalArgumentException(); List l; synchronized (_errpgs) { l = (List)_errpgs.get(deviceType); if (l == null) _errpgs.put(deviceType, l = new LinkedList()); } String previous = null; synchronized (l) { //remove the previous definition for (Iterator it = l.iterator(); it.hasNext();) { final ErrorPage errpg = (ErrorPage)it.next(); if (errpg.type.equals(type)) { previous = errpg.location; it.remove(); break; } } l.add(new ErrorPage(type, location)); } return previous; } /** * @deprecated As of release 2.4.1, replaced by {@link #getErrorPage(String, Throwable)}. */ public String getErrorPage(Throwable error) { return getErrorPage("ajax", error); } /** Returns the error page that matches the specified error, or null if not found. * * @param deviceType the device type: ajax or mil * @param error the exception being thrown * @since 2.4.1 */ public String getErrorPage(String deviceType, Throwable error) { if (!_errpgs.isEmpty()) { final List l; synchronized (_errpgs) { l = (List)_errpgs.get(deviceType); } if (l != null) { synchronized (l) { for (Iterator it = l.iterator(); it.hasNext();) { final ErrorPage errpg = (ErrorPage)it.next(); if (errpg.type.isInstance(error)) return errpg.location; } } } } return null; } private static class ErrorPage { private final Class type; private final String location; private ErrorPage(Class type, String location) { this.type = type; this.location = location; } };}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -