- From: Thomas Gambet via cvs-syncmail <cvsmail@w3.org>
- Date: Thu, 06 Aug 2009 10:13:29 +0000
- To: www-validator-cvs@w3.org
Update of /sources/public/2006/unicorn/src/org/w3/unicorn/route In directory hutz:/tmp/cvs-serv23605/src/org/w3/unicorn/route Modified Files: Tag: dev2 RoutesDocument.java Route.java RouteParser.java Log Message: generated routes with xbean Index: Route.java =================================================================== RCS file: /sources/public/2006/unicorn/src/org/w3/unicorn/route/Attic/Route.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -d -r1.1.2.1 -r1.1.2.2 --- Route.java 5 Aug 2009 17:21:39 -0000 1.1.2.1 +++ Route.java 6 Aug 2009 10:13:27 -0000 1.1.2.2 @@ -16,7 +16,7 @@ public interface Route extends org.apache.xmlbeans.XmlObject { public static final org.apache.xmlbeans.SchemaType type = (org.apache.xmlbeans.SchemaType) - org.apache.xmlbeans.XmlBeans.typeSystemForClassLoader(Route.class.getClassLoader(), "schemaorg_apache_xmlbeans.system.s69AE826127FB706696DECA7E095DD405").resolveHandle("route089etype"); + org.apache.xmlbeans.XmlBeans.typeSystemForClassLoader(Route.class.getClassLoader(), "schemaorg_apache_xmlbeans.system.s4FE8461B33D13E8C61AF1BD580DE601A").resolveHandle("route089etype"); /** * Gets a List of "pattern" elements @@ -108,7 +108,7 @@ /** * Gets (as xml) the "action" element */ - org.w3.unicorn.route.ClassString xgetAction(); + org.apache.xmlbeans.XmlToken xgetAction(); /** * True if has "action" element @@ -123,7 +123,7 @@ /** * Sets (as xml) the "action" element */ - void xsetAction(org.w3.unicorn.route.ClassString action); + void xsetAction(org.apache.xmlbeans.XmlToken action); /** * Unsets the "action" element @@ -161,6 +161,36 @@ void unsetUrl(); /** + * Gets the "type" attribute + */ + java.lang.String getType(); + + /** + * Gets (as xml) the "type" attribute + */ + org.apache.xmlbeans.XmlToken xgetType(); + + /** + * True if has "type" attribute + */ + boolean isSetType(); + + /** + * Sets the "type" attribute + */ + void setType(java.lang.String type); + + /** + * Sets (as xml) the "type" attribute + */ + void xsetType(org.apache.xmlbeans.XmlToken type); + + /** + * Unsets the "type" attribute + */ + void unsetType(); + + /** * A factory class with static methods for creating instances * of this type. */ Index: RoutesDocument.java =================================================================== RCS file: /sources/public/2006/unicorn/src/org/w3/unicorn/route/Attic/RoutesDocument.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -d -r1.1.2.1 -r1.1.2.2 --- RoutesDocument.java 5 Aug 2009 17:21:39 -0000 1.1.2.1 +++ RoutesDocument.java 6 Aug 2009 10:13:27 -0000 1.1.2.2 @@ -17,7 +17,7 @@ public interface RoutesDocument extends org.apache.xmlbeans.XmlObject { public static final org.apache.xmlbeans.SchemaType type = (org.apache.xmlbeans.SchemaType) - org.apache.xmlbeans.XmlBeans.typeSystemForClassLoader(RoutesDocument.class.getClassLoader(), "schemaorg_apache_xmlbeans.system.s69AE826127FB706696DECA7E095DD405").resolveHandle("routes1c21doctype"); + org.apache.xmlbeans.XmlBeans.typeSystemForClassLoader(RoutesDocument.class.getClassLoader(), "schemaorg_apache_xmlbeans.system.s4FE8461B33D13E8C61AF1BD580DE601A").resolveHandle("routes1c21doctype"); /** * Gets the "routes" element @@ -42,7 +42,7 @@ public interface Routes extends org.apache.xmlbeans.XmlObject { public static final org.apache.xmlbeans.SchemaType type = (org.apache.xmlbeans.SchemaType) - org.apache.xmlbeans.XmlBeans.typeSystemForClassLoader(Routes.class.getClassLoader(), "schemaorg_apache_xmlbeans.system.s69AE826127FB706696DECA7E095DD405").resolveHandle("routesa8fbelemtype"); + org.apache.xmlbeans.XmlBeans.typeSystemForClassLoader(Routes.class.getClassLoader(), "schemaorg_apache_xmlbeans.system.s4FE8461B33D13E8C61AF1BD580DE601A").resolveHandle("routesa8fbelemtype"); /** * Gets a List of "route" elements @@ -91,36 +91,6 @@ void removeRoute(int i); /** - * Gets the "index" element - */ - org.w3.unicorn.route.Index getIndex(); - - /** - * Sets the "index" element - */ - void setIndex(org.w3.unicorn.route.Index index); - - /** - * Appends and returns a new empty "index" element - */ - org.w3.unicorn.route.Index addNewIndex(); - - /** - * Gets the "error404" element - */ - org.w3.unicorn.route.Error404 getError404(); - - /** - * Sets the "error404" element - */ - void setError404(org.w3.unicorn.route.Error404 error404); - - /** - * Appends and returns a new empty "error404" element - */ - org.w3.unicorn.route.Error404 addNewError404(); - - /** * A factory class with static methods for creating instances * of this type. */ Index: RouteParser.java =================================================================== RCS file: /sources/public/2006/unicorn/src/org/w3/unicorn/route/Attic/RouteParser.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -d -r1.1.2.1 -r1.1.2.2 --- RouteParser.java 5 Aug 2009 17:21:39 -0000 1.1.2.1 +++ RouteParser.java 6 Aug 2009 10:13:27 -0000 1.1.2.2 @@ -1,43 +1,65 @@ package org.w3.unicorn.route; +import java.io.File; import java.net.MalformedURLException; -import java.net.URL; +import java.util.ArrayList; +import java.util.List; import java.util.regex.Pattern; import javax.servlet.http.HttpServletRequest; import org.apache.log4j.Logger; -//import org.w3c.unicorn.route.Route; -import org.w3.unicorn.action.Error404Action; -import org.w3.unicorn.action.IndexAction; -import org.w3.unicorn.action.ObserveAction; +import org.w3.unicorn.util.Property; 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"); + private static List<Route> routeList; + private static Route index; + private static Route error404; - /*public static Route getRoute(HttpServletRequest request) throws MalformedURLException { + + public static void init() throws Exception { + File routesXML = new File(Property.get("PATH_TO_CONF_FILES", "ROUTE_XML")); - logger.debug("PathInfo: "+request.getPathInfo()); - Route route = new Route(); + RoutesDocument docXML = RoutesDocument.Factory.parse(routesXML); + + List<Route> tempRouteList = docXML.getRoutes().getRouteList(); + routeList = new ArrayList<Route>(); + + for(Route route : tempRouteList) { + logger.info("Route found: " + route.toString()); + + if (route.isSetType() && route.getType().equals("index")) { + index = route; + routeList.add(index); + } else if (route.isSetType() && route.getType().equals("404")) { + error404 = route; + } else { + routeList.add(route); + } + } + } + + public static Route getRoute(HttpServletRequest request) throws MalformedURLException { + logger.debug("PathInfo: "+request.getPathInfo()); 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; + if(pathInfo.equals("") || pathInfo.equals("/")) { + logger.debug("Coresponding action: " + index.getAction()); + return index; } - }*/ + + for(Route route : routeList) { + for (String patternString : route.getPatternList()) { + Pattern pattern = Pattern.compile(patternString); + if (pattern.matcher(pathInfo).matches()) { + logger.debug("Coresponding action: " + route.getAction()); + return route; + } + } + } + logger.debug("Coresponding action: " + error404.getAction()); + return error404; + } }
Received on Thursday, 6 August 2009 10:13:43 UTC