Ejemplo n.º 1
0
 public String locate(String path) {
   try {
     if (path.startsWith("~./")) {
       path =
           Servlets.locate(
               _ctx,
               _request,
               ClassWebResource.PATH_PREFIX + path.substring(2),
               Locators.getDefault());
       return "~." + path.substring(ClassWebResource.PATH_PREFIX.length());
     }
     return Servlets.locate(_ctx, _request, path, null);
   } catch (ServletException ex) {
     throw new UiException(ex);
   }
 }
Ejemplo n.º 2
0
  /**
   * Constructs an execution for the given HTTP request.
   *
   * @param creating which page is being creating for this execution, or null if none is being
   *     created.
   */
  public ExecutionImpl(
      ServletContext ctx,
      HttpServletRequest request,
      HttpServletResponse response,
      Desktop desktop,
      Page creating) {
    super(desktop, creating);
    _ctx = ctx;
    _request = request;
    _response = response;
    _xelctx = new ReqContext();

    Servlets.getBrowser(request); // update request info

    _attrs =
        new AttributesMap() {
          @SuppressWarnings("unchecked")
          protected Enumeration<String> getKeys() {
            return _request.getAttributeNames();
          }

          protected Object getValue(String key) {
            return _request.getAttribute(key);
          }

          protected void setValue(String key, Object val) {
            _request.setAttribute(key, val);
          }

          protected void removeValue(String key) {
            _request.removeAttribute(key);
          }
        };
  }
Ejemplo n.º 3
0
 // -- super --//
 protected long getLastModified(HttpServletRequest request) {
   final String pi = Https.getThisPathInfo(request);
   if (pi != null
       && pi.startsWith(ClassWebResource.PATH_PREFIX)
       && pi.indexOf('*') < 0 // language independent
       && !Servlets.isIncluded(request)) {
     // If a resource extension is registered for the extension,
     // we assume the content is dynamic
     final String ext = Servlets.getExtension(pi, false);
     if (ext == null || getClassWebResource().getExtendlet(ext) == null) {
       if (_lastModified == 0) _lastModified = new Date().getTime();
       // Hard to know when it is modified, so cheat it..
       return _lastModified;
     }
   }
   return -1;
 }
Ejemplo n.º 4
0
 public void include(Writer out, String page, Map<String, ?> params, int mode) throws IOException {
   try {
     if (!dispatch(out, page, params, mode, true))
       Servlets.include(
           _ctx, _request, HttpBufferedResponse.getInstance(_response, out), page, params, mode);
   } catch (ServletException ex) {
     throw new UiException(ex);
   }
 }
  @AfterCompose
  public void afterCompose(@ContextParam(ContextType.VIEW) Component view) {
    Double ie = Servlets.getBrowser(request, "ie");
    if (ie != null && ie < 8.0) {
      Clients.showNotification("This application does not support IE6/7", true);
    }

    Selectors.wireComponents(view, this, false);
  }
  @Init
  public void init() {

    mobile = Servlets.getBrowser(request, "mobile") != null;

    if (mobile) {
      css = "css/tablet.css.dsp";
    } else {
      css = "css/desktop.css.dsp";
    }

    menuGroups =
        new MenuGroupBean[] {
          new MenuGroupBean(
              "MAGAZZINO",
              new ListModelArray<MenuItemBean>(
                  new MenuItemBean[] {
                    new MenuItemBean("images/navigation/menu/articoli24.png", "Articoli"),
                    new MenuItemBean("images/navigation/menu/categorie24.png", "Categorie")
                  })),
          new MenuGroupBean(
              "ANAGRAFICHE",
              new ListModelArray<MenuItemBean>(
                  new MenuItemBean[] {
                    new MenuItemBean("images/navigation/menu/fornitori24.png", "Fornitori"),
                    new MenuItemBean("images/navigation/menu/clienti24.png", "Clienti")
                    //							,
                    //							new MenuItemBean(
                    //									"",
                    //									"Agenti")
                  })),
          new MenuGroupBean(
              "SCADENZE e PAGAMENTI",
              new ListModelArray<MenuItemBean>(
                  new MenuItemBean[] {
                    new MenuItemBean("images/navigation/menu/scadenziario24.png", "Scadenziario"),
                    new MenuItemBean("images/navigation/menu/promemoria24.png", "Promemoria")
                  })),
          new MenuGroupBean(
              "DOCUMENTI",
              new ListModelArray<MenuItemBean>(
                  new MenuItemBean[] {
                    new MenuItemBean(
                        "images/navigation/menu/documenti24.png", "Gestione Documenti"),
                    new MenuItemBean("images/navigation/menu/fatture24.png", "Fatture"),
                    new MenuItemBean("images/navigation/menu/ordini24.png", "Ordini"),
                    new MenuItemBean("images/navigation/menu/preventivi24.png", "Preventivi"),
                    new MenuItemBean(
                        "images/navigation/menu/spedizioni24.png", "Vendita al pubblico")
                  }))
        };

    user = new User();
    user.setUsername(authService.getUserCredential().getUsername());
  }
Ejemplo n.º 7
0
 /** Returns whether the page can be directly included. */
 private static boolean isDirectInclude(ClassWebResource cwr, String path) {
   final String ext = Servlets.getExtension(path);
   final Extendlet extlet = ext != null ? cwr.getExtendlet(ext) : null;
   if (extlet != null) {
     try {
       return extlet.getFeature(Extendlet.ALLOW_DIRECT_INCLUDE);
     } catch (Throwable ex) { // backward compatibility
     }
   }
   return true;
 }
Ejemplo n.º 8
0
  public void forward(Writer out, String page, Map<String, ?> params, int mode) throws IOException {
    final Visualizer uv = getVisualizer();
    // uv is null if it is called in DesktopInit (with TemporaryExecution)
    if (uv != null && uv.isEverAsyncUpdate())
      throw new IllegalStateException("Use sendRedirect instead when processing user's request");

    setVoided(true);

    try {
      if (!dispatch(out, page, params, mode, false))
        Servlets.forward(
            _ctx, _request, HttpBufferedResponse.getInstance(_response, out), page, params, mode);
    } catch (ServletException ex) {
      throw new UiException(ex);
    }
  }
Ejemplo n.º 9
0
  // called by Provider
  InputStream getResourceAsStream(HttpServletRequest request, String path, boolean locate)
      throws IOException, ServletException {
    if (locate)
      path = Servlets.locate(_webctx.getServletContext(), request, path, _webctx.getLocator());

    if (_cache.getCheckPeriod() >= 0) {
      // Due to Web server might cache the result, we use URL if possible
      try {
        URL url = _webctx.getResource(path);
        if (url != null) return url.openStream();
      } catch (Throwable ex) {
        log.warningBriefly("Unable to read from URL: " + path, ex);
      }
    }

    // Note: _webctx will handle the renaming for debugJS (.src.js)
    return _webctx.getResourceAsStream(path);
  }
Ejemplo n.º 10
0
 @Override
 public Double getBrowser(String name) {
   return Servlets.getBrowser(_request, name);
 }
Ejemplo n.º 11
0
 @Override
 public String getBrowser() {
   return Servlets.getBrowser(_request);
 }
Ejemplo n.º 12
0
 /** @deprecated As of release 6.0.0, replaced with {@link #getBrowser(String)}. */
 public boolean isSafari() {
   return Servlets.isSafari(_request);
 }
Ejemplo n.º 13
0
 /** @deprecated As of release 6.0.0, replaced with {@link #getBrowser(String)}. */
 public boolean isHilDevice() {
   return Servlets.isHilDevice(_request);
 }
Ejemplo n.º 14
0
 /** @deprecated As of release 6.0.0, replaced with {@link #getBrowser(String)}. */
 public boolean isGecko3() {
   return Servlets.isGecko3(_request);
 }
Ejemplo n.º 15
0
 /** @deprecated As of release 6.0.0, replaced with {@link #getBrowser(String)}. */
 public boolean isOpera() {
   return Servlets.isOpera(_request);
 }
Ejemplo n.º 16
0
 /** @deprecated As of release 6.0.0, replaced with {@link #getBrowser(String)}. */
 public boolean isRobot() {
   return Servlets.isRobot(_request);
 }
Ejemplo n.º 17
0
 /** @deprecated As of release 6.0.0, replaced with {@link #getBrowser(String)}. */
 public boolean isExplorer7() {
   return Servlets.isExplorer7(_request);
 }
Ejemplo n.º 18
0
 private static boolean shallSession(ClassWebResource cwr, String pi) {
   return cwr.getExtendlet(Servlets.getExtension(pi, false)) != null
       || (pi != null && pi.indexOf('*') >= 0);
   // Optimize the access of static resources (for GAE)
 }
Ejemplo n.º 19
0
 @Override
 public String getUserAgent() {
   return Servlets.getUserAgent(_request);
 }
Ejemplo n.º 20
0
 public boolean isForwarded() {
   return Servlets.isForwarded(_request);
 }
Ejemplo n.º 21
0
 public boolean isIncluded() {
   return Servlets.isIncluded(_request);
 }
Ejemplo n.º 22
0
  /**
   * 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);
  }
Ejemplo n.º 23
0
  /**
   * Loads, parses and returns the resource of the specified URI, or null if not found. The parser
   * is defined by the loader defined in {@link ResourceCache}.
   *
   * @param cache the resource cache. Note: its loader must extend from {@link ResourceLoader}.
   * @param path the URI path
   * @param extra the extra parameter that will be passed to {@link
   *     ResourceLoader#parse(String,File,Object)} and {@link
   *     ResourceLoader#parse(String,URL,Object)}
   */
  public static final <V> V get(
      ResourceCache<V> cache, ServletContext ctx, String path, Object extra) {
    // 20050905: Tom Yeh
    // We don't need to handle the default name if user specifies only a dir
    // because it is handled by the container directly
    // And, web  developer has to specify <welcome-file> in web.xml
    URL url = null;
    if (path == null || path.length() == 0) path = "/";
    else if (path.charAt(0) != '/') {
      if (path.indexOf("://") > 0) {
        try {
          url = new URL(path);
        } catch (java.net.MalformedURLException ex) {
          throw new SystemException(ex);
        }
      } else path = '/' + path;
    }

    if (url == null) {
      if (path.startsWith("/~")) {
        final ServletContext ctx0 = ctx;
        final String path0 = path;
        final int j = path.indexOf('/', 2);
        final String ctxpath;
        if (j >= 0) {
          ctxpath = "/" + path.substring(2, j);
          path = path.substring(j);
        } else {
          ctxpath = "/" + path.substring(2);
          path = "/";
        }

        final ExtendletContext extctx = Servlets.getExtendletContext(ctx, ctxpath.substring(1));
        if (extctx != null) {
          url = extctx.getResource(path);
          //					if (log.debugable()) log.debug("Resolving "+path0+" to "+url);
          if (url == null) return null;
          try {
            return cache.get(new ResourceInfo(path, url, extra));
          } catch (Throwable ex) {
            final IOException ioex = getIOException(ex);
            if (ioex == null) throw SystemException.Aide.wrap(ex);
            log.warningBriefly("Unable to load " + url, ioex);
          }
          return null;
        }

        ctx = ctx.getContext(ctxpath);
        if (ctx == null) { // failed
          //					if (log.debugable()) log.debug("Context not found: "+ctxpath);
          ctx = ctx0;
          path = path0; // restore
        }
      }

      final String flnm = ctx.getRealPath(path);
      if (flnm != null) {
        try {
          return cache.get(new ResourceInfo(path, new File(flnm), extra));
          // it is loader's job to check the existence
        } catch (Throwable ex) {
          final IOException ioex = getIOException(ex);
          if (ioex == null) throw SystemException.Aide.wrap(ex);
          log.warningBriefly("Unable to load " + flnm, ioex);
        }
        return null;
      }
    }

    // try url because some server uses JAR format
    try {
      if (url == null) url = ctx.getResource(path);
      if (url != null) return cache.get(new ResourceInfo(path, url, extra));
    } catch (Throwable ex) {
      final IOException ioex = getIOException(ex);
      if (ioex == null) throw SystemException.Aide.wrap(ex);
      log.warningBriefly("Unable to load " + path, ioex);
    }
    return null;
  }
Ejemplo n.º 24
0
 /** @deprecated As of release 6.0.0, replaced with {@link #getBrowser(String)}. */
 public boolean isBrowser(String type) {
   return Servlets.isBrowser(_request, type);
 }