use of org.directwebremoting.AjaxFilter in project ma-core-public by infiniteautomation.
the class AnnotationsConfigurator method processGlobalFilter.
/**
* Global Filters apply to all classes
* @param clazz The class to use as a filter
* @param globalFilterAnn The filter annotation
* @param container The IoC container to configure
* @throws InstantiationException In case we can't create the given clazz
* @throws IllegalAccessException In case we can't create the given clazz
*/
private void processGlobalFilter(Class<?> clazz, GlobalFilter globalFilterAnn, Container container) throws InstantiationException, IllegalAccessException {
if (!AjaxFilter.class.isAssignableFrom(clazz)) {
throw new IllegalArgumentException(clazz.getName() + " is not an AjaxFilter implementation");
}
Map<String, String> filterParams = getParamsMap(globalFilterAnn.params());
AjaxFilter filter = (AjaxFilter) clazz.newInstance();
if (filter != null) {
LocalUtil.setParams(filter, filterParams, null);
AjaxFilterManager filterManager = (AjaxFilterManager) container.getBean(AjaxFilterManager.class.getName());
filterManager.addAjaxFilter(filter);
}
}
use of org.directwebremoting.AjaxFilter in project ma-core-public by infiniteautomation.
the class AnnotationsConfigurator method processFilter.
/**
* Process the @Filter annotaion
* @param filterAnn The filter annotation
* @param name The Javascript name of the class to filter
* @param container The IoC container to configure
*/
private void processFilter(Filter filterAnn, String name, Container container) {
Map<String, String> filterParams = getParamsMap(filterAnn.params());
AjaxFilter filter = (AjaxFilter) LocalUtil.classNewInstance(name, filterAnn.type().getName(), AjaxFilter.class);
if (filter != null) {
LocalUtil.setParams(filter, filterParams, null);
AjaxFilterManager filterManager = (AjaxFilterManager) container.getBean(AjaxFilterManager.class.getName());
filterManager.addAjaxFilter(filter, name);
}
}
use of org.directwebremoting.AjaxFilter in project ma-core-public by infiniteautomation.
the class SpringConfigurator method configure.
/* (non-Javadoc)
* @see org.directwebremoting.Configurator#configure(org.directwebremoting.Container)
*/
public void configure(Container container) {
AccessControl accessControl = (AccessControl) container.getBean(AccessControl.class.getName());
AjaxFilterManager ajaxFilterManager = (AjaxFilterManager) container.getBean(AjaxFilterManager.class.getName());
ConverterManager converterManager = (ConverterManager) container.getBean(ConverterManager.class.getName());
CreatorManager creatorManager = (CreatorManager) container.getBean(CreatorManager.class.getName());
// Configure the creator types
if (creatorTypes != null) {
for (Iterator it = creatorTypes.entrySet().iterator(); it.hasNext(); ) {
Map.Entry entry = (Map.Entry) it.next();
String typeName = (String) entry.getKey();
String className = (String) entry.getValue();
creatorManager.addCreatorType(typeName, className);
}
}
// Configure the converter types
if (converterTypes != null) {
for (Iterator it = converterTypes.entrySet().iterator(); it.hasNext(); ) {
Map.Entry entry = (Map.Entry) it.next();
String typeName = (String) entry.getKey();
String className = (String) entry.getValue();
converterManager.addConverterType(typeName, className);
}
}
// Configure the creators
if (creators != null) {
try {
for (Iterator it = creators.entrySet().iterator(); it.hasNext(); ) {
Map.Entry entry = (Map.Entry) it.next();
String scriptName = (String) entry.getKey();
CreatorConfig creatorConfig = (CreatorConfig) entry.getValue();
if (creatorConfig.getCreator() != null) {
Creator creator = creatorConfig.getCreator();
creatorManager.addCreator(scriptName, creator);
} else {
String creatorName = creatorConfig.getCreatorType();
Map params = creatorConfig.getParams();
creatorManager.addCreator(scriptName, creatorName, params);
}
List excludes = creatorConfig.getExcludes();
for (Iterator eit = excludes.iterator(); eit.hasNext(); ) {
String exclude = (String) eit.next();
accessControl.addExcludeRule(scriptName, exclude);
}
List includes = creatorConfig.getIncludes();
for (Iterator iit = includes.iterator(); iit.hasNext(); ) {
String include = (String) iit.next();
accessControl.addIncludeRule(scriptName, include);
}
Properties auth = creatorConfig.getAuth();
for (Iterator ait = auth.entrySet().iterator(); ait.hasNext(); ) {
Map.Entry aentry = (Map.Entry) ait.next();
String methodName = (String) aentry.getKey();
String role = (String) aentry.getValue();
accessControl.addRoleRestriction(scriptName, methodName, role);
}
List filters = creatorConfig.getFilters();
for (Iterator fit = filters.iterator(); fit.hasNext(); ) {
Object obj = fit.next();
if (obj instanceof String) {
String filterName = (String) obj;
AjaxFilter filter = (AjaxFilter) LocalUtil.classNewInstance(filterName, filterName, AjaxFilter.class);
if (filter != null) {
ajaxFilterManager.addAjaxFilter(filter, scriptName);
}
} else if (obj instanceof AjaxFilter) {
AjaxFilter filter = (AjaxFilter) obj;
ajaxFilterManager.addAjaxFilter(filter, scriptName);
} else {
throw new IllegalArgumentException(Messages.getString("SpringConfigurator.InvalidFilter", scriptName, obj));
}
}
}
} catch (Exception ex) {
ex.printStackTrace();
throw new IllegalArgumentException(ex.toString());
}
}
// Configure the converters
if (converters != null) {
try {
for (Iterator it = converters.entrySet().iterator(); it.hasNext(); ) {
Map.Entry entry = (Map.Entry) it.next();
String match = (String) entry.getKey();
ConverterConfig converterConfig = (ConverterConfig) entry.getValue();
Map params = converterConfig.getParams();
if (converterConfig.getIncludes().size() > 0) {
params.put("include", StringUtils.collectionToCommaDelimitedString(converterConfig.getIncludes()));
}
if (converterConfig.getExcludes().size() > 0) {
params.put("exclude", StringUtils.collectionToCommaDelimitedString(converterConfig.getExcludes()));
}
// params.put("force", Boolean.valueOf(converterConfig.isForce()));
if (StringUtils.hasText(converterConfig.getJavascriptClassName())) {
params.put("javascript", converterConfig.getJavascriptClassName());
}
converterManager.addConverter(match, converterConfig.getType(), params);
}
} catch (Exception ex) {
throw new IllegalArgumentException(Messages.getString("SpringConfigurator.ConfigureConverterError"));
}
}
// Configure the signatures
if (StringUtils.hasText(signatures)) {
SignatureParser sigp = new SignatureParser(converterManager, creatorManager);
sigp.parse(signatures);
}
}
use of org.directwebremoting.AjaxFilter in project ma-core-public by infiniteautomation.
the class FluentConfigurator method flush.
/**
* Takes and configuration that is in progress and calls methods on the
* various objects to enable that configuration.
*/
private void flush() {
switch(state) {
case STATE_INIT_CONVERT:
// do nothing;
break;
case STATE_INIT_CREATE:
// do nothing;
break;
case STATE_ALLOW_CONVERT:
try {
if (params == null) {
converterManager.addConverter(match, converter, EMPTY_MAP);
} else {
converterManager.addConverter(match, converter, params);
}
} catch (Exception e) {
log.warn("Failed to add converter of type='" + converter + "', match=" + match + ": ", e);
}
params = null;
match = null;
converter = null;
break;
case STATE_ALLOW_CREATE:
try {
if (params == null) {
creatorManager.addCreator(scriptName, typeName, EMPTY_MAP);
} else {
creatorManager.addCreator(scriptName, typeName, params);
}
if (filters != null) {
for (Iterator it = filters.iterator(); it.hasNext(); ) {
String className = (String) it.next();
AjaxFilter filter = (AjaxFilter) LocalUtil.classNewInstance(scriptName, className, AjaxFilter.class);
if (filter != null) {
LocalUtil.setParams(filter, Collections.EMPTY_MAP, Collections.EMPTY_LIST);
ajaxFilterManager.addAjaxFilter(filter, scriptName);
}
}
}
} catch (Exception e) {
log.warn("Failed to add creator of type='" + typeName + "', scriptName=" + scriptName + ": ", e);
}
params = null;
scriptName = null;
typeName = null;
filters = null;
break;
case STATE_ALLOW_FILTER:
try {
Class impl = LocalUtil.classForName(filterClassName);
AjaxFilter object = (AjaxFilter) impl.newInstance();
if (params != null) {
LocalUtil.setParams(object, params, Collections.EMPTY_LIST);
}
ajaxFilterManager.addAjaxFilter(object);
} catch (ClassCastException ex) {
log.error(filterClassName + " does not implement " + AjaxFilter.class.getName(), ex);
} catch (NoClassDefFoundError ex) {
log.info("Missing class for filter (class='" + filterClassName + "'). Cause: " + ex.getMessage());
} catch (Exception ex) {
log.error("Failed to add filter: class=" + filterClassName, ex);
}
params = null;
filterClassName = null;
break;
case STATE_SIGNATURE:
if (signature != null && signature.length() > 0) {
SignatureParser sigp = new SignatureParser(converterManager, creatorManager);
sigp.parse(signature.toString());
}
break;
default:
break;
}
}
use of org.directwebremoting.AjaxFilter in project ma-core-public by infiniteautomation.
the class DwrXmlConfigurator method loadFilter.
/**
* Internal method to load the convert element
* @param allower The element to read
*/
private void loadFilter(Element allower) {
String type = allower.getAttribute(ATTRIBUTE_CLASS);
try {
Class impl = LocalUtil.classForName(type);
AjaxFilter object = (AjaxFilter) impl.newInstance();
LocalUtil.setParams(object, createSettingMap(allower), ignore);
ajaxFilterManager.addAjaxFilter(object);
} catch (ClassCastException ex) {
log.error(type + " does not implement " + AjaxFilter.class.getName(), ex);
} catch (NoClassDefFoundError ex) {
log.info("Missing class for filter (class='" + type + "'). Cause: " + ex.getMessage());
} catch (Exception ex) {
log.error("Failed to add filter: class=" + type, ex);
}
}
Aggregations