On Wed, Mar 12, 2008 at 10:10 AM, <[EMAIL PROTECTED]> wrote:
> Author: etnu
> Date: Wed Mar 12 02:10:33 2008
> New Revision: 636258
>
> URL: http://svn.apache.org/viewvc?rev=636258&view=rev
> Log:
> Fix for SHINDIG-83
>
>
> Modified:
> incubator/shindig/trunk/features/core/util.js
>
>
> incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/GadgetRenderer.java
>
>
> incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/HttpUtil.java
>
> Modified: incubator/shindig/trunk/features/core/util.js
> URL:
> http://svn.apache.org/viewvc/incubator/shindig/trunk/features/core/util.js?rev=636258&r1=636257&r2=636258&view=diff
>
> ==============================================================================
> --- incubator/shindig/trunk/features/core/util.js (original)
> +++ incubator/shindig/trunk/features/core/util.js Wed Mar 12 02:10:33 2008
> @@ -92,6 +92,14 @@
> return String.fromCharCode(value);
> }
>
> + /**
> + * Initializes feature parameters.
> + */
> + function init(config) {
> + features = config["core.util"] || {};
> + }
> + gadgets.config.register("core.util", null, init);
this breaks the sample container.
it seems like rpc.js?c=1 pulls in the core library. unfortunately, when in
container mode gadgets.config does not exist which causes a js error.
rpc wraps this call inside of a flag check, can you do something similar
here?
ps - i suppose i need to make a samplecontainer test somehow so that we stop
breaking it without knowing...
>
> +
> return /** @scope gadgets.util */ {
>
> /**
> @@ -142,12 +150,13 @@
> */
> makeClosure : function (scope, callback, var_args) {
> // arguments isn't a real array, so we copy it into one.
> - var tmpArgs = [];
> + var baseArgs = [];
> for (var i = 2, j = arguments.length; i < j; ++i) {
> - tmpArgs.push(arguments[i]);
> + baseArgs.push(arguments[i]);
> }
> return function() {
> // append new arguments.
> + var tmpArgs = baseArgs.slice();
> for (var i = 0, j = arguments.length; i < j; ++i) {
> tmpArgs.push(arguments[i]);
> }
> @@ -287,15 +296,6 @@
> */
> unescapeString : function(str) {
> return str.replace(/&#([0-9]+);/g, unescapeEntity);
> - },
> -
> - /**
> - * @param {Object} featureData The features that are supported, and
> - * their parameters.
> - * @private Only to be used by the container, not gadgets.
> - */
> - init : function (featureData) {
> - features = featureData;
> }
> };
> }();
>
> Modified:
> incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/GadgetRenderer.java
> URL:
> http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/GadgetRenderer.java?rev=636258&r1=636257&r2=636258&view=diff
>
> ==============================================================================
> ---
> incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/GadgetRenderer.java
> (original)
> +++
> incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/GadgetRenderer.java
> Wed Mar 12 02:10:33 2008
> @@ -27,7 +27,9 @@
> import org.apache.shindig.gadgets.GadgetServerConfigReader;
> import org.apache.shindig.gadgets.JsLibrary;
> import org.apache.shindig.gadgets.SyndicatorConfig;
> +import org.apache.shindig.gadgets.spec.Feature;
> import org.apache.shindig.gadgets.spec.MessageBundle;
> +import org.apache.shindig.gadgets.spec.ModulePrefs;
> import org.apache.shindig.gadgets.spec.View;
>
> import org.json.JSONArray;
> @@ -206,7 +208,7 @@
> libs.add(library.getFeature());
> }
>
> - appendJsConfig(libs, inlineJs);
> + appendJsConfig(gadget, libs, inlineJs);
>
> // message bundles for prefs object.
> MessageBundle bundle = gadget.getMessageBundle();
> @@ -318,13 +320,39 @@
> }
>
> /**
> + * Appends javascript configuration to the bottom of an existing script
> block.
> + *
> + * Appends special configuration for gadgets.util.hasFeature and
> + * gadgets.util.getFeatureParams to the output js.
> + *
> + * This can't be handled via the normal configuration mechanism because
> it is
> + * something that varies per request.
> + *
> + * Only explicitly <Require>'d and <Optional> features will be added.
> + *
> + * @param gadget
> * @param reqs The features you require.
> * @param js Existing js, to which the configuration will be appended.
> */
> - private void appendJsConfig(Set<String> reqs, StringBuilder js) {
> + private void appendJsConfig(Gadget gadget, Set<String> reqs,
> + StringBuilder js) {
> GadgetServerConfigReader config = state.getGadgetServer().getConfig();
> SyndicatorConfig syndConf = config.getSyndicatorConfig();
> - js.append(HttpUtil.getJsConfig(syndConf, context, reqs));
> + JSONObject json = HttpUtil.getJsConfig(syndConf, context, reqs);
> + // Add gadgets.util support. This is calculated dynamically based on
> + // request inputs.
> + ModulePrefs prefs = gadget.getSpec().getModulePrefs();
> + JSONObject featureMap = new JSONObject();
> + try {
> + for (Feature feature : prefs.getFeatures().values()) {
> + featureMap.put(feature.getName(), feature.getParams());
> + }
> + json.put("core.util", featureMap);
> + } catch (JSONException e) {
> + // Shouldn't be possible.
> + throw new RuntimeException(e);
> + }
> +
> js.append("gadgets.config.init(").append(json.toString()).append(");");
> }
>
> /**
>
> Modified:
> incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/HttpUtil.java
> URL:
> http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/HttpUtil.java?rev=636258&r1=636257&r2=636258&view=diff
>
> ==============================================================================
> ---
> incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/HttpUtil.java
> (original)
> +++
> incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/HttpUtil.java
> Wed Mar 12 02:10:33 2008
> @@ -68,20 +68,18 @@
> * @param context
> * @param features
> */
> - public static String getJsConfig(SyndicatorConfig config,
> + public static JSONObject getJsConfig(SyndicatorConfig config,
> GadgetContext context, Set<String> features) {
> JSONObject syndFeatures =
> config.getJsonObject(context.getSyndicator(),
> "gadgets.features");
> if (syndFeatures != null) {
> String[] featArray = features.toArray(new String[features.size()]);
> try {
> - JSONObject featureConfig = new JSONObject(syndFeatures,
> featArray);
> - return "\ngadgets.config.init(" + featureConfig.toString() +
> - (context.getDebug() ? ");" : ", true);");
> + return new JSONObject(syndFeatures, featArray);
> } catch (JSONException e) {
> - return "";
> + return null;
> }
> }
> - return "";
> + return new JSONObject();
> }
> }
>
>
>