From 3e4807157e3c244820dd4d5149997970530e4fcb Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 23 Aug 2017 00:47:37 +0300 Subject: www: Twitter Cards --- .../src/main/java/com/juick/util/MessageUtils.java | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'juick-core/src/main/java/com/juick/util') diff --git a/juick-core/src/main/java/com/juick/util/MessageUtils.java b/juick-core/src/main/java/com/juick/util/MessageUtils.java index a901fac1..03b677d4 100644 --- a/juick-core/src/main/java/com/juick/util/MessageUtils.java +++ b/juick-core/src/main/java/com/juick/util/MessageUtils.java @@ -17,8 +17,13 @@ package com.juick.util; +import com.juick.Message; +import com.juick.Tag; +import org.apache.commons.codec.CharEncoding; import org.apache.commons.lang3.StringUtils; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -137,4 +142,22 @@ public class MessageUtils { msg = msg.replaceAll("\n", "
\n"); return msg; } + + public static String getMessageHashTags(final Message jmsg) { + StringBuilder hashtags = new StringBuilder(); + for (Tag tag : jmsg.getTags()) { + hashtags.append("#").append(tag).append(" "); + } + return hashtags.toString(); + } + + // TODO: check if it is really needed + public static String percentEncode(final String s) { + String ret = StringUtils.EMPTY; + try { + ret = URLEncoder.encode(s, CharEncoding.UTF_8).replace("+", "%20").replace("*", "%2A").replace("%7E", "~"); + } catch (UnsupportedEncodingException e) { + } + return ret; + } } -- cgit v1.2.3