@Test public final void parseTitleTest() { final String html = "<html><title>Some webpage</title></html>"; final LinkInformation link = new LinkInformation(); sut.parseInformation(html, link, TEST_ACCOUNT); Assert.assertEquals("Some webpage", link.getTitle()); }
@Override public void parseInformation(final String htmlString, final LinkInformation link, final String inAccountId) { Pattern titlePattern = Pattern.compile("<title>(.*?)</title>", Pattern.CASE_INSENSITIVE); Matcher matcher = titlePattern.matcher(htmlString); String title = ""; if (matcher.find()) { title = StringEscapeUtils.unescapeHtml(matcher.group(1)); log.info("Found title: " + title); } else { title = link.getUrl(); } if (title.length() > maxLength) { String endWith = "..."; title = title.substring(0, maxLength - (1 + endWith.length())); title += endWith; } link.setTitle(title); }
HtmlLinkTitleParser implements HtmlLinkInformationParserStrategy { @Override public void parseInformation(final String htmlString, final LinkInformation link, final String inAccountId) { Pattern titlePattern = Pattern.compile("<title>(.*?)</title>", Pattern.CASE_INSENSITIVE); Matcher matcher = titlePattern.matcher(htmlString); String title = ""; if (matcher.find()) { title = StringEscapeUtils.unescapeHtml(matcher.group(1)); log.info("Found title: " + title); } else { title = link.getUrl(); } if (title.length() > maxLength) { String endWith = "..."; title = title.substring(0, maxLength - (1 + endWith.length())); title += endWith; } link.setTitle(title); } }
HtmlLinkTitleParser implements HtmlLinkInformationParserStrategy { @Override public void parseInformation(final String htmlString, final LinkInformation link, final String inAccountId) { Pattern titlePattern = Pattern.compile("<title>(.*?)</title>", Pattern.CASE_INSENSITIVE); Matcher matcher = titlePattern.matcher(htmlString); String title = ""; if (matcher.find()) { title = StringEscapeUtils.unescapeHtml(matcher.group(1)); log.info("Found title: " + title); } else { title = link.getUrl(); } if (title.length() > maxLength) { String endWith = "..."; title = title.substring(0, maxLength - (1 + endWith.length())); title += endWith; } link.setTitle(title); } HtmlLinkTitleParser(final int inMaxLength); }
HtmlLinkTitleParser implements HtmlLinkInformationParserStrategy { @Override public void parseInformation(final String htmlString, final LinkInformation link, final String inAccountId) { Pattern titlePattern = Pattern.compile("<title>(.*?)</title>", Pattern.CASE_INSENSITIVE); Matcher matcher = titlePattern.matcher(htmlString); String title = ""; if (matcher.find()) { title = StringEscapeUtils.unescapeHtml(matcher.group(1)); log.info("Found title: " + title); } else { title = link.getUrl(); } if (title.length() > maxLength) { String endWith = "..."; title = title.substring(0, maxLength - (1 + endWith.length())); title += endWith; } link.setTitle(title); } HtmlLinkTitleParser(final int inMaxLength); @Override void parseInformation(final String htmlString, final LinkInformation link, final String inAccountId); }
HtmlLinkTitleParser implements HtmlLinkInformationParserStrategy { @Override public void parseInformation(final String htmlString, final LinkInformation link, final String inAccountId) { Pattern titlePattern = Pattern.compile("<title>(.*?)</title>", Pattern.CASE_INSENSITIVE); Matcher matcher = titlePattern.matcher(htmlString); String title = ""; if (matcher.find()) { title = StringEscapeUtils.unescapeHtml(matcher.group(1)); log.info("Found title: " + title); } else { title = link.getUrl(); } if (title.length() > maxLength) { String endWith = "..."; title = title.substring(0, maxLength - (1 + endWith.length())); title += endWith; } link.setTitle(title); } HtmlLinkTitleParser(final int inMaxLength); @Override void parseInformation(final String htmlString, final LinkInformation link, final String inAccountId);  }