Author: mhermanto
Date: Tue Oct 26 00:14:59 2010
New Revision: 1027320
URL: http://svn.apache.org/viewvc?rev=1027320&view=rev
Log:
Avoid schema resolution for type=url gadget
http://codereview.appspot.com/2714041/
Modified:
shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/spec/View.java
shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/spec/ViewTest.java
Modified:
shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/spec/View.java
URL:
http://svn.apache.org/viewvc/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/spec/View.java?rev=1027320&r1=1027319&r2=1027320&view=diff
==============================================================================
---
shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/spec/View.java
(original)
+++
shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/spec/View.java
Tue Oct 26 00:14:59 2010
@@ -18,14 +18,14 @@
package org.apache.shindig.gadgets.spec;
import com.google.common.base.Objects;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Maps;
+
import org.apache.shindig.common.uri.Uri;
+import org.apache.shindig.common.uri.UriBuilder;
import org.apache.shindig.common.xml.XmlUtil;
import org.apache.shindig.gadgets.AuthType;
import org.apache.shindig.gadgets.variables.Substitutions;
-
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Maps;
-
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
@@ -160,6 +160,12 @@ public class View implements RequestAuth
content = substituter.substituteString(view.content);
base = view.base;
href = base.resolve(substituter.substituteUri(view.href));
+
+ // Facilitates type=url support of dual-schema endpoints.
+ if (view.getType() == ContentType.URL && view.href.getScheme() == null) {
+ href = new UriBuilder(href).setScheme(null).toUri();
+ }
+
Map<String, String> attributes = Maps.newHashMap();
for (Map.Entry<String, String> entry : view.attributes.entrySet()) {
attributes.put(entry.getKey(),
substituter.substituteString(entry.getValue()));
Modified:
shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/spec/ViewTest.java
URL:
http://svn.apache.org/viewvc/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/spec/ViewTest.java?rev=1027320&r1=1027319&r2=1027320&view=diff
==============================================================================
---
shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/spec/ViewTest.java
(original)
+++
shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/spec/ViewTest.java
Tue Oct 26 00:14:59 2010
@@ -19,17 +19,17 @@
package org.apache.shindig.gadgets.spec;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
import org.apache.shindig.common.uri.Uri;
import org.apache.shindig.common.xml.XmlUtil;
import org.apache.shindig.expressions.Expressions;
import org.apache.shindig.expressions.RootELResolver;
import org.apache.shindig.gadgets.variables.Substitutions;
import org.apache.shindig.gadgets.variables.Substitutions.Type;
-
import org.junit.Assert;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
import org.junit.Test;
import java.util.Arrays;
@@ -195,10 +195,19 @@ public class ViewTest {
View view = new View("test", Arrays.asList(XmlUtil.parse(xml)), SPEC_URL);
view = view.substitute(substituter);
- assertEquals(SPEC_URL.resolve(Uri.parse("/bar")), view.getHref());
+ assertEquals(Uri.parse("//example.org/bar"), view.getHref());
}
@Test
+ public void testHrefWithoutSchemaResolution() throws Exception {
+ String href = "//xyz.com/gadget.xml";
+ String xml = "<Content type=\"url\" href=\"" + href + "\"/>";
+
+ View view = new View("test", Arrays.asList(XmlUtil.parse(xml)), SPEC_URL);
+ assertEquals(Uri.parse(href), view.getHref());
+ }
+
+ @Test
public void authAttributes() throws Exception {
String xml = "<Content type='html' sign_owner='false' sign_viewer='false'
foo='bar' " +
"yo='momma' sub='__MSG_view__'/>";