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(); }
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(); }