fixed the new line http resolved issue, however still need to handle the www only case and the dot at the end one

git-svn-id: https://svn.research-infrastructures.eu/d4science/gcube/trunk/portlets/user/share-updates@93937 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Massimiliano Assante 2014-03-31 17:02:52 +00:00
parent adfc37a961
commit 33c3bf0e23
4 changed files with 21 additions and 18 deletions

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<classpath> <classpath>
<classpathentry kind="src" output="target/share-updates-1.2.2-SNAPSHOT/WEB-INF/classes" path="src/main/java"> <classpathentry kind="src" output="target/share-updates-1.2.3-SNAPSHOT/WEB-INF/classes" path="src/main/java">
<attributes> <attributes>
<attribute name="optional" value="true"/> <attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
@ -31,5 +31,5 @@
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="output" path="target/share-updates-1.2.2-SNAPSHOT/WEB-INF/classes"/> <classpathentry kind="output" path="target/share-updates-1.2.3-SNAPSHOT/WEB-INF/classes"/>
</classpath> </classpath>

View File

@ -1,5 +1,5 @@
eclipse.preferences.version=1 eclipse.preferences.version=1
jarsExcludedFromWebInfLib= jarsExcludedFromWebInfLib=
lastWarOutDir=/Users/massi/Documents/workspace/share-updates/target/share-updates-1.2.2-SNAPSHOT lastWarOutDir=/Users/massi/Documents/workspace/share-updates/target/share-updates-1.2.3-SNAPSHOT
warSrcDir=src/main/webapp warSrcDir=src/main/webapp
warSrcDirIsOutput=false warSrcDirIsOutput=false

View File

@ -13,7 +13,7 @@
<groupId>org.gcube.portlets.user</groupId> <groupId>org.gcube.portlets.user</groupId>
<artifactId>share-updates</artifactId> <artifactId>share-updates</artifactId>
<packaging>war</packaging> <packaging>war</packaging>
<version>1.2.2-SNAPSHOT</version> <version>1.2.3-SNAPSHOT</version>
<name>gCube Share Updates Portlet</name> <name>gCube Share Updates Portlet</name>
<description> <description>

View File

@ -150,7 +150,7 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
public ClientFeed share(String postText, FeedType feedType, PrivacyLevel pLevel, public ClientFeed share(String postText, FeedType feedType, PrivacyLevel pLevel,
String vreId, LinkPreview preview, String urlThumbnail, ArrayList<String> mentionedUserFullNames,String fileName, String filePathOnServer, boolean notifyGroup) { String vreId, LinkPreview preview, String urlThumbnail, ArrayList<String> mentionedUserFullNames,String fileName, String filePathOnServer, boolean notifyGroup) {
String escapedFeedText = escapeHtml(postText); String escapedFeedText = escapeHtmlAndTransformUrl(postText);
ArrayList<PickingUser> mentionedUsers = null; ArrayList<PickingUser> mentionedUsers = null;
if (mentionedUserFullNames != null && ! mentionedUserFullNames.isEmpty()) { if (mentionedUserFullNames != null && ! mentionedUserFullNames.isEmpty()) {
@ -187,16 +187,17 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
if (escapedFeedText.compareTo(ShareUpdateForm.NO_TEXT_FILE_SHARE) == 0) { if (escapedFeedText.compareTo(ShareUpdateForm.NO_TEXT_FILE_SHARE) == 0) {
textToPost = convertFileNameAnchorHTML(url); textToPost = convertFileNameAnchorHTML(url);
} else { } else {
textToPost = transformUrls(escapedFeedText); textToPost = escapedFeedText;
System.out.println("textToPost=" + textToPost);
} }
ScopeBean scope = new ScopeBean(session.getScope()); ScopeBean scope = new ScopeBean(session.getScope());
String vreId2Set = scope.is(Type.VRE) ? scope.toString() : ""; String vreId2Set = scope.is(Type.VRE) ? scope.toString() : "";
Feed toShare = new Feed(UUID.randomUUID().toString(), feedType, username, feedDate, Feed toShare = new Feed(UUID.randomUUID().toString(), feedType, username, feedDate,
vreId2Set, url, urlThumbnail, textToPost, pLevel, fullName, email, thumbnailURL, linkTitle, linkDesc, host); vreId2Set, url, urlThumbnail, textToPost, pLevel, fullName, email, thumbnailURL, linkTitle, linkDesc, host);
_log.trace("Attempting to save Feed with text: " + escapedFeedText + " Level: " + pLevel); _log.trace("Attempting to save Feed with text: " + textToPost + " Level: " + pLevel);
boolean result = store.saveUserFeed(toShare); boolean result = store.saveUserFeed(toShare);
@ -285,7 +286,7 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
return toReturn; return toReturn;
} }
/** /**
* utilty method that convert a url ina text in a clickable url by the browser * utility method that convert a url ina text in a clickable url by the browser
* and if the user has just pasted a link, converts the link in: shared a link * and if the user has just pasted a link, converts the link in: shared a link
* @param feedText * @param feedText
* @return the text with the clickable url in it * @return the text with the clickable url in it
@ -295,7 +296,7 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
// separate input by spaces ( URLs have no spaces ) // separate input by spaces ( URLs have no spaces )
String [] parts = feedText.split("\\s"); String [] parts = feedText.split("\\s");
// Attempt to convert each item into an URL. // Attempt to convert each item into an URL.
for (int i = 0; i < parts.length; i++) { for (int i = 0; i < parts.length; i++) {
if (parts[i].startsWith("http")) { if (parts[i].startsWith("http")) {
try { try {
URL url = new URL(parts[i]); URL url = new URL(parts[i]);
@ -355,7 +356,7 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
_log.info("Returning test USER = " + session.getUsername()); _log.info("Returning test USER = " + session.getUsername());
HashMap<String, String> fakeVreNames = new HashMap<String, String>(); HashMap<String, String> fakeVreNames = new HashMap<String, String>();
//fakeVreNames.put("/gcube/devsec/devVRE","devVRE"); fakeVreNames.put("/gcube/devsec/devVRE","devVRE");
//fakeVreNames.put("/gcube/devNext/NexNext","NexNext"); //fakeVreNames.put("/gcube/devNext/NexNext","NexNext");
UserInfo user = new UserInfo(session.getUsername(), fullName, thumbnailURL, email, "fakeAccountUrl", true, false, fakeVreNames); UserInfo user = new UserInfo(session.getUsername(), fullName, thumbnailURL, email, "fakeAccountUrl", true, false, fakeVreNames);
@ -554,17 +555,19 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
* @param html the html string to escape * @param html the html string to escape
* @return the escaped string * @return the escaped string
*/ */
private String escapeHtml(String html) { private String escapeHtmlAndTransformUrl(String html) {
if (html == null) { if (html == null) {
return null; return null;
} }
String toReturn = html.replaceAll("&", "&amp;").replaceAll("<", "&lt;") String toReturn = html.replaceAll("&", "&amp;").replaceAll("<", "&lt;")
.replaceAll(">", "&gt;"); .replaceAll(">", "&gt;");
// then replace all the line breaks by <br/>, and all the double spaces by the html version &nbsp; // replace all the line breaks by <br/>
toReturn = toReturn.replaceAll("(\r\n|\n)","<br />"); toReturn = toReturn.replaceAll("(\r\n|\n)"," <br/> ");
//transfrom the URL in a clickable URL
toReturn = transformUrls(toReturn);
// then replace all the double spaces by the html version &nbsp;
toReturn = toReturn.replaceAll("\\s\\s","&nbsp;&nbsp;"); toReturn = toReturn.replaceAll("\\s\\s","&nbsp;&nbsp;");
return toReturn; return toReturn;
} }
@ -700,14 +703,14 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
try { try {
title = getTitleFromHeader(pageUrl); title = getTitleFromHeader(pageUrl);
ms = new MetaSeeker(connection, pageUrl); ms = new MetaSeeker(connection, pageUrl);
//try the metadata, otherwise ask the guesser //try the metadata, otherwise ask the guesser
description = (ms.getContent("description") != null && ! ms.getContent("description").isEmpty()) ? ms.getContent("description") : createDescriptionFromContent(link); description = (ms.getContent("description") != null && ! ms.getContent("description").isEmpty()) ? ms.getContent("description") : createDescriptionFromContent(link);
ArrayList<String> images = new ArrayList<String>(); ArrayList<String> images = new ArrayList<String>();
images = getImagesWithCleaner(pageUrl); images = getImagesWithCleaner(pageUrl);
toReturn = new LinkPreview(title, description, link, host, images); toReturn = new LinkPreview(title, description, link, host, images);
} catch(Exception e) { } catch(Exception e) {
_log.error("[MANUAL-PARSE] Something wrong with the meta seeker returning ... "); _log.error("[MANUAL-PARSE] Something wrong with the meta seeker returning ... ");
return toReturn; return toReturn;
@ -787,7 +790,7 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
for (int i = 0; i < upTo; i++) { for (int i = 0; i < upTo; i++) {
if (imgs[i].hasAttribute("src")) { if (imgs[i].hasAttribute("src")) {
String imageUrl = getImageUrlFromSrcAttribute(pageURL, imgs[i].getAttributeByName("src")); String imageUrl = getImageUrlFromSrcAttribute(pageURL, imgs[i].getAttributeByName("src"));
images.add(imageUrl); images.add(imageUrl);
_log.trace("[FOUND image] " + imageUrl); _log.trace("[FOUND image] " + imageUrl);
} }
} }