2019-01-22 18:22:17 +01:00
|
|
|
package org.gcube.socialnetworking.token;
|
|
|
|
|
2019-01-23 14:58:59 +01:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
import org.apache.commons.codec.binary.Base64;
|
|
|
|
|
2019-01-22 18:22:17 +01:00
|
|
|
public class ReplaceableToken extends Token {
|
|
|
|
|
|
|
|
protected String tokenReplacement;
|
|
|
|
|
2019-01-23 15:51:28 +01:00
|
|
|
public static String createHref(String baseURL, String attributeName, String attributeValue) {
|
2019-01-23 14:58:59 +01:00
|
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
|
|
stringBuilder.append(baseURL);
|
|
|
|
stringBuilder.append("?");
|
|
|
|
stringBuilder.append(new String(Base64.encodeBase64(attributeName.getBytes())));
|
|
|
|
stringBuilder.append("=");
|
|
|
|
stringBuilder.append(new String(Base64.encodeBase64(attributeValue.getBytes())));
|
|
|
|
return stringBuilder.toString();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-01-23 15:51:28 +01:00
|
|
|
public static String createLink(String linkTarget, String linkValue, Map<String, String> additionalAttributes) {
|
2019-01-23 14:58:59 +01:00
|
|
|
Map<String, String> attributes = new HashMap<>();
|
|
|
|
if(additionalAttributes!=null) {
|
|
|
|
attributes.putAll(additionalAttributes);
|
|
|
|
}
|
|
|
|
attributes.put("class", "link");
|
|
|
|
if(!attributes.containsKey("style")) {
|
|
|
|
attributes.put("style", "font-size:14px;");
|
|
|
|
}
|
|
|
|
attributes.put("href", linkTarget);
|
|
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
|
|
stringBuilder.append("<a ");
|
|
|
|
for(String key : attributes.keySet()) {
|
|
|
|
stringBuilder.append(key);
|
|
|
|
stringBuilder.append("=\"");
|
|
|
|
stringBuilder.append(attributes.get(key));
|
|
|
|
stringBuilder.append("\" ");
|
|
|
|
}
|
|
|
|
stringBuilder.append(">");
|
|
|
|
stringBuilder.append(linkValue);
|
|
|
|
stringBuilder.append("</a>");
|
|
|
|
return stringBuilder.toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-01-22 18:22:17 +01:00
|
|
|
public ReplaceableToken(Token token) {
|
|
|
|
super(token.token, token.delimiter, token.start, token.end);
|
|
|
|
this.tokenReplacement = token.token;
|
|
|
|
}
|
|
|
|
|
|
|
|
public ReplaceableToken(Token token, String tokenReplacement) {
|
|
|
|
super(token.token, token.delimiter, token.start, token.end);
|
|
|
|
this.tokenReplacement = tokenReplacement;
|
|
|
|
}
|
|
|
|
|
2019-01-23 14:58:59 +01:00
|
|
|
@Override
|
|
|
|
public String getDelimiter() {
|
|
|
|
return delimiter.replaceAll("(\r\n|\n)","<br/>");
|
|
|
|
}
|
|
|
|
|
2019-01-22 18:22:17 +01:00
|
|
|
public String getTokenReplacement() {
|
|
|
|
return tokenReplacement;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|