@Override
  public void updateItem(AppboxItem appboxItem, UploadFile img) {
    AppboxCategory appboxCategory = findCategoryById(appboxItem.getAppboxCategory().getId());
    if (appboxCategory == null) throw new ServiceException("appbox.category.is.not.exist");

    if (img != null) appboxItem.setImg(uploadImg(img));

    appboxItemDao.update(appboxItem);
    updateRootTime();
  }
 @Override
 public void setItemDefaultById(int appboxItemId, short isDefault) {
   try {
     AppboxItem appboxItem = appboxItemDao.findById(appboxItemId);
     if (appboxItem == null) {
       // throw new DataAccessException("input id is wrong");
       throw new RuntimeException("input id is wrong");
     }
     appboxItem.setIsDefault(isDefault);
     appboxItemDao.update(appboxItem);
   } catch (DataAccessException dse) {
     log.error(dse.toString());
     throw new ServiceException("DataAccessException", dse);
   }
 }
  @Override
  public Integer addItem(AppboxItem appboxItem, UploadFile img) {
    AppboxCategory appboxCategory = findCategoryById(appboxItem.getAppboxCategory().getId());
    if (appboxCategory == null) throw new ServiceException("appbox.category.is.not.exist");

    appboxItem.setPostTime(System.currentTimeMillis());
    appboxItem.setMatchTime(0L);
    appboxItem.setMatchStatue(-1);

    appboxItem.setImg(uploadImg(img));

    Integer id = (Integer) appboxItemDao.save(appboxItem);
    updateRootTime();
    return id;
  }
  @Override
  public int match(AppboxItem appboxItem) {

    CrawlerMatcher cm = new CrawlerMatcher();
    try {
      cm.setUrl(appboxItem.getSource());
      String[] regexs = {
        appboxItem.getTitleRegex(), appboxItem.getUrlRegex(), appboxItem.getPicRegex()
      };

      cm.setRegexs(regexs);
      cm.setCharSet(appboxItem.getCharSet());
      cm.execute();

      int isUpdate = 0;
      if (cm.getResult()[0] == null || !cm.getResult()[0].equals(appboxItem.getTitle())) {
        appboxItem.setTitle(cm.getResult()[0]);
        isUpdate = 1;
      }
      if (cm.getResult()[1] == null || !cm.getResult()[1].equals(appboxItem.getUrl())) {
        appboxItem.setUrl(completionUrl(appboxItem.getSource(), cm.getResult()[1]));
        isUpdate = 1;
      }
      if (cm.getResult()[2] == null || !cm.getResult()[2].equals(appboxItem.getImgUrl())) {
        String imgUrl = completionUrl(appboxItem.getSource(), cm.getResult()[2]);
        appboxItem.setImgUrl(imgUrl);
        // TODO check table appboxImg to verify that the pic has been stored
        if (!checkImgUrl(imgUrl)) {}

        isUpdate = 1;
      }
      /*else if(!cm.getResult()[2].equals(appboxItem.getImgUrl())){
      	//TODO processing image
      	String completeUrl = completionUrl(appboxItem.getSource(), cm.getResult()[2]);
      	fileStore(appboxItem, completeUrl);
      	isUpdate = 1;
      }*/

      if (isUpdate == 1) {
        appboxItem.setMatchTime(System.currentTimeMillis());
      }

      int statue;

      if (cm.getResult()[0] == null && cm.getResult()[1] == null && cm.getResult()[2] == null)
        statue = -1;
      else if (cm.getResult()[0] != null && cm.getResult()[1] != null && cm.getResult()[2] != null)
        statue = 0;
      else statue = 1;

      appboxItem.setMatchStatue(statue);

      appboxItemDao.update(appboxItem);
      return statue;

    } catch (crawlerException e) {
      e.printStackTrace();
      throw new ServiceException(e.getMessage(), e);
    }
  }