use of org.openmrs.module.web.filter.ModuleFilterConfig in project openmrs-core by openmrs.
the class WebModuleUtil method loadFilters.
/**
* This method will initialize and store this module's filters
*
* @param module - The Module to load and register Filters
* @param servletContext - The servletContext within which this method is called
*/
public static void loadFilters(Module module, ServletContext servletContext) {
// Load Filters
Map<String, Filter> filters = new HashMap<>();
try {
for (ModuleFilterDefinition def : ModuleFilterDefinition.retrieveFilterDefinitions(module)) {
if (moduleFiltersByName.containsKey(def.getFilterName())) {
throw new ModuleException("A filter with name <" + def.getFilterName() + "> has already been registered.");
}
ModuleFilterConfig config = ModuleFilterConfig.getInstance(def, servletContext);
Filter f = (Filter) ModuleFactory.getModuleClassLoader(module).loadClass(def.getFilterClass()).newInstance();
f.init(config);
filters.put(def.getFilterName(), f);
}
} catch (ModuleException e) {
throw e;
} catch (Exception e) {
throw new ModuleException("An error occurred initializing Filters for module: " + module.getModuleId(), e);
}
moduleFilters.put(module, filters.values());
moduleFiltersByName.putAll(filters);
log.debug("Module: " + module.getModuleId() + " successfully loaded " + filters.size() + " filters.");
// Load Filter Mappings
List<ModuleFilterMapping> modMappings = ModuleFilterMapping.retrieveFilterMappings(module);
moduleFilterMappings.addAll(modMappings);
log.debug("Module: " + module.getModuleId() + " successfully loaded " + modMappings.size() + " filter mappings.");
}
Aggregations