W3C home > Mailing lists > Public > www-validator-cvs@w3.org > August 2009

2006/unicorn/src/org/w3c/unicorn/route RouteParser.java,NONE,1.1.2.1 Route.java,NONE,1.1.2.1

From: Thomas Gambet via cvs-syncmail <cvsmail@w3.org>
Date: Wed, 05 Aug 2009 10:26:43 +0000
To: www-validator-cvs@w3.org
Message-Id: <E1MYdhj-0004yA-Pv@lionel-hutz.w3.org>
Update of /sources/public/2006/unicorn/src/org/w3c/unicorn/route
In directory hutz:/tmp/cvs-serv19002/src/org/w3c/unicorn/route

Added Files:
      Tag: dev2
	RouteParser.java Route.java 
Log Message:
New project

--- NEW FILE: Route.java ---
package org.w3c.unicorn.route;

import java.net.URL;
import org.w3c.unicorn.action.Action;

public class Route {
	
	private URL url;
	private boolean isRedirect;
	private Class<? extends Action> actionClass;
	
	public Route() {
		
	}

	public Class<? extends Action> getActionClass() {
		return actionClass;
	}

	public void setActionClass(Class<? extends Action> actionClass) {
		this.actionClass = actionClass;
	}

	public URL getUrl() {
		return url;
	}

	public void setUrl(URL url) {
		this.url = url;
	}

	public boolean isRedirect() {
		return isRedirect;
	}

	public void setRedirect(boolean isRedirect) {
		this.isRedirect = isRedirect;
	}

	public String getAction() {
		return actionClass.getSimpleName();
	}
}

--- NEW FILE: RouteParser.java ---
package org.w3c.unicorn.route;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.regex.Pattern;
import javax.servlet.http.HttpServletRequest;
import org.apache.log4j.Logger;
import org.w3c.unicorn.route.Route;
import org.w3c.unicorn.action.Error404Action;
import org.w3c.unicorn.action.IndexAction;
import org.w3c.unicorn.action.ObserveAction;

public class RouteParser {

	private static Logger logger = Logger.getLogger("RouteParser");
	
	private static Pattern indexPattern = Pattern.compile("/");
	private static Pattern observePattern = Pattern.compile("/observe");
	private static Pattern dlPattern = Pattern.compile("/download");
	
	public static Route getRoute(HttpServletRequest request) throws MalformedURLException {
		
		logger.debug("PathInfo: "+request.getPathInfo());
		Route route = new Route();
		
		String pathInfo = request.getPathInfo();
		
		if (indexPattern.matcher(pathInfo).matches()) {
			route.setActionClass(IndexAction.class);
			return route;
		} else if (observePattern.matcher(pathInfo).matches()) {
			route.setActionClass(ObserveAction.class);
			return route;
		} else if (dlPattern.matcher(pathInfo).matches()) {
			route.setRedirect(true);
			route.setUrl(new URL("http://google.com"));
			return route;
		}else {
			route.setActionClass(Error404Action.class);
			return route;
		}
	}
}
Received on Wednesday, 5 August 2009 10:26:53 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 7 January 2015 15:17:37 UTC