2019-01-24 11:47:03 +01:00
|
|
|
package org.gcube.socialnetworking.socialtoken;
|
2019-01-22 18:22:17 +01:00
|
|
|
|
2019-01-23 14:58:59 +01:00
|
|
|
import org.gcube.portal.databook.client.GCubeSocialNetworking;
|
2019-01-24 11:50:00 +01:00
|
|
|
import org.gcube.socialnetworking.tokenization.Token;
|
2019-01-23 14:58:59 +01:00
|
|
|
|
2019-01-25 15:28:07 +01:00
|
|
|
public class HashTagToken extends ReplaceableToken {
|
2019-01-22 18:22:17 +01:00
|
|
|
|
2019-01-25 15:28:07 +01:00
|
|
|
protected SanitizedHashTag sanitizedTag;
|
2019-01-25 15:27:32 +01:00
|
|
|
|
2019-01-25 15:28:07 +01:00
|
|
|
public HashTagToken(String token, String delimiter, int start, int end) {
|
2019-01-23 18:01:42 +01:00
|
|
|
super(token, delimiter, start, end);
|
|
|
|
}
|
|
|
|
|
2019-01-25 15:28:07 +01:00
|
|
|
public HashTagToken(Token token) {
|
2019-01-23 14:58:59 +01:00
|
|
|
super(token);
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getTokenReplacement() {
|
|
|
|
if(!replaced) {
|
2019-01-25 15:27:32 +01:00
|
|
|
try {
|
|
|
|
String tag = getTag();
|
|
|
|
String linkTarget = ReplaceableToken.createHref("", GCubeSocialNetworking.HASHTAG_OID, tag);
|
|
|
|
tokenReplacement = ReplaceableToken.createLink(linkTarget, tag, null) + sanitizedTag.getPostfix();
|
|
|
|
} catch(Exception e) {
|
|
|
|
tokenReplacement = token;
|
|
|
|
}
|
|
|
|
|
2019-01-23 14:58:59 +01:00
|
|
|
replaced = true;
|
|
|
|
}
|
2019-01-23 17:05:15 +01:00
|
|
|
return tokenReplacement;
|
2019-01-22 18:22:17 +01:00
|
|
|
}
|
|
|
|
|
2019-01-25 15:27:32 +01:00
|
|
|
public String getTag() throws Exception {
|
|
|
|
if(sanitizedTag==null) {
|
2019-01-25 15:28:07 +01:00
|
|
|
sanitizedTag = new SanitizedHashTag(token);
|
2019-01-25 15:27:32 +01:00
|
|
|
}
|
|
|
|
return sanitizedTag.getTag();
|
|
|
|
}
|
|
|
|
|
2019-01-22 18:22:17 +01:00
|
|
|
}
|