0
|
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 <html>
|
|
46 <head>
|
|
47 <title>Test Macro</title>
|
|
48 </head>
|
|
49 <body>
|
|
50 <form method="post">
|
|
51 <p>Macro:<br/>
|
|
52 <textarea name="macro" rows="30" cols="90" wrap="off">
|
|
53 <macro name="test">
|
|
54
|
|
55 </macro>
|
|
56 </textarea>
|
|
57 </macro>
|
|
58 <p><input type="submit" value="run macro"></p>
|
|
59 </form>
|
|
60 </body>
|
|
61 </html>
|
|
62 <%
|
|
63 return;
|
|
64 }
|
|
65 response.setContentType("text/plain");
|
|
66 List<Module> modules = ModuleManager.getGenericModules();
|
|
67 Source source = Source.getInstance("test", macro);
|
|
68 Module module = new NamlModule( "test", Collections.singleton(source), Collections.<String>emptySet() );
|
|
69 modules.add(module);
|
|
70 Program program = Program.getInstance(modules);
|
|
71 try {
|
|
72 Template template = program.getTemplate("test",
|
|
73 BasicNamespace.class, NabbleNamespace.class, ServletNamespace.class
|
|
74 );
|
|
75 ModuleManager.run( template, out, Collections.<String,Object>emptyMap(),
|
|
76 new BasicNamespace(template), new NabbleNamespace(site), new ServletNamespace(request, response)
|
|
77 );
|
|
78 } catch(CompileException e) {
|
|
79 throw new RuntimeException(e);
|
|
80 }
|
|
81 }
|
|
82
|
|
83 }
|
|
84 %>
|