コード例 #1
0
 private void parsePointAPIComment(JSONObject comm, PointMessage msg, PointMessage parent)
     throws JSONException, ParseException {
   PointUser pu = new PointUser();
   msg.User = pu;
   JSONObject author = comm.getJSONObject("author");
   pu.UName = author.getString("login");
   pu.FullName = author.getString("name");
   pu.UID = author.getInt("id");
   if (author.has("avatar") && author.get("avatar") != JSONObject.NULL) {
     pu.avatarUrl = author.getString("avatar");
   }
   msg.Text = comm.getString("text");
   msg.is_rec = comm.getBoolean("is_rec");
   msg.Timestamp = parsePointAPIDate(comm.getString("created"));
   msg.setMID(parent.getMID());
   msg.setRID(comm.getInt("id"));
   Object toCommentId = comm.get("to_comment_id");
   if (toCommentId != JSONObject.NULL) {
     msg.setReplyTo(comm.getInt("to_comment_id"));
   }
   msg.microBlogCode = PointMessageID.CODE;
 }
コード例 #2
0
  public ArrayList<JuickMessage> parseWebMessageListPure(String htmlStr) {
    ArrayList<JuickMessage> retval = new ArrayList<JuickMessage>();

    Document parsed = Jsoup.parse(htmlStr);
    Elements posts = parsed.select("div");
    ISimpleDateFormat sdf;
    ISimpleDateFormat sdf2;
    sdf = DevJuickComMessages.sdftz.createSDF("yyyy dd MMM HH:mm", "en", "US", "UTC");
    sdf2 = DevJuickComMessages.sdftz.createSDF("yyyy dd MMM HH:mm", "ru", "RU", "UTC");
    Calendar cal = Calendar.getInstance();
    int currentYear = cal.get(Calendar.YEAR);
    for (Element post : posts) {
      String postClass = post.attr("class");
      if (postClass.equals("post") || postClass.startsWith("post ")) {
        PointMessage message = new PointMessage();
        message.User = new JuickUser();
        message.User.UName = post.select("div[class=info] > a > img").attr("alt");
        if (message.User.UName.length() == 0) {
          message.User.UName = post.select("div[class=author] > a").text();
        }
        String dataId = post.attr("data-id");
        String dataCommentId = post.attr("data-comment-id");
        String dataToCommentId = post.attr("data-to-comment-id");
        message.setMID(new PointMessageID(message.User.UName, dataId, 0));
        if (dataCommentId.length() > 0) {
          message.setRID(Integer.parseInt(dataCommentId));
        }
        if (dataToCommentId.length() > 0) {
          message.setReplyTo(Integer.parseInt(dataToCommentId));
        }
        message.tags = new Vector<String>();
        for (Element el : post.select("a[class=tag]")) {
          message.tags.add(el.text());
        }
        message.microBlogCode = PointMessageID.CODE;
        StringBuilder dt = new StringBuilder();
        for (Element el : post.select("div[class=created]")) {
          dt.append(" ");
          dt.append(el.text());
        }
        try {
          message.Timestamp = new Date(sdf.parse(currentYear + " " + dt.toString().trim()));
        } catch (IllegalArgumentException e) {
          try {
            message.Timestamp = new Date(sdf2.parse(currentYear + " " + dt.toString().trim()));
          } catch (IllegalArgumentException e1) {
            continue;
          }
        }
        Date mt = message.Timestamp;
        if (mt.getTime() > System.currentTimeMillis() + 50 * 24 * 60 * 60 * 1000L) {
          Calendar cal2 = Calendar.getInstance();
          cal2.setTime(mt);
          cal2.set(Calendar.YEAR, cal2.get(Calendar.YEAR) - 1);
          message.Timestamp = cal2.getTime();
        }
        Elements postEls = post.select("div[class=text-content]");
        if (postEls.size() < 1) {
          postEls = post.select("div[class=text]");
        }
        String referencedImages = "";
        Elements postimg = post.select("a[class=postimg]");
        for (Element as : postimg) {
          Elements imgs = as.select("img");
          for (Element img : imgs) {
            String src = img.attr("src");
            referencedImages += " " + src;
          }
        }
        message.csrf_token = post.select("input[name=csrf_token]").attr("value");
        // last part
        if (postEls.size() < 1) {
          message.Text = "Error parsing text ;-(";
        } else {
          Element elem = cleanupElement(postEls.get(0));
          postEls.get(0).appendChild(elem); // add to document
          Document.OutputSettings os = elem.ownerDocument().outputSettings();
          os.prettyPrint(false);
          String text = Utils.replace(elem.toString(), "\n", " ");
          text = Utils.replace(text, "&amp;", "&"); // this was improperly done in cleanupElement
          while (true) {
            long olds = text.length();
            text = Utils.replace(text, "  ", " ");
            long news = text.length();
            if (news == olds) break;
          }
          try {
            message.replies = Integer.parseInt(post.select("span[class=cn]").text());
          } catch (Exception ex) {
          }
          text += referencedImages;
          message.Text = unwebMessageTextPoint(text);
        }
        retval.add(message);
      }
    }

    for (JuickMessage juickMessage : retval) {
      if (juickMessage.getRID() != 0
          && juickMessage.getReplyTo() != 0
          && !juickMessage.Text.startsWith("@")) {
        String uzur = null;
        for (JuickMessage scan : retval) {
          if (scan.getRID() == juickMessage.getReplyTo()) {
            uzur = scan.User.UName;
            break;
          }
        }
        if (uzur != null) {
          juickMessage.Text = "@" + uzur + " " + juickMessage.Text;
        }
      }
    }

    return retval;
  }