/*package*/ static List<Trends> constructTrendsList(Response res) throws WeiboException { JSONObject json = res.asJSONObject(); List<Trends> trends; try { Date asOf = parseDate(json.getString("as_of")); JSONObject trendsJson = json.getJSONObject("trends"); trends = new ArrayList<Trends>(trendsJson.length()); Iterator ite = trendsJson.keys(); while (ite.hasNext()) { String key = (String) ite.next(); JSONArray array = trendsJson.getJSONArray(key); Trend[] trendsArray = jsonArrayToTrendArray(array); if (key.length() == 19) { // current trends trends.add(new Trends(res, asOf, parseDate(key, "yyyy-MM-dd HH:mm:ss"), trendsArray)); } else if (key.length() == 16) { // daily trends trends.add(new Trends(res, asOf, parseDate(key, "yyyy-MM-dd HH:mm"), trendsArray)); } else if (key.length() == 10) { // weekly trends trends.add(new Trends(res, asOf, parseDate(key, "yyyy-MM-dd"), trendsArray)); } } Collections.sort(trends); return trends; } catch (JSONException jsone) { throw new WeiboException(jsone.getMessage() + ":" + res.asString(), jsone); } }
/*package*/ static Trends constructTrends(Response res) throws WeiboException { JSONObject json = res.asJSONObject(); try { Date asOf = parseDate(json.getString("as_of")); JSONArray array = json.getJSONArray("trends"); Trend[] trendsArray = jsonArrayToTrendArray(array); return new Trends(res, asOf, asOf, trendsArray); } catch (JSONException jsone) { throw new WeiboException(jsone.getMessage() + ":" + res.asString(), jsone); } }
/*modify by sycheng add json define */ /*package*/ Comment(Response res) throws WeiboException { super(res); JSONObject json = res.asJSONObject(); try { id = json.getLong("id"); text = json.getString("text"); source = json.getString("source"); createdAt = parseDate(json.getString("created_at"), "EEE MMM dd HH:mm:ss z yyyy"); if (!json.isNull("user")) user = new User(json.getJSONObject("user")); } catch (JSONException je) { throw new WeiboException(je.getMessage() + ":" + json.toString(), je); } }
/* modify by hezhou add some field*/ static List<Comment> constructComments(Response res) throws WeiboException { try { JSONArray list = res.asJSONArray(); int size = list.length(); List<Comment> comments = new ArrayList<Comment>(size); for (int i = 0; i < size; i++) { comments.add(new Comment(list.getJSONObject(i))); } return comments; } catch (JSONException jsone) { throw new WeiboException(jsone); } catch (WeiboException te) { throw te; } }
/*package*/ static List<Comment> constructStatuses(Response res, Weibo weibo) throws WeiboException { Document doc = res.asDocument(); if (isRootNodeNilClasses(doc)) { return new ArrayList<Comment>(0); } else { try { ensureRootNodeNameIs("statuses", doc); NodeList list = doc.getDocumentElement().getElementsByTagName("status"); int size = list.getLength(); List<Comment> statuses = new ArrayList<Comment>(size); for (int i = 0; i < size; i++) { Element status = (Element) list.item(i); statuses.add(new Comment(res, status, weibo)); } return statuses; } catch (WeiboException te) { ensureRootNodeNameIs("nil-classes", doc); return new ArrayList<Comment>(0); } } }
/*package*/ Comment(Response res, Weibo weibo) throws WeiboException { super(res); Element elem = res.asDocument().getDocumentElement(); init(res, elem, weibo); }