public StatusWapper obtainWeibo(Timeline tm, JcUser jcUser, int page) { StatusWapper statusWapper = null; int i = 0; try { statusWapper = tm.getUserTimeline(COUNT_PER_PAGE, page, jcUser); LOG.debug(++callCount + "st call weibo api (now is userTimeline)"); } catch (WeiboException e) { LOG.error("occured a exception when obtaining weibo use weibo api" + e); LOG.error(++callCount + "st call weibo api (now is comments) cause error"); // outOfLimit = true; jcUser.setOutOfLimit(true); return null; } // download pictures and/or obtain comments List<Status> statuses = statusWapper.getStatuses(); for (i = 0; i < statuses.size(); i++) { Status s = statuses.get(i); Place place = new Place(); try { if (s.getLatitude() != -1 && s.getLongitude() != -1) s.setFormatedAddress(place.formattedAddress(s.getLatitude(), s.getLongitude())); else s.setFormatedAddress(null); } catch (Exception e) { LOG.error("occured a exception when format address " + e); LOG.error("try again"); try { if (s.getLatitude() != -1 && s.getLongitude() != -1) s.setFormatedAddress(place.formattedAddress(s.getLatitude(), s.getLongitude())); else s.setFormatedAddress(null); } catch (Exception e2) { LOG.error("occured a exception when format address " + e2); s.setFormatedAddress(null); } } if (s.getCommentsCount() > 0) s.setComments(obtainComments(s)); statuses.set(i, downloadImage(s)); // if (callCount >= limit || outOfLimit == true) if (jcUser.isOutOfLimit()) break; } LOG.debug("this time get statues count is" + statuses.size()); int index = 0; // if (callCount >= limit || outOfLimit == true) if (jcUser.isOutOfLimit()) index = i; else index = i + 1; int len = statuses.size(); int times = len - index; for (int j = 0; j < times; j++) { Status s = statuses.remove(index); LOG.debug( "removing id:" + s.getId() + ", creatAt:" + StringUtil.formatDate(s.getCreatedAt(), "yyyy-MM-dd HH:mm")); } LOG.debug("after remove get statues count is" + statuses.size()); LOG.debug("after remove get statusWapper.statues count is" + statusWapper.getStatuses().size()); return statusWapper; }
public String formatWeibo(URI fileUri, Status status) { // String debugBeforeTemp = null; // String debugAfterTemp = null; String template = ""; int begin; int end; try { template = DataUtil.readFlatFile(new File(fileUri)); } catch (FileNotFoundException e) { LOG.debug("not found file:" + fileUri + "' \n" + e); } catch (IOException e2) { LOG.debug("occured exception read file '" + fileUri + "' \n" + e2); } begin = template.indexOf("${"); end = template.indexOf("}", begin); while (begin != -1) { String name = template.substring(begin + 2, end); String value = ""; try { LinkedList<String> names = new LinkedList<String>(Arrays.asList(name.split("\\."))); names.poll(); // remove string 'status' value = ReflectionUtil.getValue(status, names); } catch (NoSuchMethodException e1) { LOG.error("occured a exception status'id=" + status.getId() + ",:" + e1); } catch (IllegalAccessException e2) { LOG.error("occured a exception status'id=" + status.getId() + ",:" + e2); } catch (IllegalArgumentException e3) { LOG.error("occured a exception status'id=" + status.getId() + ",:" + e3); } catch (InvocationTargetException e4) { LOG.error("occured a exception status'id=" + status.getId() + ",:" + e4); } catch (NullPointerException e5) { LOG.error( "try to get value of '" + name + "' occured a exception status'id=" + status.getId() + ",:" + e5); } name = name.replace(".", "\\u002E"); // LOG.debug("regex:"+"\\$\\{"+name+"\\}"); value = StringUtil.escapeChar(value); // debugBeforeTemp = temp; try { template = template.replaceFirst("\\u0024\\u007B" + name + "\\u007D", value); // debugAfterTemp = temp; } catch (IllegalArgumentException e) { // LOG.debug("temp which before replaced:"+debugBeforeTemp); // LOG.debug("replace value:"+value); // LOG.debug("temp which after replaced:"+debugAfterTemp); // throw e; LOG.error("occured exception when format weibo,status'id=" + status.getId() + ",:" + e); return ""; } begin = template.indexOf("${"); end = template.indexOf("}", begin); } return template; }