Java Code Examples for com.google.gwt.json.client.JSONObject#keySet()

The following examples show how to use com.google.gwt.json.client.JSONObject#keySet() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MockMapFeatureBase.java    From appinventor-extensions with Apache License 2.0 6 votes vote down vote up
/**
 * Process the information from the feature's GeoJSON properties field. Subclasses may override
 * this function to set default values, but _must_ call super.processFromGeoJSON() otherwise
 * properties defined in superclasses will not get set.
 *
 * @param parent the mock feature collection that will contain the feature
 * @param properties the properties object from the GeoJSON
 */
protected void processFromGeoJSON(MockFeatureCollection parent, JSONObject properties) {
  setStrokeWidthProperty(DEFAULT_STROKE_COLOR);
  setStrokeColorProperty(DEFAULT_STROKE_WIDTH);
  String name = null;
  for (String key : properties.keySet()) {
    if (key.equalsIgnoreCase(PROPERTY_NAME_NAME)) {
      name = properties.get(key).isString().stringValue();
    } else {
      processPropertyFromGeoJSON(key, properties.get(key));
    }
  }
  processFeatureName(this, parent, name);
  // Use the name as the title if the properties did not include one (issue #1425)
  if (getPropertyValue(PROPERTY_NAME_TITLE).isEmpty()) {
    changeProperty(PROPERTY_NAME_TITLE, getPropertyValue(PROPERTY_NAME_NAME));
  }
}
 
Example 2
Source File: GadgetUserPrefs.java    From swellrt with Apache License 2.0 6 votes vote down vote up
/**
 * Extracts default preference values from the gadget metadata JSON object
 * returned from GGS.
 *
 * @param prefs the preference JSON object received from GGS.
 */
public void parseDefaultValues(JSONObject prefs) {
  if (prefs != null) {
    for (String pref : prefs.keySet()) {
      if (!has(pref)) {
        JSONObject prefJson = prefs.get(pref).isObject();
        if (prefJson != null) {
          JSONValue value = prefJson.get("default");
          if ((value != null) && (value.isString() != null)) {
            put(pref, value.isString().stringValue());
            log("Gadget pref '" + pref + "' = '" + get(pref) + "'");
          }
        } else {
          log("Invalid pref '" + pref + "' value in Gadget metadata.");
        }
      }
    }
  }
}
 
Example 3
Source File: DataSelectionEvent.java    From dashbuilder with Apache License 2.0 6 votes vote down vote up
public static void fire(HasDataSelectionEventHandlers source, Object sender, JavaScriptObject data) {
    DataSelectionEvent event = new DataSelectionEvent(sender);
    JSONObject array = new JSONObject(data);
    event.series = new LinkedList<Series>();
    for(String key : array.keySet()){

        JSONObject obj = array.get(key).isObject();
        if(obj != null){
            Series series1 = JavaScriptObject.createObject().cast();
            series1.setValue(obj.get("value").isNumber().doubleValue());
            series1.setColor(obj.get("fillColor").isString().stringValue());
            event.series.add(series1);
        }
    }
    source.fireEvent(event);
}
 
Example 4
Source File: GadgetUserPrefs.java    From incubator-retired-wave with Apache License 2.0 6 votes vote down vote up
/**
 * Extracts default preference values from the gadget metadata JSON object
 * returned from GGS.
 *
 * @param prefs the preference JSON object received from GGS.
 */
public void parseDefaultValues(JSONObject prefs) {
  if (prefs != null) {
    for (String pref : prefs.keySet()) {
      if (!has(pref)) {
        JSONObject prefJson = prefs.get(pref).isObject();
        if (prefJson != null) {
          JSONValue value = prefJson.get("default");
          if ((value != null) && (value.isString() != null)) {
            put(pref, value.isString().stringValue());
            log("Gadget pref '" + pref + "' = '" + get(pref) + "'");
          }
        } else {
          log("Invalid pref '" + pref + "' value in Gadget metadata.");
        }
      }
    }
  }
}
 
Example 5
Source File: UploadResponse.java    From core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private String extractFailure(final JSONObject response) {
    String failure = "n/a";
    JSONValue failureValue = response.get(FAILURE_DESCRIPTION);
    if (failureValue.isString() != null) {
        failure = failureValue.isString().stringValue();
    } else if (failureValue.isObject() != null) {
        JSONObject failureObject = failureValue.isObject();
        for (String key : failureObject.keySet()) {
            if (key.contains("failure") && failureObject.get(key).isString() != null) {
                failure = failureObject.get(key).isString().stringValue();
                break;
            }
        }
    }
    return failure;
}
 
Example 6
Source File: BitcoinJSONViewer.java    From bitcoin-transaction-explorer with MIT License 5 votes vote down vote up
private void drawObject(final FlowPanel container, final int n, final JSONObject jsonObject) {
  for (final String key : jsonObject.keySet()) {
    container.add(createHeader(n, key));

    final FlowPanel subPanel = new FlowPanel();

    container.add(subPanel);
    subPanel.getElement().getStyle().setProperty("border", "2px solid gray");
    subPanel.getElement().getStyle().setProperty("marginLeft", "4px");
    subPanel.getElement().getStyle().setProperty("padding", "12px");

    display(n + 1, subPanel, jsonObject.get(key));
  }
}
 
Example 7
Source File: LoadCompatMatrix.java    From core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void execute(Control<BootstrapContext> control) {

    TextResource compat = TextResources.INSTANCE.compat();
    JSONValue root = JSONParser.parseLenient(compat.getText());
    JSONObject versionList = root.isObject();
    Set<String> keys = versionList.keySet();
    for (String key : keys) {
        modelVersions.put(key, versionList.get(key).isString().stringValue());
    }

    System.out.println("Build against Core Model Version: " + modelVersions.get("core-version"));
    control.proceed();
}
 
Example 8
Source File: GadgetMetadata.java    From swellrt with Apache License 2.0 4 votes vote down vote up
/**
 * Parses JSON object to extract metadata information.
 *
 * @param gadget JSON object returned in the gadget field from the server.
 */
public void parse(JSONObject gadget) {
  iframeUrl = getJsonStringValue(gadget, "iframeUrl");
  // Get rid of the protocol as we should rely on the browser to do the right
  // thing with "//" as the beginning of the url.
  // By doing this it also works around an issue in shindig where it shouldn't
  // put "//" in front of "http://" see:
  // https://issues.apache.org/jira/browse/SHINDIG-1460?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12928110#action_12928110
  // This work around may no longer be needed on the next version of shindig
  // Added null check on iframeUrl.Issue #166:Client shiny on broken gadget.
  if(iframeUrl != null) {
    iframeUrl = iframeUrl.replaceFirst("^//http[s]?://", "//");
  }
  url = getJsonStringValue(gadget, "url");
  moduleId = getJsonStringValue(gadget, "moduleId");
  title = getJsonStringValue(gadget, "title");
  titleUrl = getJsonStringValue(gadget, "titleUrl");
  directoryTitle = getJsonStringValue(gadget, "directoryTitle");
  thumbnail = getJsonStringValue(gadget, "thumbnail");
  screenshot = getJsonStringValue(gadget, "screenshot");
  author = getJsonStringValue(gadget, "author");
  authorEmail = getJsonStringValue(gadget, "authorEmail");
  height = getJsonLongValue(gadget, "height");
  width = getJsonLongValue(gadget, "width");
  scrolling = getJsonBooleanValue(gadget, "scrolling");
  // Added null check on gadget.get("userPrefs").Issue #166:Client shiny on broken gadget.
  if(gadget.get("userPrefs") != null) {
    userPrefs.parseDefaultValues(gadget.get("userPrefs").isObject());
  }
  JSONObject gadgetViews = getJsonObjectValue(gadget, "views");
  if (gadgetViews != null) {
    View lastView = null;
    for (String viewName : gadgetViews.keySet()) {
      JSONObject viewJson = gadgetViews.get(viewName).isObject();
      View v = new View();
      v.type = viewName;
      v.preferredHeight = getJsonLongValue(viewJson, "preferredHeight");
      v.preferredWidth = getJsonLongValue(viewJson, "preferredWidth");
      views.put(v.type, v);
      lastView = v;
    }
  }
}
 
Example 9
Source File: GadgetMetadata.java    From incubator-retired-wave with Apache License 2.0 4 votes vote down vote up
/**
 * Parses JSON object to extract metadata information.
 *
 * @param gadget JSON object returned in the gadget field from the server.
 */
public void parse(JSONObject gadget) {
  iframeUrl = getJsonStringValue(gadget, "iframeUrl");
  // Get rid of the protocol as we should rely on the browser to do the right
  // thing with "//" as the beginning of the url.
  // By doing this it also works around an issue in shindig where it shouldn't
  // put "//" in front of "http://" see:
  // https://issues.apache.org/jira/browse/SHINDIG-1460?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12928110#action_12928110
  // This work around may no longer be needed on the next version of shindig
  // Added null check on iframeUrl.Issue #166:Client shiny on broken gadget.
  if(iframeUrl != null) {
    iframeUrl = iframeUrl.replaceFirst("^//http[s]?://", "//");
  }
  url = getJsonStringValue(gadget, "url");
  moduleId = getJsonStringValue(gadget, "moduleId");
  title = getJsonStringValue(gadget, "title");
  titleUrl = getJsonStringValue(gadget, "titleUrl");
  directoryTitle = getJsonStringValue(gadget, "directoryTitle");
  thumbnail = getJsonStringValue(gadget, "thumbnail");
  screenshot = getJsonStringValue(gadget, "screenshot");
  author = getJsonStringValue(gadget, "author");
  authorEmail = getJsonStringValue(gadget, "authorEmail");
  height = getJsonLongValue(gadget, "height");
  width = getJsonLongValue(gadget, "width");
  scrolling = getJsonBooleanValue(gadget, "scrolling");
  // Added null check on gadget.get("userPrefs").Issue #166:Client shiny on broken gadget.
  if(gadget.get("userPrefs") != null) {
    userPrefs.parseDefaultValues(gadget.get("userPrefs").isObject());
  }
  JSONObject gadgetViews = getJsonObjectValue(gadget, "views");
  if (gadgetViews != null) {
    View lastView = null;
    for (String viewName : gadgetViews.keySet()) {
      JSONObject viewJson = gadgetViews.get(viewName).isObject();
      View v = new View();
      v.type = viewName;
      v.preferredHeight = getJsonLongValue(viewJson, "preferredHeight");
      v.preferredWidth = getJsonLongValue(viewJson, "preferredWidth");
      views.put(v.type, v);
      lastView = v;
    }
  }
}