tagging seems working, missing notifications
git-svn-id: https://svn.research-infrastructures.eu/d4science/gcube/trunk/portlets/user/share-updates@73547 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
a527575090
commit
1a56979f8d
5
pom.xml
5
pom.xml
|
@ -131,6 +131,11 @@
|
|||
<artifactId>jtidy</artifactId>
|
||||
<version>r938</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jsoup</groupId>
|
||||
<artifactId>jsoup</artifactId>
|
||||
<version>1.6.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.eliasbalasis</groupId>
|
||||
<artifactId>tibcopagebus4gwt</artifactId>
|
||||
|
|
|
@ -24,6 +24,7 @@ import com.google.gwt.user.client.Window;
|
|||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||
import com.google.gwt.user.client.ui.Button;
|
||||
import com.google.gwt.user.client.ui.Composite;
|
||||
import com.google.gwt.user.client.ui.HTML;
|
||||
import com.google.gwt.user.client.ui.HTMLPanel;
|
||||
import com.google.gwt.user.client.ui.Image;
|
||||
import com.google.gwt.user.client.ui.ListBox;
|
||||
|
@ -128,36 +129,37 @@ public class ShareUpdateForm extends Composite {
|
|||
}
|
||||
|
||||
@UiHandler("submitButton")
|
||||
void onClick(ClickEvent e) {
|
||||
Window.alert("Please wait, Implementation to be completed");
|
||||
// shareupdateService.getUserSettings(new AsyncCallback<UserSettings>() {
|
||||
// public void onFailure(Throwable caught) {
|
||||
// Window.alert("Ops! we encountered some problems delivering your message, server is not responding, please try again in a short while.");
|
||||
// }
|
||||
// public void onSuccess(UserSettings result) {
|
||||
// if (result.getUserInfo().getUsername().equals("test.user")) {
|
||||
// Window.alert("Your session has expired, please log out and login again");
|
||||
// return;
|
||||
// }
|
||||
// myUserInfo = result.getUserInfo();
|
||||
// String toShare = shareTextArea.getText().trim();
|
||||
// if (toShare.equals(SHARE_UPDATE_TEXT) || toShare.equals(ERROR_UPDATE_TEXT) || toShare.equals("")) {
|
||||
// shareTextArea.addStyleName("error");
|
||||
// shareTextArea.setText(ERROR_UPDATE_TEXT);
|
||||
// return;
|
||||
// }
|
||||
// //then you can post
|
||||
// postTweet(toShare);
|
||||
// }
|
||||
// });
|
||||
void onClick(ClickEvent e) {
|
||||
shareupdateService.getUserSettings(new AsyncCallback<UserSettings>() {
|
||||
public void onFailure(Throwable caught) {
|
||||
Window.alert("Ops! we encountered some problems delivering your message, server is not responding, please try again in a short while.");
|
||||
}
|
||||
public void onSuccess(UserSettings result) {
|
||||
if (result.getUserInfo().getUsername().equals("test.user")) {
|
||||
Window.alert("Your session has expired, please log out and login again");
|
||||
return;
|
||||
}
|
||||
myUserInfo = result.getUserInfo();
|
||||
String toShare = shareTextArea.getText().trim();
|
||||
if (toShare.equals(SHARE_UPDATE_TEXT) || toShare.equals(ERROR_UPDATE_TEXT) || toShare.equals("")) {
|
||||
shareTextArea.addStyleName("error");
|
||||
shareTextArea.setText(ERROR_UPDATE_TEXT);
|
||||
return;
|
||||
}
|
||||
//then you can post, but pass html
|
||||
String toPost = shareTextArea.getHTML().trim();
|
||||
postTweet(toPost);
|
||||
}
|
||||
});
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param textToPost
|
||||
*/
|
||||
private void postTweet(String textToPost) {
|
||||
String toShare = escapeHtml(textToPost);
|
||||
if (! checkTextLength(toShare)) {
|
||||
//String toShare = escapeHtml(textToPost);
|
||||
String toShare = textToPost;
|
||||
if (! checkTextLength(new HTML(toShare).getText())) { //need to convert it to text
|
||||
Window.alert("We found a single word containing more than 50 chars and it's not a link, is it meaningful?");
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ import com.google.gwt.event.shared.HandlerManager;
|
|||
import com.google.gwt.user.client.DOM;
|
||||
import com.google.gwt.user.client.Event;
|
||||
import com.google.gwt.user.client.Timer;
|
||||
import com.google.gwt.user.client.Window;
|
||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||
import com.google.gwt.user.client.ui.HTML;
|
||||
|
||||
|
@ -82,7 +83,7 @@ public class SmartTextArea extends ContentEditDiv {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* paste and other events overridden
|
||||
*/
|
||||
|
@ -95,7 +96,7 @@ public class SmartTextArea extends ContentEditDiv {
|
|||
Timer t = new Timer() {
|
||||
@Override
|
||||
public void run() {
|
||||
String toCheck = extractLink(getText());
|
||||
String toCheck = extractLink(getHTML());
|
||||
if (toCheck != null) {
|
||||
GWT.log("toCheck1:" + toCheck);
|
||||
ShareUpdateForm.get().checkLink(new HTML(toCheck).getText());
|
||||
|
@ -134,12 +135,29 @@ public class SmartTextArea extends ContentEditDiv {
|
|||
* @return null if there's no link present
|
||||
*/
|
||||
private String extractLink(String textToCheck) {
|
||||
GWT.log("textToCheck:" + textToCheck);
|
||||
String [] parts = textToCheck.split("\\s");
|
||||
// Attempt to convert each item into an URL.
|
||||
for( String item : parts ) {
|
||||
if (item.startsWith("http")) {
|
||||
return item;
|
||||
}
|
||||
if (item.startsWith("href") || item.startsWith("HREF")) { //this is for (damned) safari because sometimes it paste <a href="http... nsteand of http
|
||||
textToCheck = textToCheck.replaceAll("\"", " ");
|
||||
textToCheck = textToCheck.replaceAll("href", " ");
|
||||
textToCheck = textToCheck.replaceAll("HREF", " ");
|
||||
return extractLink(textToCheck);
|
||||
}
|
||||
}
|
||||
//else we try plain text here (chrome)
|
||||
String plainText = new HTML(textToCheck).getText();
|
||||
if (textToCheck.length() != plainText.length()) {
|
||||
plainText = textToCheck.replaceAll("nbsp;", " ");
|
||||
String [] pparts = plainText.split("\\s");
|
||||
for( String item : pparts ) {
|
||||
if (item.startsWith("http"))
|
||||
return item;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -16,12 +16,15 @@ import javax.net.ssl.SSLContext;
|
|||
import javax.net.ssl.TrustManager;
|
||||
import javax.net.ssl.X509TrustManager;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.validator.routines.UrlValidator;
|
||||
import org.gcube.application.framework.core.session.ASLSession;
|
||||
import org.gcube.application.framework.core.session.SessionManager;
|
||||
import org.gcube.common.core.utils.logging.GCUBEClientLog;
|
||||
import org.gcube.portal.custom.communitymanager.OrganizationsUtil;
|
||||
import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
|
||||
import org.gcube.portal.databook.client.GCubeSocialNetworking;
|
||||
import org.gcube.portal.databook.server.DBCassandraAstyanaxImpl;
|
||||
import org.gcube.portal.databook.server.DatabookStore;
|
||||
import org.gcube.portal.databook.shared.ClientFeed;
|
||||
|
@ -49,11 +52,15 @@ import org.gcube.vomanagement.usermanagement.impl.liferay.LiferayGroupManager;
|
|||
import org.gcube.vomanagement.usermanagement.impl.liferay.LiferayUserManager;
|
||||
import org.gcube.vomanagement.usermanagement.model.GroupModel;
|
||||
import org.gcube.vomanagement.usermanagement.model.UserModel;
|
||||
import org.htmlcleaner.HtmlCleaner;
|
||||
import org.htmlcleaner.TagNode;
|
||||
import org.htmlparser.beans.StringBean;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.w3c.tidy.Tidy;
|
||||
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
|
||||
import com.liferay.portal.kernel.exception.PortalException;
|
||||
import com.liferay.portal.kernel.exception.SystemException;
|
||||
|
@ -107,7 +114,7 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
|
|||
String user = (String) this.getThreadLocalRequest().getSession().getAttribute(ScopeHelper.USERNAME_ATTRIBUTE);
|
||||
if (user == null) {
|
||||
_log.warn("USER IS NULL setting test.user and Running OUTSIDE PORTAL");
|
||||
// user = "test.user";
|
||||
// user = "test.user";
|
||||
user = "massimiliano.assante";
|
||||
SessionManager.getInstance().getASLSession(sessionID, user).setScope("/gcube/devsec/devVRE");
|
||||
withinPortal = false;
|
||||
|
@ -118,13 +125,82 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
|
|||
System.out.println("SessionID = " + sessionID);
|
||||
return SessionManager.getInstance().getASLSession(sessionID, user);
|
||||
}
|
||||
|
||||
private ArrayList<String> extractPeopleTags(String postText) {
|
||||
ArrayList<String> toReturn = new ArrayList<String>();
|
||||
String toParse = "<html><head></head><body>" + postText + "</body></html>";
|
||||
|
||||
HtmlCleaner cleaner = new HtmlCleaner();
|
||||
// parse the string HTML
|
||||
TagNode pageData = cleaner.clean(toParse);
|
||||
TagNode[] inputElements = pageData.getElementsByName("input", true);
|
||||
if (inputElements != null) {
|
||||
for (int i = 0; i < inputElements.length; i++) {
|
||||
System.out.println("Found input " + inputElements[i].getAttributes().get("value"));
|
||||
toReturn.add(inputElements[i].getAttributes().get("value"));
|
||||
}
|
||||
} else {
|
||||
_log.trace("No person tags in this post");
|
||||
}
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
private static String html2text(String html) {
|
||||
return Jsoup.parse(html).text();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* this method is used when posting a feed
|
||||
*
|
||||
* It converts the tagged people <input with the actual person profile link, not trivial
|
||||
*
|
||||
* @param postText is the html you get from the contentDIV smartarea sth like:
|
||||
* text text text <input .... value="Massimiliano Assante" ... type="text"><span> etc etc</span>
|
||||
*
|
||||
* @return a String ready to be posted
|
||||
*/
|
||||
private String transformPost(String postText) {
|
||||
ArrayList<String> taggedPeople = extractPeopleTags(postText);
|
||||
if (taggedPeople == null || taggedPeople.size() == 0) { //there are no tagged people, remove html and go
|
||||
String escapedFeedText = escapeHtml(postText); //here escape html to avoid xss attacks
|
||||
String html = "<html><head></head><body>" + escapedFeedText + "</body></html>";
|
||||
return html2text(html);
|
||||
} else {
|
||||
// this is needed to reconstruct the place of people tags, selfexplaining i think
|
||||
int i = 0;
|
||||
while (postText.contains("<input readonly=")) {
|
||||
//the replacing does not affect html but affects the While guard
|
||||
postText = postText.replaceFirst("<input readonly=", "_usr_place_holder_["+i+"]<input readonly =");
|
||||
i++;
|
||||
}
|
||||
String html = "<html><head></head><body>" + postText + "</body></html>";
|
||||
String postWithPlaceHolders = html2text(html);
|
||||
_log.trace("before cure: " + postWithPlaceHolders);
|
||||
/*
|
||||
* at this point you have the html removed and somthing like "text text text _usr_place_holder_[0] text text text _usr_place_holder_[1]"
|
||||
* you need to replace _usr_place_holder_[i](s) with the people with same index in taggedPeople ArrayList
|
||||
*/
|
||||
String escapedFeedText = escapeHtml(postWithPlaceHolders); //here escape html to avoid xss attacks
|
||||
ArrayList<String> usernames = getSelectedUserIds(taggedPeople);
|
||||
i = 0;
|
||||
for (String tagged : taggedPeople) {
|
||||
String username = (i < usernames.size()) ? usernames.get(i) : "";
|
||||
String taggedHTML = "<a class=\"link\" href=\""+GCubeSocialNetworking.USER_PROFILE_LINK+"?uid=\""+ username + "\">"+tagged+"</a> ";
|
||||
escapedFeedText = escapedFeedText.replace("_usr_place_holder_["+i+"]", taggedHTML);
|
||||
i++;
|
||||
}
|
||||
_log.trace("After cure: " + escapedFeedText);
|
||||
return escapedFeedText;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public ClientFeed share(String feedText, FeedType feedType, PrivacyLevel pLevel, String vreId, String linkTitle,
|
||||
String linkDesc, String url, String urlThumbnail, String host) {
|
||||
|
||||
String escapedFeedText = escapeHtml(feedText);
|
||||
public ClientFeed share(String postText, FeedType feedType, PrivacyLevel pLevel, String vreId, String linkTitle, String linkDesc, String url, String urlThumbnail, String host) {
|
||||
|
||||
String escapedFeedText = transformPost(postText);
|
||||
String username = getASLSession().getUsername();
|
||||
String email = username+"@isti.cnr.it";
|
||||
String fullName = username+" FULL";
|
||||
|
@ -179,6 +255,7 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
|
|||
replaceAmpersand(toShare.getDescription()), fullName, email, thumbnailURL, toShare.getLinkTitle(), toShare.getLinkDescription(),
|
||||
toShare.getUriThumbnail(), toShare.getLinkHost());
|
||||
return cf;
|
||||
|
||||
}
|
||||
|
||||
private UserSettings getUserSettingsFromSession() {
|
||||
|
@ -256,7 +333,7 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
|
|||
HashMap<String, String> fakeVreNames = new HashMap<String, String>();
|
||||
fakeVreNames.put("/gcube/devsec/devVRE","devVRE");
|
||||
//fakeVreNames.put("/gcube/devNext/NexNext","NexNext");
|
||||
|
||||
|
||||
UserInfo user = new UserInfo(getASLSession().getUsername(), fullName, thumbnailURL, email, "fakeAccountUrl", true, false, fakeVreNames);
|
||||
return new UserSettings(user, 0, session.getScopeName(), isInfrastructureScope());
|
||||
}
|
||||
|
@ -283,7 +360,7 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
|
|||
toReturn.put(vre.getGroupId(), vre.getGroupName());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return toReturn;
|
||||
}
|
||||
/**
|
||||
|
@ -597,6 +674,27 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
|
|||
return getASLSession().getScope().isInfrastructure();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the screennames of the addressee (user logins e.g. pino.pini)
|
||||
*/
|
||||
public ArrayList<String> getSelectedUserIds(ArrayList<String> fullNames) {
|
||||
if (fullNames == null)
|
||||
return new ArrayList<String>();
|
||||
else {
|
||||
ArrayList<PickingUser> allUsers = getPortalUsers();
|
||||
ArrayList<String> toReturn = new ArrayList<String>();
|
||||
for (String fullName : fullNames)
|
||||
for (PickingUser puser : allUsers) {
|
||||
if (puser.getFullName().compareTo(fullName) == 0) {
|
||||
toReturn.add(puser.getUsername());
|
||||
break;
|
||||
}
|
||||
}
|
||||
return toReturn;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<PickingUser> getPortalUsers() {
|
||||
ArrayList<PickingUser> portalUsers = new ArrayList<PickingUser>();
|
||||
|
|
Loading…
Reference in New Issue