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

org.javalite.activeweb.IgnoreSpec Maven / Gradle / Ivy

There is a newer version: 3.5-j11
Show newest version
package org.javalite.activeweb;

import org.javalite.app_config.AppConfig;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* Created by igor on 4/29/14.
*/
public class IgnoreSpec {
    private List ignorePatterns = new ArrayList<>();
    private String exceptEnvironment;

    IgnoreSpec(String[] ignores){
        for (String ignore : ignores) {
            ignorePatterns.add(Pattern.compile(ignore));
        }
    }

    protected boolean ignores(String path){
        boolean matches = false;
        for (Pattern pattern : ignorePatterns) {
            Matcher m = pattern.matcher(path);
            matches = m.matches();
            if (matches && exceptEnvironment != null
                    && exceptEnvironment.equals(AppConfig.activeEnv())) {
                matches = false; //-- need to ignore
            }
        }
        return matches;
    }

    /**
     * Sets an environment in which NOT TO ignore a URI. Typical use is to process some URIs in
     * development environment, such as compile CSS, or do special image processing. In other environments,
     * this URL will be ignored, given that resource is pre-processed and available from container.
     *
     * @param environment name of environment in which NOT to ignore this URI.
     */
    public void exceptIn(String environment){
        this.exceptEnvironment = environment;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy