Beispiel #1
0
 public static JSONArray parseJSONArray(String jsonText) {
   if (jsonText != null && 0 < jsonText.length()) {
     JSONValue jsonValue = JSONParser.parse(jsonText);
     if (jsonValue != null) {
       return jsonValue.isArray();
     }
   }
   return null;
 }
Beispiel #2
0
 //
 // Utility methods, also useful when parsing third-party JSON
 //
 public static JSONObject parseJSONObject(String jsonText) {
   if (jsonText != null && 0 < jsonText.length()) {
     // TODO: use GWT json utils class to do safe parsing
     JSONValue jsonValue = JSONParser.parse(jsonText);
     if (jsonValue != null) {
       return jsonValue.isObject();
     }
   }
   return null;
 }
Beispiel #3
0
 /**
  * 静态函数:根据输入的Json字符串,解析成一个完整的菜单树
  *
  * @param menuStr Json字符串
  * @return 菜单树形根节点
  */
 public static GWTMenu GetMenuList(String menuStr) {
   // 解析菜单
   JSONValue obj1 = JSONParser.parse(menuStr);
   JSONArray menuList = obj1.isArray();
   GWTMenu menu = new GWTMenu();
   for (int i = 0; i < menuList.size(); i++) {
     AddGWTMenu(menu, menuList.get(i));
   }
   return menu;
 }
Beispiel #4
0
    private void addProperties(Response response) {
      GWT.log(response.getText(), null);
      try {
        // parse the response text into JSON
        JSONValue jsonValue = JSONParser.parse(response.getText());
        JSONArray jsonArray = jsonValue.isArray();

        if (jsonArray != null) {
          for (int index = 0; index < jsonArray.size(); index++) {
            addProperty(((JSONObject) jsonArray.get(index)), index);
          }
        } else {
          throw new JSONException("Invalid Json structure when retrieve the Sling nodes");
        }
      } catch (JSONException e) {
        e.printStackTrace();
        GWT.log("ResourceGrids - Could not parse JSON", e);
      }
    }
 @SuppressWarnings({"rawtypes", "deprecation", "unchecked"})
 protected Object[] extractDate(Criteria criteria, OperatorId operator, Map values, String key) {
   Object value;
   String jsObj = JSON.encode(criteria.getJsObj());
   JSONObject criteriaObj = JSONParser.parse(jsObj).isObject();
   JSONObject valueObj = criteriaObj.get(key).isObject();
   if (valueObj != null) {
     value = parseRelativeDate((Map<String, String>) values.get(key));
   } else {
     value = values.get(key);
   }
   if (OperatorId.GREATER_THAN.getValue().equals(operator.getValue())
       || OperatorId.LESS_OR_EQUAL.getValue().equals(operator.getValue())) {
     ((Date) value).setHours(23);
     ((Date) value).setMinutes(59);
   } else {
     ((Date) value).setHours(0);
     ((Date) value).setMinutes(0);
   }
   return new Object[] {value};
 }
Beispiel #6
0
  /** {@code ClickHandler} */
  @Override
  public void onClick(ClickEvent event) {
    NativeEvent nativeEvent = event.getNativeEvent();
    Element element = DOM.eventGetTarget(Event.as(nativeEvent));
    element =
        GWTUtils.getElementWithAttr((com.google.gwt.user.client.Element) element.cast(), "uid");
    Element dataQueryEl = null;
    if (element != null) {
      dataQueryEl =
          GWTUtils.findDataQueryElement((com.google.gwt.user.client.Element) element.cast());
      String uid = element.getAttribute("uid");
      String json = dataQueryEl.getAttribute("data-query");

      if (!GWTUtils.isEmpty(uid)) {
        JSONObject targetJson = null;
        if (!GWTUtils.isEmpty(json)) {
          targetJson = (JSONObject) JSONParser.parse(json);
        }
        processClickEvent(uid, targetJson);
      }
    } else {
      return;
    }
  }