2016-05-24 17:29:26 +02:00
|
|
|
package org.gcube.social_networking.socialutillibrary;
|
|
|
|
|
|
|
|
import java.net.MalformedURLException;
|
|
|
|
import java.net.URL;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.regex.Matcher;
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
|
|
|
import org.apache.commons.codec.binary.Base64;
|
|
|
|
import org.gcube.common.portal.GCubePortalConstants;
|
|
|
|
import org.gcube.common.portal.PortalContext;
|
|
|
|
import org.gcube.common.scope.impl.ScopeBean;
|
|
|
|
import org.gcube.common.scope.impl.ScopeBean.Type;
|
|
|
|
import org.gcube.portal.databook.client.GCubeSocialNetworking;
|
2018-06-19 12:31:03 +02:00
|
|
|
import org.gcube.portlets.widgets.pickitem.shared.ItemBean;
|
2016-05-24 17:29:26 +02:00
|
|
|
import org.gcube.vomanagement.usermanagement.GroupManager;
|
2016-05-25 12:37:32 +02:00
|
|
|
import org.gcube.vomanagement.usermanagement.RoleManager;
|
2016-05-24 17:29:26 +02:00
|
|
|
import org.gcube.vomanagement.usermanagement.UserManager;
|
|
|
|
import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager;
|
2016-05-25 12:37:32 +02:00
|
|
|
import org.gcube.vomanagement.usermanagement.impl.LiferayRoleManager;
|
2016-05-24 17:29:26 +02:00
|
|
|
import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
|
2016-05-25 12:37:32 +02:00
|
|
|
import org.gcube.vomanagement.usermanagement.model.GCubeGroup;
|
|
|
|
import org.gcube.vomanagement.usermanagement.model.GCubeTeam;
|
2016-05-24 17:29:26 +02:00
|
|
|
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
|
|
|
|
import org.htmlparser.beans.StringBean;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
public class Utils {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* logger
|
|
|
|
*/
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(Utils.class);
|
2016-10-04 17:05:18 +02:00
|
|
|
|
2016-09-08 14:45:08 +02:00
|
|
|
/**
|
|
|
|
* Hashtag regex enhanced for ticket #4937
|
|
|
|
*/
|
2019-03-04 17:44:38 +01:00
|
|
|
|
2017-12-14 12:34:20 +01:00
|
|
|
private static final String HASHTAG_REGEX = "^#\\w+([-_.]?\\w+)*|\\s#\\w+([-_.]?\\w+)*|(?<=[\\[({])#\\w+([-_.]?\\w+)";
|
2016-05-25 12:37:32 +02:00
|
|
|
|
2018-01-19 11:55:54 +01:00
|
|
|
/**
|
|
|
|
* IPv4 regex
|
|
|
|
*/
|
2019-03-04 17:44:38 +01:00
|
|
|
|
2018-01-19 11:55:54 +01:00
|
|
|
public static final String IPV4_REGEX = "\\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* IPV6 regex needs to be put in square brackets, see below
|
|
|
|
*/
|
2019-03-04 17:44:38 +01:00
|
|
|
|
2018-01-19 11:55:54 +01:00
|
|
|
public static final String IPV6_REGEX = "\\b(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}\\b";
|
|
|
|
|
2016-10-06 16:54:45 +02:00
|
|
|
/**
|
|
|
|
* Pattern for URLS
|
|
|
|
*/
|
2019-03-04 17:44:38 +01:00
|
|
|
|
2016-10-06 16:54:45 +02:00
|
|
|
private static final Pattern URL_PATTERN = Pattern.compile(
|
|
|
|
"\\b(((ht|f)tp(s?)\\:\\/\\/|~\\/|\\/)|www.)" +
|
2018-01-19 11:55:54 +01:00
|
|
|
"(\\w+:\\w+@)?((([-\\w]+\\.)+(com|org|net|gov" +
|
2016-10-06 16:54:45 +02:00
|
|
|
"|mil|biz|info|mobi|name|aero|jobs|museum" +
|
2018-01-19 11:55:54 +01:00
|
|
|
"|travel|[a-z]{2,5}))|("+ IPV4_REGEX +")|(\\["+ IPV6_REGEX +"\\]))(:[\\d]{1,5})?" +
|
2018-01-19 14:38:38 +01:00
|
|
|
"(((\\/([-\\w~!$+@|.,=]|%[a-fA-F\\d]{2})+)+|\\/)+|\\?|#)?" +
|
2017-11-08 16:30:10 +01:00
|
|
|
"((\\?([-\\w~!$+|.,*:]|%[a-fA-F\\d{2}])+=?" +
|
|
|
|
"([-\\w~!$+|.,*:=]|%[a-fA-F\\d]{2})*)" +
|
|
|
|
"(&(?:[-\\w~!$+|.,*:]|%[a-fA-F\\d{2}])+=?" +
|
|
|
|
"([-\\w~!$+|.,*:=]|%[a-fA-F\\d]{2})*)*)*" +
|
|
|
|
"(#([-\\w~!$+|.,*:=]|%[a-fA-F\\d]{2})*)?\\b");
|
2016-10-06 16:54:45 +02:00
|
|
|
|
2016-05-24 17:29:26 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param preview
|
|
|
|
* @return
|
|
|
|
*/
|
2016-05-24 17:33:10 +02:00
|
|
|
public static String convertFileNameAnchorHTML(String url) {
|
2016-05-24 17:29:26 +02:00
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
sb.append("<span style=\"color:gray; font-size:12px;\">shared </span><a class=\"link\" href=\"").append(url).append("\" target=\"_blank\">").append("a file.").append("</a> ").toString();
|
|
|
|
return sb.toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param session the Asl Session
|
|
|
|
* @param withinPortal true when is on Liferay portal
|
2016-05-25 12:37:32 +02:00
|
|
|
* @return the users plus the groups belonging to the current organization (scope)
|
2016-05-24 17:29:26 +02:00
|
|
|
*/
|
2016-05-25 12:37:32 +02:00
|
|
|
public static ArrayList<ItemBean> getDisplayableItemBeans(String scope, String currUser, boolean withinPortal) {
|
|
|
|
ArrayList<ItemBean> portalBeans = new ArrayList<ItemBean>();
|
2016-05-24 17:29:26 +02:00
|
|
|
try {
|
|
|
|
if (withinPortal) {
|
|
|
|
UserManager um = new LiferayUserManager();
|
|
|
|
GroupManager gm = new LiferayGroupManager();
|
2016-05-25 12:37:32 +02:00
|
|
|
RoleManager rm = new LiferayRoleManager();
|
2016-05-24 17:29:26 +02:00
|
|
|
ScopeBean sb = new ScopeBean(scope);
|
|
|
|
List<GCubeUser> users = null;
|
2016-05-25 12:37:32 +02:00
|
|
|
List<GCubeTeam> teams = null;
|
2016-05-24 17:29:26 +02:00
|
|
|
|
2016-05-25 12:37:32 +02:00
|
|
|
if (sb.is(Type.INFRASTRUCTURE)){
|
2016-05-24 17:29:26 +02:00
|
|
|
users = um.listUsersByGroup(gm.getRootVO().getGroupId());
|
2016-05-25 12:37:32 +02:00
|
|
|
|
|
|
|
// we need to retrieve vres to whom the current user belongs and then retrieve their teams
|
|
|
|
List<GCubeGroup> groupsOfCurrentUser = gm.listGroupsByUser(um.getUserId(currUser));
|
|
|
|
|
|
|
|
teams = new ArrayList<GCubeTeam>();
|
|
|
|
|
|
|
|
// retrieve the teams of each group
|
|
|
|
for (GCubeGroup gCubeGroup : groupsOfCurrentUser) {
|
|
|
|
List<GCubeTeam> partialTeamList = rm.listTeamsByGroup(gCubeGroup.getGroupId());
|
|
|
|
if(partialTeamList != null && !partialTeamList.isEmpty())
|
|
|
|
teams.addAll(partialTeamList);
|
|
|
|
}
|
|
|
|
|
|
|
|
logger.debug("Teams retrieved are " + teams);
|
|
|
|
|
|
|
|
}
|
2016-05-24 17:29:26 +02:00
|
|
|
else if (sb.is(Type.VRE)) { //must be in VRE
|
|
|
|
//get the name from the scope
|
|
|
|
String orgName = scope.substring(scope.lastIndexOf("/")+1, scope.length());
|
|
|
|
//ask the users
|
|
|
|
users = um.listUsersByGroup(gm.getGroupId(orgName));
|
2016-05-25 12:37:32 +02:00
|
|
|
// ask the teams
|
|
|
|
teams = rm.listTeamsByGroup(gm.getGroupId(orgName));
|
|
|
|
logger.debug("Teams retrieved are " + teams);
|
2016-05-24 17:29:26 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
logger.error("Error, you must be in SCOPE VRE OR INFRASTURCTURE, you are in VO SCOPE returning no users");
|
2016-05-25 12:37:32 +02:00
|
|
|
return portalBeans;
|
2016-05-24 17:29:26 +02:00
|
|
|
}
|
|
|
|
for (GCubeUser user : users) {
|
|
|
|
if (user.getUsername().compareTo("test.user") != 0 && user.getUsername().compareTo(currUser) != 0) { //skip test.user & current user
|
2016-05-25 12:37:32 +02:00
|
|
|
portalBeans.add(new ItemBean(user.getUserId()+"", user.getUsername(), user.getFullname(), user.getUserAvatarURL()));
|
2016-05-24 17:29:26 +02:00
|
|
|
}
|
|
|
|
}
|
2016-05-25 12:37:32 +02:00
|
|
|
for (GCubeTeam gCubeTeam : teams) {
|
|
|
|
portalBeans.add(new ItemBean(gCubeTeam.getTeamId()+"", gCubeTeam.getTeamName()));
|
|
|
|
}
|
2016-05-24 17:29:26 +02:00
|
|
|
}
|
|
|
|
else { //test users
|
2016-05-25 12:37:32 +02:00
|
|
|
portalBeans.add(new ItemBean("12111", "massimiliano.assante", "Test User #1", ""));
|
|
|
|
portalBeans.add(new ItemBean("14111", "massimiliano.assante", "Test Second User #2", ""));
|
|
|
|
portalBeans.add(new ItemBean("11511", "massimiliano.assante", "Test Third User", ""));
|
|
|
|
portalBeans.add(new ItemBean("11611", "massimiliano.assante", "Test Fourth User", ""));
|
|
|
|
portalBeans.add(new ItemBean("11711", "massimiliano.assante", "Test Fifth User", ""));
|
|
|
|
portalBeans.add(new ItemBean("11811", "massimiliano.assante", "Test Sixth User", ""));
|
|
|
|
portalBeans.add(new ItemBean("15811", "massimiliano.assante", "Ninth Testing User", ""));
|
|
|
|
portalBeans.add(new ItemBean("15811", "massimiliano.assante", "Eighth Testing User", ""));
|
|
|
|
portalBeans.add(new ItemBean("11211", "giogio.giorgi", "Seventh Test User", ""));
|
|
|
|
portalBeans.add(new ItemBean("2222", "pino.pinetti", "Tenth Testing User", ""));
|
2016-05-24 17:29:26 +02:00
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
logger.error("Error in server get all contacts ", e);
|
|
|
|
}
|
2016-05-25 12:37:32 +02:00
|
|
|
return portalBeans;
|
2016-05-24 17:29:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* utility method that extract the hashtags from a text
|
|
|
|
* @param postText
|
|
|
|
* @return the list of hashtags present in the text
|
|
|
|
*/
|
2019-03-04 17:44:38 +01:00
|
|
|
|
2016-05-24 17:33:10 +02:00
|
|
|
public static List<String> getHashTags(String postText) {
|
2016-05-24 17:29:26 +02:00
|
|
|
List<String> hashtags = new ArrayList<>();
|
2016-09-08 14:45:08 +02:00
|
|
|
Pattern MY_PATTERN = Pattern.compile(HASHTAG_REGEX);//Pattern.compile("^#\\w+|\\s#\\w+");
|
2016-05-24 17:29:26 +02:00
|
|
|
Matcher matcher = MY_PATTERN.matcher(postText);
|
|
|
|
while (matcher.find()) {
|
|
|
|
hashtags.add("#"+matcher.group().replace(" ", "").replace("#", ""));
|
|
|
|
}
|
|
|
|
return hashtags;
|
|
|
|
}
|
2016-05-25 12:37:32 +02:00
|
|
|
|
2016-05-24 17:29:26 +02:00
|
|
|
/**
|
2016-10-06 16:54:45 +02:00
|
|
|
* utility method that extract an url ina text when you paste a link.
|
|
|
|
* It returns the first (if any) meaningful url among the ones available.
|
2016-05-24 17:29:26 +02:00
|
|
|
* @param feedText
|
|
|
|
* @return the text with the clickable url in it
|
|
|
|
*/
|
2019-03-04 17:44:38 +01:00
|
|
|
|
2016-05-24 17:33:10 +02:00
|
|
|
public static String extractURL(String feedText) {
|
2016-05-24 17:29:26 +02:00
|
|
|
// separate input by spaces ( URLs have no spaces )
|
|
|
|
feedText = feedText.replaceAll("(\r\n|\n)"," <br/> ");
|
|
|
|
String [] parts = feedText.split("\\s");
|
|
|
|
// Attempt to convert each item into an URL.
|
|
|
|
for( String item : parts ) {
|
|
|
|
String toCheck = getHttpToken(item);
|
2016-10-06 16:54:45 +02:00
|
|
|
logger.debug("To check is " + toCheck);
|
2016-05-24 17:29:26 +02:00
|
|
|
if (toCheck != null) {
|
|
|
|
try {
|
|
|
|
new URL(toCheck);
|
|
|
|
return toCheck;
|
|
|
|
} catch (MalformedURLException e) {
|
|
|
|
// If there was an URL then it's not valid
|
2016-10-06 16:54:45 +02:00
|
|
|
logger.error("MalformedURLException skipping token " + toCheck);
|
2016-05-24 17:29:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Escape an html string. Escaping data received from the client helps to
|
|
|
|
* prevent cross-site script vulnerabilities.
|
|
|
|
*
|
|
|
|
* @param html the html string to escape
|
|
|
|
* @return the escaped string
|
|
|
|
*/
|
2019-03-04 17:44:38 +01:00
|
|
|
|
2016-05-24 17:33:10 +02:00
|
|
|
public static String escapeHtmlAndTransformUrl(String html) {
|
2016-05-24 17:29:26 +02:00
|
|
|
if (html == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
String toReturn = escapeHtml(html);
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
2016-05-25 12:37:32 +02:00
|
|
|
|
2016-05-24 17:29:26 +02:00
|
|
|
/**
|
|
|
|
* Escape an html string. Escaping data received from the client helps to
|
|
|
|
* prevent cross-site script vulnerabilities.
|
|
|
|
*
|
|
|
|
* @param html the html string to escape
|
|
|
|
* @return the escaped string
|
|
|
|
*/
|
2019-03-04 17:44:38 +01:00
|
|
|
|
2016-05-24 17:33:10 +02:00
|
|
|
public static String escapeHtml(String html) {
|
2016-05-24 17:29:26 +02:00
|
|
|
return html.replaceAll("&", "&").replaceAll("<", "<")
|
|
|
|
.replaceAll(">", ">");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2019-03-04 17:44:38 +01:00
|
|
|
|
2016-05-24 17:33:10 +02:00
|
|
|
public static String transformUrls(String feedText) {
|
2016-05-24 17:29:26 +02:00
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
// 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++) {
|
|
|
|
String toCheck = getHttpToken(parts[i]);
|
|
|
|
if (toCheck != null) {
|
|
|
|
try {
|
|
|
|
URL url = new URL(toCheck);
|
|
|
|
if (i == 0 && parts.length == 1) //then he shared just a link
|
|
|
|
return sb.append("<span style=\"color:gray; font-size:12px;\">shared </span><a class=\"link\" href=\"").append(url).append("\" target=\"_blank\">").append("a link.").append("</a> ").toString();
|
|
|
|
// If possible then replace with anchor...
|
|
|
|
sb.append("<a class=\"link\" style=\"font-size:14px;\" href=\"").append(url).append("\" target=\"_blank\">").append(url).append("</a> ");
|
|
|
|
} catch (MalformedURLException e) {
|
|
|
|
// If there was an URL then it's not valid
|
2016-10-06 16:54:45 +02:00
|
|
|
logger.error("MalformedURLException not converting token = " + toCheck);
|
|
|
|
sb.append(parts[i]);
|
|
|
|
sb.append(" ");
|
|
|
|
//return feedText;
|
2016-05-24 17:29:26 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
sb.append(parts[i]);
|
|
|
|
sb.append(" ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return sb.toString();
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* check the tokens of a pasted text and see if there's any http link in it
|
|
|
|
* @param item a text token
|
|
|
|
* @return the actual http link
|
|
|
|
*/
|
2019-03-04 17:44:38 +01:00
|
|
|
|
2016-10-06 16:54:45 +02:00
|
|
|
public static String getHttpToken(String originalItem) {
|
|
|
|
// apply pattern
|
|
|
|
String item = null;
|
2018-01-19 11:55:54 +01:00
|
|
|
|
2017-04-13 16:54:24 +02:00
|
|
|
//needed because we escape the text and a URL containing the "&" would arrive ad & and the matcher below would stop at ;
|
|
|
|
if (originalItem.startsWith("http") || originalItem.startsWith("www") ) {
|
|
|
|
originalItem = originalItem.replaceAll("amp;", "");
|
|
|
|
}
|
2018-01-19 11:55:54 +01:00
|
|
|
|
2016-10-06 16:54:45 +02:00
|
|
|
Matcher matcher = URL_PATTERN.matcher(originalItem);
|
|
|
|
if(matcher.find()){
|
|
|
|
logger.debug("Found match url " + matcher.group());
|
|
|
|
item = matcher.group();
|
|
|
|
}else
|
|
|
|
return null;
|
|
|
|
|
|
|
|
item = item.startsWith("www") ? "http://"+item : item;
|
|
|
|
logger.debug("getHttpToken returns -> " + item);
|
|
|
|
return item;
|
2016-05-24 17:29:26 +02:00
|
|
|
}
|
2016-10-04 17:05:18 +02:00
|
|
|
|
|
|
|
/**
|
2016-05-24 17:29:26 +02:00
|
|
|
* convert the mentioned people in HTML anchor and also Encode the params Base64
|
|
|
|
* @param escapedFeedText
|
|
|
|
* @param taggedPeople
|
|
|
|
* @return
|
|
|
|
*/
|
2019-03-04 17:44:38 +01:00
|
|
|
|
2016-05-24 17:33:10 +02:00
|
|
|
public static String convertMentionPeopleAnchorHTML(String escapedFeedText, ArrayList<ItemBean> taggedPeople, HttpServletRequest request) {
|
2016-05-25 12:37:32 +02:00
|
|
|
String pageToRedirectURL = "";
|
|
|
|
String httpGETAttrName = "";
|
|
|
|
String httpGETAttrValue ="";
|
2019-03-04 17:44:38 +01:00
|
|
|
PortalContext pContext = PortalContext.getConfiguration();
|
|
|
|
String gatewayURL = pContext.getGatewayURL(request);
|
2016-05-24 17:29:26 +02:00
|
|
|
for (ItemBean tagged : taggedPeople) {
|
2016-05-25 12:37:32 +02:00
|
|
|
if (! tagged.isItemGroup()) {
|
2019-03-04 17:44:38 +01:00
|
|
|
StringBuilder sb = new StringBuilder(gatewayURL)
|
|
|
|
.append(pContext.getSiteLandingPagePath(request))
|
|
|
|
.append(GCubePortalConstants.USER_PROFILE_FRIENDLY_URL);
|
|
|
|
pageToRedirectURL = sb.toString();
|
2016-05-25 12:37:32 +02:00
|
|
|
httpGETAttrName = GCubeSocialNetworking.USER_PROFILE_OID;
|
|
|
|
httpGETAttrValue = tagged.getName();
|
|
|
|
} else {
|
|
|
|
long teamId = Long.parseLong(tagged.getId());
|
|
|
|
try {
|
|
|
|
GCubeTeam theTeam = new LiferayRoleManager().getTeam(teamId);
|
2016-05-25 23:17:02 +02:00
|
|
|
//returns the VRE url e.g. /devVRE
|
2016-05-25 12:37:32 +02:00
|
|
|
String vreURL = new LiferayGroupManager().getGroup(theTeam.getGroupId()).getFriendlyURL();
|
|
|
|
//append the members url
|
2019-03-04 17:44:38 +01:00
|
|
|
StringBuilder sb = new StringBuilder(gatewayURL)
|
|
|
|
.append(GCubePortalConstants.PREFIX_GROUP_URL)
|
|
|
|
.append(vreURL)
|
|
|
|
.append(GCubePortalConstants.GROUP_MEMBERS_FRIENDLY_URL);
|
|
|
|
pageToRedirectURL= sb.toString();
|
2016-05-25 12:37:32 +02:00
|
|
|
httpGETAttrName = GCubeSocialNetworking.GROUP_MEMBERS_OID;
|
|
|
|
httpGETAttrValue = tagged.getId();
|
|
|
|
} catch (Exception e) {
|
2016-05-25 14:56:28 +02:00
|
|
|
logger.error("Error while retrieving team", e);
|
2016-05-25 12:37:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
String taggedHTML = "<a class=\"link\" href=\""+pageToRedirectURL
|
2016-05-24 17:29:26 +02:00
|
|
|
+"?"+
|
2016-05-25 12:37:32 +02:00
|
|
|
new String(Base64.encodeBase64(httpGETAttrName.getBytes()))+"="+
|
|
|
|
new String(Base64.encodeBase64(httpGETAttrValue.getBytes()))+"\">"+tagged.getAlternativeName()+"</a> ";
|
2016-05-24 17:29:26 +02:00
|
|
|
escapedFeedText = escapedFeedText.replace(tagged.getAlternativeName(), taggedHTML);
|
|
|
|
}
|
|
|
|
return escapedFeedText;
|
|
|
|
}
|
2016-05-25 12:37:32 +02:00
|
|
|
|
2016-05-24 17:29:26 +02:00
|
|
|
/**
|
|
|
|
* convert the hashtag in HTML anchor and also Encode the params Base64
|
|
|
|
* @param escapedFeedText
|
|
|
|
* @param hashtags
|
|
|
|
* @return
|
|
|
|
*/
|
2019-03-04 17:44:38 +01:00
|
|
|
|
2016-05-24 17:33:10 +02:00
|
|
|
public static String convertHashtagsAnchorHTML(String escapedFeedText, List<String> hashtags) {
|
2016-05-24 17:29:26 +02:00
|
|
|
for (String hashtag : hashtags) {
|
|
|
|
String taggedHTML = "<a class=\"link\" style=\"font-size:14px;\" href=\"?"+
|
|
|
|
new String(Base64.encodeBase64(GCubeSocialNetworking.HASHTAG_OID.getBytes()))+"="+
|
|
|
|
new String(Base64.encodeBase64(hashtag.getBytes()))+"\">"+hashtag+"</a>";
|
|
|
|
//TODO: does not work if the word is no preceeded by #
|
|
|
|
//dirty trick: double replace because \\boundaries do not accept # char
|
|
|
|
final String placeholder = "ñöñö-ñöñö";
|
|
|
|
String first = escapedFeedText.replaceAll("(?i)\\b"+hashtag.substring(1)+"\\b", placeholder);
|
|
|
|
escapedFeedText = first.replaceAll("#"+placeholder, taggedHTML);
|
|
|
|
//this is needed if there is a word equal to an hashtagged one without '#' e.g. #job and job
|
|
|
|
escapedFeedText = escapedFeedText.replaceAll(placeholder, hashtag.substring(1));
|
|
|
|
}
|
|
|
|
return escapedFeedText;
|
|
|
|
}
|
2016-05-25 12:37:32 +02:00
|
|
|
|
2016-05-24 17:29:26 +02:00
|
|
|
/**
|
|
|
|
* generate the description parsing the content (Best Guess)
|
|
|
|
* @param link the link to check
|
|
|
|
* @return the description guessed
|
|
|
|
*/
|
2016-05-24 17:33:10 +02:00
|
|
|
public static String createDescriptionFromContent(String link) {
|
2016-05-24 17:29:26 +02:00
|
|
|
StringBean sb = new StringBean();
|
|
|
|
sb.setURL(link);
|
|
|
|
sb.setLinks(false);
|
|
|
|
String description = sb.getStrings();
|
|
|
|
description = ((description.length() > 256) ? description.substring(0, 256)+"..." : description);
|
|
|
|
return description;
|
|
|
|
}
|
2018-01-19 11:55:54 +01:00
|
|
|
|
2017-05-16 16:04:17 +02:00
|
|
|
/**
|
|
|
|
* Remove HTML tags from text by using the following '\\<[^>]*>"'
|
|
|
|
* @param text
|
|
|
|
* @return a String without html tags
|
|
|
|
*/
|
2019-03-04 17:44:38 +01:00
|
|
|
|
2017-05-16 16:04:17 +02:00
|
|
|
public static String removeHTMLFromText(String text){
|
2018-01-19 11:55:54 +01:00
|
|
|
|
2017-05-16 16:04:17 +02:00
|
|
|
if(text == null)
|
|
|
|
return null;
|
|
|
|
else
|
|
|
|
return text.replaceAll("\\<[^>]*>","");
|
2018-01-19 11:55:54 +01:00
|
|
|
|
2017-05-16 16:04:17 +02:00
|
|
|
}
|
2016-05-24 17:29:26 +02:00
|
|
|
}
|