Replaced the "Restarts" class with individual restart classes.
[jsvc.git] / src / dolda / jsvc / util / StdResponse.java
1 package dolda.jsvc.util;
2
3 import dolda.jsvc.*;
4 import java.io.*;
5
6 public class StdResponse extends RequestRestart {
7     private final int code;
8     private final String title;
9     
10     public StdResponse(int code, String title, String message) {
11         super(message);
12         this.code = code;
13         this.title = title;
14     }
15     
16     public StdResponse(int code, String message) {
17         this(code, "An error occurred", message);
18     }
19     
20     public StdResponse(int code) {
21         this(code, Misc.statustext(code));
22     }
23     
24     public void respond(Request req) {
25         req.status(code);
26         req.outheaders().put("Content-Type", "text/html; charset=utf-8");
27         PrintWriter out;
28         out = new PrintWriter(new OutputStreamWriter(req.output(), Misc.utf8));
29         out.println("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
30         out.println("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">");
31         out.println("<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en-US\">");
32         out.println("<head><title>" + title + "</title></head>");
33         out.println("<body>");
34         out.println("<h1>" + title + "</h1>");
35         out.println(getMessage());
36         out.println("</body>");
37         out.println("</html>");
38         out.flush();
39     }
40 }