What I need is to get first image of string... I have
notice.getFullContent()
which returns html string...p tags...strong tags...img tag...
What I need is to get the src of the first image. I'm doing this:
Document doc = Jsoup.parse(notice.getFullContent());
Element imageElement = doc.select("img").first();
imageURL = imageElement.absUrl("src");
But when i go to page, it doesn't work. I'm in jsp of liferay instance. Thanks in advance,
SOLVED
Document doc = Jsoup.parse(notice.getFullContent());
String imageURL = "";
String description = "";
Element imageElement = doc.select("img").first();
if(imageElement != null)
{
imageURL = imageElement.attr("src");
}
Element descriptionElement = doc.select("p").first();
if(descriptionElement != null)
{
description = descriptionElement.text();
}
if(description.isEmpty() || description == null)
{
description = notice.getTitle();
}
The purpose was use these values to add meta og tags, like this:
<liferay-util:html-top>
<meta content="<%="WEBSITE/post?id="+id %>" property="og:url">
<meta content="article" property="og:type">
<meta content="<%=notice.getTitle() %>" property="og:title">
<meta content="<%=imageURL %>" property="og:image">
<meta content="<%=description %>" property="og:description">
</liferay-util:html-top>
thanks!