abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From calav...@apache.org
Subject svn commit: r701390 - in /incubator/abdera/java/trunk/server/src: main/java/org/apache/abdera/protocol/server/impl/RouteManager.java test/java/org/apache/abdera/protocol/server/test/route/RouteTest.java
Date Fri, 03 Oct 2008 14:27:33 GMT
Author: calavera
Date: Fri Oct  3 07:27:32 2008
New Revision: 701390

URL: http://svn.apache.org/viewvc?rev=701390&view=rev
Log:
fixes ABDERA-180: RouteManager.resolve doesn't find the best match.

Now, RouteManager checks if the uri and the pattern are equal and if they aren't equal it
tryies to match them

Modified:
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/RouteManager.java
    incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/test/route/RouteTest.java

Modified: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/RouteManager.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/RouteManager.java?rev=701390&r1=701389&r2=701390&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/RouteManager.java
(original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/RouteManager.java
Fri Oct  3 07:27:32 2008
@@ -136,17 +136,44 @@
     if (idx != -1) {
       uri = uri.substring(0, idx);
     }
-    for(RouteTargetType target : targets) {
-      if (target.route.match(uri)) {
-        CollectionAdapter ca = route2CA.get(target.route);
-        if (ca != null) {
-          context.setAttribute(DefaultWorkspaceManager.COLLECTION_ADAPTER_ATTRIBUTE, ca);
-        }
-        return getTarget(context, target.route, uri, target.targetType);
-      }
+    
+    RouteTargetType target = get(uri);
+    if (target == null) {    
+    	target = match(uri);
     }
+    
+    if (target != null) {    	
+        return getTarget(context, target, uri);
+    }    
+    
     return null;
   }
+  
+  private RouteTargetType get(String uri) {	  
+	  for(RouteTargetType target : targets) {		  
+		  if (target.route.getPattern().equals(uri)) {
+			  return target;
+		  }
+	  }	  
+	  return null;
+  }
+  
+  private RouteTargetType match(String uri) {
+	  for(RouteTargetType target : targets) {
+	      if (target.route.match(uri)) {
+	    	  return target;
+	      }
+	  }
+	  return null;
+  }
+  
+  private Target getTarget(RequestContext context, RouteTargetType target, String uri) {
+	  CollectionAdapter ca = route2CA.get(target.route);
+      if (ca != null) {
+        context.setAttribute(DefaultWorkspaceManager.COLLECTION_ADAPTER_ATTRIBUTE, ca);
+      }
+      return getTarget(context, target.route, uri, target.targetType);
+  }
 
   private Target getTarget(
     RequestContext context,

Modified: incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/test/route/RouteTest.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/test/route/RouteTest.java?rev=701390&r1=701389&r2=701390&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/test/route/RouteTest.java
(original)
+++ incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/test/route/RouteTest.java
Fri Oct  3 07:27:32 2008
@@ -30,7 +30,9 @@
 import org.apache.abdera.i18n.templates.Route;
 import org.apache.abdera.protocol.server.RequestContext;
 import org.apache.abdera.protocol.server.Target;
+import org.apache.abdera.protocol.server.TargetType;
 import org.apache.abdera.protocol.server.impl.RouteManager;
+import org.apache.abdera.protocol.server.impl.RouteManager.RouteTarget;
 import org.junit.Test;
 
 public class RouteTest extends Assert {
@@ -209,4 +211,18 @@
 
 		assertEquals(expected, manager.urlFor(request, "entry", context));
 	}
+	
+	@Test
+	public void testStaticResolve() throws Exception {
+		RouteManager manager = new RouteManager();
+		manager.addRoute(new Route("collection", "/:coll"), TargetType.TYPE_COLLECTION)
+			.addRoute(new Route("openSearch", "/openSearch.xml"), TargetType.TYPE_ENTRY);
+		
+		RequestContext request = createMock(RequestContext.class);
+	    expect(request.getTargetPath()).andReturn("/openSearch.xml");
+	    replay(request);
+	    
+	    RouteTarget target = (RouteTarget) manager.resolve(request);
+	    assertEquals("/openSearch.xml", target.getRoute().getPattern());
+	}
 }



Mime
View raw message