/** * Generates and returns the ZK specific HTML tags such as stylesheet and JavaScript. * * <p>For each desktop, we have to generate a set of HTML tags to load ZK Client engine, style * sheets and so on. For ZUL pages, it is generated automatically by page.dsp. However, for ZHTML * pages, we have to generate these tags with special component such as org.zkoss.zhtml.Head, such * that the result HTML page is legal. * * @param exec the execution (never null) * @return the string holding the HTML tags, or null if already generated. * @param wapp the Web application. If null, exec.getDesktop().getWebApp() is used. So you have to * specify it if the execution is not associated with desktop (a fake execution, such as * JSP/DSP). * @param deviceType the device type, such as ajax. If null, exec.getDesktop().getDeviceType() is * used. So you have to specify it if the execution is not associated with desktop (a fake * execution). * @see #outHeaderZkTags */ public static String outZkTags(Execution exec, WebApp wapp, String deviceType) { if (exec.getAttribute(ATTR_ZK_TAGS_GENERATED) != null) return null; exec.setAttribute(ATTR_ZK_TAGS_GENERATED, Boolean.TRUE); final StringBuffer sb = new StringBuffer(512) .append('\n') .append(outLangStyleSheets(exec, wapp, deviceType)) .append(outLangJavaScripts(exec, wapp, deviceType)); final Desktop desktop = exec.getDesktop(); if (desktop != null && exec.getAttribute(ATTR_DESKTOP_JS_GENED) == null) { sb.append("<script class=\"z-runonce\" type=\"text/javascript\">\nzkdt('") .append(desktop.getId()) .append("','") .append(getContextURI(exec)) .append("','") .append(desktop.getUpdateURI(null)) .append("','") .append(desktop.getRequestPath()) .append("');") .append(outSpecialJS(desktop)) .append("\n</script>\n"); } return sb.toString(); }
public String nextDesktopId(Desktop desktop) { if (desktop.getAttribute("Id_Num") == null) { String number = "0"; desktop.setAttribute("Id_Num", number); } return null; }
// @Override public void render(Page page, Writer out) throws IOException { final Desktop desktop = _exec.getDesktop(); out.write("<script type=\"text/javascript\">zkpb('"); out.write(page.getUuid()); out.write("','"); out.write(desktop.getId()); out.write("','"); out.write(getContextURI()); out.write("','"); out.write(desktop.getUpdateURI(null)); out.write("','"); out.write(desktop.getRequestPath()); out.write('\''); String style = page.getStyle(); if (style != null && style.length() > 0) { out.write(",{style:'"); out.write(style); out.write("'}"); } out.write(");zkpe();</script>\n"); for (Component root = page.getFirstRoot(); root != null; root = root.getNextSibling()) { // HtmlPageRenders.outStandalone(_exec, root, 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); if (resourceURL != null) { page.removeAttribute(ATTR_PORTLET2_RESOURCEURL, Page.PAGE_SCOPE); out.write("<script type=\"text/javascript\">zk.portlet2AjaxURI = '"); out.write(resourceURL); out.write("';</script>"); } } outSEOContent(page, out); out.write("</div>"); }
/** * Process the event. Note: it doesn't invoke EventThreadInit and EventThreadCleanup. * * <p>This method is to implement {@link org.zkoss.zk.ui.sys.EventProcessingThread}. See also * {@link org.zkoss.zk.ui.util.Configuration#isEventThreadEnabled}. */ public void process() throws Exception { final ExecutionMonitor execmon = _desktop.getWebApp().getConfiguration().getExecutionMonitor(); // Bug 1506712: event listeners might be zscript, so we have to // keep built-in variables as long as possible final Scope scope = Scopes.beforeInterpret(_comp); // we have to push since process0 might invoke methods from zscript class try { Scopes.setImplicit("event", _event); _event = ((DesktopCtrl) _desktop).beforeProcessEvent(_event); if (_event != null) { if (execmon != null) execmon.eventStart(_event); Scopes.setImplicit("event", _event); // _event might change ((ComponentCtrl) _comp).service(_event, scope); ((DesktopCtrl) _desktop).afterProcessEvent(_event); } } finally { final Execution exec = _desktop.getExecution(); if (exec != null) // just in case ((ExecutionCtrl) exec).setExecutionInfo(null); if (execmon != null && _event != null) execmon.eventComplete(_event); Scopes.afterInterpret(); } }
private boolean isEventThreadEnabled(boolean attachedRequired) { Desktop desktop = getDesktop(); if (desktop == null) { if (attachedRequired) throw new SuspendNotAllowedException("Not attached, " + this); final Execution exec = Executions.getCurrent(); if (exec == null || (desktop = exec.getDesktop()) == null) return true; // assume enabled (safer) } return desktop.getWebApp().getConfiguration().isEventThreadEnabled(); }
private static Boolean getAutomaticTimeout(Desktop desktop) { if (desktop != null) for (Page page : desktop.getPages()) { Boolean b = ((PageCtrl) page).getAutomaticTimeout(); if (b != null) return b; } return null; }
public DefaultDesktop() { super(); dashboardController = new DashboardController(); sideController = new DashboardController(); helpController = new HelpController(); m_desktop = AEnv.getDesktop(); m_desktop.addListener(this); // subscribing to broadcast event bindEventManager(); ZKBroadCastManager.getBroadCastMgr(); EventQueue<Event> queue = EventQueues.lookup(ACTIVITIES_EVENT_QUEUE, true); queue.subscribe(this); }
private static final boolean isGroupingAllowed(Desktop desktop) { final String name = "org.zkoss.zk.ui.input.grouping.allowed"; if (desktop != null) { final Collection<Page> pages = desktop.getPages(); if (!pages.isEmpty()) { final Page page = pages.iterator().next(); Object o = page.getAttribute(name); if (o != null) return (o instanceof Boolean && ((Boolean) o).booleanValue()) || !"false".equals(o); } } if (_groupingAllowed == null) { final String s = Library.getProperty(name); _groupingAllowed = Boolean.valueOf(s == null || !"false".equals(s)); } return _groupingAllowed.booleanValue(); }
/** * Generates the special JavaScript code, such as the application's name. It shall be called, * before generating "zkmx(" and "zkx(". * * @since 5.0.6 */ public static final String outSpecialJS(Desktop desktop) { final StringBuffer sb = new StringBuffer(); // output application name String oldnm = (String) desktop.getAttribute(ATTR_APPNM); if (oldnm == null) oldnm = "ZK"; final String appnm = desktop.getWebApp().getAppName(); if (!oldnm.equals(appnm)) { sb.append("zk.appName='"); Strings.escape(sb, appnm, Strings.ESCAPE_JAVASCRIPT).append("';"); desktop.setAttribute(ATTR_APPNM, appnm); } // output zktheme cookie String oldthemenm = (String) desktop.getAttribute(ATTR_THEMENM); if (oldthemenm == null) oldthemenm = ""; final Object request = desktop.getExecution().getNativeRequest(); String themenm = ""; if (request instanceof HttpServletRequest) { themenm = ThemeFns.getThemeResolver().getTheme((HttpServletRequest) request); } if (!oldthemenm.equals(themenm)) { sb.append("zk.themeName='"); Strings.escape(sb, themenm, Strings.ESCAPE_JAVASCRIPT).append("';"); desktop.setAttribute(ATTR_THEMENM, themenm); } // output ZK ICON final Session sess = Sessions.getCurrent(); if (sess != null) { WebApp wapp = desktop.getWebApp(); if (wapp == null || "CE".equals(WebApps.getEdition()) || wapp.getAttribute("org.zkoss.zk.ui.notice") != null) { final PI pi = (PI) sess.getAttribute(ATTR_PI); boolean show = pi == null; if (show) sess.setAttribute(ATTR_PI, new PI()); else show = pi.show(); if (show) sb.append("zk.pi=1;"); } } return sb.toString(); }
/** * Returns the HTML content representing a page. * * @param au whether it is caused by asynchronous update * @param exec the execution (never null) */ public static final void outPageContent(Execution exec, Page page, Writer out, boolean au) throws IOException { final Desktop desktop = page.getDesktop(); final PageCtrl pageCtrl = (PageCtrl) page; final Component owner = pageCtrl.getOwner(); boolean contained = owner == null && exec.isIncluded(); // a standalone page (i.e., no owner), and being included by // non-ZK page (e.g., JSP). // // Revisit Bug 2001707: OK to use exec.isIncluded() since // we use PageRenderer now (rather than Servlet's include) // TODO: test again // prepare style String style = page.getStyle(); if (style == null || style.length() == 0) { style = null; String wd = null, hgh = null; if (owner instanceof HtmlBasedComponent) { final HtmlBasedComponent hbc = (HtmlBasedComponent) owner; wd = hbc.getWidth(); // null if not set hgh = hbc.getHeight(); // null if not set } if (wd != null || hgh != null || contained) { final StringBuffer sb = new StringBuffer(32); HTMLs.appendStyle(sb, "width", wd != null ? wd : "100%"); HTMLs.appendStyle(sb, "height", hgh != null ? hgh : contained ? null : "100%"); style = sb.toString(); } } RenderContext rc = null, old = null; final boolean aupg = exec.isAsyncUpdate(page); // AU this page final boolean includedAndPart = owner != null && !aupg; // this page is included and rendered with its owner final boolean divRequired = !au || includedAndPart; final boolean standalone = !au && owner == null; if (standalone) { rc = new RenderContext( out, new StringWriter(), desktop.getWebApp().getConfiguration().isCrawlable(), false); setRenderContext(exec, rc); } else if (owner != null) { old = getRenderContext(exec); // store final boolean crawlable = old != null && old.temp != null && desktop.getWebApp().getConfiguration().isCrawlable(); setRenderContext(exec, crawlable ? new RenderContext(old.temp, null, true, true) : null); } // generate div first if (divRequired) { outDivTemplateBegin(out, page.getUuid()); } if (standalone) { // switch out // don't call outDivTemplateEnd yet since rc.temp will be generated before it out = new StringWriter(); } else if (divRequired) { outDivTemplateEnd(page, out); // close it now since no rc.temp } if (includedAndPart) { out = new StringWriter(); } else if (divRequired) { // generate JS second out.write("\n<script class=\"z-runonce\" type=\"text/javascript\">\n"); } exec.setAttribute(ATTR_DESKTOP_JS_GENED, Boolean.TRUE); final int order = ComponentRedraws.beforeRedraw(false); final String extra; try { if (order < 0) { if (aupg) out.write('['); else { out.write(outSpecialJS(desktop)); out.write(divRequired ? "zkmx(" : "zkx("); } } else if (order > 0) // not first child out.write(','); out.write("\n[0,'"); // 0: page out.write(page.getUuid()); out.write("',{"); final StringBuffer props = new StringBuffer(128); final String pgid = page.getId(); if (pgid.length() > 0) appendProp(props, "id", pgid); if (owner != null) { appendProp(props, "ow", owner.getUuid()); } else { appendProp(props, "dt", desktop.getId()); appendProp(props, "cu", getContextURI(exec)); appendProp(props, "uu", desktop.getUpdateURI(null)); appendProp(props, "ru", desktop.getRequestPath()); } final String pageWgtCls = pageCtrl.getWidgetClass(); if (pageWgtCls != null) appendProp(props, "wc", pageWgtCls); if (style != null) appendProp(props, "style", style); if (!isClientROD(page)) appendProp(props, "z$rod", Boolean.FALSE); if (contained) appendProp(props, "ct", Boolean.TRUE); out.write(props.toString()); out.write("},["); for (Component root = page.getFirstRoot(); root != null; root = root.getNextSibling()) ((ComponentCtrl) root).redraw(out); out.write("]]"); } finally { extra = ComponentRedraws.afterRedraw(); } if (order < 0) { outEndJavaScriptFunc(exec, out, extra, aupg); } if (standalone) { setRenderContext(exec, null); StringBuffer sw = ((StringWriter) out).getBuffer(); out = rc.temp; if (divRequired) outDivTemplateEnd(page, out); // close tag after temp, but before perm (so perm won't be destroyed) Files.write(out, ((StringWriter) rc.perm).getBuffer()); // perm // B65-ZK-1836 Files.write( out, new StringBuffer(sw.toString().replaceAll("</(?i)(?=script>)", "<\\\\/"))); // js } else if (owner != null) { // restore setRenderContext(exec, old); } if (includedAndPart) { ((Includer) owner).setRenderingResult(((StringWriter) out).toString()); } else if (divRequired) { out.write("\n</script>\n"); } }
public String nextComponentUuid(Desktop desktop, Component comp, ComponentInfo info) { int i = Integer.parseInt(desktop.getAttribute("Id_Num").toString()); i++; // Start from 1 desktop.setAttribute("Id_Num", String.valueOf(i)); return PREFIX + i; }
public void automaticAssociations() { logger.debug("automaticAssociations()"); if (Messagebox.show( Labels.getLabel("common.automaticMsg"), Labels.getLabel("common.automatic"), Messagebox.YES | Messagebox.NO, Messagebox.QUESTION) == Messagebox.YES) { final org.zkoss.zk.ui.Desktop desktop = Executions.getCurrent().getDesktop(); if (desktop.isServerPushEnabled() == false) desktop.enableServerPush(true); Clients.showBusy(Labels.getLabel("loginHelper.working")); final CodeSystem cs1 = (CodeSystem) SessionHelper.getValue("selectedCS1"); final CodeSystem cs2 = (CodeSystem) SessionHelper.getValue("selectedCS2"); // start timer to enable busy message Timer timer = new Timer(); timer.schedule( new TimerTask() { @Override public void run() { try { // List<CodeSystemEntityVersionAssociation> list = new // LinkedList<CodeSystemEntityVersionAssociation>(); logger.debug("cs1: " + cs1.getName()); logger.debug("cs2: " + cs2.getName()); long csvId1 = cs1.getCodeSystemVersions().get(0).getVersionId(); long csvId2 = cs2.getCodeSystemVersions().get(0).getVersionId(); logger.debug("csvId1: " + csvId1); logger.debug("csvId2: " + csvId2); // ListCodeSystemConceptsRequestType ListCodeSystemConceptsResponse.Return response1 = WebServiceHelper.listCodeSystemConcepts(csvId1); ListCodeSystemConceptsResponse.Return response2 = WebServiceHelper.listCodeSystemConcepts(csvId2); logger.debug("result 1: " + response1.getReturnInfos().getMessage()); logger.debug("result 2: " + response2.getReturnInfos().getMessage()); Executions.activate(desktop); if (response1.getReturnInfos().getStatus() == Status.OK && response2.getReturnInfos().getStatus() == Status.OK) { for (CodeSystemEntity cse1 : response1.getCodeSystemEntity()) { CodeSystemEntityVersion csev1 = cse1.getCodeSystemEntityVersions().get(0); CodeSystemConcept csc1 = csev1.getCodeSystemConcepts().get(0); for (CodeSystemEntity cse2 : response2.getCodeSystemEntity()) { CodeSystemEntityVersion csev2 = cse2.getCodeSystemEntityVersions().get(0); CodeSystemConcept csc2 = csev2.getCodeSystemConcepts().get(0); // check same code if (csc1.getCode().equals(csc2.getCode())) { // match addAutomaticMatch(csev1, csev2); } // check containing text if (csc1.getTerm().toLowerCase().contains(csc2.getTerm().toLowerCase())) { addAutomaticMatch(csev1, csev2); } if (csc2.getTerm().toLowerCase().contains(csc1.getTerm().toLowerCase())) { addAutomaticMatch(csev2, csev1); } } } } // read data of both codesystems /*Include incL = (Include) getFellow("incContentLeft"); ContentAssociationEditor contentEditor1 = (ContentAssociationEditor)incL.getDynamicProperty("instance"); Include incR = (Include) getFellow("incContentRight"); ContentAssociationEditor contentEditor2 = (ContentAssociationEditor)incL.getDynamicProperty("instance"); ContentConcepts content1 = contentEditor1.getContent(); ContentConcepts content2 = contentEditor2.getContent(); TreeModel model1 = content1.getConcepts().getTreeConcepts().getModel(); logger.debug("root: " + model1.getRoot().getClass().getCanonicalName());*/ // Executions.schedule(desktop, el, new Event("finish", null, "")); Clients.clearBusy(); Executions.deactivate(desktop); } catch (Exception ex) { LoggingOutput.outputException(ex, this); try { Executions.activate(desktop); Clients.clearBusy(); Messagebox.show(ex.getLocalizedMessage()); Executions.deactivate(desktop); } catch (Exception e) { } } } }, 10); } }
private void saveAssociations() { logger.debug("saveAssociations()"); final org.zkoss.zk.ui.Desktop desktop = Executions.getCurrent().getDesktop(); if (desktop.isServerPushEnabled() == false) desktop.enableServerPush(true); final EventListener el = this; Clients.showBusy(Labels.getLabel("common.saveChanges") + "..."); final List<CodeSystemEntityVersionAssociation> failureList = new LinkedList<CodeSystemEntityVersionAssociation>(); // Import durchführen Timer timer = new Timer(); timer.schedule( new TimerTask() { @Override public void run() { try { String sFailure = ""; logger.debug( "save associations, count: " + genericList.getListbox().getListModel().getSize()); // save associations // for(Object obj : genericList.getListbox().getListModel()) for (int i = 0; i < genericList.getListbox().getListModel().getSize(); ++i) { GenericListRowType row = (GenericListRowType) genericList.getListbox().getListModel().getElementAt(i); logger.debug("row type: " + row.getData().getClass().getCanonicalName()); if (row.getData() instanceof CodeSystemEntityVersionAssociation) { CodeSystemEntityVersionAssociation cseva = (CodeSystemEntityVersionAssociation) row.getData(); // cseva.getCodeSystemEntityVersionByCodeSystemEntityVersionId1() CreateConceptAssociationRequestType request = new CreateConceptAssociationRequestType(); request.setLoginToken(SessionHelper.getSessionId()); request.setCodeSystemEntityVersionAssociation(cseva); CreateConceptAssociationResponse.Return response = WebServiceHelper.createConceptAssociation(request); logger.debug("result: " + response.getReturnInfos().getMessage()); if (response.getReturnInfos().getStatus() == de.fhdo.terminologie.ws.conceptassociation.Status.FAILURE) { failureList.add(cseva); sFailure = response.getReturnInfos().getMessage(); } } } // Executions.schedule(desktop, el, new Event("finish", null, "")); Executions.activate(desktop); Clients.clearBusy(); List<GenericListRowType> rows = new LinkedList<GenericListRowType>(); for (CodeSystemEntityVersionAssociation cseva : failureList) { rows.add(createRow(cseva)); } genericList.setDataList(rows); // reload side lists (change mapping entries) reloadLists(); if (sFailure.length() > 0) throw new Exception(sFailure); // Messagebox.show(sFailure); Executions.deactivate(desktop); // Executions.schedule(desktop, el, new Event("updateStatus", null, // msg)); } catch (Exception ex) { LoggingOutput.outputException(ex, this); try { Executions.activate(desktop); Clients.clearBusy(); Messagebox.show(ex.getLocalizedMessage()); Executions.deactivate(desktop); } catch (Exception e) { } } } }, 100); }
/** * Open a download dialog to save the specified content at the client with the suggested file * name. * * @param media the media to download * @param flnm the suggested file name, e.g., myfile.pdf. If null, {@link Media#getName} is * assumed. */ public static void save(Media media, String flnm) { final Desktop desktop = Executions.getCurrent().getDesktop(); ((WebAppCtrl) desktop.getWebApp()) .getUiEngine() .addResponse(new AuDownload(new DownloadURL(media, flnm))); // Bug 2114380 }
/** * Setup this processor before processing the event by calling {@link #process}. * * <p>Note: it doesn't invoke {@link ExecutionCtrl#onActivate} */ public void setup() { SessionsCtrl.setCurrent(_desktop.getSession()); final Execution exec = _desktop.getExecution(); ExecutionsCtrl.setCurrent(exec); ((ExecutionCtrl) exec).setCurrentPage(getPage()); }
/** * Returns HTML tags to include all JavaScript files and codes that are required when loading a * ZUML page (never null). * * <p>FUTURE CONSIDERATION: we might generate the inclusion on demand instead of all at once. * * @param exec the execution (never null) * @param wapp the Web application. If null, exec.getDesktop().getWebApp() is used. So you have to * specify it if the execution is not associated with desktop (a fake execution, such as * JSP/DSP). * @param deviceType the device type, such as ajax. If null, exec.getDesktop().getDeviceType() is * used. So you have to specify it if the execution is not associated with desktop (a fake * execution). */ public static final String outLangJavaScripts(Execution exec, WebApp wapp, String deviceType) { if (exec.isAsyncUpdate(null) || exec.getAttribute(ATTR_LANG_JS_GENED) != null) return ""; // nothing to generate exec.setAttribute(ATTR_LANG_JS_GENED, Boolean.TRUE); final Desktop desktop = exec.getDesktop(); if (wapp == null) wapp = desktop.getWebApp(); if (deviceType == null) deviceType = desktop != null ? desktop.getDeviceType() : "ajax"; final StringBuffer sb = new StringBuffer(1536); final Set<JavaScript> jses = new LinkedHashSet<JavaScript>(32); for (LanguageDefinition langdef : LanguageDefinition.getByDeviceType(deviceType)) jses.addAll(langdef.getJavaScripts()); for (JavaScript js : jses) append(sb, js); sb.append("\n<!-- ZK ").append(wapp.getVersion()); if (WebApps.getFeature("ee")) sb.append(" EE"); else if (WebApps.getFeature("pe")) sb.append(" PE"); sb.append(' ').append(wapp.getBuild()); Object o = wapp.getAttribute("org.zkoss.zk.ui.notice"); if (o != null) sb.append(o); sb.append(" -->\n"); int tmout = 0; final Boolean autoTimeout = getAutomaticTimeout(desktop); if (autoTimeout != null ? autoTimeout.booleanValue() : wapp.getConfiguration().isAutomaticTimeout(deviceType)) { if (desktop != null) { tmout = desktop.getSession().getMaxInactiveInterval(); } else { Object req = exec.getNativeRequest(); if (req instanceof HttpServletRequest) { final HttpSession hsess = ((HttpServletRequest) req).getSession(false); if (hsess != null) { final Session sess = SessionsCtrl.getSession(wapp, hsess); if (sess != null) { tmout = sess.getMaxInactiveInterval(); } else { // try configuration first since HttpSession's timeout is set // when ZK Session is created (so it is not set yet) // Note: no need to setMaxInactiveInternval here since it will // be set later or not useful at the end tmout = wapp.getConfiguration().getSessionMaxInactiveInterval(); if (tmout <= 0) // system default tmout = hsess.getMaxInactiveInterval(); } } else tmout = wapp.getConfiguration().getSessionMaxInactiveInterval(); } } if (tmout > 0) { // unit: seconds int extra = tmout / 8; tmout += extra > 60 ? 60 : extra < 5 ? 5 : extra; // Add extra seconds to ensure it is really timeout } } final boolean keepDesktop = exec.getAttribute(Attributes.NO_CACHE) == null && !"page".equals(ExecutionsCtrl.getPageRedrawControl(exec)), groupingAllowed = isGroupingAllowed(desktop); final String progressboxPos = org.zkoss.lang.Library.getProperty("org.zkoss.zul.progressbox.position", ""); if (tmout > 0 || keepDesktop || progressboxPos.length() > 0 || !groupingAllowed) { sb.append("<script class=\"z-runonce\" type=\"text/javascript\">\nzkopt({"); if (keepDesktop) sb.append("kd:1,"); if (!groupingAllowed) sb.append("gd:1,"); if (tmout > 0) sb.append("to:").append(tmout).append(','); if (progressboxPos.length() > 0) sb.append("ppos:'").append(progressboxPos).append('\''); if (sb.charAt(sb.length() - 1) == ',') sb.setLength(sb.length() - 1); sb.append("});\n</script>"); } final Device device = Devices.getDevice(deviceType); String s = device.getEmbedded(); if (s != null) sb.append(s).append('\n'); return sb.toString(); }
/** * Process asynchronous update requests from the client. * * @since 3.0.0 */ protected void process(Session sess, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { final String errClient = request.getHeader("ZK-Error-Report"); if (errClient != null) if (log.debugable()) log.debug("Error found at client: " + errClient + "\n" + Servlets.getDetail(request)); // parse desktop ID final WebApp wapp = sess.getWebApp(); final WebAppCtrl wappc = (WebAppCtrl) wapp; final AuDecoder audec = getAuDecoder(wapp); final String dtid = audec.getDesktopId(request); if (dtid == null) { // Bug 1929139: incomplete request (IE only) if (log.debugable()) { final String msg = "Incomplete request\n" + Servlets.getDetail(request); log.debug(msg); } response.sendError(467, "Incomplete request"); return; } Desktop desktop = getDesktop(sess, dtid); if (desktop == null) { final String cmdId = audec.getFirstCommand(request); if (!"rmDesktop".equals(cmdId)) desktop = recoverDesktop(sess, request, response, wappc, dtid); if (desktop == null) { response.setIntHeader("ZK-Error", response.SC_GONE); // denote timeout sessionTimeout(request, response, wapp, dtid); return; } } WebManager.setDesktop(request, desktop); // reason: a new page might be created (such as include) final String sid = request.getHeader("ZK-SID"); if (sid != null) // Some client might not have ZK-SID response.setHeader("ZK-SID", sid); // parse commands final Configuration config = wapp.getConfiguration(); final List aureqs; boolean keepAlive = false; try { final boolean timerKeepAlive = config.isTimerKeepAlive(); aureqs = audec.decode(request, desktop); for (Iterator it = aureqs.iterator(); it.hasNext(); ) { final String cmdId = ((AuRequest) it.next()).getCommand(); keepAlive = !(!timerKeepAlive && Events.ON_TIMER.equals(cmdId)) && !"dummy".equals(cmdId); // dummy is used for PollingServerPush for piggyback if (keepAlive) break; // done } } catch (Throwable ex) { log.warningBriefly(ex); responseError(request, response, Exceptions.getMessage(ex)); return; } if (aureqs.isEmpty()) { final String errmsg = "Illegal request: cmd required"; log.debug(errmsg); responseError(request, response, errmsg); return; } ((SessionCtrl) sess).notifyClientRequest(keepAlive); // if (log.debugable()) log.debug("AU request: "+aureqs); final DesktopCtrl desktopCtrl = (DesktopCtrl) desktop; final Execution exec = new ExecutionImpl(getServletContext(), request, response, desktop, null); if (sid != null) ((ExecutionCtrl) exec).setRequestId(sid); final AuWriter out = AuWriters.newInstance(); out.setCompress(_compress); out.open( request, response, desktop.getDevice().isSupported(Device.RESEND) ? getProcessTimeout(config.getResendDelay()) : 0); // Note: getResendDelay() might return nonpositive try { wappc.getUiEngine().execUpdate(exec, aureqs, out); } catch (RequestOutOfSequenceException ex) { log.warning(ex.getMessage()); response.setHeader("ZK-SID", sid); response.setIntHeader("ZK-Error", AuResponse.SC_OUT_OF_SEQUENCE); } out.close(request, response); }
private Page getPage() { final Page page = _comp.getPage(); if (page != null) return page; return _desktop.getFirstPage(); }
private String getEncodedHref() { final Desktop dt = getDesktop(); return _href != null && dt != null ? dt.getExecution().encodeURL(_href) : null; // if desktop is null, it doesn't belong to any execution }