@Override
 public JcUser deleteWeibo(JcUser jcUser) {
   this.jcUser = jcUser;
   UserTask userTask = userTaskPersistenceService.getUserTaskByKey(jcUser.getAccessToken());
   if (userTask == null || !userTask.getTask().isAlive()) {
     if (userTask == null) userTask = new UserTask();
     else userTaskPersistenceService.delete(userTask);
     tm.client.setToken(jcUser.getAccessToken());
     List<Status> statuses = weiboPersistenceService.getAllTop(jcUser);
     if (statuses.size() == 0) {
       jcUser.setDeleteCount(-1);
       return jcUser;
     }
     DeleteTask deleteTask = new DeleteTask(jcUser.getAccessToken());
     deleteTask.setStatues(statuses);
     deleteTask.start();
     // jcUser.setDeleteTask(deleteTask);
     userTask.setKey(jcUser.getAccessToken());
     userTask.setTask(deleteTask);
     userTaskPersistenceService.save(userTask);
   }
   jcUser.setDeleteCount(destroyedIndex + 1);
   jcUser.setOutOfLimit(outOfLimit);
   return this.jcUser;
 }
 /** return HTML style weibo */
 @Override
 public String compositeWeibo(JcUser jcUser) {
   StringBuffer cs = new StringBuffer();
   URL url = null;
   String weibo = "";
   List<Status> statuses = weiboPersistenceService.getAllTop(jcUser);
   for (Status s : statuses) {
     LOG.debug("compositing weibo,status is:" + s.getId());
     String resource = "/templates/status.html";
     if (s.getRetweetedStatus() != null) {
       resource = "/templates/retweeted.html";
     }
     url = this.getClass().getResource(resource);
     try {
       cs.append(formatWeibo(url.toURI(), s));
     } catch (URISyntaxException e) {
       LOG.error(e.getMessage());
     }
   }
   url = this.getClass().getResource("/templates/weibo.html");
   try {
     weibo = DataUtil.readFlatFile(new File(url.toURI()));
   } catch (FileNotFoundException e) {
     LOG.error("not found file:/templates/weibo.html" + e);
   } catch (IOException e2) {
     LOG.error("occurred exception read file '/templates/weibo.html' \n" + e2);
   } catch (URISyntaxException e3) {
     LOG.error(e3.getMessage());
   }
   weibo = weibo.replaceAll("\\$\\{content\\}", cs.toString());
   return weibo;
 }
  /** call Weibo api to obtain weibos return count weibos have been saved */
  @Override
  public JcUser obtainWeibo(JcUser jcUser, ServletContext context) {
    int count = 0;
    int swoopCount = 0;
    int totalNumber = 0;
    int totalPage = 0;
    StatusWapper statusWapper = null;

    // get user's AccessToken by sessionId.
    // this.jcUser =
    // jcUserPersistenceService.getUserBySessionId(jcUser.getSession()); it
    // should be handled by security validation
    if (jcUser.getAccessToken() == null || jcUser.getAccessToken().length() == 0) return jcUser;
    this.jcUser = jcUser;
    preparePath(context);

    tm.client.setToken(jcUser.getAccessToken());
    c.client.setToken(jcUser.getAccessToken());

    // begin to obtain weibo from weibo api.
    statusWapper = obtainWeibo(tm, jcUser, 1);
    count += weiboPersistenceService.saveStatuses(statusWapper.getStatuses());
    swoopCount += statusWapper.getStatuses().size();

    totalNumber = (int) (statusWapper.getTotalNumber()); // total weibos the
    // user have
    totalPage = totalNumber % 100 == 0 ? totalNumber / 100 : totalNumber / 100 + 1;
    // because weibo api has a limit that only 100 weibos can be obtained
    // each request.
    for (int page = 2; page < totalPage; page++) {
      statusWapper = obtainWeibo(tm, jcUser, page);
      // if (callCount >= limit || outOfLimit == true)
      if (jcUser.isOutOfLimit()) break;
      count += weiboPersistenceService.saveStatuses(statusWapper.getStatuses());
      swoopCount += statusWapper.getStatuses().size();
    }
    LOG.debug("obtained " + swoopCount + " Weibos");
    LOG.debug("save " + count + " Weibos");
    this.jcUser.setWeiboCount(count);
    this.jcUser.setThumbnailCount(thumbnailCount);
    this.jcUser.setLargeCount(largeCount);
    this.jcUser.setCommentCount(commentCount);
    return this.jcUser;
  }