Fixing find URL

git-svn-id: https://svn.research-infrastructures.eu/d4science/gcube/trunk/portlets/user/share-updates@176813 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2019-01-25 10:01:29 +00:00
parent d0aad689dc
commit 44c92bd0ab
2 changed files with 13 additions and 4 deletions

View File

@ -26,8 +26,6 @@ import javax.imageio.ImageIO;
import javax.imageio.ImageReader;
import javax.imageio.stream.ImageInputStream;
import net.coobird.thumbnailator.Thumbnails;
import org.apache.commons.fileupload.util.Streams;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.util.PDFTextStripper;
@ -37,7 +35,6 @@ import org.apache.tika.io.TikaInputStream;
import org.apache.tika.metadata.Metadata;
import org.apache.tika.mime.MediaType;
import org.gcube.applicationsupportlayer.social.storage.FTPManager;
import org.gcube.common.portal.PortalContext;
import org.gcube.portal.databook.shared.ImageType;
import org.gcube.portlets.user.shareupdates.shared.LinkPreview;
import org.slf4j.Logger;
@ -46,6 +43,8 @@ import org.slf4j.LoggerFactory;
import com.sun.pdfview.PDFFile;
import com.sun.pdfview.PDFPage;
import com.sun.pdfview.PDFParseException;
import net.coobird.thumbnailator.Thumbnails;
/**
*
* @author Massimiliano Assante, ISTI-CNR

View File

@ -719,6 +719,16 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
return toReturn;
}
protected String findFirstLink(String message) {
try {
SocialMessageParser messageParser = new SocialMessageParser(message);
List<URLToken> urlTokens = messageParser.getURLTokens();
return urlTokens.get(0).getExtractedURL().toString();
}catch (Exception e) {
return null;
}
}
/**
* tries the following in the indicated order for Populating the Link preview
* Open Graph protocol
@ -731,7 +741,7 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
LinkPreview toReturn = null;
_log.info("to check " + linkToCheck);
//look for a url in text
linkToCheck = Utils.extractURL(linkToCheck);
linkToCheck = findFirstLink(linkToCheck);
if (linkToCheck == null)
return null; //no url