예제 #1
0
  @Override
  protected void onResponseReceived(
      boolean succeed, JSONObject jsonResponse, Request request, Response response) {
    if (succeed) {
      // Parsing project
      Project proj = getProps().getProject();
      proj.setName(project);
      JSONProjectParser projParser = new JSONProjectParser();
      JSONObject projectJSON = jsonResponse.get(JSONConstants.KEY_PROJECT).isObject();
      projParser.fillProject(proj, projectJSON);

      // Parsing current user
      User user = getProps().getUser();
      user.setLogin(login);
      user.setPwd(pwd);
      JSONObject userJSON = jsonResponse.get(JSONConstants.KEY_USER).isObject();
      JSONUserParser userParser = new JSONUserParser();
      userParser.fillUser(user, userJSON);

      // parsing of the project members
      JSONMemberParser.parseListMembers(jsonResponse, proj);

      parentScreen.onValidLogin();
    } else {
      parentScreen.onWrongLogin();
    }
  }
예제 #2
0
  @Override
  protected void onInit(final JSONValue data) {

    try {
      final JSONArray criteria = data.isArray();
      this.criteria.clear();

      for (int i = 0; i < criteria.size(); i++) {
        final JSONObject searchTypeJSON = criteria.get(i).isObject();
        final Map<String, Criterion> searchType = new LinkedHashMap<String, Criterion>();

        for (int j = 0; j < searchTypeJSON.get("elements").isArray().size(); j++) {
          final Criterion criterion = Criterion.readMe(j, searchTypeJSON);
          if (j == 0
              && (selectedCriterion == null && i == 0
                  || selectedCriterion != null
                      && criterion.displaytype.equalsIgnoreCase(selectedCriterion.displaytype))) {
            selectedCriterion = criterion;
            selectedCriterionHistory.put(selectedCriterion.displaytype, selectedCriterion);
          }
          searchType.put(criterion.getName(), criterion);
        }
        this.criteria.put(
            searchTypeJSON.get("displaytype").isString().stringValue().trim(), searchType);
      }
    } catch (final Exception e) {
      getLogger().severe(getClass().getName().replace("Impl", "") + ".onInit() : " + e);
    }
  }
예제 #3
0
  // translate the json for an elective to the class attributes
  protected void translateJson(JSONObject winJson) {
    String startDate, endDate;

    handle = winJson.get("handle").isString().stringValue();

    id = (int) winJson.get("id").isNumber().doubleValue();

    complete = winJson.get("complete").isBoolean().booleanValue();

    // what are the dates that this elective spans?
    JSONString firstPeriod = winJson.get("firstPeriod").isString();
    if (firstPeriod != null) {
      String startStr = firstPeriod.stringValue();
      Date start = DateTimeFormat.getFormat("yyyy-MM-dd HH:mm:ss").parse(startStr);
      startDate = DateTimeFormat.getFormat("yyyy-MM-dd").format(start);
    } else {
      startDate = "None";
    }

    JSONString lastPeriod = winJson.get("lastPeriod").isString();
    if (lastPeriod != null) {
      String endStr = lastPeriod.stringValue();
      Date end = DateTimeFormat.getFormat("yyyy-MM-dd HH:mm:ss").parse(endStr);
      endDate = DateTimeFormat.getFormat("yyyy-MM-dd").format(end);
    } else {
      endDate = "None";
    }

    // the header is a summary: [date range] time, complete (id)
    header = "Elective [" + startDate + " - " + endDate + "] (" + Integer.toString(id) + "): ";
  }
  public static <KeyType, ValueType> Map<KeyType, ValueType> toMap(
      JSONValue value,
      AbstractJsonEncoderDecoder<KeyType> keyEncoder,
      AbstractJsonEncoderDecoder<ValueType> valueEncoder,
      Style style) {
    if (value == null || value.isNull() != null) {
      return null;
    }

    switch (style) {
      case DEFAULT:
      case SIMPLE:
        {
          JSONObject object = value.isObject();
          if (object == null) {
            throw new DecodingException("Expected a json object, but was given: " + value);
          }

          HashMap<KeyType, ValueType> rc = new HashMap<KeyType, ValueType>(object.size() * 2);
          for (String key : object.keySet()) {
            rc.put(keyEncoder.decode(key), valueEncoder.decode(object.get(key)));
          }
          return rc;
        }
      case JETTISON_NATURAL:
        {
          JSONObject object = value.isObject();
          if (object == null) {
            throw new DecodingException("Expected a json object, but was given: " + value);
          }
          value = object.get("entry");
          if (value == null) {
            throw new DecodingException("Expected an entry array not found");
          }
          JSONArray entries = value.isArray();
          if (entries == null) {
            throw new DecodingException("Expected an entry array, but was given: " + value);
          }

          HashMap<KeyType, ValueType> rc = new HashMap<KeyType, ValueType>(object.size() * 2);
          for (int i = 0; i < entries.size(); i++) {
            JSONObject entry = entries.get(i).isObject();
            if (entry == null)
              throw new DecodingException("Expected an entry object, but was given: " + value);
            JSONValue key = entry.get("key");
            if (key == null) throw new DecodingException("Expected an entry key field not found");
            JSONString k = key.isString();
            if (k == null)
              throw new DecodingException(
                  "Expected an entry key to be a string, but was given: " + value);
            rc.put(keyEncoder.decode(k.stringValue()), valueEncoder.decode(entry.get("value")));
          }
          return rc;
        }
      default:
        throw new UnsupportedOperationException(
            "The encoding style is not yet supported: " + style.name());
    }
  }
예제 #5
0
  private static ServerEvent parseJsonEvent(String msg) {
    try {
      JSONObject eventJ = JSONParser.parseStrict(msg).isObject();
      Name name = new Name(eventJ.get("name").isString().stringValue(), "");
      ServerEvent.Scope scope =
          ServerEvent.Scope.valueOf(eventJ.get("scope").isString().stringValue());
      ServerEvent.DataType dataType =
          eventJ.get("dataType") == null
              ? ServerEvent.DataType.STRING
              : ServerEvent.DataType.valueOf(eventJ.get("dataType").isString().stringValue());
      Serializable data;
      String from = eventJ.get("from") == null ? null : eventJ.get("from").toString();
      if (dataType == ServerEvent.DataType.BG_STATUS) {
        data = BackgroundStatus.parse(eventJ.get("data").isString().stringValue());
      } else if (dataType == ServerEvent.DataType.JSON) {
        data = eventJ.get("data").isObject().toString();
      } else {
        data = eventJ.get("data").isString().stringValue();
      }
      ServerEvent sEvent = new ServerEvent(name, scope, dataType, data);
      sEvent.setFrom(from);
      return sEvent;

    } catch (Exception e) {
      GwtUtil.getClientLogger()
          .log(Level.WARNING, "Unable to parse json message into ServerEvent: " + msg, e);
      return null;
    }
  }
예제 #6
0
  public Album(JSONObject jsonObject, G3Viewer a_Container) {
    m_UploadControl = a_Container.getUploadControl();
    m_ID = Utils.extractId(jsonObject.get("id"));
    m_Title = ((JSONString) jsonObject.get("title")).stringValue();
    m_Sort = ((JSONString) jsonObject.get("sort")).stringValue();

    m_Container = a_Container;
    m_View = a_Container.getView();
    m_DropController = new AlbumTreeDropController(this);
    m_Label = initComponents();
  }
예제 #7
0
 public void onJsonReceived(JSONValue jsonValue) {
   JSONObject jsonObject = jsonValue.isObject();
   if (jsonObject == null) {
     return;
   }
   if (jsonObject.containsKey("serverTime"))
     lastSyncDate.put(gameId, (long) jsonObject.get("serverTime").isNumber().doubleValue());
   if (jsonObject.get("error") != null) {
     Authentication.getInstance().disAuthenticate();
   } else {
     onJsonArrayReceived(jsonObject);
   }
 }
예제 #8
0
 public void updateValues(JSONValue a_Jso) {
   JSONObject jso = a_Jso.isObject();
   if (jso != null) {
     m_Title = ((JSONString) jso.get("title")).stringValue();
     String oldSort = m_Sort;
     m_Sort = ((JSONString) jso.get("sort")).stringValue();
     if (!oldSort.equals(m_Sort)) {
       if (m_View.getCurrentAlbum() == this) {
         select();
       }
     }
     m_Label.setText(m_Title);
   }
 }
예제 #9
0
    private void addProperty(JSONObject jsonObject, int index) {

      Item item =
          new Item(
              jsonObject.get("itemType").isString().stringValue(),
              jsonObject.get("multi").isBoolean().booleanValue(),
              jsonObject.get("name").isString().stringValue(),
              jsonObject.get("type").isString().stringValue(),
              jsonObject.get("value").isString().stringValue());

      if (item.getItemType().equals(ExplorerConstants.PROPERTY))
        addToPropertyGrid(propertyGrid, item);
      else addToChildrenResourceGrid(resourceGrid, item);
    }
예제 #10
0
  private void populateTests() {
    display.getTestSelection().deselectAll();
    display.getTestTable().clear();

    JSONArray tests = staticData.getData("tests").isArray();
    for (JSONObject test : new JSONArrayList<JSONObject>(tests)) {
      if (!includeExperimentalTests() && test.get("experimental").isBoolean().booleanValue()) {
        continue;
      }
      String testType = test.get("test_type").isString().stringValue();
      if (testType.equals(getSelectedTestType())) {
        display.getTestTable().addRow(test);
      }
    }
  }
 @Override
 public UserDetails deserialize(String json) {
   JSONValue parsed = JSONParser.parseStrict(json);
   JSONObject jsonObj = parsed.isObject();
   UserDetailsDTO user = new UserDetailsDTO();
   if (jsonObj != null) {
     user.setUsername(jsonObj.get(UserDetailsDTO.USERNAME_FIELD).toString());
     JSONArray array = jsonObj.get(UserDetailsDTO.AUTHORITIES_FIELD).isArray();
     for (int i = 0; i < array.size(); i++) {
       JSONValue obj = array.get(i);
       user.getAuthorities().add(obj.toString());
     }
   }
   return user;
 }
예제 #12
0
  /*
   * view Album contents
   */
  private void viewAlbum(JSONValue a_Value) {

    JSONArray jsonArray = (JSONArray) a_Value;

    Item item = null;
    int id;
    JSONObject jso;

    m_Items.clear();

    for (int i = 0; i < jsonArray.size(); ++i) {
      jso = (JSONObject) jsonArray.get(i);
      id = Utils.extractId(jso.get("id"));

      if (m_IDtoItem.containsKey(id)) {
        item = m_IDtoItem.get(id);
        item.updateValues(jso);
      } else {
        item = new Item(this, jso, m_Container);
        m_IDtoItem.put(id, item);

        if (item.isAlbum()) {
          linkAlbum(item);
        }
      }
      m_Items.add(item);
    }

    m_View.setAlbum(this);
    addPendingDownloads();
  }
예제 #13
0
 public List<JsonStream> readStreamRepeated(
     JSONObject jsonObject, String fieldLabel, int fieldNumber)
     throws InvalidProtocolBufferException {
   List<JsonStream> fieldStreamRepeated = null;
   if (jsonObject != null) {
     JSONValue fieldValue = jsonObject.get(fieldLabel);
     if (fieldValue != null) {
       JSONArray fieldJSONArray = jsonValueToArray(fieldValue);
       if (fieldJSONArray != null) {
         fieldStreamRepeated = new ArrayList<JsonStream>();
         for (int i = 0; i < fieldJSONArray.size(); ++i) {
           JsonStream fieldStream = null;
           JSONObject fieldJSONObject = jsonValueToObject(fieldJSONArray.get(i));
           if (fieldJSONObject != null) {
             fieldStream = this.newStream(fieldJSONObject);
           }
           if (fieldStream != null) {
             fieldStreamRepeated.add(fieldStream);
           } else {
             throw InvalidProtocolBufferException.failedToReadObjectRepeated(fieldLabel);
           }
         }
       } else {
         throw InvalidProtocolBufferException.failedToReadObjectRepeated(fieldLabel);
       }
     }
   }
   return fieldStreamRepeated;
 }
예제 #14
0
 protected List<String> readStringRepeated(
     JSONObject jsonObject, String fieldLabel, int fieldNumber)
     throws InvalidProtocolBufferException {
   List<String> fieldStringRepeated = null;
   if (jsonObject != null && fieldLabel != null) {
     JSONValue fieldValue = jsonObject.get(fieldLabel);
     if (fieldValue != null) {
       JSONArray fieldJSONArray = jsonValueToArray(fieldValue);
       if (fieldJSONArray != null) {
         fieldStringRepeated = new ArrayList<String>();
         for (int i = 0; i < fieldJSONArray.size(); ++i) {
           String fieldString = jsonValueToString(fieldJSONArray.get(i));
           if (fieldString != null) {
             fieldStringRepeated.add(fieldString);
           } else {
             throw InvalidProtocolBufferException.failedToReadStringRepeated(fieldLabel);
           }
         }
       } else {
         throw InvalidProtocolBufferException.failedToReadStringRepeated(fieldLabel);
       }
     }
   }
   return fieldStringRepeated;
 }
예제 #15
0
    @Override
    public void onResponseReceived(Request request, Response response) {
      JSONValue j = JSONParser.parseStrict(response.getText());
      JSONObject obj = j.isObject();
      if (obj != null && obj.containsKey("error")) {
        Window.alert(obj.get("error").isString().stringValue());
        changeButtonSelection();
        setTextEnabled(false);
        clearTextBoxes();
        singleSelectionModel.clear();
      } else {
        List<OrganismInfo> organismInfoList =
            OrganismInfoConverter.convertJSONStringToOrganismInfoList(response.getText());
        dataGrid.setSelectionModel(singleSelectionModel);
        MainPanel.getInstance().getOrganismInfoList().clear();
        MainPanel.getInstance().getOrganismInfoList().addAll(organismInfoList);
        changeButtonSelection();
        OrganismChangeEvent organismChangeEvent = new OrganismChangeEvent(organismInfoList);
        organismChangeEvent.setAction(OrganismChangeEvent.Action.LOADED_ORGANISMS);
        Annotator.eventBus.fireEvent(organismChangeEvent);

        // in the case where we just add one . . .we should refresh the app state
        if (organismInfoList.size() == 1) {
          MainPanel.getInstance().getAppState();
        }
      }
      if (savingNewOrganism) {
        savingNewOrganism = false;
        setNoSelection();
        changeButtonSelection(false);
        loadingDialog.hide();
      }
    }
예제 #16
0
    private void addTreeItem(JSONObject jsonObject, int index) {

      Node node =
          new Node(
              jsonObject.get("id").isString().stringValue(),
              jsonObject.get("leaf").isBoolean().booleanValue(),
              jsonObject.get("text").isString().stringValue());
      if (node.getText() != null) {
        TreeItem item = new TreeItem();
        item.setText(node.getText());
        item.setUserObject(node);
        if (!node.isLeaf()) item.addItem(""); // Temporarily add an item so we can expand this node

        treeItem.addItem(item);
      }
    }
예제 #17
0
 @Override
 protected void updateGroupPeriod(JSONObject json) {
   JSONObject winJson = json.get("elective").isObject();
   translateJson(winJson);
   loadPeriodGroup();
   // update the elective periods
   epe.loadData();
 }
  public EditProblemInterview(JSONObject interview) {

    this.setSpacing(20);

    this.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);

    String companyUniqueID = ConvertJson.convertToString(interview.get("company"));
    if (companyUniqueID == null) {

      companyUniqueID =
          ConvertJson.convertToString(UniqueIDGlobalVariables.companyUniqueID.get("ID"));

      ConvertJson.setStringValue(interview, companyUniqueID, "company");
    }

    String interviewerUniqueID = ConvertJson.convertToString(interview.get("interviewer"));
    if (interviewerUniqueID == null && UniqueIDGlobalVariables.uniqueID != null) {

      interviewerUniqueID = ConvertJson.convertToString(UniqueIDGlobalVariables.uniqueID.get("ID"));

      ConvertJson.setStringValue(interview, interviewerUniqueID, "interviewer");
    }
    this.add(FormField.getStringField("Interviewer", interviewerUniqueID));

    String date = ConvertJson.convertToString(interview.get("datetime"));
    if (date == null) {
      dateTime.setValue(new Date());
    } else {
      dateTime.setValue(new Date(new Long(date)));
    }

    this.add(FormField.getFormField("<font color=red>*</font> Date", dateTime));

    String problem = ConvertJson.convertToString(interview.get("problem"));
    problemField = new ProblemsListbox(problem);
    this.add(FormField.getFormField("<font color=red>*</font> Problem", problemField));

    String customerName = ConvertJson.convertToString(interview.get("customerName"));
    customerNameField.setValue(customerName);
    this.add(FormField.getFormField("<font color=red>*</font> Customer Name", customerNameField));

    String customerUniqueID = ConvertJson.convertToString(interview.get("customerUniqueID"));
    customerUniqueIDField.setValue(customerUniqueID);
    this.add(FormField.getFormField("Customer UniqueID", customerUniqueIDField));

    String videoURLValue = ConvertJson.convertToString(interview.get("videoURL"));
    videoURLField.setValue(videoURLValue);
    this.add(FormField.getFormField("Video URL", videoURLField));
    videoURLField.setWidth("300px");

    String notesValue = ConvertJson.convertToString(interview.get("notes"));
    notes.setHTML(notesValue);
    this.add(FormField.getFormField("Notes", notes));
    notes.setSize("300px", "100px");
  }
 /**
  * EventBus実装での同期メッセージング イベントでの実装が、他と同レベルなコンテキストに書かれてしまう事が、どうしても欠点として映る。
  *
  * @param toName
  * @param command
  * @param tagValue
  */
 public void sCall(String toName, String command, JSONObject... tagValue) {
   for (JSONObject currentChild : childList) {
     if (currentChild.get(CHILDLIST_KEY_CHILD_NAME).isString().stringValue().equals(toName)) {
       String toID = currentChild.get(CHILDLIST_KEY_CHILD_ID).isString().stringValue();
       JSONObject messageMap =
           getMessageStructure(
               MS_CATEGOLY_CALLCHILD,
               UUID.uuid(8, 16),
               getName(),
               getID(),
               toName,
               toID,
               command,
               tagValue);
       MessageMasterHub.getMaster().syncMessage(messageMap.toString());
       addSendLog(messageMap);
     }
   }
 }
  public static Productivity convertJsonToProductivityEntry(JSONObject jsonEntry) {

    Productivity productivity = new Productivity();

    try {

      productivity.setDate(ConvertJsonp.convertToDate(jsonEntry.get(TIME)));

      productivity.setClassesCount(ConvertJsonp.convertToInteger(jsonEntry.get(TOTAL_FILES)));

      productivity.setClassActivityCount(
          ConvertJsonp.convertToInteger(jsonEntry.get(TOTAL_EFFORT)));

    } catch (JSONException e) {

      e.printStackTrace();
    }

    return productivity;
  }
 /**
  * 非同期メッセージを子供へと送信するメソッド 子供へのメッセージング
  *
  * @param toName
  * @param command
  * @param tagValue
  */
 public void call(String toName, String command, JSONObject... tagValue) {
   //		Window.alert("送る前までは来てる	"+childList);
   for (JSONObject currentChild : childList) {
     //			Window.alert("currentChild	"+currentChild);
     if (currentChild.get(CHILDLIST_KEY_CHILD_NAME).isString().stringValue().equals(toName)) {
       String toID = currentChild.get(CHILDLIST_KEY_CHILD_ID).isString().stringValue();
       JSONObject messageMap =
           getMessageStructure(
               MS_CATEGOLY_CALLCHILD,
               UUID.uuid(8, 16),
               getName(),
               getID(),
               toName,
               toID,
               command,
               tagValue);
       sendAsyncMessage(messageMap);
       //				Window.alert("送った");
     }
   }
 }
예제 #22
0
  /**
   * 添加子菜单
   *
   * @param parentMenu 父菜单
   * @param menuItem Json对象
   */
  private static void AddGWTMenu(GWTMenu parentMenu, JSONValue menuItem) {
    JSONObject itemObj = menuItem.isObject();

    if (NeedAdd(GetString(itemObj, "Role")) && IsClient(GetString(itemObj, "Type"))) {
      GWTMenu menu =
          new GWTMenu(
              menuID++,
              GetString(itemObj, Desc),
              GetString(itemObj, IconName),
              GetString(itemObj, URL));

      menu.AddTabItem(itemObj.get(TabItem).isArray());
      JSONArray childList = itemObj.get("Child").isArray();
      if (childList != null) {
        for (int i = 0; i < childList.size(); i++) {
          AddGWTMenu(menu, childList.get(i));
        }
      }
      parentMenu.children.add(menu);
    }
  }
 public static JSONObject toObjectFromWrapper(JSONValue value, String name) {
   JSONObject object = value.isObject();
   if (object == null) {
     throw new DecodingException("Expected a json object, but was given: " + object);
   }
   JSONValue result = object.get(name);
   if (result == null) {
     // no wrapper found but that is possible within the hierarchy
     return toObject(value);
   }
   return toObject(result);
 }
 @Override
 public void buildWidget(JSONObject jsonObj, Widget parent) {
   VkMenuBarHorizontal tree = (VkMenuBarHorizontal) parent;
   addAttributes(jsonObj, parent);
   JSONArray items = jsonObj.get("items").isArray();
   for (int i = 0; i < items.size(); i++) {
     JSONObject item = items.get(i).isObject();
     JSONValue js = item.get("js");
     if (js != null)
       ((VkMenuBarHorizontalEngine)
               VkStateHelper.getInstance()
                   .getWidgetEngineMapping()
                   .getEngineMap()
                   .get(((IVkWidget) tree).getWidgetName()))
           .addMenuItem(
               tree,
               item.get("html").isString().stringValue(),
               item.get("js").isString().stringValue());
     else if (item.containsKey("child")) {
       JSONObject childObj = item.get("child").isObject();
       JSONString widgetName = childObj.get("widgetName").isString();
       Widget widget = VkStateHelper.getInstance().getEngine().getWidget(widgetName.stringValue());
       VkStateHelper.getInstance().getEngine().addWidget(widget, ((IVkPanel) tree));
       VkStateHelper.getInstance()
           .getWidgetEngineMapping()
           .getEngineMap()
           .get(((IVkWidget) widget).getWidgetName())
           .buildWidget(childObj, widget);
       // addAttributes(childObj, widget);
     } else if (item.get("separator") == null) {
       VkMenuBarHorizontal subTree =
           (VkMenuBarHorizontal)
               VkStateHelper.getInstance()
                   .getEngine()
                   .getWidget(VkMenuBarVertical.NAME); // all submenus are vertical
       // addAttributes(item.get("menu").isObject(), subTree);
       tree.addItem(new MenuItem(item.get("html").isString().stringValue(), subTree));
       VkStateHelper.getInstance()
           .getWidgetEngineMapping()
           .getEngineMap()
           .get(((IVkWidget) tree).getWidgetName())
           .buildWidget(item.get("menu").isObject(), subTree);
     } else addSeparator(tree);
   }
 }
예제 #25
0
  public static void onMessage(String msg) {
    try {
      GwtUtil.getClientLogger().log(Level.INFO, "onMessage: " + msg);

      ServerEvent sEvent = parseJsonEvent(msg);
      Name name = sEvent == null ? null : sEvent.getName();
      Serializable data = sEvent.getData();

      if (name == null) {
        GwtUtil.getClientLogger().log(Level.INFO, "Failed to evaluate: " + msg);
      }
      if (name.equals(Name.EVT_CONN_EST)) {
        JSONObject dataJ = JSONParser.parseStrict(sEvent.getData().toString()).isObject();
        String sEventInfo =
            dataJ.get("connID").isString().stringValue()
                + "_"
                + dataJ.get("channel").isString().stringValue();
        Cookies.setCookie("seinfo", sEventInfo);
        GwtUtil.getClientLogger()
            .log(Level.INFO, "Websocket connection established: " + sEventInfo);
      } else if (data instanceof BackgroundStatus) {
        WebEvent<String> ev =
            new WebEvent<String>(
                ClientEventQueue.class, name, ((BackgroundStatus) data).serialize());
        WebEventManager.getAppEvManager().fireEvent(ev);
        GwtUtil.getClientLogger()
            .log(Level.INFO, "Event: Name:" + name.getName() + ", Data: " + ev.getData());
      } else {
        WebEvent<String> ev =
            new WebEvent<String>(ClientEventQueue.class, name, String.valueOf(data));
        WebEventManager.getAppEvManager().fireEvent(ev);
        GwtUtil.getClientLogger()
            .log(Level.INFO, "Event: Name:" + name.getName() + ", Data: " + sEvent.getData());
      }
    } catch (Exception e) {
      GwtUtil.getClientLogger()
          .log(Level.WARNING, "Exception interpreting incoming message: " + msg, e);
    }
  }
  /**
   * @param jsonObj
   * @param key
   * @return
   */
  public static JSONArray getArray(final JSONObject jsonObj, final String key) {
    JSONArray ret = null; // assume failure

    if (jsonObj != null && key != null) {
      JSONValue val = jsonObj.get(key);

      if (val != null) {
        ret = val.isArray();
      }
    }

    return ret;
  }
예제 #27
0
 private void showList(String json) {
   JSONValue v = JSONParser.parseStrict(json);
   System.out.println("BlackList showList , json = " + json);
   JSONObject jo = v.isObject();
   page = (int) jo.get("page").isNumber().doubleValue();
   size = (int) jo.get("size").isNumber().doubleValue();
   JSONArray array = jo.get("list").isArray();
   ListDataProvider<BlackListRowData> provider = new ListDataProvider<BlackListRowData>();
   provider.addDataDisplay(cellTable);
   List<BlackListRowData> list = provider.getList();
   for (int i = 0; i < array.size(); i++) {
     JSONObject obj = array.get(i).isObject();
     int monetId = (int) obj.get("monetId").isNumber().doubleValue();
     String reason = obj.get("reason").isString().stringValue();
     String expire = obj.get("expire").isString().stringValue();
     BlackListRowData data = new BlackListRowData();
     data.setMonetId(monetId);
     data.setReason(reason);
     data.setExpire(expire);
     list.add(data);
   }
 }
예제 #28
0
 protected String readString(JSONObject jsonObject, String fieldLabel, int fieldNumber)
     throws InvalidProtocolBufferException {
   String fieldString = null;
   if (jsonObject != null && fieldLabel != null) {
     JSONValue fieldValue = jsonObject.get(fieldLabel);
     if (fieldValue != null) {
       fieldString = jsonValueToString(fieldValue);
       if (fieldString == null) {
         throw InvalidProtocolBufferException.failedToReadString(fieldLabel);
       }
     }
   }
   return fieldString;
 }
예제 #29
0
 protected Boolean readBoolean(JSONObject jsonObject, String fieldLabel, int fieldNumber)
     throws InvalidProtocolBufferException {
   Boolean fieldBoolean = null;
   if (jsonObject != null && fieldLabel != null) {
     JSONValue fieldValue = jsonObject.get(fieldLabel);
     if (fieldValue != null) {
       fieldBoolean = jsonValueToBoolean(fieldValue);
       if (fieldBoolean == null) {
         throw InvalidProtocolBufferException.failedToReadBoolean(fieldLabel);
       }
     }
   }
   return fieldBoolean;
 }
예제 #30
0
 protected Integer readInteger(JSONObject jsonObject, String fieldLabel, int fieldNumber)
     throws InvalidProtocolBufferException {
   Integer fieldInteger = null;
   if (jsonObject != null && fieldLabel != null) {
     JSONValue fieldValue = jsonObject.get(fieldLabel);
     if (fieldValue != null) {
       fieldInteger = jsonValueToInteger(fieldValue);
       if (fieldInteger == null) {
         throw InvalidProtocolBufferException.failedToReadInteger(fieldLabel);
       }
     }
   }
   return fieldInteger;
 }