Package org.zkoss.zk.ui

Examples of org.zkoss.zk.ui.Desktop


   * @param autocreate whether to create one if not found
   * @since 3.0.0
   */
  public Desktop getDesktop(Session sess, ServletRequest request,
  ServletResponse response, String path, boolean autocreate) {
    Desktop desktop = (Desktop)request.getAttribute(ATTR_DESKTOP);
    if (desktop == null && autocreate) {
      if (log.debugable()) log.debug("Create desktop for "+path);
      request.setAttribute(ATTR_DESKTOP,
        desktop = newDesktop(sess, request, response, path));
    }
View Full Code Here


    final TemporaryExecution de = new TemporaryExecution(
      _ctx, (HttpServletRequest)request,
      (HttpServletResponse)response, null);
    ExecutionsCtrl.setCurrent(de);
    try {
      Desktop desktop =
        ((WebAppCtrl)_wapp).getUiFactory().newDesktop(
        new RequestInfoImpl(_wapp, sess, null, request, loc),
        _updateURI, path);
      return !de.isVoided() ? desktop: null;
    } finally {
View Full Code Here

    boolean download = false;
    try {
      final WebApp wapp = sess.getWebApp();
      final WebAppCtrl wappc = (WebAppCtrl)wapp;
      final UiEngine uieng = wappc.getUiEngine();
      final Desktop desktop = wappc.getDesktopCache(sess).getDesktop(dtid);
      final DesktopCtrl desktopCtrl = (DesktopCtrl)desktop;

      final Execution oldexec = Executions.getCurrent();
      final Execution exec = new ExecutionImpl(
        _ctx, request, response, desktop, null);
      uieng.activate(exec);

      final Configuration config = wapp.getConfiguration();
      boolean err = false;
      try {
        config.invokeExecutionInits(exec, oldexec);
        desktopCtrl.invokeExecutionInits(exec, oldexec);

        media = desktopCtrl.getDownloadMedia(uuid, false);
        if (media != null) {
          download = true; //yes, it is for download
        } else {
          final Component comp = desktop.getComponentByUuid(uuid);
          final Object cc = ((ComponentCtrl)comp).getExtraCtrl();
          if (!(cc instanceof DynamicMedia))
            throw new ServletException(DynamicMedia.class+" must be implemented by getExtraCtrl() of "+comp);
          media = ((DynamicMedia)cc).getMedia(l >= 0 ? pi.substring(l): "");
          if (media == null) {
View Full Code Here

  }
 
  public boolean service(AuRequest request, boolean everError) {
    if ("updateResult".equals(request.getCommand())) {
      final Map data = request.getData();
      Desktop desktop = request.getDesktop();
      final String uuid = (String) request.getData().get("wid");
      final String sid = (String) request.getData().get("sid");
      Events.postEvent(new UploadEvent(Events.ON_UPLOAD,
          desktop.getComponentByUuid(uuid),
          parseResult((List)AuRequests.getUpdateResult(request))));

      Map precent = (Map) desktop.getAttribute(Attributes.UPLOAD_PERCENT);
      Map size = (Map)desktop.getAttribute(Attributes.UPLOAD_SIZE);
      final String key = uuid + '_' + sid;
      precent.remove(key);
      size.remove(key);
      return true;
    }
View Full Code Here

    && getDefinition().getMoldNames().contains("trendy")) //Toolbarbutton doesn't support trendy
      setMold("trendy");
  }

  private String getEncodedHref() {
    final Desktop dt = getDesktop();
    return _auxinf != null && _auxinf.href != null && dt != null ?
      dt.getExecution().encodeURL(_auxinf.href): null;
      //if desktop is null, it doesn't belong to any execution
  }
View Full Code Here

      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;
    }

    sess.setAttribute(Attributes.GAE_FIX, new Integer(0)); //enforce GAE to write session
    ((SessionCtrl)sess).notifyClientRequest(keepAlive);

//    if (log.debugable()) log.debug("AU request: "+aureqs);
    final DesktopCtrl desktopCtrl = (DesktopCtrl)desktop;
    final Execution exec =
      new ExecutionImpl(_ctx, 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) {
View Full Code Here

  protected Desktop recoverDesktop(Session sess,
  HttpServletRequest request, HttpServletResponse response,
  WebAppCtrl wappc, String dtid) {
    final FailoverManager failover = wappc.getFailoverManager();
    if (failover != null) {
      Desktop desktop = null;
      try {
        if (failover.isRecoverable(sess, dtid)) {
          desktop = WebManager.getWebManager(_ctx)
            .getDesktop(sess, request, response, null, true);
          if (desktop == null) //forward or redirect
View Full Code Here

      return;
    }

    final Map attrs = new HashMap();
    String alert = null, uuid = null, nextURI = null, sid = null;
    Desktop desktop = null;
    try {
      if (!isMultipartContent(request)) {
        if ("uploadInfo".equals(request.getParameter("cmd"))) {
          uuid = request.getParameter("wid");
          sid = request.getParameter("sid");
          desktop = ((WebAppCtrl)sess.getWebApp()).getDesktopCache(sess).getDesktop(request.getParameter("dtid"));
          Map precent = (Map) desktop.getAttribute(Attributes.UPLOAD_PERCENT);
          Map size = (Map)desktop.getAttribute(Attributes.UPLOAD_SIZE);
          final String key = uuid + '_' + sid;
          Object sinfo = size.get(key);
          if (sinfo instanceof String) {
            response.getWriter().append("error:" + sinfo);
            size.remove(key);
            precent.remove(key);
            return;
          }
          final Integer p = (Integer)precent.get(key);
          final Long cb = (Long)sinfo;
          response.getWriter().append((p != null ? p.intValue(): -1)+ ","
                +(cb != null ? cb.longValue(): -1));
          return;
        } else
          alert = "enctype must be multipart/form-data";
      } else {
        uuid = request.getParameter("uuid");
        sid = request.getParameter("sid");
        if (uuid == null || uuid.length() == 0) {
          alert = "uuid is required!";
        } else {
          attrs.put("uuid", uuid);
          attrs.put("sid", sid);

          final String dtid = request.getParameter("dtid");
          if (dtid == null || dtid.length() == 0) {
            alert = "dtid is required!";
          } else {
            desktop = ((WebAppCtrl)sess.getWebApp())
              .getDesktopCache(sess).getDesktop(dtid);
            final Map params = parseRequest(request, desktop, uuid + '_' + sid);
            nextURI = (String)params.get("nextURI");
           
            // Bug 3054784
            params.put("native", request.getParameter("native"));
            processItems(desktop, params, attrs);
          }
        }
      }
    } catch (Throwable ex) {
      if (uuid == null) {
        uuid = request.getParameter("uuid");
        if (uuid != null)
          attrs.put("uuid", uuid);
      }
      if (nextURI == null)
        nextURI = request.getParameter("nextURI");

      if (ex instanceof ComponentNotFoundException) {
        alert = Messages.get(MZk.UPDATE_OBSOLETE_PAGE, uuid);
      } else if (ex instanceof IOFileUploadException) {
        log.debug("File upload cancelled!");
      } else {
        alert = handleError(ex);
      }

      if (desktop != null) {
        Map precent = (Map) desktop.getAttribute(Attributes.UPLOAD_PERCENT);
        Map size = (Map)desktop.getAttribute(Attributes.UPLOAD_SIZE);
        final String key = uuid + '_' + sid;
        if (precent != null) {
          precent.remove(key);
          size.remove(key);
        }
      }
    }
    if (attrs.get("contentId") == null && alert == null)
      alert = "contentId is required!";
     
    if (alert != null) {
      if (desktop == null) {
        response.setIntHeader("ZK-Error", HttpServletResponse.SC_GONE);
        return;
      }
      Map precent = (Map) desktop.getAttribute(Attributes.UPLOAD_PERCENT);
      Map size = (Map)desktop.getAttribute(Attributes.UPLOAD_SIZE);
      final String key = uuid + '_' + sid;
      if (precent != null) {
        precent.remove(key);
        size.put(key, alert);
      }
View Full Code Here

  /**
   * @param appendable whether the URL is used as a base that can append
   * other URI.
   */
  private String encode(String uri, boolean appendable) {
    final Desktop dt = getDesktop();
    if (uri != null && dt != null) { //if desktop is null, it doesn't belong to any execution
      uri = dt.getExecution().encodeURL(uri);
      final int j = uri.lastIndexOf(";jsession");
      if (j >= 0)
        uri = uri.substring(0, j);
    }
    return uri;
View Full Code Here

      throw new IllegalArgumentException();
    final Execution exec = Executions.getCurrent();
    if (exec == null)
      throw new IllegalStateException("execution required");

    final Desktop desktop = exec.getDesktop();
    synchronized (_dts) {
      boolean startRequired = false;
      DesktopThread dtthd = (DesktopThread)_dts.get(desktop);
      if (dtthd == null) {
        desktop.addListener(new EQCleanup());
          //OK to call addListener since it is the current desktop
        _dts.put(desktop, dtthd = new DesktopThread(desktop));
        startRequired = true;
      }

      dtthd.subscribe(listener, callback, async);

      if (startRequired) {
        if (!desktop.isServerPushEnabled()) {
          dtthd.enableCurrentServerPush();
          desktop.addListener(new EQService(dtthd));
            //add here since desktop is the current desktop
        }
        dtthd.start();
      }
    }
View Full Code Here

TOP

Related Classes of org.zkoss.zk.ui.Desktop

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.