Filters.java 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import javax.inject.*;
  2. import play.*;
  3. import play.mvc.EssentialFilter;
  4. import play.http.HttpFilters;
  5. import play.mvc.*;
  6. import filters.ExampleFilter;
  7. /**
  8. * This class configures filters that run on every request. This
  9. * class is queried by Play to get a list of filters.
  10. *
  11. * Play will automatically use filters from any class called
  12. * <code>Filters</code> that is placed the root package. You can load filters
  13. * from a different class by adding a `play.http.filters` setting to
  14. * the <code>application.conf</code> configuration file.
  15. */
  16. @Singleton
  17. public class Filters implements HttpFilters {
  18. private final Environment env;
  19. private final EssentialFilter exampleFilter;
  20. /**
  21. * @param env Basic environment settings for the current application.
  22. * @param exampleFilter A demonstration filter that adds a header to
  23. */
  24. @Inject
  25. public Filters(Environment env, ExampleFilter exampleFilter) {
  26. this.env = env;
  27. this.exampleFilter = exampleFilter;
  28. }
  29. @Override
  30. public EssentialFilter[] filters() {
  31. // Use the example filter if we're running development mode. If
  32. // we're running in production or test mode then don't use any
  33. // filters at all.
  34. if (env.mode().equals(Mode.DEV)) {
  35. return new EssentialFilter[] { exampleFilter };
  36. } else {
  37. return new EssentialFilter[] {};
  38. }
  39. }
  40. }