/** * Sets the FilterConfig <em>and</em> the {@code ServletContext} as attributes of this class for use by * subclasses. That is: * <pre> * this.filterConfig = filterConfig; * setServletContext(filterConfig.getServletContext());</pre> * * @param filterConfig the FilterConfig instance provided by the Servlet container at start-up. */ public void setFilterConfig(FilterConfig filterConfig) { this.filterConfig = filterConfig; setServletContext(filterConfig.getServletContext()); }
/** * Sets the filter's {@link #setFilterConfig filterConfig} and then immediately calls * {@link #onFilterConfigSet() onFilterConfigSet()} to trigger any processing a subclass might wish to perform. * * @param filterConfig the servlet container supplied FilterConfig instance. * @throws javax.servlet.ServletException if {@link #onFilterConfigSet() onFilterConfigSet()} throws an Exception. */ public final void init(FilterConfig filterConfig) throws ServletException { setFilterConfig(filterConfig); try { onFilterConfigSet(); } catch (Exception e) { if (e instanceof ServletException) { throw (ServletException) e; } else { if (log.isErrorEnabled()) { log.error("Unable to start Filter: [" + e.getMessage() + "].", e); } throw new ServletException(e); } } }
/** * Returns the value for the named {@code init-param}, or {@code null} if there was no {@code init-param} * specified by that name. * * @param paramName the name of the {@code init-param} * @return the value for the named {@code init-param}, or {@code null} if there was no {@code init-param} * specified by that name. */ protected String getInitParam(String paramName) { FilterConfig config = getFilterConfig(); if (config != null) { return StringUtils.clean(config.getInitParameter(paramName)); } return null; }
/** * Returns a StringBuilder instance with the {@link #getName() name}, or if the name is {@code null}, just the * {@code super.toStringBuilder()} instance. * * @return a StringBuilder instance to use for appending String data that will eventually be returned from a * {@code toString()} invocation. */ protected StringBuilder toStringBuilder() { String name = getName(); if (name == null) { return super.toStringBuilder(); } else { StringBuilder sb = new StringBuilder(); sb.append(name); return sb; } }