/** Returns the ZK version, such as "1.1.0" and "2.0.0". * @since 6.0.3 */ public static String getVersion() { return WebApps.getCurrent().getVersion(); }
/** Returns the build identifier, such as 2007121316. * * <p>Each time ZK is built, a different build identifier is assigned. * @since 6.0.3 */ public static String getBuild() { return WebApps.getCurrent().getBuild(); }
/** * Returns the edition whether valid or invalid. * @since 6.5.5 */ public static boolean isEditionValid() { WebApp current = WebApps.getCurrent(); return !("CE".equals(getEdition()) || current == null || current.getAttribute("org.zkoss.zk.ui.notice") == null); }
@Override public void modifyHandshake(ServerEndpointConfig config, HandshakeRequest request, HandshakeResponse response) { HttpSession httpSession = (HttpSession) request.getHttpSession(); org.zkoss.zk.ui.Session sess = SessionsCtrl.getSession(WebApps.getCurrent(), httpSession); config.getUserProperties().put(getClass().getName(), sess); }
/** Default: If parent is null, execute the @Destroy method if any. * @see ComponentCtrl#beforeParentChanged * @since 3.6.2 */ public void beforeParentChanged(Component parent) { //ZK-1148, add a @destroy annotation method. if (parent == null)//detach WebApps.getCurrent().getConfiguration().invokeCallback("destroy", this); }
private void beforeComponentPageChanged(Page page) { //ZK-1148, add a @destroy annotation method. if (page == null) WebApps.getCurrent().getConfiguration().invokeCallback("destroy", this); } private void afterComponentPageChanged(Page newpg, Page oldpg) {
/** * Generates moment.js and moment-timezone-with-data.js string. * * @since 8.5.1 */ public static final String outMomentJavascript(ServletRequest request, ServletResponse response) throws IOException { final StringBuffer result = new StringBuffer(); final WebApp webApp = WebApps.getCurrent(); final Execution exec = new FakeExecution(webApp.getServletContext(), request, response, null, null); result.append("if (!zk.mm) { var temp; if (window.moment) { temp = window.moment; }"); result.append(Devices.loadJavaScript(exec, "~./js/zk/ext/moment.js")); result.append(Devices.loadJavaScript(exec, "~./js/zk/ext/moment-timezone-with-data.js")); result.append("zk.mm = window.moment; window.moment = temp; }"); String path = Library.getProperty("org.zkoss.zk.moment.timezone.path"); if (path != null) { String json = null; try { json = Devices.loadFileContentAsString(exec, path); } catch (Exception e) { log.warn(e.getMessage()); } if (json != null) { result.append("var tzdata ="); result.append(json); result.append("; zk.mm.tz.load(tzdata);"); } } return result.toString(); }
public <T extends Event> EventQueue<T> lookup(String name, String scope, boolean autoCreate) { final boolean bAppScope = EventQueues.APPLICATION.equals(scope); final boolean bSessionScope = EventQueues.SESSION.equals(scope); // if the scope is in session or application, it won't need an Execution // to work with this event queue for publishing if (bSessionScope && Sessions.getCurrent() == null) { throw new IllegalStateException("Current session is not available"); } else if (bAppScope || bSessionScope) { return lookup0(name, bAppScope ? (Scope) WebApps.getCurrent() : Sessions.getCurrent(), autoCreate); } else if (EventQueues.DESKTOP.equals(scope)) { final Execution exec = Executions.getCurrent(); if (exec == null) throw new IllegalStateException("Not in an execution"); final Desktop desktop = exec.getDesktop(); Map<String, EventQueue<T>> eqs = cast((Map) desktop.getAttribute(ATTR_EVENT_QUEUES)); if (eqs == null) desktop.setAttribute(ATTR_EVENT_QUEUES, eqs = new HashMap<String, EventQueue<T>>(4)); EventQueue<T> eq = eqs.get(name); if (autoCreate && eq == null) eqs.put(name, eq = new DesktopEventQueue<T>()); if (log.isDebugEnabled()) { log.debug("Lookup event queue: name [{}], scope [{}], autoCreate [{}]", name, scope, autoCreate); } return eq; } else throw new UnsupportedOperationException("Unknown scope: " + scope); }
/** * Generates Locale-dependent strings in JavaScript syntax. * @since 6.5.1 */ public static final String outLocaleJavaScript(ServletRequest request, ServletResponse response) throws IOException { final StringBuffer result = new StringBuffer(4096); final WebApp webApp = WebApps.getCurrent(); final Execution exec = new FakeExecution(webApp.getServletContext(), request, response, null, null); //the same as AjaxDevice.reloadMessages() result.append(Devices.loadJavaScript(exec, "~./js/zk/lang/msgzk*.js")); result.append(Wpds.outLocaleJavaScript()); for (LanguageDefinition langdef : LanguageDefinition.getByDeviceType("ajax")) //WpdExtendlet.getDeviceType() also return "ajax" directly... for (MessageLoader loader : langdef.getMessageLoaders()) loader.load(result, exec); return result.toString(); }
public void destroy() { Configuration config = WebApps.getCurrent().getConfiguration(); for (Component root: this.getRoots()) { config.invokeCallback("destroy", root); } super.destroy(); try { if (_ips != null) { final List<Interpreter> ips = new ArrayList<Interpreter>(_ips.values()); _ips.clear(); _ips = null; //not just clear since it is better to NPE than memory leak for (Interpreter ip : ips) { try { ip.destroy(); } catch (Throwable ex) { log.warn("Failed to destroy " + ip, ex); } } } } catch (Throwable ex) { //avoid racing log.warn("Failed to clean up interpreters of " + this, ex); } //theoretically, the following is not necessary, but, to be safe... _desktop = null; _owner = null; _listeners = null; _resolvers = null; _mappers = null; _attrs.getAttributes().clear(); }
/** * Loads the content of a file as a String. * * @since 8.5.1 */ public static String loadFileContentAsString(Execution exec, String path) throws IOException { path = exec.locate(path); //ZK-1345: use WebApps.getCurrent() instead of exec.getDesktop().getWebApp() InputStream is = WebApps.getCurrent().getResourceAsStream(path); if (is == null) throw new UiException("Unable to load " + path); final byte[] bs = Files.readAll(is); Files.close(is); return new String(bs, "UTF-8"); //UTF-8 is assumed }
private void init() { _phaseListeners = new LinkedList<PhaseListener>(ZKBinderPhaseListeners.getSystemPhaseListeners()); String clz = Library.getProperty(PHASE_LISTENER_CLASS_KEY); if (!Strings.isEmpty(clz)) { try { addPhaseListener((PhaseListener) Classes.forNameByThread(clz).newInstance()); } catch (Exception e) { _log.error("Error when initial phase listener:" + clz, e); } } // ZK-1148: @Destroy support Configuration conf = WebApps.getCurrent().getConfiguration(); if (!conf.hasCallBack("destroy")) { conf.registerCallBack("destroy", new DestroyCallback()); } }
WebApp webApp = WebApps.getCurrent(); Configuration configuration = webApp.getConfiguration();
if (execution == null || WebApps.getCurrent().getServletContext().getMajorVersion() < 3 || (desktopImpl != null && desktopImpl.isServerPushEnabled() && desktopImpl.getServerPush() instanceof PollingServerPush)) { eq.close();
applyAttrAnnot(attrAnnHelper, compInfo, attnm, attvaltrim, true, location(attr)); Set<String> binderAnnotations = WebApps.getCurrent().getConfiguration().getBinderAnnotations(); for (String annot : binderAnnotations) { if (attvaltrim.contains(annot)) {
WebApp webApp = WebApps.getCurrent(); Configuration configuration = webApp.getConfiguration(); Map<String, DataHandlerInfo> dataHandlers = configuration.getDataHandlers();
applyAttrAnnot(attrAnnHelper, compInfo, attnm, attvaltrim, true, location(attr)); Configuration config = WebApps.getCurrent().getConfiguration(); if (config.getBinderInitAttribute().equals(attnm)) isMVVM = true;