Ejemplo n.º 1
0
    public boolean accept(Resource res) {

      if (res.isDirectory()) return allowDir;

      // load content
      String str = null;
      try {
        str = IOUtil.toString(res, "UTF-8");
      } catch (IOException e) {
        return false;
      }

      int index = str.indexOf(':');
      if (index != -1) {
        long expires = Caster.toLongValue(str.substring(0, index), -1L);
        // check is for backward compatibility, old files have no expires date inside. they do ot
        // expire
        if (expires != -1) {
          if (expires < System.currentTimeMillis()) {
            return true;
          }
          str = str.substring(index + 1);
          return false;
        }
      }
      // old files not having a timestamp inside
      else if (res.lastModified() <= time) {
        return true;
      }
      return false;
    }
Ejemplo n.º 2
0
  public static void include(
      PageContext pc, ServletRequest req, ServletResponse rsp, String relPath)
      throws ServletException, IOException {
    relPath = optimizeRelPath(pc, relPath);
    boolean inline = HttpServletResponseWrap.get();
    // print.out(rsp+":"+pc.getResponse());
    RequestDispatcher disp = getRequestDispatcher(pc, relPath);

    if (inline) {
      // RequestDispatcher disp = getRequestDispatcher(pc,relPath);
      disp.include(req, rsp);
      return;
    }

    try {
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      HttpServletResponseWrap hsrw = new HttpServletResponseWrap(pc.getHttpServletResponse(), baos);
      HttpServletResponseWrap.set(true);

      // RequestDispatcher disp = getRequestDispatcher(pc,relPath);

      disp.include(req, hsrw);
      if (!hsrw.isCommitted()) hsrw.flushBuffer();
      pc.write(IOUtil.toString(baos.toByteArray(), ReqRspUtil.getCharacterEncoding(pc, hsrw)));
    } finally {
      HttpServletResponseWrap.release();
      ThreadLocalPageContext.register(pc);
    }
  }