You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shindig.apache.org by hs...@apache.org on 2012/05/04 23:34:50 UTC

svn commit: r1334192 - in /shindig/trunk: content/samplecontainer/examples/templates/ java/gadgets/src/main/java/org/apache/shindig/gadgets/config/

Author: hsaputra
Date: Fri May  4 21:34:50 2012
New Revision: 1334192

URL: http://svn.apache.org/viewvc?rev=1334192&view=rev
Log:
SHINDIG-1548 | Shindig does not accept relative URLs for template libraries | Patch from Erik BI. Thanks much

Added:
    shindig/trunk/content/samplecontainer/examples/templates/RelativeTemplateLibrary.xml
    shindig/trunk/content/samplecontainer/examples/templates/TestTemplateLibrary.xml
Modified:
    shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/config/CoreUtilConfigContributor.java

Added: shindig/trunk/content/samplecontainer/examples/templates/RelativeTemplateLibrary.xml
URL: http://svn.apache.org/viewvc/shindig/trunk/content/samplecontainer/examples/templates/RelativeTemplateLibrary.xml?rev=1334192&view=auto
==============================================================================
--- shindig/trunk/content/samplecontainer/examples/templates/RelativeTemplateLibrary.xml (added)
+++ shindig/trunk/content/samplecontainer/examples/templates/RelativeTemplateLibrary.xml Fri May  4 21:34:50 2012
@@ -0,0 +1,35 @@
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<Module>
+  <ModulePrefs title="RelativeTemplateLibrary">
+    <Require feature="opensocial-templates">
+	  <Param name="requireLibrary">TestTemplateLibrary.xml</Param>
+	</Require>  
+  </ModulePrefs>
+  <Content type="html">
+    <![CDATA[
+    <div>
+      <p>Simple test of gadget using template library with relative path</p>
+    </div>
+	<script type="text/os-template" xmlns:foo="http://foo.com/">
+      <foo:HelloWorld />
+    </script>
+    ]]>
+  </Content>
+</Module>

Added: shindig/trunk/content/samplecontainer/examples/templates/TestTemplateLibrary.xml
URL: http://svn.apache.org/viewvc/shindig/trunk/content/samplecontainer/examples/templates/TestTemplateLibrary.xml?rev=1334192&view=auto
==============================================================================
--- shindig/trunk/content/samplecontainer/examples/templates/TestTemplateLibrary.xml (added)
+++ shindig/trunk/content/samplecontainer/examples/templates/TestTemplateLibrary.xml Fri May  4 21:34:50 2012
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Templates xmlns:foo="http://foo.com/">
+  <Namespace prefix="foo" url="http://foo.com/"/>
+  <Template tag="foo:HelloWorld">
+    <div>Hello World from template library with relative url!</div>
+  </Template>
+</Templates>
\ No newline at end of file

Modified: shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/config/CoreUtilConfigContributor.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/config/CoreUtilConfigContributor.java?rev=1334192&r1=1334191&r2=1334192&view=diff
==============================================================================
--- shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/config/CoreUtilConfigContributor.java (original)
+++ shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/config/CoreUtilConfigContributor.java Fri May  4 21:34:50 2012
@@ -22,6 +22,8 @@ import java.util.Collection;
 import java.util.Map;
 import java.util.Set;
 
+import com.google.common.collect.Lists;
+import org.apache.shindig.common.uri.Uri;
 import org.apache.shindig.gadgets.Gadget;
 import org.apache.shindig.gadgets.admin.GadgetAdminStore;
 import org.apache.shindig.gadgets.features.FeatureRegistry;
@@ -39,6 +41,8 @@ import com.google.inject.Singleton;
  */
 @Singleton
 public class CoreUtilConfigContributor implements ConfigContributor {
+  private static final String TEMPLATES_FEATURE_NAME = "opensocial-templates";
+  private static final String REQUIRE_LIBRARY_PARAM = "requireLibrary";
 
   private final FeatureRegistry registry;
   private final GadgetAdminStore gadgetAdminStore;
@@ -50,7 +54,6 @@ public class CoreUtilConfigContributor i
     this.gadgetAdminStore = gadgetAdminStore;
   }
 
-
   /** {@inheritDoc} */
   public void contribute(Map<String, Object> config, Gadget gadget) {
     // Add gadgets.util support. This is calculated dynamically based on request inputs.
@@ -69,10 +72,29 @@ public class CoreUtilConfigContributor i
       Map<String, Object> paramFeaturesInConfig = Maps.newHashMap();
       for (String paramName : feature.getParams().keySet()) {
         Collection<String> paramValues = feature.getParams().get(paramName);
-        if (paramValues.size() == 1) {
-          paramFeaturesInConfig.put(paramName, paramValues.iterator().next());
+        // Resolve the template URL to convert relative URL to absolute URL relative to gadget URL.
+        if (TEMPLATES_FEATURE_NAME.equals(feature.getName())
+            && REQUIRE_LIBRARY_PARAM.equals(paramName)) {
+          Uri abURI = null;
+          if (paramValues.size() == 1) {
+            abURI = Uri.parse(paramValues.iterator().next().trim());
+            abURI = gadget.getContext().getUrl().resolve(abURI);
+            paramFeaturesInConfig.put(paramName, abURI.toString());
+          } else {
+            Collection<String> abReqLibs = Lists.newArrayList();
+            for (String libraryUrl : paramValues) {
+              abURI = Uri.parse(libraryUrl.trim());
+              abURI = gadget.getContext().getUrl().resolve(abURI);
+              abReqLibs.add(abURI.toString());
+            }
+            paramFeaturesInConfig.put(paramName, abReqLibs);
+          }
         } else {
-          paramFeaturesInConfig.put(paramName, paramValues);
+          if (paramValues.size() == 1) {
+            paramFeaturesInConfig.put(paramName, paramValues.iterator().next());
+          } else {
+            paramFeaturesInConfig.put(paramName, paramValues);
+          }
         }
       }