Example #1
0
  public void testTorrent(AjaxBehaviorEvent event) {
    // TODO Это точно такая же часть как и в testMessage
    FacesContext context = FacesContext.getCurrentInstance();
    UIComponent component = UIComponent.getCurrentComponent(context);
    String url = (String) ((UIInput) component.findComponent("filmLinkRutracker")).getValue();

    WebBrowser webBrowser = new WebBrowser(LogEnum.WEB.getLog());
    //

    String regexp =
        (String) ((UIInput) component.findComponent("filmRegexpSerialNumber")).getValue();
    FacesMessage message = new FacesMessage();
    try {
      webBrowser.goToUrl(url);
      filmEdit.setTitle(webBrowser.getTitle());
      TorrentFile torrent = webBrowser.downloadTorrentFile(webBrowser.getTorrentUrl());
      ByteArrayInputStream bais = new ByteArrayInputStream(torrent.getContent());
      TorrentInfo info = new TorrentInfo(new BufferedInputStream(bais));
      StringBuilder builder = new StringBuilder();
      for (String fileName : info.getInfo()) {
        builder
            .append(fileName)
            .append(" № серии: \"")
            .append(MessageUtils.parseEpisode(fileName, regexp))
            .append("\"  ");
      }
      message.setSummary(builder.toString());
      message.setSeverity(FacesMessage.SEVERITY_INFO);
    } catch (CoreException e) {
      message.setSeverity(FacesMessage.SEVERITY_ERROR);
      message.setSummary(e.getMessage());
    }
    context.addMessage("otherMessageHidden", message);
    context.renderResponse();
  }
Example #2
0
  public void saveFilm(AjaxBehaviorEvent event) {
    WebBrowser webBrowser = new WebBrowser(LogEnum.WEB.getLog());
    try {
      webBrowser.goToUrl(filmEdit.getLinkRutracker());
      filmEdit.setTitle(webBrowser.getTitle());
    } catch (CoreException e) {
      // TODO Избавится от такого большого исключения сделать один статический метод
      FacesMessage error = new FacesMessage();
      error.setSeverity(FacesMessage.SEVERITY_ERROR);
      error.setSummary(e.getMessage());
      throw new ValidatorException(error);
    }

    if (filmEdit.getType() != TypeDistributionEnum.SERIALS.getType()) {
      filmEdit.setRegexpSerialNumber(null);
      filmEdit.setSeasonNumber(null);
    }
    DaoFactory.getInstance().getDistributionDao().addDistribution(filmEdit);
    if (filmList.size() > 0) filmList.add(0, filmEdit);
    filmList.add(filmEdit);
  }
Example #3
0
  public void testMessage(AjaxBehaviorEvent event) {
    FacesContext context = FacesContext.getCurrentInstance();
    UIComponent component = UIComponent.getCurrentComponent(context);
    String url = (String) ((UIInput) component.findComponent("filmLinkRutracker")).getValue();

    WebBrowser webBrowser = new WebBrowser(LogEnum.WEB.getLog());
    FacesMessage message = new FacesMessage();
    try {
      webBrowser.goToUrl(url);
      String title = webBrowser.getTitle();
      filmEdit.setTitle(title);
      String regexp = (String) ((UIInput) component.findComponent("filmMailRegexp")).getValue();
      String mailMessage =
          (String) ((UIInput) component.findComponent("filmMailMessage")).getValue();
      message.setSummary(MessageUtils.createMessage(title, regexp, mailMessage));
      message.setSeverity(FacesMessage.SEVERITY_INFO);
    } catch (CoreException e) {
      message.setSeverity(FacesMessage.SEVERITY_ERROR);
      message.setSummary(e.getMessage());
    }
    context.addMessage("otherMessageHidden", message);
    context.renderResponse();
  }