Package org.zkoss.zk.ui.sys

Examples of org.zkoss.zk.ui.sys.WebAppCtrl


   */
  private void process(Session sess,
  HttpServletRequest request, HttpServletResponse response,
  PageDefinition pagedef, String path) throws ServletException, IOException {
    final WebApp wapp = sess.getWebApp();
    final WebAppCtrl wappc = (WebAppCtrl)wapp;

    final Desktop desktop =
      getWebManager().getDesktop(sess, request, response, path, true);
    if (desktop == null) //forward or redirect
      return;

    final RequestInfo ri = new RequestInfoImpl(
      wapp, sess, desktop, request, PageDefinitions.getLocator(wapp, path));

    final boolean compress = _webctx.shallCompress(request, "zul");
    final Page page = WebManager.newPage(
      wappc.getUiFactory(), ri, pagedef, response, path);
    final Execution exec = new ExecutionImpl(
      getServletContext(), request, response, desktop, page);
    final Writer out = compress ? (Writer)new StringWriter(): response.getWriter();
    wappc.getUiEngine().execNewPage(exec, pagedef, page, out);

    if (compress) {
      final String result = ((StringWriter)out).toString();

      try {
View Full Code Here


  protected boolean process(Session sess,
  HttpServletRequest request, HttpServletResponse response, String path,
  boolean bRichlet)
  throws ServletException, IOException {
    final WebApp wapp = sess.getWebApp();
    final WebAppCtrl wappc = (WebAppCtrl)wapp;
    final Configuration config = wapp.getConfiguration();

    final boolean bInclude = Servlets.isIncluded(request);
    final boolean compress = _compress && !bInclude;
    final Writer out = compress ? (Writer)new StringWriter(): response.getWriter();
    final DesktopRecycle dtrc = bInclude ? null: config.getDesktopRecycle();
    Desktop desktop = dtrc != null ?
      Utils.beforeService(dtrc, _ctx, sess, request, response, path): null;

    try {
      if (desktop != null) { //recycle
        final Page page = Utils.getMainPage(desktop);
        if (page != null) {
          final Execution exec = new ExecutionImpl(
            _ctx, request, response, desktop, page);
          _webman.setDesktop(request, desktop);
          wappc.getUiEngine().recycleDesktop(exec, page, out);
        } else
          desktop = null; //something wrong (not possible; just in case)
      }
      if (desktop == null) {
        desktop = _webman.getDesktop(sess, request, response, path, true);
        if (desktop == null) //forward or redirect
          return true;

        final RequestInfo ri = new RequestInfoImpl(
          wapp, sess, desktop, request,
          PageDefinitions.getLocator(wapp, path));
        sess.setAttribute(Attributes.GAE_FIX, new Integer(0));
        ((SessionCtrl)sess).notifyClientRequest(true);

        final UiFactory uf = wappc.getUiFactory();
        if (uf.isRichlet(ri, bRichlet)) {
          final Richlet richlet = uf.getRichlet(ri, path);
          if (richlet == null)
            return false; //not found

          final Page page = WebManager.newPage(uf, ri, richlet, response, path);
          final Execution exec = new ExecutionImpl(
            _ctx, request, response, desktop, page);
          wappc.getUiEngine().execNewPage(exec, richlet, page, out);
            //no need to set device type here, since UiEngine will do it later
        } else {
          final PageDefinition pagedef = uf.getPageDefinition(ri, path);
          if (pagedef == null)
            return false; //not found

          final Page page = WebManager.newPage(uf, ri, pagedef, response, path);
          final Execution exec = new ExecutionImpl(
            _ctx, request, response, desktop, page);
          wappc.getUiEngine().execNewPage(exec, pagedef, page, out);
        }
      }

      if (compress) {
        final String result = ((StringWriter)out).toString();
View Full Code Here

  throws ServletException, IOException {
    if (log.debugable()) log.debug("Content to filter:\n"+content);

    final WebManager webman = WebManager.getWebManager(_ctx);
    final WebApp wapp = webman.getWebApp();
    final WebAppCtrl wappc = (WebAppCtrl)wapp;
    final Session sess = webman.getSession(_ctx, request);
    final Object old = I18Ns.setup(sess, request, response, _charset);
    try {
      final String path = Https.getThisServletPath(request);
      final Desktop desktop =
        webman.getDesktop(sess, request, response, path, true);
      if (desktop == null) //forward or redirect
        return;

      final RequestInfo ri = new RequestInfoImpl(
        wapp, sess, desktop, request, null);
      ((SessionCtrl)sess).notifyClientRequest(true);
      final UiFactory uf = wappc.getUiFactory();
      final PageDefinition pagedef =
        uf.getPageDefinitionDirectly(ri, content, _ext);

      final Page page = WebManager.newPage(uf, ri, pagedef, response, path);
      final Execution exec =
        new ExecutionImpl(_ctx, request, response, desktop, page);
      final StringWriter out = new StringWriter(4096*2);
      wappc.getUiEngine().execNewPage(exec, pagedef, page, out);

      //bug 1738368: Jetty refuses wrong content length
      //so we have to calculate it again here
      //(Note: we have to set content length since the servlet
      //being filtering might set content-length, which is,
View Full Code Here

      webman = new WebManager(ctx, updateURI);
    }

    final Session sess = WebManager.getSession(ctx, request);
    final WebApp wapp = sess.getWebApp();
    final WebAppCtrl wappc = (WebAppCtrl)wapp;
    final Object old = I18Ns.setup(sess, request, response,
      wapp.getConfiguration().getResponseCharset());
    Execution exec = null;
    try {
      final Desktop desktop = webman.getDesktop(sess, request, response, path, true);
      if (desktop == null) //forward or redirect
        return;

      final RequestInfo ri = new RequestInfoImpl(
        wapp, sess, desktop, request,
        PageDefinitions.getLocator(wapp, path));
      sess.setAttribute(Attributes.GAE_FIX, new Integer(0));
      ((SessionCtrl)sess).notifyClientRequest(true);

      final UiFactory uf = wappc.getUiFactory();
      final Richlet richlet = new StandaloneRichlet(comp);

      final Page page = WebManager.newPage(uf, ri, richlet, response, path);
      exec = new ExecutionImpl(ctx, request, response, desktop, page);
      exec.setAttribute(Attributes.PAGE_REDRAW_CONTROL, "page");
      exec.setAttribute(Attributes.PAGE_RENDERER, new PageRenderer(exec));

      wappc.getUiEngine().execNewPage(exec, richlet, page, out);
          //no need to set device type here, since UiEngine will do it later
    } finally {
      I18Ns.cleanup(request, old);
      if (exec != null) {
        exec.removeAttribute(Attributes.PAGE_REDRAW_CONTROL);
View Full Code Here

  RenderResponse response, String path, boolean bRichlet)
  throws PortletException, IOException {
    if (D.ON && log.debugable()) log.debug("Creates from "+path);
    final WebManager webman = getWebManager();
    final WebApp wapp = webman.getWebApp();
    final WebAppCtrl wappc = (WebAppCtrl)wapp;

    final HttpServletRequest httpreq = RenderHttpServletRequest.getInstance(request);
    final HttpServletResponse httpres = RenderHttpServletResponse.getInstance(response);
    final ServletContext svlctx = (ServletContext)wapp.getNativeContext();

    final DesktopRecycle dtrc = wapp.getConfiguration().getDesktopRecycle();
    Desktop desktop = dtrc != null ? Utils.beforeService(dtrc, svlctx, sess, httpreq, httpres, path): null;

    try {
      if (desktop != null) { //recycle
        final Page page = Utils.getMainPage(desktop);
        if (page != null) {
          final Execution exec =
            new ExecutionImpl(svlctx, httpreq, httpres, desktop, page);
          fixContentType(response);
          wappc.getUiEngine()
            .recycleDesktop(exec, page, response.getWriter());
        } else
          desktop = null; //something wrong (not possible; just in case)
      }

      if (desktop == null) {
        desktop = webman.getDesktop(sess, httpreq, httpres, path, true);
        if (desktop == null) //forward or redirect
          return true;

        final RequestInfo ri = new RequestInfoImpl(
          wapp, sess, desktop, httpreq,
          PageDefinitions.getLocator(wapp, path));
        ((SessionCtrl)sess).notifyClientRequest(true);

        final Page page;
        final PageRenderPatch patch = getRenderPatch();
        final Writer out = patch.beforeRender(ri);
        final UiFactory uf = wappc.getUiFactory();
        if (uf.isRichlet(ri, bRichlet)) {
          final Richlet richlet = uf.getRichlet(ri, path);
          if (richlet == null)
            return false; //not found

          page = WebManager.newPage(uf, ri, richlet, httpres, path);
          final Execution exec =
            new ExecutionImpl(svlctx, httpreq, httpres, desktop, page);
          fixContentType(response);
          wappc.getUiEngine().execNewPage(exec, richlet, page,
            out != null ? out: response.getWriter());
        } else if (path != null) {
          final PageDefinition pagedef = uf.getPageDefinition(ri, path);
          if (pagedef == null)
            return false; //not found

          page = WebManager.newPage(uf, ri, pagedef, httpres, path);
          final Execution exec =
            new ExecutionImpl(svlctx, httpreq, httpres, desktop, page);
          fixContentType(response);
          wappc.getUiEngine().execNewPage(exec, pagedef, page,
            out != null ? out: response.getWriter());
        } else
          return true; //nothing to do

        if (out != null)
View Full Code Here

      setDeviceType(deviceType);

    final Configuration config = _wapp.getConfiguration();
    _exec = exec; //fake
    try {
      final WebAppCtrl wappc = (WebAppCtrl)_wapp;
      final DesktopCache dc = _sess != null ? wappc.getDesktopCache(_sess): null;
        //_sess is null if in a working thread
      final IdGenerator idgen = wappc.getIdGenerator();
      if (idgen != null)
        _id = idgen.nextDesktopId(this);
      if (_id == null)
        _id = nextDesktopId(dc);
      else if (idgen != null)
View Full Code Here

    Media media;
    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);
View Full Code Here

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

    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) {
      log.warning(ex.getMessage());
      response.setHeader("ZK-SID", sid);
      response.setIntHeader("ZK-Error", AuResponse.SC_OUT_OF_SEQUENCE);
    }
View Full Code Here

TOP

Related Classes of org.zkoss.zk.ui.sys.WebAppCtrl

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.