All Downloads are FREE. Search and download functionalities are using the official Maven repository.

co.mewf.humpty.servlet.WildcardHelper Maven / Gradle / Ivy

There is a newer version: 0.3.0
Show newest version
package co.mewf.humpty.servlet;

import co.mewf.humpty.config.Context;

import org.apache.commons.io.FilenameUtils;

class WildcardHelper {

  private final String uri;
  private final Context context;
  private final String extension;

  WildcardHelper(String uri, Context context) {
    this.uri = uri;
    this.context = context;
    this.extension = FilenameUtils.getExtension(uri).isEmpty() ? FilenameUtils.getExtension(uri) : FilenameUtils.getExtension(context.getBundleName());
  }

  public boolean hasWildcard() {
    return uri.contains("*");
  }

  /**
   * @return path of the directory before the first wildcard
   */
  public String getRootDir() {
    String rootDir = uri.substring(0, uri.indexOf('*'));
    if (!rootDir.startsWith("/")) {
      rootDir = "/" + rootDir;
    }

    return rootDir;
  }

  /**
   * @return true if fileName is acceptable within the context of this uri and bundle
   */
  public boolean matches(String fileName) {
    return FilenameUtils.isExtension(fileName, extension);
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy