public Desktop getDesktop() { return _page != null ? _page.getDesktop() : null; }
public final void setCurrentPage(Page curpage) { if (_curpage != null && curpage != null && _curpage != curpage) { Desktop _curdt = _curpage.getDesktop(), curdt = curpage.getDesktop(); if (_curdt != null && curdt != null && _curdt != curdt) throw new IllegalStateException("Change current page to another desktop? " + curpage); } _curpage = curpage; }
/** Called when this component replaced the given component, * and the children of the given component shall be 'merged' to this component. * @param replaced the component that this component will replace. * @exception IllegalStateException if this method has been called twice * (we can modify the algorithm to support but not worth). */ public void onChildrenMerged(Component replaced, boolean bListener) { if (_uuids != null) throw new IllegalStateException("called twice"); final List<String> uuids = new LinkedList<String>(); final List<String[]> idmap = new LinkedList<String[]>(); final List<Object[]> evtmap = bListener ? new LinkedList<Object[]>() : null; final Page page = getPage(); mapChildren(page != null ? (DesktopCtrl) page.getDesktop() : null, uuids, idmap, evtmap, replaced); _uuids = uuids.toArray(new String[uuids.size()]); _idmap = !idmap.isEmpty() ? idmap.toArray(new String[idmap.size()][]) : null; _evtmap = evtmap != null && !evtmap.isEmpty() ? evtmap.toArray(new Object[evtmap.size()][]) : null; }
/** Default: handles special event listeners. * @see ComponentCtrl#onPageDetached * @since 3.0.0 */ public void onPageDetached(Page page) { onListenerChange(page.getDesktop(), false); processCallback(AFTER_PAGE_DETACHED); }
public void onPageAttached(Page newpage, Page oldpage) { super.onPageAttached(newpage, oldpage); if (newpage != null) { final DesktopCtrl desktopCtrl = (DesktopCtrl) newpage.getDesktop(); for (String uuid : _uuids) desktopCtrl.mapComponent(uuid, this); } }
/** Default: handles special event listeners. * @see ComponentCtrl#onPageAttached * @since 3.0.0 */ public void onPageAttached(Page newpage, Page oldpage) { if (oldpage == null) //new added onListenerChange(newpage.getDesktop(), true); processCallback(AFTER_PAGE_ATTACHED); }
public void onPageDetached(Page page) { super.onPageDetached(page); final DesktopCtrl desktopCtrl = (DesktopCtrl) page.getDesktop(); for (String uuid : _uuids) desktopCtrl.mapComponent(uuid, null); }
/** Returns the UI engine based on {@link #_page}'s getDesktop(). * Don't call this method when _page is null. */ private UiEngine getAttachedUiEngine() { return ((WebAppCtrl) _page.getDesktop().getWebApp()).getUiEngine(); }
private Execution getExecution() { return _page != null ? _page.getDesktop().getExecution() : Executions.getCurrent(); }
public String nextPageUuid(Page page) { final Desktop desktop = page.getDesktop(); String number; if ((number = (String) desktop.getAttribute(ID_NUM)) == null) { number = "0"; desktop.setAttribute(ID_NUM, number); } int i = Integer.parseInt(number); i++; desktop.setAttribute(ID_NUM, String.valueOf(i)); return ComponentsCtrl.toAutoId(ID_PREFIX, i); }
/** Sets the content type to the specified execution for the given page. * @param exec the execution (never null) */ public static final void setContentType(Execution exec, Page page) { String contentType = ((PageCtrl) page).getContentType(); if (contentType == null) { contentType = page.getDesktop().getDevice().getContentType(); if (contentType == null) contentType = ""; } final int j = contentType.indexOf(';'); if (j < 0) { final String cs = page.getDesktop().getWebApp().getConfiguration().getResponseCharset(); if (cs != null && cs.length() > 0) contentType += ";charset=" + cs; } ((ExecutionCtrl) exec).setContentType(contentType); }
public void init(Page owner, String zslang) { super.init(owner, zslang); if (System.getProperty("python.home") == null) System.setProperty("python.home", System.getProperty("java.io.tmpdir")); PySystemState.initialize(); PySystemState.add_extdir(owner.getDesktop().getWebApp().getRealPath("/WEB-INF/lib"), true); PySystemState.add_classdir(owner.getDesktop().getWebApp().getRealPath("/WEB-INF/classes")); _ip = new PythonInterpreter(new Variables()); }
public void init(Page owner, String zslang) { super.init(owner, zslang); if (System.getProperty("python.home") == null) System.setProperty("python.home", System.getProperty("java.io.tmpdir")); PySystemState.initialize(); PySystemState.add_extdir(owner.getDesktop().getWebApp().getRealPath("/WEB-INF/lib"), true); PySystemState.add_classdir(owner.getDesktop().getWebApp().getRealPath("/WEB-INF/classes")); _ip = new PythonInterpreter(new Variables()); }
/** Checks whether it is OK to detach the specified page. * @param page the page to detach (never null). */ private static void checkDetach(Page page) { final Execution exec = Executions.getCurrent(); if (exec == null) throw new UiException("You cannot access a desktop other than an event listener"); if (page.getDesktop() != exec.getDesktop()) throw new UiException("You cannot access components belong to other desktop"); }
/** Instantiates a composer of the given object. * This method will invoke {@link org.zkoss.zk.ui.sys.UiFactory#newComposer} * to instantiate the composer if page is not null. * @param page the page that the composer will be created for. * Ignored if null. * @param o the composer instance, the class of the composer to instantiate, * or the name of the class of the composer. * If <code>o</code> is an instance of {@link Composer}, it is returned * directly. */ public static Composer newComposer(Page page, Object o) throws Exception { Class cls; if (o instanceof String) { final String clsnm = ((String) o).trim(); if (page != null) return ((WebAppCtrl) page.getDesktop().getWebApp()).getUiFactory().newComposer(page, clsnm); cls = Classes.forNameByThread(clsnm); } else if (o instanceof Class) { cls = (Class) o; if (page != null) return ((WebAppCtrl) page.getDesktop().getWebApp()).getUiFactory().newComposer(page, cls); } else return (Composer) o; return (Composer) cls.newInstance(); }
protected String getSpecialRendererOutput(Component comp) throws IOException { if (_page != null) { final JsContentRenderer renderer = new JsContentRenderer(); PropertiesRenderer[] prs = _page.getDesktop().getWebApp().getConfiguration().getPropertiesRenderers(); for (int j = 0; j < prs.length; j++) prs[j].renderProperties(comp, renderer); return renderer.getBuffer().toString(); } return ""; }
/** Generates the SEO content for the given page. * Nothing is generated if the SEO content has been generated or it shall not be generated. * <p>The SEO content shall be placed inside <code><div class="z-temp"></code>. * <p>If a page renderer generates <code><div class="z-temp"></code> by itself, * it must invoke this method. * @since 5.0.9 */ public static void outSEOContent(Page page, Writer out) throws IOException { if (page != null && ((PageCtrl) page).getOwner() == null) { //only the topmost page shall generate SEO final SEORenderer[] sds = page.getDesktop().getWebApp().getConfiguration().getSEORenderers(); for (int j = 0; j < sds.length; ++j) sds[j].render(page, out); } }
private static void outDivTemplateEnd(Page page, Writer out) throws IOException { final Desktop dt; if (page != null && (dt = page.getDesktop()) != null) { if (dt.getAttribute(ATTR_DESKTOP_CLIENTINFO) != null) { dt.removeAttribute(ATTR_DESKTOP_CLIENTINFO); if (!"CE".equals(WebApps.getEdition())) out.write( "<script type=\"text/javascript\">if(zk.clientinfo === undefined)zk.clientinfo = true;</script>"); } if (dt.getAttribute(ATTR_DESKTOP_VISIBILITYCHANGE) != null) { dt.removeAttribute(ATTR_DESKTOP_VISIBILITYCHANGE); out.write( "<script type=\"text/javascript\">if(zk.visibilitychange === undefined)zk.visibilitychange = true;</script>"); } String resourceURL = (String) page.getAttribute(ATTR_PORTLET2_RESOURCEURL, Page.PAGE_SCOPE), namespace = (String) page.getAttribute(ATTR_PORTLET2_NAMESPACE, Page.PAGE_SCOPE); if (resourceURL != null) { page.removeAttribute(ATTR_PORTLET2_RESOURCEURL, Page.PAGE_SCOPE); page.removeAttribute(ATTR_PORTLET2_NAMESPACE, Page.PAGE_SCOPE); // B65-ZK-2210: store url and namespace per desktop. out.write("<script type=\"text/javascript\">if(!zk.portlet2Data) zk.portlet2Data = {};\n" + "zk.portlet2Data['" + dt.getId() + "'] = {" + "resourceURL: '" + resourceURL + "', " + "namespace: '" + namespace + "'};</script>"); } } outSEOContent(page, out); out.write("</div>"); }
/** Returns the doc type, or null if not available. * It is null or <!DOCTYPE ...>. */ public static final String outDocType(Execution exec, Page page) { if (exec.getAttribute(DOCTYPE_GENED) == null && !exec.isAsyncUpdate(null)) { exec.setAttribute(DOCTYPE_GENED, Boolean.TRUE); final String docType = ((PageCtrl) page).getDocType(); return trimAndLF(docType != null ? docType : page.getDesktop().getDevice().getDocType()); } return ""; }
private void afterComponentPageChanged(Page newpg, Page oldpg) { if (newpg == oldpg) return; final Desktop desktop = (oldpg != null ? oldpg : newpg).getDesktop(); if (desktop == null) return; //just in case //Note: if newpg and oldpg both non-null, they must be the same if (oldpg != null) { ((DesktopCtrl) desktop).afterComponentDetached(this, oldpg); desktop.getWebApp().getConfiguration().afterComponentDetached(this, oldpg); } else { ((DesktopCtrl) desktop).afterComponentAttached(this, newpg); desktop.getWebApp().getConfiguration().afterComponentAttached(this, newpg); } }