1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sourceforge.jeuclid.testsuite;
20
21 import java.io.IOException;
22 import java.io.InputStream;
23 import java.io.OutputStream;
24
25 import javax.servlet.ServletException;
26 import javax.servlet.http.HttpServlet;
27 import javax.servlet.http.HttpServletRequest;
28 import javax.servlet.http.HttpServletResponse;
29 import javax.xml.transform.Result;
30 import javax.xml.transform.Source;
31 import javax.xml.transform.stream.StreamResult;
32 import javax.xml.transform.stream.StreamSource;
33
34
35
36
37
38
39
40 public class Servlet3 extends HttpServlet {
41
42 private static final int BLOCK_SIZE = 4096;
43
44
45
46
47 private static final long serialVersionUID = 1L;
48
49 private static final TestSuiteProcessor TSP = TestSuiteProcessor
50 .getInstance();
51
52
53
54
55 public Servlet3() {
56 }
57
58
59 @Override
60 protected void doGet(final HttpServletRequest req,
61 final HttpServletResponse resp) throws ServletException,
62 IOException {
63 final String file = req.getPathInfo();
64 final InputStream stream = Thread.currentThread()
65 .getContextClassLoader().getResourceAsStream(
66 "mml3-testsuite/" + file);
67 if (stream == null) {
68 resp.sendError(HttpServletResponse.SC_NOT_FOUND, file);
69 } else {
70 final OutputStream out = resp.getOutputStream();
71
72 boolean processed = false;
73 if (file.endsWith(".xhtml")) {
74 final Source inputSource = new StreamSource(stream);
75 final Result result = new StreamResult(out);
76 processed = Servlet3.TSP.process(inputSource, result, true);
77 }
78 if (!processed) {
79 final byte[] buf = new byte[Servlet3.BLOCK_SIZE];
80 int count = stream.read(buf);
81 while (count > -1) {
82 out.write(buf, 0, count);
83 count = stream.read(buf);
84 }
85 }
86 }
87 }
88
89 }