From 44c92bd0abcd636ad95c698f01181875191c6bc0 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Fri, 25 Jan 2019 10:01:29 +0000 Subject: [PATCH] Fixing find URL git-svn-id: https://svn.research-infrastructures.eu/d4science/gcube/trunk/portlets/user/share-updates@176813 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../user/shareupdates/server/FilePreviewer.java | 5 ++--- .../shareupdates/server/ShareUpdateServiceImpl.java | 12 +++++++++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/gcube/portlets/user/shareupdates/server/FilePreviewer.java b/src/main/java/org/gcube/portlets/user/shareupdates/server/FilePreviewer.java index f81e2d4..2404b58 100644 --- a/src/main/java/org/gcube/portlets/user/shareupdates/server/FilePreviewer.java +++ b/src/main/java/org/gcube/portlets/user/shareupdates/server/FilePreviewer.java @@ -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 diff --git a/src/main/java/org/gcube/portlets/user/shareupdates/server/ShareUpdateServiceImpl.java b/src/main/java/org/gcube/portlets/user/shareupdates/server/ShareUpdateServiceImpl.java index 5e52a03..66a6759 100644 --- a/src/main/java/org/gcube/portlets/user/shareupdates/server/ShareUpdateServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/shareupdates/server/ShareUpdateServiceImpl.java @@ -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 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