Exemplo n.º 1
1
  public static HashMap<String, JSONObject> getGates(JSONObject model) {
    HashMap<String, JSONObject> resultHash = new HashMap<String, JSONObject>();

    HashMap<String, JSONObject> worldJSONs = getWorlds(model);

    for (JSONObject worldJSON : worldJSONs.values()) {
      JSONObject gateJSON = worldJSON.optJSONObject("gate");

      if (gateJSON != null) {
        String objectId = gateJSON.optString("itemId");
        if (!TextUtils.isEmpty(objectId)) {
          resultHash.put(objectId, gateJSON);
        }
      }
    }

    HashMap<String, JSONObject> missionJSONs = getMissions(model);
    for (JSONObject missionJSON : missionJSONs.values()) {
      JSONObject gateJSON = missionJSON.optJSONObject("gate");

      if (gateJSON != null) {
        String objectId = gateJSON.optString("itemId");
        if (!TextUtils.isEmpty(objectId)) {
          resultHash.put(objectId, gateJSON);
        }
      }
    }

    findInternalLists(resultHash, new String[] {"GatesListAND", "GatesListOR"}, "gates");

    return resultHash;
  }
 public ModelLocalCar(JSONObject object) throws JSONException {
   if (object != null) {
     store = new ModelStoreSelected(object.optJSONObject("store"));
     storePostInfo = new ModelStorePostInfo(object.optJSONObject("storePostInfo"));
     diliver = new ModelDiliver(object.optJSONObject("diliver"));
     payment = new ModelPayment(object.optJSONObject("payment"));
     JSONArray array = object.optJSONArray("goods");
     if (array != null) {
       goodsMoney = 0;
       postFee = 0;
       for (int i = 0; i < array.length(); i++) {
         ModelLocalCarGoods goods = new ModelLocalCarGoods(array.optJSONObject(i));
         carGoods.add(goods);
         if (goods.isSelected()) {
           goodsCount += goods.getGoodsCount();
           goodsMoney += goods.getGoodsCount() * goods.getGoods().getRetailPrice();
         } else {
           isSelected = false;
         }
       }
       if (diliver.getType() != ModelDiliver.TYPE_SELF
           & goodsMoney > 0
           & goodsMoney < storePostInfo.getHawManyPackages()) {
         // 非自取,购物金额大于0且小于免邮金额
         postFee = storePostInfo.getPostage();
       }
       totalMoney = goodsMoney + postFee;
     }
   }
   setStorePostInfo();
 }
Exemplo n.º 3
0
 @Override
 public void parseJson(String jsonStr) {
   JSONObject jsonObject = getJsonObject(jsonStr);
   if (jsonObject.optJSONObject("users") != null) {
     pageInfo = getPageInfo(jsonObject.optJSONObject("users"), UserInfo.class);
   }
 }
Exemplo n.º 4
0
  private static String extractMakeAndModelFromJSON(
      JSONObject json, String firstSearchString, String secondSearchString) {
    if (json == null) {
      return null;
    }

    JSONObject formatObject = json.optJSONObject("format");
    if (formatObject != null) {
      JSONObject tagsObject = formatObject.optJSONObject("tags");
      if (tagsObject != null) {
        String firstDesiredValue = tagsObject.optString(firstSearchString);
        if (!firstDesiredValue.equals("")) {
          return firstDesiredValue;
        }
        String secondDesiredValue = tagsObject.optString(secondSearchString);
        if (!secondDesiredValue.equals("")) {
          return secondDesiredValue;
        }
      }
    }

    LOGGER.debug(
        "Could not extract " + firstSearchString + " or " + secondSearchString + " from json.");
    return null;
  }
Exemplo n.º 5
0
 public final boolean wN()
 {
   if ((bAX != null) && (bAX.optJSONObject("WifiBizInfo") != null) && (bAX.optJSONObject("WifiBizInfo").optInt("IsWXWiFi") == 1)) {
     bBz = true;
   }
   return bBz;
 }
Exemplo n.º 6
0
  public static PinItem genPinItem(JSONObject pItem) {
    PinItem pi;
    try {
      JSONArray comObj;
      JSONObject commentObj;
      Comment comment;
      pi = new PinItem();
      pi.setPinItem(pItem);
      pi.getImages()
          .setThumb_loc(
              Calculator.getFileFromUrl(pItem.optJSONObject(IMAGES).optString(THUMBNAIL)));
      pi.getImages()
          .setMob_loc(Calculator.getFileFromUrl(pItem.optJSONObject(IMAGES).optString(MOBILE)));
      pi.getUser().setJUser(pItem.getJSONObject(USER));
      pi.getBoard().setBoard(pItem.getJSONObject(BOARD));
      comObj = pItem.optJSONArray(COMMENTS);
      if (null != comObj) {
        for (int j = 0; j < comObj.length(); j++) {
          commentObj = comObj.getJSONObject(j);
          comment = pi.newComment(commentObj);
          comment.getUser().setJUser(commentObj.getJSONObject(USER));
          pi.getComments().add(comment);
        }
      }

    } catch (JSONException e) {
      e.printStackTrace();
      return null;
    } finally {
      System.gc();
    }

    return pi;
  }
  public static JSONObject fillTables(JSONObject tables, JSONObject rows) {

    try {

      // Get table id
      Iterator<?> keys = rows.keys();

      while (keys.hasNext()) {
        String key = (String) keys.next(); // should be table1, table2 ,...
        if (key.indexOf("table") > -1) {
          // find key table rows in tables
          if (tables.optJSONObject("content").has(key)) {
            JSONArray tablerows =
                tables.optJSONObject("content").getJSONObject(key).optJSONArray("rows");
            if (tablerows == null) return tables;
            // Append rows
            JSONArray datarows = rows.optJSONArray(key);
            if (datarows == null) return tables;

            for (int n = 0; n < datarows.length(); n++) {
              JSONObject row = datarows.getJSONObject(n);
              tablerows.put(row);
            }
          }
        }
      }
      return tables;

    } catch (Exception ex) {
      log.warn(ex, "Error filling table layout template for printout");
    }
    return null;
  }
Exemplo n.º 8
0
  /**
   * Gets a map property deserialized values from the cache or from the underlying JSONObject
   *
   * @param property the property name
   * @param typeClass the type of JSONResponse contained in the property
   * @return the map of json response style objects associated to this property in the JSON response
   */
  @SuppressWarnings("unchecked")
  private Map<String, ?> getMap(String property, Class<?> typeClass) {
    Map<String, Object> map = null;
    if (!propertyMap.containsKey(property)) {
      JSONObject jsonMap = delegate.optJSONObject(property);
      if (jsonMap != null) {
        map = new LinkedHashMap<String, Object>(jsonMap.length());

        while (jsonMap.keys().hasNext()) {
          String key = (String) jsonMap.keys().next();
          JSONObject jsonObject = jsonMap.optJSONObject(key);
          try {
            Object response = typeClass.newInstance();
            ((JSONResponse) response).fromJSON(jsonObject);
            map.put(key, response);
          } catch (JSONException e) {
            throw new RuntimeException(e);
          } catch (InstantiationException e) {
            throw new RuntimeException(e);
          } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
          }
        }
        propertyMap.put(property, map);
      }
    } else {
      map = (Map<String, Object>) propertyMap.get(property);
    }
    return map;
  }
  /**
   * Deserialize the Sheet
   *
   * @param sheetJSON
   * @return
   * @throws Exception
   */
  private Sheet deserializeSheet(JSONObject sheetJSON) throws Exception {
    String name = sheetJSON.getString(WorkSheetSerializationUtils.NAME);
    JSONObject header = sheetJSON.optJSONObject(WorkSheetSerializationUtils.HEADER);
    String layout = sheetJSON.optString(WorkSheetSerializationUtils.LAYOUT);
    JSONObject footer = sheetJSON.optJSONObject(WorkSheetSerializationUtils.FOOTER);

    JSONObject filtersJSON = sheetJSON.optJSONObject(WorkSheetSerializationUtils.FILTERS);
    List<Filter> filters = deserializeSheetFilters(filtersJSON);
    FiltersPosition position = FiltersPosition.TOP;
    if (filtersJSON != null) {
      position =
          FiltersPosition.valueOf(
              filtersJSON.getString(WorkSheetSerializationUtils.POSITION).toUpperCase());
    }

    JSONArray filtersOnDomainValuesJSON =
        sheetJSON.optJSONArray(WorkSheetSerializationUtils.FILTERS_ON_DOMAIN_VALUES);
    List<Attribute> filtersOnDomainValues =
        deserializeSheetFiltersOnDomainValues(filtersOnDomainValuesJSON);

    logger.debug("Deserializing sheet " + name);
    SheetContent content = deserializeContent(sheetJSON);
    logger.debug("Sheet " + name + " deserialized successfully");

    return new Sheet(
        name, layout, header, filters, position, content, filtersOnDomainValues, footer);
  }
Exemplo n.º 10
0
  /**
   * Constructs a Rate from a JSONObject.
   *
   * @param rateInformationJson The JSONObject holding the data to construct this object with.
   */
  public Rate(final JSONObject rateInformationJson) {

    final List<Room> localRooms;
    final JSONObject roomGroupJson = rateInformationJson.optJSONObject("RoomGroup");
    if (roomGroupJson != null && roomGroupJson.optJSONArray("Room") != null) {
      final JSONArray roomJson = roomGroupJson.optJSONArray("Room");
      localRooms = new ArrayList<Room>(roomJson.length());
      for (int i = 0; i < roomJson.length(); i++) {
        localRooms.add(new Room(roomJson.optJSONObject(i)));
      }
    } else if (roomGroupJson != null && roomGroupJson.optJSONObject("Room") != null) {
      localRooms = Collections.singletonList(new Room(roomGroupJson.optJSONObject("Room")));
    } else {
      localRooms = Collections.emptyList();
    }

    final JSONObject chargeableObject = rateInformationJson.optJSONObject("ChargeableRateInfo");
    final JSONObject convertedObject = rateInformationJson.optJSONObject("ConvertedRateInfo");

    chargeable = new RateInformation(chargeableObject);
    converted = convertedObject == null ? null : new RateInformation(convertedObject);

    promo = rateInformationJson.optBoolean("@promo");
    roomGroup = Collections.unmodifiableList(localRooms);
  }
Exemplo n.º 11
0
  public static GridContent miniParse(String obj) {
    GridContent gc = new GridContent();
    try {
      JSONObject jObj = new JSONObject(obj);
      gc.setNext_page_url(jObj.getJSONObject(PAGINATION).optString(NEXT));
      JSONArray pins = jObj.getJSONArray(PINS);
      JSONObject pItem;
      for (int i = 0; i < pins.length(); i++) {
        pItem = pins.getJSONObject(i);
        gc.add(
            gc
            .new SmallPinItem(
                pItem.optString(ID),
                0,
                Calculator.getFileFromUrl(pItem.optJSONObject(IMAGES).optString(THUMBNAIL)),
                pItem.optJSONObject(IMAGES).optString(THUMBNAIL)));
      }

    } catch (JSONException e) {
      e.printStackTrace();
      return null;
    } finally {
      System.gc();
    }

    return gc;
  }
 /**
  * @param defaultValuesConfiguration a {@link JSONObject} with two properties: {@value
  *     #PROP_DEFAULTS} and {@value #PROP_OBJECT_TYPE_HIERARCHY}
  */
 public void importConfiguration(JSONObject defaultValuesConfiguration) {
   if (defaultValuesConfiguration == null) {
     return;
   }
   importConfiguration(
       defaultValuesConfiguration.optJSONObject(PROP_DEFAULTS),
       defaultValuesConfiguration.optJSONObject(PROP_OBJECT_TYPE_HIERARCHY));
 }
Exemplo n.º 13
0
  /**
   * 团购商品列表
   *
   * @param json
   * @return
   */
  public static HotPromTheTemBean parseGroupBuyListJson(String json) {

    JsonResult result = new JsonResult(json);
    if (!result.isSuccess()) {
      return null;
    }
    JSONObject content = result.getJsContent();
    HotPromTheTemBean hotPromThem = new HotPromTheTemBean();

    try {
      ActivityInfo info = new ActivityInfo();

      JSONObject activityInfoObject = content.optJSONObject(JK_PROMOTION_ACTIVITY_INFO);
      if (activityInfoObject != null) {
        info.setActivityId(activityInfoObject.optString(JK_ACTIVITY_ID));
        info.setActivityName(activityInfoObject.optString(JK_ACTIVITY_NAME));
        info.setActivityRule(activityInfoObject.optString(JK_ACTIVITY_RULE));
      }
      hotPromThem.setActivityInfo(info);

      JSONObject extendAttrObj = content.optJSONObject(JK_ACTIVITYEXTENDATTR);
      if (extendAttrObj != null) {
        hotPromThem.setBananerImgUrl(extendAttrObj.optString(JK_BANANERIMGURL)); //
        hotPromThem.setBgImgUrl(extendAttrObj.optString(JK_BGIMGURL)); //
        hotPromThem.setBgColor(extendAttrObj.optString(JK_BGCOLOR)); //
        hotPromThem.setGoodsbgColor(extendAttrObj.optString(JK_GOODSBGCOLOR)); //
        hotPromThem.setSkuOrgPriceColor(extendAttrObj.optString(JK_SKUORGPRICECOLOR)); //
        hotPromThem.setPromPriceColor(extendAttrObj.optString(JK_PROMPRICECOLOR)); //
        hotPromThem.setSkuNameColor(extendAttrObj.optString(JK_SKUNAMECOLOR)); // ;
        hotPromThem.setGoodsBorderColor(extendAttrObj.optString(JK_GOODSBORDERCOLOR));
      }
      JSONArray goodsArray = content.optJSONArray(JK_GROUP_BUY_LIST);
      if (goodsArray != null) {
        ArrayList<Goods> goodList = new ArrayList<Goods>();
        for (int i = 0, length = goodsArray.length(); i < length; i++) {
          JSONObject item = goodsArray.getJSONObject(i);
          GroupBuyProduct goods = new GroupBuyProduct();
          goods.setGoodsNo(item.optString(JK_GOODS_NO));
          goods.setSkuID(item.optString(JK_SKU_ID));
          goods.setSkuNo(item.optString(JK_SKU_NO));
          goods.setSkuName(item.optString(JK_SKU_NAME));
          String skuThumbImgUrl = item.optString(JK_SKU_THUMB_IMG_URL);
          goods.setSkuThumbImgUrl(UrlMatcher.getFitGridThumbUrl(skuThumbImgUrl));
          goods.setOriginalPrice(item.optString(JK_SKU_ORIGINAL_PRICE));
          goods.setPromPrice(item.optString(JK_GROUP_BUY_SALE_PRICE));
          goods.setSalePromoItem(item.optString(JK_GROUP_BUY_SALE_PROM_ID));
          goodList.add(goods);
        } // end for
        hotPromThem.setGoodslist(goodList);
      } // end if

    } catch (JSONException e) {
      e.printStackTrace();
      return null;
    }

    return hotPromThem;
  }
Exemplo n.º 14
0
  @Override
  public void populate(JSONObject data) {

    units = new Units();
    units.populate(data.optJSONObject("units"));

    item = new Item();
    item.populate(data.optJSONObject("item"));
  }
Exemplo n.º 15
0
  public void fillInEchoNestInfo() throws IOException, EchoNestException {
    if (artist == null || title == null) {
      JSONObject songProfile = null;
      try {
        songProfile =
            EchoNestQuery.get("song", "profile", "id=" + EchoNestId + "&bucket=audio_summary");
      } catch (EchoNestException e) {
      }

      JSONObject song = songProfile.optJSONArray("songs").optJSONObject(0);

      artist = new Artist(song.optString("artist_name"), song.optString("artist_id"));
      title = song.optString("title");
      duration = song.optJSONObject("audio_summary").optInt("duration");
    } else if (EchoNestId == null) {
      String artistName = URLEncoder.encode(artist.getName(), "UTF-8");
      String title = URLEncoder.encode(this.title, "UTF-8");

      JSONObject songSearch = null;
      try {
        songSearch =
            EchoNestQuery.get(
                "song",
                "search",
                "artist="
                    + artistName
                    + "&title="
                    + title
                    + "&results=1"
                    + "&bucket=audio_summary");
      } catch (EchoNestException e) {
      }

      JSONArray songs = songSearch.optJSONArray("songs");
      if (songs.length() == 0) throw new EchoNestException(6, "No items found.");

      JSONObject song = songs.optJSONObject(0);

      artist = new Artist(song.optString("artist_name"), song.optString("artist_id"));
      EchoNestId = song.optString("id");
      duration = song.optJSONObject("audio_summary").optInt("duration");
    } else if (duration == -1) {
      JSONObject songProfile = null;
      try {
        songProfile =
            EchoNestQuery.get("song", "profile", "id=" + EchoNestId + "&bucket=audio_summary");
      } catch (EchoNestException e) {
      }

      duration =
          songProfile
              .optJSONArray("songs")
              .optJSONObject(0)
              .optJSONObject("audio_summary")
              .optInt("duration");
    }
  }
Exemplo n.º 16
0
 public static SmallPinItem buildSPI(JSONObject pItem, int rownum, GridContent gc)
     throws JSONException {
   return gc
   .new SmallPinItem(
       pItem.optString(ID),
       rownum,
       Calculator.getFileFromUrl(pItem.optJSONObject(IMAGES).optString(THUMBNAIL)),
       pItem.optJSONObject(IMAGES).optString(THUMBNAIL));
 }
Exemplo n.º 17
0
 /**
  * 设定字段的值
  *
  * @param obj 待赋值字段的对象
  * @param field 字段
  * @param jo json实例
  */
 @SuppressWarnings("unused")
 private static void setField(Object obj, Field field, JSONObject jo) {
   String name = field.getName();
   Class<?> clazz = field.getType();
   try {
     if (isArray(clazz)) { // 数组
       Class<?> c = clazz.getComponentType();
       JSONArray ja = jo.optJSONArray(name);
       if (!isNull(ja)) {
         Object array = parseArray(ja, c);
         field.set(obj, array);
       }
     } else if (isCollection(clazz)) { // 泛型集合
       // 获取定义的泛型类型
       Class<?> c = null;
       Type gType = field.getGenericType();
       if (gType instanceof ParameterizedType) {
         ParameterizedType ptype = (ParameterizedType) gType;
         Type[] targs = ptype.getActualTypeArguments();
         if (targs != null && targs.length > 0) {
           Type t = targs[0];
           c = (Class<?>) t;
         }
       }
       JSONArray ja = jo.optJSONArray(name);
       if (!isNull(ja)) {
         Object o = parseCollection(ja, clazz, c);
         field.set(obj, o);
       }
     } else if (isSingle(clazz)) { // 值类型
       Object o = jo.opt(name);
       if (o != null) {
         field.set(obj, o);
       }
     } else if (isObject(clazz)) { // 对象
       JSONObject j = jo.optJSONObject(name);
       if (!isNull(j)) {
         Object o = parseObject(j, clazz);
         field.set(obj, o);
       }
     } else if (isList(clazz)) { // 列表
       JSONObject j = jo.optJSONObject(name);
       if (!isNull(j)) {
         Object o = parseObject(j, clazz);
         field.set(obj, o);
       }
     } else {
       throw new Exception("unknow type!");
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Exemplo n.º 18
0
 /**
  * Constructs a List of Rate objects from a RateInfos JSONObject.
  *
  * @param object The JSONObject which holds a RateInfos field which holds an array of
  *     RateInformation objects.
  * @return A fully constructed Rate list.
  */
 public static List<Rate> parseFromRateInformations(final JSONObject object) {
   final String rateInformationId = "RateInfos";
   if (object.optJSONArray(rateInformationId) != null) {
     final JSONArray rateInformations = object.optJSONArray(rateInformationId);
     return parseRates(rateInformations);
   } else if (object.optJSONObject(rateInformationId) != null) {
     final JSONObject rateInformation = object.optJSONObject(rateInformationId);
     return parseRates(rateInformation);
   }
   // if neither of the if/else above, then this was a sabre response that
   // requires ANOTHER call to get the rate information but that is handled
   // by the RoomAvailability request, so we do nothing with the rates.
   return Collections.singletonList(null);
 }
  private void addMailboxList(JSONObject response) {
    JSONObject inbox = response.optJSONObject("inbox");
    if (inbox != null) {
      messageCount = inbox.optInt("message_count");
      unreadCount = inbox.optInt("unread_count");

      m_mailboxUnread.setText(String.valueOf(unreadCount));
      m_mailboxUnread.setVisibility(unreadCount > 0 ? View.VISIBLE : View.GONE);
      m_application.setMailUnreadCount(unreadCount);

      currentPage = inbox.optInt("page");
      JSONArray messages = inbox.optJSONArray("messages");
      if (messages != null) {
        for (int i = 0; i < messages.length(); i++) {
          JSONObject message = messages.optJSONObject(i);
          glitchMail mail = new glitchMail();

          mail.id = message.optInt("message_id");
          mail.currants = message.optInt("currants");
          mail.text = message.optString("text");
          if (mail.text.equalsIgnoreCase("null")) {
            mail.text = "";
          }
          mail.received = message.optLong("received");
          mail.replied = message.optInt("replied") == 1;
          mail.is_expedited = message.optBoolean("is_expedited");
          mail.is_read = message.optBoolean("is_read");

          JSONObject sender = message.optJSONObject("sender");
          if (sender != null) {
            mail.sender_tsid = sender.optString("tsid");
            mail.sender_label = sender.optString("label");
            mail.sender_avatar = sender.optString("singles_url");
          }

          JSONObject item = message.optJSONObject("item");
          if (item != null) {
            mail.item = new glitchMailItem();
            mail.item.tsid = item.optString("class_tsid");
            mail.item.name = item.optString("name");
            mail.item.count = item.optInt("count");
            mail.item.desc = item.optString("desc");
            mail.item.icon = item.optString("icon");
          }

          m_mailList.add(mail);
        }
      }
    }
  }
Exemplo n.º 20
0
  private static JSONObject getJSONFromRedis(
      Jedis jedis, String keyword, String category, String site) {

    if (logger.isDebugEnabled()) {
      logger.debug("get from redis key: " + RedisCacheUtil.getStoreKey(keyword, category));
    }

    String extJsonStr = jedis.get(RedisCacheUtil.getStoreKey(keyword, category));

    if (extJsonStr == null) {
      return null;
    }

    try {
      JSONObject extJson = new JSONObject(extJsonStr);
      if (!StringUtils.isBlank(site)) {
        List<Integer> siteIdList = new ArrayList<Integer>(StringUtil.parseSite(site));
        int programmeSize = extJson.optInt("size");
        for (int i = 0; i < programmeSize; i++) {
          JSONObject channelJson = extJson.optJSONObject(new Integer(i).toString());
          if (channelJson == null) continue;
          String nameType = StringUtils.trimToEmpty(channelJson.optString("nameTypes"));

          JSONArray programmeArr = channelJson.optJSONArray(nameType);
          if (programmeArr == null || programmeArr.length() <= 0) continue;

          for (int j = 0; j < programmeArr.length(); j++) {
            JSONObject oneProJson = programmeArr.optJSONObject(j);
            JSONObject programmeInfo = oneProJson.optJSONObject("programme");

            List<String> tmpSiteList = ProgrammeSearcher.getProSiteStrList(siteIdList);
            programmeInfo.put("sites", tmpSiteList);

            JSONObject proSiteJson = oneProJson.optJSONObject("programmeSite");
            JSONObject newProSiteJson = new JSONObject();
            for (int siteId : siteIdList) {
              newProSiteJson.put(siteId + "", proSiteJson.optJSONObject(siteId + ""));
            }
            oneProJson.put("programmeSite", newProSiteJson);
          }
        }
      }

      return extJson;
    } catch (JSONException e) {
      logger.error("JSON Format error", e);
    }

    return null;
  }
Exemplo n.º 21
0
 private IGPSObject parseSUBFRAME(final JSONObject json) throws ParseException {
   IGPSObject gps;
   final SUBFRAMEObject subframe = new SUBFRAMEObject();
   subframe.setDevice(json.optString("device", null));
   subframe.setMSBs(json.optInt("TOW17"));
   subframe.setSatelliteNumber(json.optInt("tSV"));
   subframe.setSubframeNumber(json.optInt("frame"));
   subframe.setScaled(json.optBoolean("scaled", false));
   subframe.setPageid(json.optInt("pageid"));
   if (json.has("system_message")) {
     subframe.setSystemMessage(json.optString("system_message"));
   } else if (json.has(ALMANACObject.NAME)) {
     subframe.setAlmanac((ALMANACObject) this.parse(json.optJSONObject(ALMANACObject.NAME)));
   } else if (json.has(EPHEM1Object.NAME)) {
     subframe.setEphem1((EPHEM1Object) this.parse(json.optJSONObject(EPHEM1Object.NAME)));
   } else if (json.has(EPHEM2Object.NAME)) {
     subframe.setEphem2((EPHEM2Object) this.parse(json.optJSONObject(EPHEM2Object.NAME)));
   } else if (json.has(EPHEM3Object.NAME)) {
     subframe.setEphem3((EPHEM3Object) this.parse(json.optJSONObject(EPHEM3Object.NAME)));
   } else if (json.has(ERDObject.NAME)) {
     subframe.setErd((ERDObject) this.parse(json.optJSONObject(ERDObject.NAME)));
   } else if (json.has(HEALTHObject.NAME)) {
     subframe.setHealth((HEALTHObject) this.parse(json.optJSONObject(HEALTHObject.NAME)));
   } else if (json.has(HEALTH2Object.NAME)) {
     subframe.setHealth2((HEALTH2Object) this.parse(json.optJSONObject(HEALTH2Object.NAME)));
   } else if (json.has(IONOObject.NAME)) {
     subframe.setIono((IONOObject) this.parse(json.optJSONObject(IONOObject.NAME)));
   } else {
     AbstractResultParser.LOG.error("Unknown subframe: {}", json.toString());
   }
   gps = subframe;
   return gps;
 }
 protected void importDefaults(JSONObject jsonDefaults) {
   if (jsonDefaults == null) {
     return;
   }
   for (Iterator it = jsonDefaults.keys(); it.hasNext(); ) {
     String type = (String) it.next();
     JSONObject jsonProperties = jsonDefaults.optJSONObject(type);
     for (Iterator it2 = jsonProperties.keys(); it2.hasNext(); ) {
       String prop = (String) it2.next();
       Object value = jsonProperties.opt(prop);
       // Add to map
       Map<String, Object> propMap = m_defaults.get(type);
       if (propMap == null) {
         propMap = new HashMap<>();
         m_defaults.put(type, propMap);
       }
       Object oldValue = propMap.get(prop);
       if (value instanceof JSONObject && oldValue instanceof JSONObject) {
         // Combine
         JsonObjectUtility.mergeProperties((JSONObject) oldValue, (JSONObject) value);
       } else {
         // Override (cannot be combined)
         propMap.put(prop, value);
       }
     }
   }
 }
 private SheetContent deserializeContent(JSONObject sheetJSON) throws Exception {
   SheetContent toReturn = null;
   JSONObject content = sheetJSON.optJSONObject(WorkSheetSerializationUtils.CONTENT);
   if (content == null) {
     logger.warn(
         "Sheet content not found for sheet ["
             + sheetJSON.getString(WorkSheetSerializationUtils.NAME)
             + "].");
     return null;
   }
   String designer = content.getString(WorkSheetSerializationUtils.DESIGNER);
   if (WorkSheetSerializationUtils.DESIGNER_PIVOT.equals(designer)) {
     toReturn =
         (CrosstabDefinition)
             SerializationManager.deserialize(
                 content.getJSONObject(WorkSheetSerializationUtils.CROSSTABDEFINITION),
                 "application/json",
                 CrosstabDefinition.class);
     ((CrosstabDefinition) toReturn).setStatic(false);
   } else if (WorkSheetSerializationUtils.DESIGNER_STATIC_PIVOT.equals(designer)) {
     toReturn =
         (CrosstabDefinition)
             SerializationManager.deserialize(
                 content.getJSONObject(WorkSheetSerializationUtils.CROSSTABDEFINITION),
                 "application/json",
                 CrosstabDefinition.class);
     ((CrosstabDefinition) toReturn).setStatic(true);
   } else if (WorkSheetSerializationUtils.DESIGNER_TABLE.equals(designer)) {
     toReturn = deserializeTable(content);
   } else {
     toReturn = deserializeChart(content);
   }
   return toReturn;
 }
Exemplo n.º 24
0
  public void fromJson(JSONObject jsonObject) throws JSONException {
    if (null == jsonObject) {
      return;
    }

    JSONArray subItemArray;

    this.uid = jsonObject.optInt("uid");

    this.sid = jsonObject.optString("sid");

    this.by_id = jsonObject.optInt("by_id");

    this.by_no = jsonObject.optInt("by_no");

    this.count = jsonObject.optInt("count");

    this.sort_by = jsonObject.optInt("sort_by");
    LOCATION location = new LOCATION();
    location.fromJson(jsonObject.optJSONObject("location"));
    this.location = location;

    this.service_type = jsonObject.optInt("service_type");

    this.ver = jsonObject.optInt("ver");
    return;
  }
 public ModelAwardHistory(JSONObject object) throws JSONException {
   if (object != null) {
     jsonObject = object;
     if (object.has("id")) {
       if (!object.optString("id").equalsIgnoreCase("null")) {
         id = object.optString("id");
       }
     }
     if (object.has("winDate")) {
       if (!object.optString("winDate").equalsIgnoreCase("null")) {
         winDate = object.optString("winDate");
       }
     }
     if (object.has("orderNumber")) {
       if (!object.optString("orderNumber").equalsIgnoreCase("null")) {
         orderNumber = object.optString("orderNumber");
       }
     }
     if (object.has("prizeId")) {
       if (!object.optString("prizeId").equalsIgnoreCase("null")) {
         prizeId = object.optString("prizeId");
       }
     }
     if (object.has("winMoney")) {
       if (!object.optString("winMoney").equalsIgnoreCase("null")) {
         winMoney = object.optDouble("winMoney");
       }
     }
     isGrant = object.optInt("isGrant");
     award = new ModelAward(object.optJSONObject("prize"));
   }
 }
Exemplo n.º 26
0
 public Type[] getTypeOptions(String groupName) {
   try {
     JSONObject obj = data.optJSONObject(groupName);
     if (obj != null && "action".equals(obj.optString("type"))) {
       String defaultValue = obj.optString("default", "");
       JSONArray arr = obj.getJSONArray("values");
       Type[] options = new Type[arr.length()];
       for (int i = 0; i < options.length; i++) {
         JSONObject option = arr.getJSONObject(i);
         options[i] = new Type();
         String id = option.getString("id");
         String name = option.getString("name");
         String action = option.getString("action");
         options[i].setId(id);
         options[i].setName(name);
         options[i].setAction(action);
         options[i].setDefault(id.equals(defaultValue));
       }
       return options;
     }
   } catch (JSONException e) {
     // ignore
   }
   return new Type[0];
 }
Exemplo n.º 27
0
  private static boolean isEquivalent(JSONObject fromBig, JSONObject fromSmall) {
    String nameBig = fromBig.optString("name");
    String nameSmall = fromSmall.optString("name");
    JSONObject sourceBig = fromBig.optJSONObject("source");
    JSONObject sourceSmall = fromSmall.optJSONObject("source");

    if (sourceSmall != null && nameBig != null && nameSmall != null && sourceBig != null) {
      String uriBig = sourceBig.optString("url");
      String uriSmall = sourceSmall.optString("url");
      if (uriBig != null
          && uriSmall != null
          && uriBig.equalsIgnoreCase(uriSmall)
          && nameSmall.equalsIgnoreCase(nameBig)) return true;
    }
    return false;
  }
Exemplo n.º 28
0
 private VacancyModel parseVacancyInfo(String jsonResponceString) {
   VacancyModel model = new VacancyModel();
   ArrayList<VacancyItemModel> data = new ArrayList<VacancyItemModel>();
   try {
     JSONObject jObj = new JSONObject(jsonResponceString);
     JSONArray jItems = jObj.getJSONArray(JSON_PARAMETER_ITEMS);
     model.setPage(jObj.getInt(JSON_PARAMETER_PAGE));
     model.setPages(jObj.getInt(JSON_PARAMETER_PAGES));
     for (int i = 0; i < jItems.length(); i++) {
       JSONObject item = jItems.getJSONObject(i);
       VacancyItemModel modelItem = new VacancyItemModel();
       modelItem.setId(item.getInt(JSON_PARAMETER_ID));
       modelItem.setName(item.getString(JSON_PARAMETER_NAME));
       modelItem.setUrl((item.getString(JSON_PARAMETER_URL)));
       PublisherItemModel publisher = new PublisherItemModel();
       JSONObject jPublisher = item.getJSONObject(JSON_PARAMETER_EMPLOYER);
       publisher.setId(jPublisher.getInt(JSON_PARAMETER_ID));
       publisher.setName(jPublisher.getString(JSON_PARAMETER_NAME));
       SimpleDateFormat formatter =
           new SimpleDateFormat(DATE_FORMAT, activity.getResources().getConfiguration().locale);
       modelItem.setDate(formatter.parse(item.getString(JSON_PARAMETER_CREATED_AT)));
       JSONObject jIcons = jPublisher.optJSONObject(JSON_PARAMETER_LOGO);
       if (jIcons != null) {
         String iconUrl = jIcons.getString(JSON_PARAMETER_90);
         publisher.setIconUrl(iconUrl);
       }
       modelItem.setPublisher(publisher);
       data.add(modelItem);
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
   model.setItems(data);
   return model;
 }
Exemplo n.º 29
0
 private MediaConstraints constraintsFromJSON(String jsonString) throws JSONException {
   if (jsonString == null) {
     return null;
   }
   MediaConstraints constraints = new MediaConstraints();
   JSONObject json = new JSONObject(jsonString);
   JSONObject mandatoryJSON = json.optJSONObject("mandatory");
   if (mandatoryJSON != null) {
     JSONArray mandatoryKeys = mandatoryJSON.names();
     if (mandatoryKeys != null) {
       for (int i = 0; i < mandatoryKeys.length(); ++i) {
         String key = mandatoryKeys.getString(i);
         String value = mandatoryJSON.getString(key);
         constraints.mandatory.add(new MediaConstraints.KeyValuePair(key, value));
       }
     }
   }
   JSONArray optionalJSON = json.optJSONArray("optional");
   if (optionalJSON != null) {
     for (int i = 0; i < optionalJSON.length(); ++i) {
       JSONObject keyValueDict = optionalJSON.getJSONObject(i);
       String key = keyValueDict.names().getString(0);
       String value = keyValueDict.getString(key);
       constraints.optional.add(new MediaConstraints.KeyValuePair(key, value));
     }
   }
   return constraints;
 }
Exemplo n.º 30
0
  @Test
  public void testDiffModifiedByOrion() throws Exception {
    URI workspaceLocation = createWorkspace(getMethodName());

    String projectName = getMethodName();
    JSONObject project = createProjectOrLink(workspaceLocation, projectName, gitDir.toString());
    String projectId = project.getString(ProtocolConstants.KEY_ID);

    WebRequest request = getPutFileRequest(projectId + "/test.txt", "hello");
    WebResponse response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

    JSONObject gitSection = project.optJSONObject(GitConstants.KEY_GIT);
    assertNotNull(gitSection);
    String gitDiffUri = gitSection.getString(GitConstants.KEY_DIFF);

    request = getGetGitDiffRequest(gitDiffUri);
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
    StringBuilder sb = new StringBuilder();
    sb.append("diff --git a/test.txt b/test.txt").append("\n");
    sb.append("index 30d74d2..b6fc4c6 100644").append("\n");
    sb.append("--- a/test.txt").append("\n");
    sb.append("+++ b/test.txt").append("\n");
    sb.append("@@ -1 +1 @@").append("\n");
    sb.append("-test").append("\n");
    sb.append("\\ No newline at end of file").append("\n");
    sb.append("+hello").append("\n");
    sb.append("\\ No newline at end of file").append("\n");
    String[] parts = parseMultiPartResponse(response);
    assertEquals(sb.toString(), parts[1]);
  }