// Path: backend/src/main/java/org/haagensoftware/netty/webserver/util/Matcher.java
// public interface Matcher {
//     public boolean match(String uri);
// }


import org.apache.log4j.Logger;
import org.haagensoftware.netty.webserver.util.Matcher;
import org.jboss.netty.channel.*;
import org.jboss.netty.handler.codec.http.HttpRequest;
import org.jboss.netty.handler.execution.ExecutionHandler;
import org.jboss.netty.handler.execution.OrderedMemoryAwareThreadPoolExecutor;
import java.util.LinkedHashMap;
import java.util.Map;
            //use the default handler is specified
            if (!matchFound && defaultHandler != null) {
            	addOrReplaceHandler(ctx.getPipeline(), defaultHandler, "default-handler");
        	} else if (!matchFound && handleNotFound) {
        		//Use the not found handler if specified
        		addOrReplaceHandler(ctx.getPipeline(), HANDLER_404, "404-handler");
        	}
        }

        super.handleUpstream(ctx, e);
    }

	private void addOrReplaceHandler(ChannelPipeline pipeline, ChannelHandler channelHandler, String handleName) {
		synchronized (pipeline) {
		    if (pipeline.get(handleName) == null) {
		    	pipeline.addLast(handleName, channelHandler);
		    } else {
		    	pipeline.replace(handleName, handleName, channelHandler);
		    }
		}
	}
	
	private void removeHandler(ChannelPipeline pipeline, String handleName) {
		synchronized (pipeline) {
			if (pipeline.get(handleName) != null) {
				pipeline.remove(handleName);
			}
		}
	}

// Path: backend/src/main/java/org/haagensoftware/netty/webserver/util/Matcher.java
// public interface Matcher {
//     public boolean match(String uri);
// }


// Path: backend/src/main/java/no/haagensoftware/netty/webserver/handler/RouterHandler.java
import org.apache.log4j.Logger;
import org.haagensoftware.netty.webserver.util.Matcher;
import org.jboss.netty.channel.*;
import org.jboss.netty.handler.codec.http.HttpRequest;
import org.jboss.netty.handler.execution.ExecutionHandler;
import org.jboss.netty.handler.execution.OrderedMemoryAwareThreadPoolExecutor;
import java.util.LinkedHashMap;
import java.util.Map;

            //use the default handler is specified
            if (!matchFound && defaultHandler != null) {
            	addOrReplaceHandler(ctx.getPipeline(), defaultHandler, "default-handler");
        	} else if (!matchFound && handleNotFound) {
        		//Use the not found handler if specified
        		addOrReplaceHandler(ctx.getPipeline(), HANDLER_404, "404-handler");
        	}
        }

        super.handleUpstream(ctx, e);
    }

	private void addOrReplaceHandler(ChannelPipeline pipeline, ChannelHandler channelHandler, String handleName) {
		synchronized (pipeline) {
		    if (pipeline.get(handleName) == null) {
		    	pipeline.addLast(handleName, channelHandler);
		    } else {
		    	pipeline.replace(handleName, handleName, channelHandler);
		    }
		}
	}
	
	private void removeHandler(ChannelPipeline pipeline, String handleName) {
		synchronized (pipeline) {
			if (pipeline.get(handleName) != null) {
				pipeline.remove(handleName);
			}
		}
	}

    private class StartsWithMatcher implements Matcher {