Exemplo n.º 1
0
  public static Collection<File> getAllResources(ContentContext ctx) {
    GlobalContext globalContext = GlobalContext.getInstance(ctx.getRequest());
    StaticConfig staticConfig = StaticConfig.getInstance(ctx.getRequest().getSession());

    File staticDir =
        new File(
            URLHelper.mergePath(globalContext.getDataFolder(), staticConfig.getStaticFolder()));

    Collection<File> outFiles = new LinkedList<File>();
    getAllResource(outFiles, staticDir);

    return outFiles;
  }
Exemplo n.º 2
0
  /**
   * extract a relative path from a full path.
   *
   * @param application the servlet context.
   * @param fullPath a full path
   * @return retrun a relative path (sample: /var/data/static/test.png -> /test.png)
   */
  public static String extractResourceDir(
      StaticConfig staticConfig, GlobalContext globalContext, String fullPath) {
    String realPath =
        URLHelper.mergePath(globalContext.getDataFolder(), staticConfig.getStaticFolder());

    realPath = ResourceHelper.getLinuxPath(realPath);
    fullPath = ResourceHelper.getLinuxPath(fullPath);

    if (fullPath.startsWith(realPath)) {
      return fullPath.substring(realPath.length());
    }
    return fullPath;
  }