DSL stands for (at least here) Dynamic Scripting Languages like Python, Perl, Ruby, Groovy, Beanshell, etc. Mentawai can be extended to support any DSL language for configuration through its abstract class org.mentawai.core.ScriptApplicationManager. Mentawai comes with built-in support for BeanShell through the org.mentawai.core.BshApplicationManager, but support for JRuby, Jython and Groovy may come soon as other people extend ScriptApplicationManager to do so.
The advantages of a DSL may be:
Below we show an example of how to configure your mentawai application with BeanShell. First you have to tell your application that you want to use the BshApplicationManager and not the good and old ApplicationManager which is loaded by default:
<servlet> <servlet-name>Controller</servlet-name> <servlet-class>org.mentawai.core.Controller</servlet-class> <init-param> <param-name>applicationManager</param-name> <param-value>org.mentawai.core.BshApplicationManager</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet>
The BshApplicationManager assumes that your ApplicationManager.bsh script file will be in the /WEB-INF/ directory and that it will contain a method definition for config(appMgr, application), where appMgr is a reference to Mentawai's application manager (org.mentawai.core.ApplicationManager) and application is a reference for the application context (org.mentawai.core.ApplicationContext) of your application. Below is an example of an ApplicationManager.bsh:
import org.mentawai.core.*; import org.mentawai.i18n.*; import org.mentawai.filter.converter.*; import calculator.*; config(appMgr, application) { appMgr.setDebugMode(true); LocaleManager.add(new Locale("pt", "BR")); LocaleManager.add(new Locale("en", "US")); appMgr.action("/calc", CalcAction.class) .on(SUCCESS, fwd("/calc.jsp")) .on(ERROR, fwd("/calc.jsp")) .filter(new CalcValidator()) .filter(new DoubleConverterFilter("numberOne", "numberTwo")); appMgr.action("/calc", CalcAction.class, "multiply") .on(SUCCESS, fwd("/calc.jsp")) .on(ERROR, fwd("/calc.jsp")) .filter(new CalcValidator()) .filter(new DoubleConverterFilter("numberOne", "numberTwo")); }
You can also extend BshApplicationManager if you want to change the default behaviour like the script name, location and method. Check