1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.seasar.tuigwaa.view;
17
18 import java.io.IOException;
19 import java.io.PrintWriter;
20 import java.io.StringWriter;
21
22 import javax.servlet.ServletException;
23 import javax.servlet.http.HttpServletRequest;
24 import javax.servlet.http.HttpServletResponse;
25 import javax.servlet.http.HttpServletResponseWrapper;
26
27 import org.seasar.framework.container.factory.SingletonS2ContainerFactory;
28
29 public class JspEngine {
30
31 public static String parse(String path) {
32
33 StringWriter swriter = new StringWriter();
34 PrintWriter writer = new PrintWriter(swriter);
35
36 HttpServletRequest req = SingletonS2ContainerFactory.getContainer()
37 .getRequest();
38 HttpServletResponse res = SingletonS2ContainerFactory.getContainer()
39 .getResponse();
40
41 try {
42 req.getRequestDispatcher(path).include(req,
43 new Response(res, writer));
44 } catch (ServletException e) {
45 e.printStackTrace();
46 } catch (IOException e) {
47 e.printStackTrace();
48 }
49
50 String ret = swriter.toString();
51 return ret;
52 }
53
54 static class Response extends HttpServletResponseWrapper {
55
56 private PrintWriter writer;
57
58 public Response(HttpServletResponse response, PrintWriter writer) {
59 super(response);
60 this.writer = writer;
61 }
62
63 public PrintWriter getWriter() throws IOException {
64 return writer;
65 }
66 }
67 }