Base class for filters that provides generic initialisation and a simple no-op destruction.
| 30 | * Base class for filters that provides generic initialisation and a simple no-op destruction. |
| 31 | */ |
| 32 | public abstract class FilterBase implements Filter { |
| 33 | |
| 34 | /** |
| 35 | * Default constructor for FilterBase. |
| 36 | */ |
| 37 | public FilterBase() { |
| 38 | // Default constructor |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * StringManager for internationalized strings. |
| 43 | */ |
| 44 | protected static final StringManager sm = StringManager.getManager(FilterBase.class); |
| 45 | |
| 46 | /** |
| 47 | * Returns the logger for this filter. |
| 48 | * |
| 49 | * @return the logger |
| 50 | */ |
| 51 | protected abstract Log getLogger(); |
| 52 | |
| 53 | |
| 54 | /** |
| 55 | * Iterates over the configuration parameters and either logs a warning, or throws an exception for any parameter |
| 56 | * that does not have a matching setter in this filter. |
| 57 | * |
| 58 | * @param filterConfig The configuration information associated with the filter instance being initialised |
| 59 | * |
| 60 | * @throws ServletException if {@link #isConfigProblemFatal()} returns {@code true} and a configured parameter does |
| 61 | * not have a matching setter |
| 62 | */ |
| 63 | @Override |
| 64 | public void init(FilterConfig filterConfig) throws ServletException { |
| 65 | Enumeration<String> paramNames = filterConfig.getInitParameterNames(); |
| 66 | while (paramNames.hasMoreElements()) { |
| 67 | String paramName = paramNames.nextElement(); |
| 68 | if (!IntrospectionUtils.setProperty(this, paramName, filterConfig.getInitParameter(paramName))) { |
| 69 | String msg = sm.getString("filterbase.noSuchProperty", paramName, this.getClass().getName()); |
| 70 | if (isConfigProblemFatal()) { |
| 71 | throw new ServletException(msg); |
| 72 | } else { |
| 73 | getLogger().warn(msg); |
| 74 | } |
| 75 | } |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Determines if an exception when calling a setter or an unknown configuration attribute triggers the failure of |
| 81 | * this filter which in turn will prevent the web application from starting. |
| 82 | * |
| 83 | * @return <code>true</code> if a problem should trigger the failure of this filter, else <code>false</code> |
| 84 | */ |
| 85 | protected boolean isConfigProblemFatal() { |
| 86 | return false; |
| 87 | } |
| 88 | } |
nothing calls this directly
no test coverage detected