@Test public final void parseTitleTest() { final String html = "<html><meta name=\"description\" content=\"some description\">Some webpage</title></html>"; final LinkInformation link = new LinkInformation(); sut.parseInformation(html, link, TEST_ACCOUNT); Assert.assertEquals("some description", link.getDescription()); }
@Override public void parseInformation(final String htmlString, final LinkInformation link, final String inAccountId) { Pattern descriptionPattern = Pattern.compile("<meta name=\"description\" content=\"(.*?)\"", Pattern.CASE_INSENSITIVE); Matcher matcher = descriptionPattern.matcher(htmlString); if (matcher.find()) { for (int i = 0; i < matcher.groupCount(); i++) { log.info("Found description: " + i + "=" + matcher.group(i)); } String desc = StringEscapeUtils.unescapeHtml(matcher.group(1)); log.info("Found description: " + desc); if (desc.length() > maxLength) { String endWith = "..."; desc = desc.substring(0, maxLength - (1 + endWith.length())); desc += endWith; } link.setDescription(desc); } }
MetaDescriptionParser implements HtmlLinkInformationParserStrategy { @Override public void parseInformation(final String htmlString, final LinkInformation link, final String inAccountId) { Pattern descriptionPattern = Pattern.compile("<meta name=\"description\" content=\"(.*?)\"", Pattern.CASE_INSENSITIVE); Matcher matcher = descriptionPattern.matcher(htmlString); if (matcher.find()) { for (int i = 0; i < matcher.groupCount(); i++) { log.info("Found description: " + i + "=" + matcher.group(i)); } String desc = StringEscapeUtils.unescapeHtml(matcher.group(1)); log.info("Found description: " + desc); if (desc.length() > maxLength) { String endWith = "..."; desc = desc.substring(0, maxLength - (1 + endWith.length())); desc += endWith; } link.setDescription(desc); } } }
MetaDescriptionParser implements HtmlLinkInformationParserStrategy { @Override public void parseInformation(final String htmlString, final LinkInformation link, final String inAccountId) { Pattern descriptionPattern = Pattern.compile("<meta name=\"description\" content=\"(.*?)\"", Pattern.CASE_INSENSITIVE); Matcher matcher = descriptionPattern.matcher(htmlString); if (matcher.find()) { for (int i = 0; i < matcher.groupCount(); i++) { log.info("Found description: " + i + "=" + matcher.group(i)); } String desc = StringEscapeUtils.unescapeHtml(matcher.group(1)); log.info("Found description: " + desc); if (desc.length() > maxLength) { String endWith = "..."; desc = desc.substring(0, maxLength - (1 + endWith.length())); desc += endWith; } link.setDescription(desc); } } MetaDescriptionParser(final int inMaxLength); }
MetaDescriptionParser implements HtmlLinkInformationParserStrategy { @Override public void parseInformation(final String htmlString, final LinkInformation link, final String inAccountId) { Pattern descriptionPattern = Pattern.compile("<meta name=\"description\" content=\"(.*?)\"", Pattern.CASE_INSENSITIVE); Matcher matcher = descriptionPattern.matcher(htmlString); if (matcher.find()) { for (int i = 0; i < matcher.groupCount(); i++) { log.info("Found description: " + i + "=" + matcher.group(i)); } String desc = StringEscapeUtils.unescapeHtml(matcher.group(1)); log.info("Found description: " + desc); if (desc.length() > maxLength) { String endWith = "..."; desc = desc.substring(0, maxLength - (1 + endWith.length())); desc += endWith; } link.setDescription(desc); } } MetaDescriptionParser(final int inMaxLength); @Override void parseInformation(final String htmlString, final LinkInformation link, final String inAccountId); }
MetaDescriptionParser implements HtmlLinkInformationParserStrategy { @Override public void parseInformation(final String htmlString, final LinkInformation link, final String inAccountId) { Pattern descriptionPattern = Pattern.compile("<meta name=\"description\" content=\"(.*?)\"", Pattern.CASE_INSENSITIVE); Matcher matcher = descriptionPattern.matcher(htmlString); if (matcher.find()) { for (int i = 0; i < matcher.groupCount(); i++) { log.info("Found description: " + i + "=" + matcher.group(i)); } String desc = StringEscapeUtils.unescapeHtml(matcher.group(1)); log.info("Found description: " + desc); if (desc.length() > maxLength) { String endWith = "..."; desc = desc.substring(0, maxLength - (1 + endWith.length())); desc += endWith; } link.setDescription(desc); } } MetaDescriptionParser(final int inMaxLength); @Override void parseInformation(final String htmlString, final LinkInformation link, final String inAccountId);  }