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:
parent
adfc37a961
commit
33c3bf0e23
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
|
@ -31,5 +31,5 @@
|
|||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</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>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
eclipse.preferences.version=1
|
||||
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
|
||||
warSrcDirIsOutput=false
|
||||
|
|
2
pom.xml
2
pom.xml
|
@ -13,7 +13,7 @@
|
|||
<groupId>org.gcube.portlets.user</groupId>
|
||||
<artifactId>share-updates</artifactId>
|
||||
<packaging>war</packaging>
|
||||
<version>1.2.2-SNAPSHOT</version>
|
||||
<version>1.2.3-SNAPSHOT</version>
|
||||
|
||||
<name>gCube Share Updates Portlet</name>
|
||||
<description>
|
||||
|
|
|
@ -150,7 +150,7 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
|
|||
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 escapedFeedText = escapeHtml(postText);
|
||||
String escapedFeedText = escapeHtmlAndTransformUrl(postText);
|
||||
|
||||
ArrayList<PickingUser> mentionedUsers = null;
|
||||
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) {
|
||||
textToPost = convertFileNameAnchorHTML(url);
|
||||
} else {
|
||||
textToPost = transformUrls(escapedFeedText);
|
||||
textToPost = escapedFeedText;
|
||||
System.out.println("textToPost=" + textToPost);
|
||||
}
|
||||
|
||||
|
||||
ScopeBean scope = new ScopeBean(session.getScope());
|
||||
String vreId2Set = scope.is(Type.VRE) ? scope.toString() : "";
|
||||
|
||||
Feed toShare = new Feed(UUID.randomUUID().toString(), feedType, username, feedDate,
|
||||
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);
|
||||
|
||||
|
@ -285,7 +286,7 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
|
|||
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
|
||||
* @param feedText
|
||||
* @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 )
|
||||
String [] parts = feedText.split("\\s");
|
||||
// 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")) {
|
||||
try {
|
||||
URL url = new URL(parts[i]);
|
||||
|
@ -355,7 +356,7 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
|
|||
|
||||
_log.info("Returning test USER = " + session.getUsername());
|
||||
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");
|
||||
|
||||
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
|
||||
* @return the escaped string
|
||||
*/
|
||||
private String escapeHtml(String html) {
|
||||
private String escapeHtmlAndTransformUrl(String html) {
|
||||
if (html == null) {
|
||||
return null;
|
||||
}
|
||||
String toReturn = html.replaceAll("&", "&").replaceAll("<", "<")
|
||||
.replaceAll(">", ">");
|
||||
|
||||
// then replace all the line breaks by <br/>, and all the double spaces by the html version
|
||||
toReturn = toReturn.replaceAll("(\r\n|\n)","<br />");
|
||||
// replace all the line breaks by <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
|
||||
toReturn = toReturn.replaceAll("\\s\\s"," ");
|
||||
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
|
@ -700,14 +703,14 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
|
|||
try {
|
||||
title = getTitleFromHeader(pageUrl);
|
||||
ms = new MetaSeeker(connection, pageUrl);
|
||||
|
||||
|
||||
//try the metadata, otherwise ask the guesser
|
||||
description = (ms.getContent("description") != null && ! ms.getContent("description").isEmpty()) ? ms.getContent("description") : createDescriptionFromContent(link);
|
||||
|
||||
ArrayList<String> images = new ArrayList<String>();
|
||||
images = getImagesWithCleaner(pageUrl);
|
||||
toReturn = new LinkPreview(title, description, link, host, images);
|
||||
|
||||
|
||||
} catch(Exception e) {
|
||||
_log.error("[MANUAL-PARSE] Something wrong with the meta seeker returning ... ");
|
||||
return toReturn;
|
||||
|
@ -787,7 +790,7 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
|
|||
for (int i = 0; i < upTo; i++) {
|
||||
if (imgs[i].hasAttribute("src")) {
|
||||
String imageUrl = getImageUrlFromSrcAttribute(pageURL, imgs[i].getAttributeByName("src"));
|
||||
images.add(imageUrl);
|
||||
images.add(imageUrl);
|
||||
_log.trace("[FOUND image] " + imageUrl);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue