private Date parsePointAPIDate(String createdStr) throws IllegalArgumentException { if (createdStr.indexOf("+") >= 0) { return new Date(sdfTz.parse(createdStr)); } else { int ix = createdStr.indexOf("."); if (ix > 0 || createdStr.length() >= ix + 4) { // remove last stuff from millis createdStr = createdStr.substring(0, ix + 4); } return new Date(sdf.parse(createdStr)); } }
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, "&", "&"); // 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; }