Mercurial Hosting > nabble
view src/nabble/view/web/tools/TestMacro.jtp @ 62:4674ed7d56df default tip
remove n2
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sat, 30 Sep 2023 20:25:29 -0600 |
parents | 7ecd1a4ef557 |
children |
line wrap: on
line source
<% package nabble.view.web.tools; import java.io.IOException; import java.io.PrintWriter; import java.util.Collections; import java.util.Map; import java.util.List; import java.util.ArrayList; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import fschmidt.html.Html; import fschmidt.util.servlet.JtpContext; import nabble.naml.namespaces.BasicNamespace; import nabble.naml.compiler.Template; import nabble.naml.compiler.Program; import nabble.naml.compiler.CommandSpec; import nabble.naml.compiler.IPrintWriter; import nabble.naml.compiler.ScopedInterpreter; import nabble.naml.compiler.CompileException; import nabble.naml.compiler.Source; import nabble.model.Site; import nabble.model.ModelHome; import nabble.view.lib.Jtp; import nabble.view.web.template.NabbleNamespace; import nabble.view.web.template.ServletNamespace; import nabble.view.web.template.NodeNamespace; import nabble.modules.ModuleManager; import nabble.modules.NamlModule; import nabble.naml.compiler.Module; public final class TestMacro extends HttpServlet { protected void service(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getWriter(); Site site = Jtp.getSiteNotNull(request); final String macro = request.getParameter("macro"); if( macro==null ) { %> <html> <head> <title>Test Macro</title> </head> <body> <form method="post"> <p>Macro:<br/> <textarea name="macro" rows="30" cols="90" wrap="off"> <macro name="test"> </macro> </textarea> </macro> <p><input type="submit" value="run macro"></p> </form> </body> </html> <% return; } response.setContentType("text/plain"); List<Module> modules = ModuleManager.getGenericModules(); Source source = Source.getInstance("test", macro); Module module = new NamlModule( "test", Collections.singleton(source), Collections.<String>emptySet() ); modules.add(module); Program program = Program.getInstance(modules); try { Template template = program.getTemplate("test", BasicNamespace.class, NabbleNamespace.class, ServletNamespace.class ); ModuleManager.run( template, out, Collections.<String,Object>emptyMap(), new BasicNamespace(template), new NabbleNamespace(site), new ServletNamespace(request, response) ); } catch(CompileException e) { throw new RuntimeException(e); } } } %>