/** Returns whether the desktop is being recovered. */ private static final boolean isRecovering(Desktop desktop) { final Execution exec = desktop.getExecution(); return exec != null && ((ExecutionCtrl) exec).isRecovering(); }
/** Returns the JavaScript codes to disable (a.k.a., stop) the server push. * It is called by {@link #stopClientPush} to prepare the script * of {@link AuScript} that will be sent to the client. */ protected String getStopScript() { final String stop = _desktop.getWebApp().getConfiguration().getPreference("PollingServerPush.stop", null); return stop != null ? stop : "zk.cpsp.stop('" + _desktop.getId() + "');"; }
public String nextComponentUuid(Desktop desktop, Component comp, ComponentInfo compInfo) { 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); }
public Object setAttribute(String name, Object value, boolean recurse) { if (recurse && !hasAttribute(name)) { if (_desktop != null) { if (_desktop.hasAttribute(name, true)) return _desktop.setAttribute(name, value, true); } } return setAttribute(name, value); }
out.write(page.getUuid()); out.write("','"); out.write(desktop.getId()); out.write("','"); out.write(getContextURI(exec)); out.write("','"); out.write(desktop.getUpdateURI(null)); out.write("','"); out.write(desktop.getRequestPath()); out.write('\''); out.write(">"); if (page != null) { final WebApp wapp = page.getDesktop().getWebApp(); String currentVersion = wapp.getVersion(); if (Utils.compareVersion(Utils.parseVersion(currentVersion),
public void log(String msg) { if (_desktop != null) _desktop.getWebApp().log(msg); else _zklog.info(msg); }
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); sb.append("zk.themeName='"); Strings.escape(sb, themenm, Strings.ESCAPE_JAVASCRIPT).append("';"); desktop.setAttribute(ATTR_THEMENM, themenm); WebApp wapp = desktop.getWebApp(); if (wapp == null || "CE".equals(WebApps.getEdition()) || wapp.getAttribute("org.zkoss.zk.ui.notice") != null) {
/** * @param evtnm the event name to echo back * @param data the data to sent with the event when echoed back * @param dt the desktop to receive the event. */ public AuEchoGlobal(String evtnm, String data, Desktop dt) { super("echoGx", new String[] { evtnm, data, dt.getId() }); }
public void render(Page page, Writer out) throws IOException { out.write(HtmlPageRenders.outLangStyleSheets(_exec, null, null)); out.write(HtmlPageRenders.outLangJavaScripts(_exec, null, null)); if (_pageDOM) { HtmlPageRenders.outPageContent(_exec, page, out, false); return; } final Desktop desktop = _exec.getDesktop(); out.write("<script class=\"z-runonce\" 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); } }
public Object getAttribute(String name) { return desktop.getAttribute(name); }
/** * Get the {@link OperationQueue} of {@linkplain OperationThread}, * It is check is there any {@linkplain OperationThread} exist in desktop. * If no, create one ,start it and store in desktop, then return thread's operation queue. * If yes, return operation queue directly. * * There is only one {@linkplain OperationThread} in each desktop. * @param desktop the associated desktop * @return a queue which associate to desktop */ public static OperationQueue getQueue(Desktop desktop) { if (desktop == null) throw new NullPointerException("desktop is null"); synchronized(desktop) { if (!desktop.isAlive()) { throw new IllegalStateException("desktop not alive:" + desktop); } OperationThread t = (OperationThread) desktop.getAttribute(DESKTOP_KEY); if (t == null) { t = new OperationThread(desktop); if(D.ON && log.debugable()){ log.debug("staring a Operation Thread for desktop:"+desktop+",name="+t.getName()); } desktop.setAttribute(DESKTOP_KEY, t); t.start(); } return t.getQueue(); } }
/** * Force transfer of session-based security context to desktop. */ @Override public void onInit(Desktop desktop) { HttpSession session = (HttpSession) desktop.getSession().getNativeSession(); getSecurityContext(session, desktop.getId()); }
public void onClose(Event evt) { if (evt.getData() == null) _result.clear(); else { final Desktop desktop = Executions.getCurrent().getDesktop(); final Configuration config = desktop.getWebApp().getConfiguration(); if (!config.isEventThreadEnabled()) { if (_listener != null) try { _listener.onEvent(new UploadEvent(Events.ON_UPLOAD, null, getResult())); } catch (Exception e) { throw new UiException(e); } else Events.postEvent(new UploadEvent(Events.ON_UPLOAD, (Component) desktop.getAttribute(ATTR_FILEUPLOAD_TARGET), getResult())); } } detach(); }
/** * Creates an instance of {@link UploadEvent} based on the event name and component, * the {@link UploadEvent} contains the latest upload media from user. * Internal Use Only. * * @param name event name * @param component component that triggers the upload event * @return upload event * @since 8.6.0 */ public static UploadEvent getLatestUploadEvent(String name, Component component) { Desktop desktop = component.getDesktop(); String uuid = component.getUuid(); final List<Media> result = cast((List) desktop.getAttribute(uuid)); desktop.removeAttribute(uuid); return new UploadEvent(name, desktop.getComponentByUuid(uuid), UploadUtils.parseResult(result)); } }
throws FileUploadException { final Map<String, Object> params = new HashMap<String, Object>(); final Configuration conf = desktop.getWebApp().getConfiguration(); int thrs = conf.getFileSizeThreshold(); int sizeThreadHold = 1024 * 128; // maximum size that will be stored in memory Integer compMaxsz = (Integer) desktop.getComponentByUuid(request.getParameter("uuid")) .getAttribute(Attributes.UPLOAD_MAX_SIZE); maxsz = compMaxsz != null ? compMaxsz : conf.getMaxUploadSize();
/** 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()); }
/** Converts the data of the specified request to a set of Component. * The data is assumed to contain a list of item ID in the * comman-separated format * * @return a set of components. */ @SuppressWarnings("unchecked") public static <T extends Component> Set<T> convertToItems(Desktop desktop, List<String> uuids) { final Set<T> items = new LinkedHashSet<T>(); if (uuids != null) for (String uuid : uuids) { final Component item = desktop.getComponentByUuidIfAny(uuid.trim()); if (item != null) items.add((T) item); //notice that it might be null (since the items might be //removed by the last request) } return items; }
public boolean service(AuRequest request, boolean everError) { if ("updateResult".equals(request.getCommand())) { final Map<String, Object> data = request.getData(); Desktop desktop = request.getDesktop(); final String uuid = (String) request.getData().get("wid"); final Component comp = desktop.getComponentByUuidIfAny(uuid); final String sid = (String) request.getData().get("sid"); if (comp == null) { Map<String, Integer> percent = cast((Map) desktop.getAttribute(Attributes.UPLOAD_PERCENT)); Map<String, Object> size = cast((Map) desktop.getAttribute(Attributes.UPLOAD_SIZE)); String key = uuid + '_' + sid; if (percent != null) { percent.remove(key); size.put(key, "Upload Aborted"); } return false; } final List<Media> result = cast((List) AuRequests.getUpdateResult(request)); Events.postEvent(new UploadEvent(Events.ON_UPLOAD, comp, UploadUtils.parseResult(result))); Map percent = (Map) desktop.getAttribute(Attributes.UPLOAD_PERCENT); Map size = (Map) desktop.getAttribute(Attributes.UPLOAD_SIZE); final String key = uuid + '_' + sid; percent.remove(key); size.remove(key); return true; } return false; }
/** Process fileitems named file0, file1 and so on. */ private static final void processItems(Desktop desktop, Map<String, Object> params, Map<String, String> attrs) throws IOException { final List<Media> meds = new LinkedList<Media>(); final boolean alwaysNative = "true".equals(params.get("native")); final Object fis = params.get("file"); if (fis instanceof FileItem) { meds.add(processItem(desktop, (FileItem) fis, alwaysNative, (org.zkoss.zk.ui.sys.DiskFileItemFactory) params.get("diskFileItemFactory"))); } else if (fis != null) { for (Iterator it = ((List) fis).iterator(); it.hasNext();) { meds.add(processItem(desktop, (FileItem) it.next(), alwaysNative, (org.zkoss.zk.ui.sys.DiskFileItemFactory) params.get("diskFileItemFactory"))); } } final String contentId = Strings .encode(new StringBuffer(12).append("z__ul_"), ((DesktopCtrl) desktop).getNextKey()).toString(); attrs.put("contentId", contentId); desktop.setAttribute(contentId, meds); }
/** Activates this request. * <p>Used internally to identify the component and page after * an execution is activated. Applications rarely need to access this * method. * @since 3.0.5 */ public void activate() throws ComponentNotFoundException { if (_uuid != null) { _comp = _desktop.getComponentByUuidIfAny(_uuid); if (_comp != null) { _page = _comp.getPage(); } else { _page = _desktop.getPageIfAny(_uuid); //it could be page UUID if (_page == null) throw new ComponentNotFoundException("Component not found: " + _uuid); } } }