You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@shindig.apache.org by li...@inuus.com on 2010/04/26 23:18:01 UTC

Inject gadgets.config into javascript servlet output for container output (issue992043)

Reviewers: shindig.remailer_gmail.com,

Message:
any comments?


Description:
The Js servlet supports a container param without a way to inject
container specific configs.  Adding this code allows one to configure
container side portion of the code.

With some work this could also allow one to run gadgets.config code
inside the js servlet output instead of the iframe.


Please review this at http://codereview.appspot.com/992043/show

Affected files:
   M  
java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/JsServlet.java


Index:  
java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/JsServlet.java
diff --git  
a/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/JsServlet.java  
b/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/JsServlet.java
index  
c88f08f0959c9feca5a6d83b8a0be65c29ac577a..21ea09496ac9dffda9a4c38d064161e23d75a9e9  
100644
---  
a/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/JsServlet.java
+++  
b/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/JsServlet.java
@@ -19,7 +19,9 @@ package org.apache.shindig.gadgets.servlet;

  import com.google.common.collect.ImmutableSet;

+import com.google.common.collect.Maps;
  import org.apache.commons.lang.StringUtils;
+import org.apache.shindig.common.JsonSerializer;
  import org.apache.shindig.common.servlet.HttpUtil;
  import org.apache.shindig.common.servlet.InjectedServlet;
  import org.apache.shindig.config.ContainerConfig;
@@ -34,6 +36,7 @@ import com.google.inject.Inject;

  import java.io.IOException;
  import java.util.Collection;
+import java.util.Map;
  import java.util.Set;

  import javax.servlet.http.HttpServletRequest;
@@ -57,6 +60,12 @@ public class JsServlet extends InjectedServlet {
      this.urlGenerator = urlGenerator;
    }

+  private ContainerConfig containerConfig;
+  @Inject
+  public void setContainerConfig(ContainerConfig containerConfig) {
+    this.containerConfig = containerConfig;
+  }
+
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
        throws IOException {
@@ -105,8 +114,8 @@ public class JsServlet extends InjectedServlet {
          return container;
        }
      };
-    Collection<? extends FeatureResource> resources =
-        registry.getFeatureResources(ctx, needed, null);
+
+    Collection<? extends FeatureResource> resources =  
registry.getFeatureResources(ctx, needed, null);
      StringBuilder jsData = new StringBuilder();
      boolean isProxyCacheable = true;
      for (FeatureResource featureResource : resources) {
@@ -121,7 +130,24 @@ public class JsServlet extends InjectedServlet {
        jsData.append(";\n");
      }

-
+    if (context == RenderingContext.CONTAINER) {
+      // Append some container specific things
+
+      Map<String, Object> features =  
containerConfig.getMap(ctx.getContainer(), "gadgets.features");
+      Map<String, Object> config =  
Maps.newHashMapWithExpectedSize(features == null ? 2 : features.size() + 2);
+
+      if (features != null) {
+        // Discard what we don't care about.
+        for (String name : needed) {
+          Object conf = features.get(name);
+          if (conf != null) {
+            config.put(name, conf);
+          }
+        }
+         
jsData.append("gadgets.config.init(").append(JsonSerializer.serialize(config)).append(");\n");
+      }
+    }
+
      if (jsData.length() == 0) {
        resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
        return;