Package com.google.gwt.json.client

Examples of com.google.gwt.json.client.JSONObject


    this.modelType = modelType;
  }

  @SuppressWarnings({"unchecked", "rawtypes"})
  public D read(Object loadConfig, Object data) {
    JSONObject jsonRoot = null;
    if (data instanceof JavaScriptObject) {
      jsonRoot = new JSONObject((JavaScriptObject) data);
    } else {
      jsonRoot = (JSONObject) JSONParser.parse((String) data);
    }
    JSONArray root = (JSONArray) jsonRoot.get(modelType.getRoot());
    int size = root.size();
    ArrayList<ModelData> models = new ArrayList<ModelData>();
    for (int i = 0; i < size; i++) {
      JSONObject obj = (JSONObject) root.get(i);
      ModelData model = newModelInstance();
      for (int j = 0; j < modelType.getFieldCount(); j++) {
        DataField field = modelType.getField(j);
        String name = field.getName();
        Class type = field.getType();
        String map = field.getMap() != null ? field.getMap() : field.getName();
        JSONValue value = obj.get(map);

        if (value == null) continue;
        if (value.isArray() != null) {
          // nothing
        } else if (value.isBoolean() != null) {
View Full Code Here


  @Override
  protected Splittable readSplittable(Object loadConfig, JavaScriptObject data) {
    if (GWT.isScript()) {
      return data.<JsoSplittable> cast();
    } else {
      JSONObject json = new JSONObject(data);
      return StringQuoter.split(json.toString());
    }
  }
View Full Code Here

          if (devicesArray != null) {

            textHTML = "Result:";

            for (int i = 0; i < devicesArray.size(); i++) {
              JSONObject deviceObj = devicesArray.get(i)
                  .isObject();
              textHTML = textHTML + "<br/>"
                  + deviceObj.get("name");
            }

            text.setHTML(textHTML);

          }
View Full Code Here

          JSONArray devicesArray = value.isArray();

          if (devicesArray != null) {
            textHTML = "Result:";
            for (int i = 0; i < devicesArray.size(); i++) {
              JSONObject deviceObj = devicesArray.get(i).isObject();
              textHTML = textHTML + "<br/>"
                  + deviceObj.get("name");
            }
            text.setHTML(textHTML);
          }
        } catch (Exception e) {
          e.printStackTrace();
View Full Code Here

   * @return the metadata object
   */
  public GadgetMetadata getTestMetadata(String xmlSource) {
    String iFrameUrl =
        "//0" + GADGET_SERVER + "/gadgets/ifr?url=http://test.com/gadget.xml&view=canvas";
    JSONObject canvasViewData = new JSONObject();
    JSONObject viewData = new JSONObject();
    viewData.put(VIEW_NAME, canvasViewData);
    JSONObject jsonData = new JSONObject();
    jsonData.put("iframeUrl", new JSONString(iFrameUrl));
    jsonData.put("views", viewData);
    jsonData.put("url", new JSONString(xmlSource));
    jsonData.put("userPrefs", new JSONObject());
    return new GadgetMetadata(jsonData);
  }
View Full Code Here

    }
    return gadgetList;
  }

  private GadgetInfo parseGadgetInfo(JSONValue item) {
    JSONObject object = item.isObject();
    if (object != null) {
      String name = object.get("name").isString().stringValue();
      String desc = object.get("desc").isString().stringValue();
      GadgetCategoryType primaryCategory =
          GadgetCategoryType.of(object.get("primaryCategory").isString().stringValue());
      GadgetCategoryType secondaryCategory =
          GadgetCategoryType.of(object.get("secondaryCategory").isString().stringValue());
      String gadgetUrl = object.get("gadgetUrl").isString().stringValue();
      String author = object.get("author").isString().stringValue();
      String submittedBy = object.get("submittedBy").isString().stringValue();
      String imageUrl = object.get("imageUrl").isString().stringValue();

      return new GadgetInfo(name, desc, primaryCategory, secondaryCategory, gadgetUrl, author,
          submittedBy, imageUrl);
    }
    return null;
View Full Code Here

   */
  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 {
View Full Code Here

    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);
View Full Code Here

    final String nonSecureGadgetDataKey = gadgetSpecUrl;
    if (fetchDataByKey(nonSecureGadgetDataKey, receiveDataCommand)) {
      return;
    }

    JSONObject request = new JSONObject();
    JSONObject requestContext = new JSONObject();
    JSONArray gadgets = new JSONArray();
    JSONObject gadget = new JSONObject();
    try {
      gadget.put("url", new JSONString(gadgetSpecUrl));
      gadgets.set(0, gadget);
      requestContext.put("container", new JSONString("wave"));
      request.put("context", requestContext);
      request.put("gadgets", gadgets);
      RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, GADGET_METADATA_PATH);
      builder.sendRequest(request.toString(), new RequestCallback() {

        public void onError(Request request, Throwable exception) {
          receiveDataCommand.onError("Error retrieving metadata from the server.", exception);
        }

        public void onResponseReceived(Request request, Response response) {
          JSONObject gadgetMetadata = null;
          try {
            gadgetMetadata =
                JSONParser.parseLenient(response.getText()).isObject().get("gadgets").isArray().get(
                    0).isObject();
          } catch (NullPointerException exception) {
View Full Code Here

  @Override
  protected Splittable readSplittable(Object loadConfig, JavaScriptObject data) {
    if (GWT.isScript()) {
      return data.<JsoSplittable> cast();
    } else {
      JSONObject json = new JSONObject(data);
      return StringQuoter.split(json.toString());
    }
  }
View Full Code Here

TOP

Related Classes of com.google.gwt.json.client.JSONObject

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.