Replaced the "Restarts" class with individual restart classes.
[jsvc.git] / src / dolda / jsvc / util / Multiplexer.java
index df9e4c2..8e5aec4 100644 (file)
@@ -5,10 +5,10 @@ import java.util.*;
 
 public class Multiplexer implements Responder {
     private Responder def;
-    private Collection<Sub> subs = new LinkedList<Sub>();
+    private Collection<Matcher> matchers = new LinkedList<Matcher>();
 
-    private static interface Sub {
-       boolean match(Request req);
+    public static interface Matcher {
+       public boolean match(Request req);
     }
     
     public Multiplexer(Responder def) {
@@ -18,13 +18,13 @@ public class Multiplexer implements Responder {
     public Multiplexer() {
        this(new Responder() {
                public void respond(Request req) {
-                   throw(Restarts.stdresponse(404, "Resource not found", "The resource you requested could not be found on this server."));
+                   throw(new StdResponse(404, "Resource not found", "The resource you requested could not be found on this server."));
                }
            });
     }
     
     public void file(final String path, final Responder responder) {
-       subs.add(new Sub() {
+       add(new Matcher() {
                public boolean match(Request req) {
                    if(req.path().equals(path)) {
                        responder.respond(req);
@@ -37,10 +37,10 @@ public class Multiplexer implements Responder {
 
     public void dir(String path, final Responder responder) {
        final String fp = Misc.stripslashes(path, true, true);
-       subs.add(new Sub() {
+       add(new Matcher() {
                public boolean match(Request req) {
                    if(req.path().equals(fp)) {
-                       throw(Restarts.redirect(fp + "/"));
+                       throw(new Redirect(fp + "/"));
                    } else if(req.path().startsWith(fp + "/")) {
                        responder.respond(RequestWrap.chpath(req, req.path().substring(fp.length() + 1)));
                        return(true);
@@ -50,9 +50,13 @@ public class Multiplexer implements Responder {
            });
     }
     
+    public void add(Matcher m) {
+       matchers.add(m);
+    }
+    
     public void respond(Request req) {
-       for(Sub s : subs) {
-           if(s.match(req))
+       for(Matcher m : matchers) {
+           if(m.match(req))
                return;
        }
        def.respond(req);