From badd703b3b183a1e0003d9a2f49d49ba59587953 Mon Sep 17 00:00:00 2001 From: Massimiliano Assante Date: Thu, 30 Apr 2015 14:13:45 +0000 Subject: [PATCH] revised email message, added VRE Description git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/invite-friends-vre@114614 82a268e6-3cf1-43bd-a215-b396298e98cf --- pom.xml | 7 +- .../invitefriends/client/ui/FormViewImpl.java | 8 +- .../server/InviteServiceImpl.java | 105 +++++++++++------- 3 files changed, 71 insertions(+), 49 deletions(-) diff --git a/pom.xml b/pom.xml index 0927da8..e100ecd 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ 1.0.0 - + org.gcube.portlets.user invite-friends-vre war @@ -76,6 +76,11 @@ gwt-bootstrap 2.3.2.0 + + org.jsoup + jsoup + 1.6.2 + junit junit diff --git a/src/main/java/org/gcube/portlets/user/invitefriends/client/ui/FormViewImpl.java b/src/main/java/org/gcube/portlets/user/invitefriends/client/ui/FormViewImpl.java index abfe909..ebb1c02 100644 --- a/src/main/java/org/gcube/portlets/user/invitefriends/client/ui/FormViewImpl.java +++ b/src/main/java/org/gcube/portlets/user/invitefriends/client/ui/FormViewImpl.java @@ -51,8 +51,7 @@ public class FormViewImpl extends Composite implements FormView, Editor"); + removedMarkup = removedMarkup.replaceAll("<", "<"); + String text = removedMarkup; + try { + Document document = Jsoup.parse(removedMarkup); + Element body = document.body(); + text = buildStringFromNode(body).toString(); + } + catch (Exception e) { + _log.error("While converting HTML into text: " +e.getMessage()); + return removedMarkup; + } + return text; + } + + private static StringBuffer buildStringFromNode(Node node) { + StringBuffer buffer = new StringBuffer(); + + if (node instanceof TextNode) { + TextNode textNode = (TextNode) node; + buffer.append(textNode.text().trim()); + } + + for (Node childNode : node.childNodes()) { + buffer.append(buildStringFromNode(childNode)); + } + + if (node instanceof Element) { + Element element = (Element) node; + String tagName = element.tagName(); + if ("p".equals(tagName) || "br".equals(tagName) || "div".equals(tagName) || "h1".equals(tagName) || "h2".equals(tagName) || "h3".equals(tagName) || "h4".equals(tagName)) { + buffer.append("\n"); + } + } + + return buffer; + } }