1 package com.atlassian.plugin.servlet.filter;
2
3 import javax.annotation.Nonnull;
4 import java.util.Locale;
5
6 /**
7 * An enumeration defining the places plugin filters can appear in an applications filter stack. The locations are
8 * defined by what operations they immediate precede or follow.
9 *
10 * @since 2.1.0
11 */
12 public enum FilterLocation {
13 AFTER_ENCODING,
14 BEFORE_LOGIN,
15 BEFORE_DECORATION,
16 BEFORE_DISPATCH;
17
18 /**
19 * Parses a filter location from a string. Characters are converted to uppercase, and dashes into underscores.
20 *
21 * @param value The filter location as a string
22 * @return The matching filter location. Will never be null.
23 * @throws IllegalArgumentException If the filter string is null or can't be matched to a filter location enum
24 */
25 @Nonnull
26 public static FilterLocation parse(String value) throws IllegalArgumentException {
27 if (value != null) {
28 return FilterLocation.valueOf(value.toUpperCase(Locale.ENGLISH).replace('-', '_'));
29 } else {
30 throw new IllegalArgumentException("Invalid filter location: null");
31 }
32 }
33 }