1 package dolda.jsvc.util;
6 public class Multiplexer implements Responder {
8 private Collection<Sub> subs = new LinkedList<Sub>();
10 private static interface Sub {
11 boolean match(Request req);
14 public Multiplexer(Responder def) {
18 public Multiplexer() {
19 this(new SimpleWriter("html") {
20 public void respond(Request req, java.io.PrintWriter out) {
22 out.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
23 out.println("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">");
24 out.println("<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en-US\">");
25 out.println("<head><title>Resource not found</title></head>");
26 out.println("<body>");
27 out.println("<h1>Resource not found</h1>");
28 out.println("The resource you requested could not be found on this server.");
29 out.println("</body>");
30 out.println("</html>");
35 public void file(final String path, final Responder responder) {
37 public boolean match(Request req) {
38 if(req.path().equals(path)) {
39 responder.respond(req);
47 public void dir(String path, final Responder responder) {
48 final String fp = Misc.stripslashes(path, true, true);
50 public boolean match(Request req) {
51 if(req.path().equals(fp)) {
52 throw(Restarts.redirect(fp + "/"));
53 } else if(req.path().startsWith(fp + "/")) {
54 responder.respond(RequestWrap.chpath(req, req.path().substring(fp.length() + 1)));
62 public void respond(Request req) {