comparison src/nabble/view/web/tools/TestMacro.java @ 0:7ecd1a4ef557

add content
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 21 Mar 2019 19:15:52 -0600
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:7ecd1a4ef557
1
2 package nabble.view.web.tools;
3
4 import java.io.IOException;
5 import java.io.PrintWriter;
6 import java.util.Collections;
7 import java.util.Map;
8 import java.util.List;
9 import java.util.ArrayList;
10 import javax.servlet.ServletException;
11 import javax.servlet.http.HttpServlet;
12 import javax.servlet.http.HttpServletRequest;
13 import javax.servlet.http.HttpServletResponse;
14 import fschmidt.html.Html;
15 import fschmidt.util.servlet.JtpContext;
16 import nabble.naml.namespaces.BasicNamespace;
17 import nabble.naml.compiler.Template;
18 import nabble.naml.compiler.Program;
19 import nabble.naml.compiler.CommandSpec;
20 import nabble.naml.compiler.IPrintWriter;
21 import nabble.naml.compiler.ScopedInterpreter;
22 import nabble.naml.compiler.CompileException;
23 import nabble.naml.compiler.Source;
24 import nabble.model.Site;
25 import nabble.model.ModelHome;
26 import nabble.view.lib.Jtp;
27 import nabble.view.web.template.NabbleNamespace;
28 import nabble.view.web.template.ServletNamespace;
29 import nabble.view.web.template.NodeNamespace;
30 import nabble.modules.ModuleManager;
31 import nabble.modules.NamlModule;
32 import nabble.naml.compiler.Module;
33
34
35 public final class TestMacro extends HttpServlet {
36
37 protected void service(HttpServletRequest request,HttpServletResponse response)
38 throws ServletException, IOException
39 {
40 PrintWriter out = response.getWriter();
41 Site site = Jtp.getSiteNotNull(request);
42 final String macro = request.getParameter("macro");
43 if( macro==null ) {
44
45 out.print( "\r\n<html>\r\n<head>\r\n<title>Test Macro</title>\r\n</head>\r\n<body>\r\n<form method=\"post\">\r\n<p>Macro:<br/>\r\n<textarea name=\"macro\" rows=\"30\" cols=\"90\" wrap=\"off\">\r\n<macro name=\"test\">\r\n\r\n</macro>\r\n</textarea>\r\n</macro>\r\n<p><input type=\"submit\" value=\"run macro\"></p>\r\n</form>\r\n</body>\r\n</html>\r\n" );
46
47 return;
48 }
49 response.setContentType("text/plain");
50 List<Module> modules = ModuleManager.getGenericModules();
51 Source source = Source.getInstance("test", macro);
52 Module module = new NamlModule( "test", Collections.singleton(source), Collections.<String>emptySet() );
53 modules.add(module);
54 Program program = Program.getInstance(modules);
55 try {
56 Template template = program.getTemplate("test",
57 BasicNamespace.class, NabbleNamespace.class, ServletNamespace.class
58 );
59 ModuleManager.run( template, out, Collections.<String,Object>emptyMap(),
60 new BasicNamespace(template), new NabbleNamespace(site), new ServletNamespace(request, response)
61 );
62 } catch(CompileException e) {
63 throw new RuntimeException(e);
64 }
65 }
66
67 }
68