set backtrack look char to 5 instead of 7

git-svn-id: https://svn.research-infrastructures.eu/d4science/gcube/trunk/portlets/user/share-updates@100450 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Massimiliano Assante 2014-10-06 12:16:44 +00:00
parent 98674d9af8
commit 921ea9647e
4 changed files with 58 additions and 13 deletions

View File

@ -61,7 +61,7 @@ public class ShareUpdateForm extends Composite {
// the label for all Vres/channels
private final static String ALL_VRES = "Share with: your Virtual Research Environments";
protected final static String SHARE_UPDATE_TEXT = "Share an update or paste a link, use “@” to mention someone";
protected final static String SHARE_UPDATE_TEXT = "Share an update or a link, use “@” to mention and “#” to categorize";
protected final static String ERROR_UPDATE_TEXT = "Looks like empty to me!";
public final static String NO_TEXT_FILE_SHARE = "_N0_73X7_SH4R3_";
private final static String LISTBOX_LEVEL = " - ";
@ -281,6 +281,7 @@ public class ShareUpdateForm extends Composite {
}
LinkPreview preview2Share = new LinkPreview(linkTitle, linkDescription, linkUrl, linkHost, null);
boolean notifyGroup = notifyListbox.getSelectedIndex() > 0;
shareupdateService.share(toShare, FeedType.TWEET, getPrivacyLevel(), vreId, preview2Share, linkUrlThumbnail, mentionedUsers, fileName, filePath, notifyGroup, new AsyncCallback<ClientFeed>() {
public void onFailure(Throwable caught) {
submitButton.setEnabled(true);

View File

@ -51,7 +51,8 @@ public class SuperPosedTextArea extends TextArea {
shareupdateService.getPortalUsers(new AsyncCallback<ArrayList<ItemBean>>() {
@Override
public void onSuccess(ArrayList<ItemBean> users) {
pickUserDlg = new PickItemsDialog('@', users, eventBus, 525, true);
pickUserDlg = new PickItemsDialog('@', users, eventBus, 525);
pickUserDlg.withPhoto();
}
@Override
public void onFailure(Throwable caught) {
@ -61,7 +62,8 @@ public class SuperPosedTextArea extends TextArea {
shareupdateService.getHashtags(new AsyncCallback<ArrayList<ItemBean>>() {
@Override
public void onSuccess(ArrayList<ItemBean> hashtags) {
pickHashtagDlg = new PickItemsDialog('#', hashtags, eventBus, 525, false);
pickHashtagDlg = new PickItemsDialog('#', hashtags, eventBus, 525);
pickHashtagDlg.withTriggerCharIncluded();
}
@Override
public void onFailure(Throwable caught) {
@ -168,7 +170,6 @@ public class SuperPosedTextArea extends TextArea {
String triggerChar = event.getTriggerChar();
String toAdd = event.getSelectedItem().getAlternativeName();
if (triggerChar.compareTo("#") == 0) { //has to be treated differently becase the # char remain present in the text unlike the @
toAdd = "#"+toAdd;
hashtags.add(toAdd);
int tPos = getText().lastIndexOf(triggerChar);

View File

@ -7,9 +7,7 @@ import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
@ -56,7 +54,6 @@ import org.gcube.vomanagement.usermanagement.model.UserModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.gwt.core.ext.linker.LinkerOrder.Order;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
@ -119,7 +116,7 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
}
public String getDevelopmentUser() {
String user = TEST_USER;
user = "massimiliano.assante";
//user = "massimiliano.assante";
return user;
}
/**
@ -136,7 +133,7 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
return false;
}
}
/**
*
*/
@ -144,7 +141,11 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
String vreId, LinkPreview preview, String urlThumbnail, ArrayList<String> mentionedUserFullNames,String fileName, String filePathOnServer, boolean notifyGroup) {
String escapedFeedText = TextTransfromUtils.escapeHtmlAndTransformUrl(postText);
List<String> hashtags = TextTransfromUtils.getHashTags(postText);
if (hashtags != null && !hashtags.isEmpty())
escapedFeedText = TextTransfromUtils.convertHashtagsAnchorHTML(escapedFeedText, hashtags);
ArrayList<ItemBean> mentionedUsers = null;
if (mentionedUserFullNames != null && ! mentionedUserFullNames.isEmpty()) {
mentionedUsers = getSelectedUserIds(mentionedUserFullNames);
@ -200,7 +201,7 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
_log.info("Attempting to save Feed with text: " + textToPost + " Level: " + pLevel + " Timeline="+vreScope2Set);
boolean result = store.saveUserFeed(toShare);
//need to put the feed into VRES Timeline too
if (pLevel == PrivacyLevel.VRES) {
_log.trace("PrivacyLevel was set to VRES attempting to write onto User's VRES Timelines");
@ -221,6 +222,7 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
_log.trace("Attempting to write onto " + vreScope2Set);
try {
store.saveFeedToVRETimeline(toShare.getKey(), vreScope2Set);
store.saveHashTags(toShare.getKey(), vreScope2Set, hashtags);
} catch (FeedIDNotFoundException e) {
_log.error("Error writing onto VRES Time Line" + vreScope2Set);
} //save the feed
@ -599,7 +601,7 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
Collections.sort(toSort, Collections.reverseOrder());
ArrayList<ItemBean> toReturn = new ArrayList<>();
for (HashTagAndOccurrence wrapper : toSort) {
String hashtag = wrapper.getHashtag().substring(1);
String hashtag = wrapper.getHashtag();
toReturn.add(new ItemBean(hashtag, hashtag, hashtag, null));
_log.trace(hashtag);
}

View File

@ -8,6 +8,10 @@ import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
@ -56,7 +60,7 @@ public class TextTransfromUtils {
* @param taggedPeople
* @return
*/
protected static String convertMentionPeopleAnchorHTML(String escapedFeedText, ArrayList<ItemBean> taggedPeople) {
protected static String convertMentionPeopleAnchorHTML(String escapedFeedText, List<ItemBean> taggedPeople) {
for (ItemBean tagged : taggedPeople) {
String taggedHTML = "<a class=\"link\" style=\"font-size:14px;\" href=\""+GCubeSocialNetworking.USER_PROFILE_LINK
+"?"+
@ -66,6 +70,40 @@ public class TextTransfromUtils {
}
return escapedFeedText;
}
/**
* utility method that extract the hashtags from a text
* @param postText
* @return the list of hashtags present in the text
*/
protected static List<String> getHashTags(String postText) {
List<String> hashtags = new ArrayList<>();
Pattern MY_PATTERN = Pattern.compile("#(\\w+)");
Matcher matcher = MY_PATTERN.matcher(postText);
while (matcher.find()) {
hashtags.add("#"+matcher.group(1));
}
return hashtags;
}
/**
* convert the hashtag in HTML anchor and also Encode the params Base64
* @param escapedFeedText
* @param hashtags
* @return
*/
protected static String convertHashtagsAnchorHTML(String escapedFeedText, List<String> hashtags) {
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>";
//dirty trick: double replace because \\boundaries do not accept # char
final String placeholder = "TO_REPLACE_4321234";
String first = escapedFeedText.replaceAll("(?i)\\b"+hashtag.substring(1)+"\\b", placeholder);
escapedFeedText = first.replaceAll("#"+placeholder, taggedHTML);
}
return escapedFeedText;
}
/**
* generate the description parsing the content (Best Guess)
@ -102,6 +140,7 @@ public class TextTransfromUtils {
toReturn = toReturn.replaceAll("\\s\\s","&nbsp;&nbsp;");
return toReturn;
}
/**
* utility method that extract an url ina text when you paste a link
* @param feedText
@ -368,4 +407,6 @@ public class TextTransfromUtils {
System.out.println("Error" + e);
}
}
}