/** * @param context Request global parameters. * @param gadget Values for the gadget being rendered. * @throws JSONException If parameters can't be extracted or aren't correctly formed. */ public JsonRpcGadgetContext(JSONObject context, JSONObject gadget) throws JSONException { this.context = context; this.gadget = gadget; url = getUrl(gadget); moduleId = getModuleId(gadget); userPrefs = getUserPrefs(gadget); locale = getLocale(context); view = context.optString("view"); ignoreCache = context.optBoolean("ignoreCache"); container = context.optString("container"); debug = context.optBoolean("debug"); }
GadgetContext context = new JsonRpcGadgetContext( requestContext, requestedGadgets.getJSONObject(i)); gadgets.add(context);
GadgetContext context = new JsonRpcGadgetContext( requestContext, requestedGadgets.getJSONObject(i)); gadgets.add(context);
/** * @param context Request global parameters. * @param gadget Values for the gadget being rendered. * @throws JSONException If parameters can't be extracted or aren't correctly formed. */ public JsonRpcGadgetContext(JSONObject context, JSONObject gadget) throws JSONException { this.context = context; this.gadget = gadget; url = getUrl(gadget); moduleId = getModuleId(gadget); userPrefs = getUserPrefs(gadget); locale = getLocale(context); view = context.optString("view"); ignoreCache = context.optBoolean("ignoreCache"); container = context.optString("container"); debug = context.optBoolean("debug"); }
GadgetContext context = new JsonRpcGadgetContext( requestContext, requestedGadgets.getJSONObject(i)); gadgets.add(context);
/** * @param context Request global parameters. * @param gadget Values for the gadget being rendered. * @throws JSONException If parameters can't be extracted or aren't correctly formed. */ public JsonRpcGadgetContext(JSONObject context, JSONObject gadget) throws JSONException { this.context = context; this.gadget = gadget; url = getUrl(gadget); moduleId = getModuleId(gadget); userPrefs = getUserPrefs(gadget); locale = getLocale(context); view = context.optString("view"); ignoreCache = context.optBoolean("ignoreCache"); container = context.optString("container"); debug = context.optBoolean("debug"); }
@Test public void testCorrectExtraction() throws Exception { JSONObject gadget = new JSONObject() .put("url", SPEC_URL) .put("moduleId", SPEC_ID) .put("prefs", prefs) .put("gadget-field", "gadget-value"); JSONObject context = new JSONObject() .put("language", Locale.US.getLanguage()) .put("country", Locale.US.getCountry().toUpperCase()) .put("context-field", "context-value"); GadgetContext jsonContext = new JsonRpcGadgetContext(context, gadget); assertEquals(SPEC_URL, jsonContext.getUrl().toString()); assertEquals(SPEC_ID, jsonContext.getModuleId()); assertEquals(Locale.US.getLanguage(), jsonContext.getLocale().getLanguage()); assertEquals(Locale.US.getCountry(), jsonContext.getLocale().getCountry()); for (String key : PREF_KEYS) { String value = jsonContext.getUserPrefs().getPref(key); assertEquals(prefs.get(key), value); } assertEquals("gadget-value", jsonContext.getParameter("gadget-field")); assertEquals("context-value", jsonContext.getParameter("context-field")); } }
@Test public void testCorrectExtraction() throws Exception { JSONObject gadget = new JSONObject() .put("url", SPEC_URL) .put("moduleId", SPEC_ID) .put("prefs", prefs) .put("gadget-field", "gadget-value"); JSONObject context = new JSONObject() .put("language", Locale.US.getLanguage()) .put("country", Locale.US.getCountry().toUpperCase()) .put("context-field", "context-value"); GadgetContext jsonContext = new JsonRpcGadgetContext(context, gadget); assertEquals(SPEC_URL, jsonContext.getUrl().toString()); assertEquals(SPEC_ID, jsonContext.getModuleId()); assertEquals(Locale.US.getLanguage(), jsonContext.getLocale().getLanguage()); assertEquals(Locale.US.getCountry(), jsonContext.getLocale().getCountry()); for (String key : PREF_KEYS) { String value = jsonContext.getUserPrefs().getPref(key); assertEquals(prefs.get(key), value); } assertEquals("gadget-value", jsonContext.getParameter("gadget-field")); assertEquals("context-value", jsonContext.getParameter("context-field")); } }
@Test public void testCorrectExtraction() throws Exception { JSONObject gadget = new JSONObject() .put("url", SPEC_URL) .put("moduleId", SPEC_ID) .put("prefs", prefs) .put("gadget-field", "gadget-value"); JSONObject context = new JSONObject() .put("language", Locale.US.getLanguage()) .put("country", Locale.US.getCountry().toUpperCase()) .put("context-field", "context-value"); GadgetContext jsonContext = new JsonRpcGadgetContext(context, gadget); assertEquals(SPEC_URL, jsonContext.getUrl().toString()); assertEquals(SPEC_ID, jsonContext.getModuleId()); assertEquals(Locale.US.getLanguage(), jsonContext.getLocale().getLanguage()); assertEquals(Locale.US.getCountry(), jsonContext.getLocale().getCountry()); for (String key : PREF_KEYS) { String value = jsonContext.getUserPrefs().getPref(key); assertEquals(prefs.get(key), value); } assertEquals("gadget-value", jsonContext.getParameter("gadget-field")); assertEquals("context-value", jsonContext.getParameter("context-field")); } }