/** Returns the update servlet of the specified application, or * null if not loaded yet. * Note: if the update servlet is not loaded, it returns null. * @since 3.0.2 */ public static DHtmlUpdateServlet getUpdateServlet(WebApp wapp) { return (DHtmlUpdateServlet) (wapp.getServletContext()).getAttribute(ATTR_UPDATE_SERVLET); }
/** Returns the Web manager of the specified {@link WebApp}, * or null if not found. * @since 5.0.5 */ public static final WebManager getWebManagerIfAny(WebApp wapp) { return getWebManagerIfAny(wapp.getServletContext()); }
/** Returns the Web manager of the specified {@link WebApp}. * @since 3.0.4 */ public static final WebManager getWebManager(WebApp wapp) { return getWebManager(wapp.getServletContext()); }
/** Returns the locator for the specified context. * * @param path the original path, or null if not available. * The original path is used to resolve a relative path. * If not specified, {@link org.zkoss.zk.ui.Desktop#getCurrentDirectory} * is used. */ public static final Locator getLocator(WebApp wapp, String path) { if (wapp == null) throw new IllegalArgumentException("null"); if (path != null && path.length() > 0 && path.charAt(0) == '/') { final int j = path.lastIndexOf('/'); path = j > 0 ? path.substring(0, j + 1) : "/"; } else { final Execution exec = Executions.getCurrent(); if (exec != null) path = exec.getDesktop().getCurrentDirectory(); } return new ServletContextLocator(wapp.getServletContext(), path); }
/** * 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(); }
/** * 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(); }
/** Returns the page definition of the specified path, or null if not * found or failed to parse. * * <p>This is the lowest method that other getPageDefinition depends. * * <p>Dependency: Execution.createComponents -& Execution.getPageDefinition * -& UiFactory.getPageDefiition -& PageDefintions.getPageDefinition * * @param locator the locator used to locate taglib and other resources. * If null, wapp is assumed ({@link WebApp} is also assumed). */ public static final PageDefinition getPageDefinition(WebApp wapp, Locator locator, String path) { wapp.getConfiguration().invokeURIInterceptors(path); //give the security a chance to reject return ResourceCaches.get(getCache(wapp), wapp.getServletContext(), path, locator); }
/** * Get the spring application context. */ public static ApplicationContext getApplicationContext() { Execution exec = Executions.getCurrent(); if (exec == null) { throw new UiException("SpringUtil can be called only under ZK environment!"); } return WebApplicationContextUtils .getRequiredWebApplicationContext(exec.getDesktop().getWebApp().getServletContext()); }
/*package*/ static CCExecution newInstance(WebApp wapp) { final ServletContext ctx = wapp.getServletContext(); final String updateURI = WebManager.getWebManager(ctx).getUpdateURI(); return new CCExecution(ctx, new DesktopImpl(wapp, updateURI, "/", null, null)); }
if (execution == null || WebApps.getCurrent().getServletContext().getMajorVersion() < 3 || (desktopImpl != null && desktopImpl.isServerPushEnabled() && desktopImpl.getServerPush() instanceof PollingServerPush)) { eq.close();
/** Creates a page. * It invokes {@link UiFactory#newPage}. However, it prepares * {@link ExecutionsCtrl#getCurrent} for {@link org.zkoss.zk.ui.sys.IdGenerator#nextPageUuid} * * <p>Note: Use this method to create a page, rather than invoking * {@link UiFactory#newPage} directly. * @since 3.6.0 */ public static Page newPage(UiFactory uf, RequestInfo ri, Richlet richlet, ServletResponse response, String path) { final DesktopCtrl desktopCtrl = (DesktopCtrl) ri.getDesktop(); final Execution exec = ExecutionsCtrl.getCurrent(); TemporaryExecution de = new TemporaryExecution(ri.getWebApp().getServletContext(), (HttpServletRequest) ri.getNativeRequest(), (HttpServletResponse) response, ri.getDesktop()); desktopCtrl.setExecution(de); ExecutionsCtrl.setCurrent(de); try { return uf.newPage(ri, richlet, path); //de won't be voided since no DesktopInit-like plugin } finally { ExecutionsCtrl.setCurrent(exec); desktopCtrl.setExecution(exec); } }
/** Creates a page. * It invokes {@link UiFactory#newPage}. However, it prepares * {@link ExecutionsCtrl#getCurrent} for {@link org.zkoss.zk.ui.sys.IdGenerator#nextPageUuid} * * <p>Note: Use this method to create a page, rather than invoking * {@link UiFactory#newPage} directly. * @since 3.6.0 */ public static Page newPage(UiFactory uf, RequestInfo ri, PageDefinition pagedef, ServletResponse response, String path) { final DesktopCtrl desktopCtrl = (DesktopCtrl) ri.getDesktop(); final Execution exec = ExecutionsCtrl.getCurrent(); TemporaryExecution de = new TemporaryExecution(ri.getWebApp().getServletContext(), (HttpServletRequest) ri.getNativeRequest(), (HttpServletResponse) response, ri.getDesktop()); desktopCtrl.setExecution(de); ExecutionsCtrl.setCurrent(de); try { return uf.newPage(ri, pagedef, path); //de won't be voided since no DesktopInit-like plugin } finally { ExecutionsCtrl.setCurrent(exec); desktopCtrl.setExecution(exec); } }
private static void desktopDestroyed(Desktop desktop) { final Session sess = desktop.getSession(); final Execution exec = new ExecutionImpl(desktop.getWebApp().getServletContext(), null, null, desktop, null); final DesktopCtrl desktopCtrl = (DesktopCtrl) desktop; final Execution oldExec = desktop.getExecution();
final ServletContext svlctx = wapp.getServletContext();