Esempio n. 1
0
  public static String parsePlaceHolder(String path, ServletContext sc) {
    ResourceProvider frp = ResourcesImpl.getFileResourceProvider();

    if (path == null) return null;
    if (path.indexOf('{') != -1) {
      if (StringUtil.startsWith(path, '{')) {

        // Web Root
        if (path.startsWith("{web-root")) {
          if (path.startsWith("}", 9))
            path =
                frp.getResource(ReqRspUtil.getRootPath(sc))
                    .getRealResource(path.substring(10))
                    .toString();
          else if (path.startsWith("-dir}", 9))
            path =
                frp.getResource(ReqRspUtil.getRootPath(sc))
                    .getRealResource(path.substring(14))
                    .toString();
          else if (path.startsWith("-directory}", 9))
            path =
                frp.getResource(ReqRspUtil.getRootPath(sc))
                    .getRealResource(path.substring(20))
                    .toString();

        } else path = SystemUtil.parsePlaceHolder(path);
      }

      if ((path.indexOf("{web-context-hash}")) != -1) {
        String id = hash(sc);
        path = StringUtil.replace(path, "{web-context-hash}", id, false);
      }
    }
    return path;
  }
Esempio 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);
    }
  }
Esempio n. 3
0
 public static String hash(ServletContext sc) {
   String id = null;
   try {
     id = MD5.getDigestAsString(ReqRspUtil.getRootPath(sc));
   } catch (IOException e) {
   }
   return id;
 }
Esempio n. 4
0
 public static String escapeQSValue(String str) {
   if (!ReqRspUtil.needEncoding(str, false)) return str;
   PageContextImpl pc = (PageContextImpl) ThreadLocalPageContext.get();
   if (pc != null) {
     try {
       return URLEncoder.encode(str, pc.getWebCharset());
     } catch (UnsupportedEncodingException e) {
     }
   }
   return URLEncoder.encode(str);
 }
Esempio n. 5
0
  /**
   * constructor of the class
   *
   * @param configServer
   * @param config
   * @param configDir
   * @param configFile
   * @param cloneServer
   */
  ConfigWebImpl(
      CFMLFactoryImpl factory,
      ConfigServerImpl configServer,
      ServletConfig config,
      Resource configDir,
      Resource configFile) {
    super(configDir, configFile);
    this.configServer = configServer;
    this.config = config;
    this.factory = factory;
    factory.setConfig(this);
    ResourceProvider frp = ResourcesImpl.getFileResourceProvider();

    this.rootDir = frp.getResource(ReqRspUtil.getRootPath(config.getServletContext()));

    // Fix for tomcat
    if (this.rootDir.getName().equals(".") || this.rootDir.getName().equals(".."))
      this.rootDir = this.rootDir.getParentResource();
  }