diff --git a/pom.xml b/pom.xml
index 4185805..4cb3752 100644
--- a/pom.xml
+++ b/pom.xml
@@ -131,6 +131,11 @@
jtidy
r938
+
+ org.jsoup
+ jsoup
+ 1.6.1
+
net.eliasbalasis
tibcopagebus4gwt
diff --git a/src/main/java/org/gcube/portlets/user/shareupdates/client/form/ShareUpdateForm.java b/src/main/java/org/gcube/portlets/user/shareupdates/client/form/ShareUpdateForm.java
index 69439b1..b19bd9b 100644
--- a/src/main/java/org/gcube/portlets/user/shareupdates/client/form/ShareUpdateForm.java
+++ b/src/main/java/org/gcube/portlets/user/shareupdates/client/form/ShareUpdateForm.java
@@ -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() {
-// 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() {
+ 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;
}
diff --git a/src/main/java/org/gcube/portlets/user/shareupdates/client/form/SmartTextArea.java b/src/main/java/org/gcube/portlets/user/shareupdates/client/form/SmartTextArea.java
index 6141fdb..28da4c2 100644
--- a/src/main/java/org/gcube/portlets/user/shareupdates/client/form/SmartTextArea.java
+++ b/src/main/java/org/gcube/portlets/user/shareupdates/client/form/SmartTextArea.java
@@ -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 extractPeopleTags(String postText) {
+ ArrayList toReturn = new ArrayList();
+ String toParse = "" + postText + "";
+
+ 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 etc etc
+ *
+ * @return a String ready to be posted
+ */
+ private String transformPost(String postText) {
+ ArrayList 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 = "" + escapedFeedText + "";
+ return html2text(html);
+ } else {
+ // this is needed to reconstruct the place of people tags, selfexplaining i think
+ int i = 0;
+ while (postText.contains("" + postText + "