shindig-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jo...@apache.org
Subject svn commit: r1146780 - in /shindig/trunk/java/gadgets/src: main/java/org/apache/shindig/gadgets/uri/DefaultJsUriManager.java test/java/org/apache/shindig/gadgets/uri/DefaultJsUriManagerTest.java
Date Thu, 14 Jul 2011 16:25:37 GMT
Author: johnh
Date: Thu Jul 14 16:25:36 2011
New Revision: 1146780

URL: http://svn.apache.org/viewvc?rev=1146780&view=rev
Log:
Get rid of unnecessary path prefix check when processing a JS URI.


Modified:
    shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/uri/DefaultJsUriManager.java
    shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/uri/DefaultJsUriManagerTest.java

Modified: shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/uri/DefaultJsUriManager.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/uri/DefaultJsUriManager.java?rev=1146780&r1=1146779&r2=1146780&view=diff
==============================================================================
--- shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/uri/DefaultJsUriManager.java
(original)
+++ shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/uri/DefaultJsUriManager.java
Thu Jul 14 16:25:36 2011
@@ -159,10 +159,6 @@ public class DefaultJsUriManager impleme
       container = ContainerConfig.DEFAULT_CONTAINER;
     }
 
-    // Get config values up front.
-    getReqConfig(container, JS_HOST_PARAM); // validate that it exists
-    String jsPrefix = getReqConfig(container, JS_PATH_PARAM);
-
     String host = uri.getAuthority();
     if (host == null) {
       issueUriFormatError("Unexpected: Js Uri has no host");
@@ -175,11 +171,11 @@ public class DefaultJsUriManager impleme
       issueUriFormatError("Unexpected: Js Uri has no path");
       return INVALID_URI;
     }
-    if (!path.startsWith(jsPrefix)) {
-      issueUriFormatError("Js Uri path invalid, expected prefix: " + jsPrefix + ", is: "
+ path);
-      return INVALID_URI;
+
+    int lastSlash = path.lastIndexOf("/");
+    if (lastSlash != -1) {
+      path = path.substring(lastSlash + 1);
     }
-    path = path.substring(jsPrefix.length());
 
     // Convenience suffix: pull off .js if present; leave alone otherwise.
     if (path.endsWith(JS_SUFFIX)) {

Modified: shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/uri/DefaultJsUriManagerTest.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/uri/DefaultJsUriManagerTest.java?rev=1146780&r1=1146779&r2=1146780&view=diff
==============================================================================
--- shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/uri/DefaultJsUriManagerTest.java
(original)
+++ shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/uri/DefaultJsUriManagerTest.java
Thu Jul 14 16:25:36 2011
@@ -204,20 +204,6 @@ public class DefaultJsUriManagerTest {
   }
 
   // processJsUri tests
-  @Test(expected = RuntimeException.class)
-  public void processMissingHostConfig() throws GadgetException {
-    ContainerConfig config = mockConfig(null, "/gadgets/js");
-    DefaultJsUriManager manager = makeManager(config, null);
-    manager.processExternJsUri(Uri.parse("http://example.com?container=" + CONTAINER));
-  }
-
-  @Test(expected = RuntimeException.class)
-  public void processMissingPathConfig() throws GadgetException {
-    ContainerConfig config = mockConfig("foo", null);
-    DefaultJsUriManager manager = makeManager(config, null);
-    manager.processExternJsUri(Uri.parse("http://example.com?container=" + CONTAINER));
-  }
-
   @Test
   public void processDefaultConfig() throws GadgetException {
     ContainerConfig config = mockDefaultConfig("foo", "/gadgets/js");
@@ -233,9 +219,13 @@ public class DefaultJsUriManagerTest {
     Uri testUri = Uri.parse("http://target-host.org/gadgets/other-js/feature" + JS_SUFFIX
+ '?' +
         Param.CONTAINER.getKey() + '=' + CONTAINER);
     JsUri jsUri = manager.processExternJsUri(testUri);
-    assertTrue(manager.hadError());
-    assertEquals(jsUri.getStatus(), UriStatus.BAD_URI);
-    assertSame(DefaultJsUriManager.INVALID_URI, jsUri);
+    assertFalse(manager.hadError());
+    List<String> extern = Lists.newArrayList("feature");
+    assertEquals(extern, jsUri.getLibs());
+    List<String> loaded = Lists.newArrayList();
+    assertEquals(loaded, jsUri.getLoadedLibs());
+    assertEquals(CONTAINER, jsUri.getContainer());
+    assertEquals(RenderingContext.GADGET, jsUri.getContext());
   }
 
   @Test
@@ -262,8 +252,6 @@ public class DefaultJsUriManagerTest {
     JsUri jsUri = manager.processExternJsUri(testUri);
     assertFalse(manager.hadError());
     List<String> extern = Lists.newArrayList("feature", "another");
-    List<String> loadsInPath = Lists.newArrayList("load1", "load2");
-    List<String> loadsInQueryParam = Lists.newArrayList("load3", "load4");
     assertCollectionEquals(jsUri.getLibs(), extern);
     assertCollectionEquals(jsUri.getLoadedLibs(), Lists.newArrayList(
         "load1", "load2", "load3", "load4"));



Mime
View raw message