Regular expression updated. Now it recognizes also hashtags such as #gcube4.1.0, #gcube4.1.0gcore etc

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/social-networking/social-util-library@132611 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2016-10-04 15:05:18 +00:00
parent 1cd487a832
commit 483c585f14
2 changed files with 6 additions and 7 deletions

View File

@ -35,12 +35,11 @@ public class Utils {
* logger * logger
*/ */
private static final Logger logger = LoggerFactory.getLogger(Utils.class); private static final Logger logger = LoggerFactory.getLogger(Utils.class);
/** /**
* Hashtag regex enhanced for ticket #4937 * Hashtag regex enhanced for ticket #4937
* If you want to accept hashtags of type #X, then you will need to use ^#\\w*[.]?\\w+|\\s#\\w*[.]?\\w+
*/ */
private static final String HASHTAG_REGEX = "^#\\w+[.]?\\w+|\\s#\\w+[.]?\\w+"; private static final String HASHTAG_REGEX = "^#\\w+([.]?\\w+)*|\\s#\\w+([.]?\\w+)*";
/** /**
* *
@ -253,8 +252,8 @@ public class Utils {
} }
return null; return null;
} }
/** /**
* convert the mentioned people in HTML anchor and also Encode the params Base64 * convert the mentioned people in HTML anchor and also Encode the params Base64
* @param escapedFeedText * @param escapedFeedText
* @param taggedPeople * @param taggedPeople
@ -264,7 +263,7 @@ public class Utils {
String pageToRedirectURL = ""; String pageToRedirectURL = "";
String httpGETAttrName = ""; String httpGETAttrName = "";
String httpGETAttrValue =""; String httpGETAttrValue ="";
for (ItemBean tagged : taggedPeople) { for (ItemBean tagged : taggedPeople) {
if (! tagged.isItemGroup()) { if (! tagged.isItemGroup()) {
pageToRedirectURL = PortalContext.getConfiguration().getSiteLandingPagePath(request)+GCubePortalConstants.USER_PROFILE_FRIENDLY_URL; pageToRedirectURL = PortalContext.getConfiguration().getSiteLandingPagePath(request)+GCubePortalConstants.USER_PROFILE_FRIENDLY_URL;

View File

@ -8,7 +8,7 @@ public class TestUnit {
//@Test //@Test
public void testHashtag() { public void testHashtag() {
String text = "This is a test with hashtag #T6 and #T6.1 but also #T6. that has '.' that is useless and #T43..43 ."; String text = "This is a test with hashtag #T6 and #T6.1 but also #T6. that has '.' that is useless and #T43.43 and #gcube4.1.0gcore #gcube4.1.0";
List<String> hashtags = Utils.getHashTags(text); List<String> hashtags = Utils.getHashTags(text);
System.out.println("Hashtags are " + hashtags); System.out.println("Hashtags are " + hashtags);
} }