git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/social-networking/social-util-library@178584 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2019-03-14 11:58:03 +00:00
parent 5a743244f3
commit d7acbe2903
2 changed files with 11 additions and 5 deletions

View File

@ -6,7 +6,7 @@ import java.util.Objects;
public class SanitizedURL {
private static String FINAL_CHARACTERS_TO_REMOVE = "[\\.\\,\\;\\)\\:\\\"\\'\\\\]";
private static String CHARACTERS_TO_REMOVE = "[\\.\\,\\;\\)\\:\\\"\\'\\\\]";
protected String prefix;
protected String postfix;
@ -17,10 +17,12 @@ public class SanitizedURL {
throw new MalformedURLException();
}
prefix = "";
if(urlString.startsWith("(")) {
prefix = urlString.substring(0,1);;
if(prefix.matches(CHARACTERS_TO_REMOVE)) {
prefix = urlString.substring(0, 1);
urlString = urlString.substring(1);
}else {
prefix = "";
}
if(urlString.startsWith("www.")) {
@ -28,7 +30,7 @@ public class SanitizedURL {
}
postfix = urlString.substring(urlString.length()-1);
if(postfix.matches(FINAL_CHARACTERS_TO_REMOVE)) {
if(postfix.matches(CHARACTERS_TO_REMOVE)) {
urlString = urlString.substring(0, urlString.length()-1);
}else {
postfix = "";

View File

@ -52,6 +52,9 @@ public class MessageParserTest {
public static final String TEST_LUCA_6 = "(www.google.it)";
public static final String TEST_LUCA_7 = "Hello (https://doodle.com/poll/not-existing-poll)";
public static final String TEST_LUCA_8 = "Hello this link \"https://virtuoso.parthenos.d4science.org/sparql?default-graph-uri=&query=SELECT+%3Ftype+%28COUNT%28%3Ftype%29+as+%3FtypeCount%29++%0D%0A%09%09%09%09%09WHERE+%7B%5B%5D+a+%3Ftype%7D%0D%0A%09%09%09%09%09GROUP+BY+%3Ftype&format=text%2Fhtml&timeout=0&debug=on\" is a SPARQL query ";
@Test
public void test() {
String message = "Prova #Pippo Pollo http://google) <a href=\"/test\">Luca</a> https://www.linkedin.com/feed/update/urn:li:activity:6488779074213801984 :) ";
@ -85,7 +88,8 @@ public class MessageParserTest {
logger.debug(messageParser.getParsedMessage());
messageParser = new SocialMessageParser(TEST_LUCA_5);
logger.debug(messageParser.getParsedMessage());
messageParser = new SocialMessageParser(TEST_LUCA_8);
logger.debug(messageParser.getParsedMessage());
}
@Test